SITL: Make the same process into a method

This commit is contained in:
murata 2022-09-28 22:52:51 +09:00 committed by Peter Barker
parent 05a638a639
commit 272e719a14
2 changed files with 18 additions and 2 deletions

View File

@ -64,7 +64,7 @@ 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
{
if (device_baud() != 0 && autopilot_baud != 0 && device_baud() != autopilot_baud) {
if (!is_match_baud()) {
return -1;
}
@ -83,7 +83,7 @@ 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
{
if (device_baud() != 0 && autopilot_baud != 0 && device_baud() != autopilot_baud) {
if (!is_match_baud()) {
return -1;
}
@ -95,3 +95,17 @@ ssize_t SerialDevice::write_to_device(const char *buffer, const size_t size) con
const ssize_t ret = from_autopilot->write((uint8_t*)buffer, size);
return ret;
}
/**
* baudrates match
*
* @retval true matched baudreate
* @retval false unmatched baudreate
*/
bool SerialDevice::is_match_baud() const
{
if (device_baud() != 0 && autopilot_baud != 0 && device_baud() != autopilot_baud) {
return false;
}
return true;
}

View File

@ -50,6 +50,8 @@ protected:
private:
bool is_match_baud(void) const;
uint32_t autopilot_baud;
};