mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-02 11:21:36 +08:00
[serial] Fix byte size, flow control, parity, stop bits configuration
This commit is contained in:
committed by
Jacob Dahl
parent
25138d0a12
commit
17f3db9231
@@ -103,25 +103,14 @@ bool SerialImpl::open()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_bytesize != ByteSize::EightBits) {
|
||||
PX4_ERR("Qurt platform only supports ByteSize::EightBits");
|
||||
return false;
|
||||
}
|
||||
// Check all non-supported configurations without duplicating the error strings
|
||||
if (!setBytesize(_bytesize)) { return false; }
|
||||
|
||||
if (_parity != Parity::None) {
|
||||
PX4_ERR("Qurt platform only supports Parity::None");
|
||||
return false;
|
||||
}
|
||||
if (!setParity(_parity)) { return false; }
|
||||
|
||||
if (_stopbits != StopBits::One) {
|
||||
PX4_ERR("Qurt platform only supports StopBits::One");
|
||||
return false;
|
||||
}
|
||||
if (!setStopbits(_stopbits)) { return false; }
|
||||
|
||||
if (_flowcontrol != FlowControl::Disabled) {
|
||||
PX4_ERR("Qurt platform only supports FlowControl::Disabled");
|
||||
return false;
|
||||
}
|
||||
if (!setFlowcontrol(_flowcontrol)) { return false; }
|
||||
|
||||
if (!validatePort(_port)) {
|
||||
PX4_ERR("Invalid port %s", _port);
|
||||
@@ -348,7 +337,12 @@ ByteSize SerialImpl::getBytesize() const
|
||||
|
||||
bool SerialImpl::setBytesize(ByteSize bytesize)
|
||||
{
|
||||
return bytesize == ByteSize::EightBits;
|
||||
if (bytesize != ByteSize::EightBits) {
|
||||
PX4_ERR("Qurt platform only supports ByteSize::EightBits");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Parity SerialImpl::getParity() const
|
||||
@@ -358,7 +352,12 @@ Parity SerialImpl::getParity() const
|
||||
|
||||
bool SerialImpl::setParity(Parity parity)
|
||||
{
|
||||
return parity == Parity::None;
|
||||
if (parity != Parity::None) {
|
||||
PX4_ERR("Qurt platform only supports Parity::None");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
StopBits SerialImpl::getStopbits() const
|
||||
@@ -368,7 +367,12 @@ StopBits SerialImpl::getStopbits() const
|
||||
|
||||
bool SerialImpl::setStopbits(StopBits stopbits)
|
||||
{
|
||||
return stopbits == StopBits::One;
|
||||
if (stopbits != StopBits::One) {
|
||||
PX4_ERR("Qurt platform only supports StopBits::One");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
FlowControl SerialImpl::getFlowcontrol() const
|
||||
@@ -378,7 +382,12 @@ FlowControl SerialImpl::getFlowcontrol() const
|
||||
|
||||
bool SerialImpl::setFlowcontrol(FlowControl flowcontrol)
|
||||
{
|
||||
return flowcontrol == FlowControl::Disabled;
|
||||
if (flowcontrol != FlowControl::Disabled) {
|
||||
PX4_ERR("Qurt platform only supports FlowControl::Disabled");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SerialImpl::getSingleWireMode() const
|
||||
@@ -388,8 +397,12 @@ bool SerialImpl::getSingleWireMode() const
|
||||
|
||||
bool SerialImpl::setSingleWireMode()
|
||||
{
|
||||
// Qurt platform does not support single wire mode
|
||||
return false;
|
||||
if (enable) {
|
||||
PX4_ERR("Qurt platform does not support single wire mode");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SerialImpl::getSwapRxTxMode() const
|
||||
@@ -399,14 +412,22 @@ bool SerialImpl::getSwapRxTxMode() const
|
||||
|
||||
bool SerialImpl::setSwapRxTxMode()
|
||||
{
|
||||
// Qurt platform does not support swap rx tx mode
|
||||
return false;
|
||||
if (enable) {
|
||||
PX4_ERR("Qurt platform does not support swap rx tx mode");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SerialImpl::setInvertedMode(bool enable)
|
||||
{
|
||||
// Qurt platform does not support inverted mode
|
||||
return false == enable;
|
||||
if (enable) {
|
||||
PX4_ERR("Qurt platform does not support inverted mode");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
bool SerialImpl::getInvertedMode() const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user