Browse Source

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.
mission-4.1.18
Jeremy Feltracco 6 years ago committed by Lucas De Marchi
parent
commit
100f06614c
  1. 3
      libraries/AP_HAL_Linux/SerialDevice.h
  2. 20
      libraries/AP_HAL_Linux/UARTDevice.cpp
  3. 1
      libraries/AP_HAL_Linux/UARTDevice.h
  4. 4
      libraries/AP_HAL_Linux/UARTDriver.cpp
  5. 2
      libraries/AP_HAL_Linux/UARTDriver.h

3
libraries/AP_HAL_Linux/SerialDevice.h

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

20
libraries/AP_HAL_Linux/UARTDevice.cpp

@ -130,3 +130,23 @@ void UARTDevice::set_flow_control(AP_HAL::UARTDriver::flow_control flow_control_
_flow_control = flow_control_setting; _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);
}

1
libraries/AP_HAL_Linux/UARTDevice.h

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

4
libraries/AP_HAL_Linux/UARTDriver.cpp

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

2
libraries/AP_HAL_Linux/UARTDriver.h

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

Loading…
Cancel
Save