Skip to content

Commit

Permalink
mavlink: added check if instance mode is serial when trying to find i…
Browse files Browse the repository at this point in the history
…f instance exists (PX4#12642)
  • Loading branch information
garfieldG authored and bozkurthan committed Sep 4, 2019
1 parent 2c3aa87 commit 54d6896
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/modules/mavlink/mavlink_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,14 @@ Mavlink::get_status_all_instances(bool show_streams_status)
}

bool
Mavlink::instance_exists(const char *device_name, Mavlink *self)
Mavlink::serial_instance_exists(const char *device_name, Mavlink *self)
{
Mavlink *inst = ::_mavlink_instances;

while (inst != nullptr) {

/* don't compare with itself */
if (inst != self && !strcmp(device_name, inst->_device_name)) {
/* don't compare with itself and with non serial instances*/
if ((inst != self) && (inst->get_protocol() == SERIAL) && !strcmp(device_name, inst->_device_name)) {
return true;
}

Expand Down Expand Up @@ -2074,7 +2074,7 @@ Mavlink::task_main(int argc, char *argv[])
}

if (get_protocol() == SERIAL) {
if (Mavlink::instance_exists(_device_name, this)) {
if (Mavlink::serial_instance_exists(_device_name, this)) {
PX4_ERR("%s already running", _device_name);
return PX4_ERROR;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/mavlink/mavlink_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class Mavlink : public ModuleParams

static int get_status_all_instances(bool show_streams_status);

static bool instance_exists(const char *device_name, Mavlink *self);
static bool serial_instance_exists(const char *device_name, Mavlink *self);

static void forward_message(const mavlink_message_t *msg, Mavlink *self);

Expand Down

0 comments on commit 54d6896

Please sign in to comment.