mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-23 16:23:56 -04:00
SITL: SITL SerialDevice optionally checks baudrates match
This commit is contained in:
parent
0d5d9c04f0
commit
0717c3409b
@ -18,6 +18,7 @@
|
|||||||
./Tools/autotest/sim_vehicle.py --gdb --debug -v ArduCopter -A --uartF=sim:nmea --speedup=1
|
./Tools/autotest/sim_vehicle.py --gdb --debug -v ArduCopter -A --uartF=sim:nmea --speedup=1
|
||||||
|
|
||||||
param set SERIAL5_PROTOCOL 9
|
param set SERIAL5_PROTOCOL 9
|
||||||
|
param set SERIAL5_BAUD 9600
|
||||||
param set RNGFND1_TYPE 17
|
param set RNGFND1_TYPE 17
|
||||||
graph RANGEFINDER.distance
|
graph RANGEFINDER.distance
|
||||||
graph GLOBAL_POSITION_INT.relative_alt/1000-RANGEFINDER.distance
|
graph GLOBAL_POSITION_INT.relative_alt/1000-RANGEFINDER.distance
|
||||||
@ -36,6 +37,8 @@ namespace SITL {
|
|||||||
class RF_NMEA : public SerialRangeFinder {
|
class RF_NMEA : public SerialRangeFinder {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
uint32_t device_baud() const override { return 9600; }
|
||||||
|
|
||||||
uint32_t packet_for_alt(uint16_t alt_cm, uint8_t *buffer, uint8_t buflen) override;
|
uint32_t packet_for_alt(uint16_t alt_cm, uint8_t *buffer, uint8_t buflen) override;
|
||||||
|
|
||||||
bool has_temperature() const override { return true; }
|
bool has_temperature() const override { return true; }
|
||||||
|
@ -64,6 +64,10 @@ ssize_t SerialDevice::read_from_autopilot(char *buffer, const size_t size) const
|
|||||||
|
|
||||||
ssize_t SerialDevice::write_to_autopilot(const char *buffer, const size_t size) const
|
ssize_t SerialDevice::write_to_autopilot(const char *buffer, const size_t size) const
|
||||||
{
|
{
|
||||||
|
if (device_baud() != 0 && autopilot_baud != 0 && device_baud() != autopilot_baud) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
const ssize_t ret = to_autopilot->write((uint8_t*)buffer, size);
|
const ssize_t ret = to_autopilot->write((uint8_t*)buffer, size);
|
||||||
// ::fprintf(stderr, "write to autopilot: (");
|
// ::fprintf(stderr, "write to autopilot: (");
|
||||||
// for (ssize_t i=0; i<ret; i++) {
|
// for (ssize_t i=0; i<ret; i++) {
|
||||||
@ -79,6 +83,10 @@ ssize_t SerialDevice::write_to_autopilot(const char *buffer, const size_t size)
|
|||||||
|
|
||||||
ssize_t SerialDevice::read_from_device(char *buffer, const size_t size) const
|
ssize_t SerialDevice::read_from_device(char *buffer, const size_t size) const
|
||||||
{
|
{
|
||||||
|
if (device_baud() != 0 && autopilot_baud != 0 && device_baud() != autopilot_baud) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
const ssize_t ret = to_autopilot->read((uint8_t*)buffer, size);
|
const ssize_t ret = to_autopilot->read((uint8_t*)buffer, size);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,12 @@ public:
|
|||||||
// methods for autopilot to use to talk to device:
|
// methods for autopilot to use to talk to device:
|
||||||
ssize_t read_from_device(char *buffer, size_t size) const;
|
ssize_t read_from_device(char *buffer, size_t size) const;
|
||||||
ssize_t write_to_device(const char *buffer, size_t size) const;
|
ssize_t write_to_device(const char *buffer, size_t size) const;
|
||||||
|
void set_autopilot_baud(uint32_t baud) { autopilot_baud = baud; }
|
||||||
|
|
||||||
// methods for simulated device to use:
|
// methods for simulated device to use:
|
||||||
ssize_t read_from_autopilot(char *buffer, size_t size) const;
|
ssize_t read_from_autopilot(char *buffer, size_t size) const;
|
||||||
virtual ssize_t write_to_autopilot(const char *buffer, size_t size) const;
|
virtual ssize_t write_to_autopilot(const char *buffer, size_t size) const;
|
||||||
|
virtual uint32_t device_baud() const { return 0; } // 0 meaning unset
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -45,6 +47,10 @@ protected:
|
|||||||
ByteBuffer *from_autopilot;
|
ByteBuffer *from_autopilot;
|
||||||
|
|
||||||
bool init_sitl_pointer();
|
bool init_sitl_pointer();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
uint32_t autopilot_baud;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user