Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mavlink_shell: set target system and component id #19815

Merged
merged 1 commit into from Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/modules/mavlink/mavlink_main.cpp
Expand Up @@ -2427,6 +2427,8 @@ Mavlink::task_main(int argc, char *argv[])
msg.timeout = 0;
msg.device = SERIAL_CONTROL_DEV_SHELL;
msg.count = _mavlink_shell->read(msg.data, sizeof(msg.data));
msg.target_system = _mavlink_shell->targetSysid();
msg.target_component = _mavlink_shell->targetCompid();
mavlink_msg_serial_control_send_struct(get_channel(), &msg);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/mavlink/mavlink_receiver.cpp
Expand Up @@ -1778,6 +1778,7 @@ MavlinkReceiver::handle_message_serial_control(mavlink_message_t *msg)
if (shell) {
// we ignore the timeout, EXCLUSIVE & BLOCKING flags of the SERIAL_CONTROL message
if (serial_control_mavlink.count > 0) {
shell->setTargetID(msg->sysid, msg->compid);
shell->write(serial_control_mavlink.data, serial_control_mavlink.count);
}

Expand Down
8 changes: 8 additions & 0 deletions src/modules/mavlink/mavlink_shell.h
Expand Up @@ -42,6 +42,7 @@
#include <stddef.h>
#include <stdint.h>
#include <px4_platform_common/tasks.h>
#include <px4_platform_common/atomic.h>

#pragma once

Expand Down Expand Up @@ -77,8 +78,15 @@ class MavlinkShell
*/
size_t available();

void setTargetID(uint8_t sysid, uint8_t compid) { _target_sysid.store(sysid); _target_compid.store(compid); }

uint8_t targetSysid() const { return _target_sysid.load(); }
uint8_t targetCompid() const { return _target_compid.load(); }
private:

px4::atomic<uint8_t> _target_sysid{};
px4::atomic<uint8_t> _target_compid{};

int _to_shell_fd = -1; /** fd to write to the shell */
int _from_shell_fd = -1; /** fd to read from the shell */
int _shell_fds[2] = { -1, -1}; /** stdin & out used by the shell */
Expand Down