mavlink: allow resetting mavlink streams to default via MAV_CMD_SET_MESSAGE_INTERVAL

This implementation does not need more resources.
It's not super efficient in terms of runtime, but it's also not something
that is called often.
This commit is contained in:
Beat Küng
2018-06-25 12:19:56 +02:00
committed by Lorenz Meier
parent 333fd9cf45
commit 84841236cb
3 changed files with 226 additions and 162 deletions
+6 -8
View File
@@ -1844,7 +1844,7 @@ MavlinkReceiver::handle_message_heartbeat(mavlink_message_t *msg)
int
MavlinkReceiver::set_message_interval(int msgId, float interval, int data_rate)
{
if (msgId == 0) {
if (msgId == MAVLINK_MSG_ID_HEARTBEAT) {
return PX4_ERROR;
}
@@ -1853,18 +1853,16 @@ MavlinkReceiver::set_message_interval(int msgId, float interval, int data_rate)
}
// configure_stream wants a rate (msgs/second), so convert here.
float rate = 0;
float rate = 0.f;
if (interval < 0) {
// stop the stream.
rate = 0;
if (interval < -0.00001f) {
rate = 0.f; // stop the stream
} else if (interval > 0) {
} else if (interval > 0.00001f) {
rate = 1000000.0f / interval;
} else {
// note: mavlink spec says rate == 0 is requesting a default rate but our streams
// don't publish a default rate so for now let's pick a default rate of zero.
rate = -2.f; // set default rate
}
bool found_id = false;