-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
core: add mavlink statustexts as debug printfs #119
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,10 @@ DeviceImpl::DeviceImpl(DroneCoreImpl *parent, | |
register_mavlink_message_handler( | ||
MAVLINK_MSG_ID_AUTOPILOT_VERSION, | ||
std::bind(&DeviceImpl::process_autopilot_version, this, _1), this); | ||
|
||
register_mavlink_message_handler( | ||
MAVLINK_MSG_ID_STATUSTEXT, | ||
std::bind(&DeviceImpl::process_statustext, this, _1), this); | ||
} | ||
|
||
DeviceImpl::~DeviceImpl() | ||
|
@@ -155,6 +159,50 @@ void DeviceImpl::process_autopilot_version(const mavlink_message_t &message) | |
unregister_timeout_handler(_autopilot_version_timed_out_cookie); | ||
} | ||
|
||
void DeviceImpl::process_statustext(const mavlink_message_t &message) | ||
{ | ||
mavlink_statustext_t statustext; | ||
mavlink_msg_statustext_decode(&message, &statustext); | ||
|
||
std::string debug_str = "mavlink "; | ||
|
||
switch (statustext.severity) { | ||
case MAV_SEVERITY_EMERGENCY: | ||
debug_str += "emergency"; | ||
break; | ||
case MAV_SEVERITY_ALERT: | ||
debug_str += "alert"; | ||
break; | ||
case MAV_SEVERITY_CRITICAL: | ||
debug_str += "critical"; | ||
break; | ||
case MAV_SEVERITY_ERROR: | ||
debug_str += "error"; | ||
break; | ||
case MAV_SEVERITY_WARNING: | ||
debug_str += "warning"; | ||
break; | ||
case MAV_SEVERITY_NOTICE: | ||
debug_str += "notice"; | ||
break; | ||
case MAV_SEVERITY_INFO: | ||
debug_str += "info"; | ||
break; | ||
case MAV_SEVERITY_DEBUG: | ||
debug_str += "debug"; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
// statustext.text is not null terminated, therefore we copy it first to | ||
// an array big enough that is zeroed. | ||
char text_with_null[sizeof(statustext.text) + 1] {}; | ||
memcpy(text_with_null, statustext.text, sizeof(statustext.text)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dirty indeed, but I don't see any other way around this if we can't control the input, and now that I think about it, can this lead to memory leaks? can someone use this to DOS an app using DroneCore by crafting big malicious messages? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think all that a malicious drone can do here is to print a bunch of memory that follows after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In conclusion, yes we make ourselves open to a crafty mavlink attack, but I'm sure this isn't the only place where this occurs |
||
|
||
LogDebug() << debug_str << ": " << text_with_null; | ||
} | ||
|
||
void DeviceImpl::heartbeats_timed_out() | ||
{ | ||
LogInfo() << "heartbeats timed out"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this enough to differentiate device as opposed to DroneCore originated warnings? Maybe text:
MAVLink: emergency
orDevice: emergency
.Might even be worth having a special class of debug for these. Just a thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed @hamishwillee, it would be good to understand when are these called and if we should be raising exceptions or alerting the users rather than just using them for debugging.
That said this PR is to have more debugging data, so we should merge and get someone to research onto what the messages mean, I want to know if we should be taking more critical actions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hamishwillee I can change it to
MAVLink: emergency
.@mrpollo to catch errors, it might make sense that the plugins check for errors and inform the API user if it is relevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with all above - yes, ideally plugins should check for errors and work out what is relevant but we need to do more research on this. IMO we should do change suggested (MAVLink: xxxx) for now, accept PR, and raise issue to look at errors as a separate task.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, merge whenever. I have created #127 to add eventual task to look at these messages.