AP_HAL_Linux: Add support for setting uart parity on Linux boards

Pass set_parity down through UART class so that set_parity actually
works for Linux boards.
This commit is contained in:
Jeremy Feltracco 2019-04-11 10:26:35 -04:00 committed by Lucas De Marchi
parent 5e683261a4
commit 100f06614c
5 changed files with 30 additions and 0 deletions

View File

@ -20,4 +20,7 @@ public:
{
/* most devices simply ignore this setting */
};
/* Depends on lower level to implement, most devices are fine with defaults */
virtual void set_parity(int v) { }
};

View File

@ -130,3 +130,23 @@ void UARTDevice::set_flow_control(AP_HAL::UARTDriver::flow_control flow_control_
_flow_control = flow_control_setting;
}
void UARTDevice::set_parity(int v)
{
struct termios t;
tcgetattr(_fd, &t);
if (v != 0) {
// enable parity
t.c_cflag |= PARENB;
if (v == 1) {
t.c_cflag |= PARODD;
} else {
t.c_cflag &= ~PARODD;
}
}
else {
// disable parity
t.c_cflag &= ~PARENB;
}
tcsetattr(_fd, TCSANOW, &t);
}

View File

@ -19,6 +19,7 @@ public:
{
return _flow_control;
}
virtual void set_parity(int v) override;
private:
void _disable_crlf();

View File

@ -457,6 +457,10 @@ void UARTDriver::_timer_tick(void)
_in_timer = false;
}
void UARTDriver::configure_parity(uint8_t v) {
_device->set_parity(v);
}
/*
return timestamp estimate in microseconds for when the start of
a nbytes packet arrived on the uart. This should be treated as a

View File

@ -45,6 +45,8 @@ public:
return _device->get_flow_control();
}
virtual void configure_parity(uint8_t v);
virtual void set_flow_control(enum flow_control flow_control_setting) override
{
_device->set_flow_control(flow_control_setting);