Skip to content

Commit

Permalink
Merge pull request #2407 from mavlink/pr-v2.12-system-debugging
Browse files Browse the repository at this point in the history
[v2.12 BACKPORT] Add some system debugging
  • Loading branch information
julianoes authored Sep 26, 2024
2 parents 27a1077 + 74f1f73 commit 0a825ac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/mavsdk/core/mavlink_command_receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void MavlinkCommandReceiver::receive_command_int(const mavlink_message_t& messag
cmd.target_component_id != MAV_COMP_ID_ALL) {
if (_debugging) {
LogDebug() << "Ignored command int to component " << (int)cmd.target_component_id
<< " instead of " << _server_component_impl.get_own_component_id();
<< " instead of " << (int)_server_component_impl.get_own_component_id();
}
return;
}
Expand Down Expand Up @@ -96,7 +96,7 @@ void MavlinkCommandReceiver::receive_command_long(const mavlink_message_t& messa
cmd.target_component_id != MAV_COMP_ID_ALL) {
if (_debugging) {
LogDebug() << "Ignored command long to component " << (int)cmd.target_component_id
<< " instead of " << _server_component_impl.get_own_component_id();
<< " instead of " << (int)_server_component_impl.get_own_component_id();
}
return;
}
Expand Down
17 changes: 17 additions & 0 deletions src/mavsdk/core/mavsdk_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ MavsdkImpl::MavsdkImpl(const Mavsdk::Configuration& configuration) :
}
}

if (const char* env_p = std::getenv("MAVSDK_SYSTEM_DEBUGGING")) {
if (std::string(env_p) == "1") {
LogDebug() << "System debugging is on.";
_system_debugging = true;
}
}

set_configuration(configuration);

_work_thread = new std::thread(&MavsdkImpl::work_thread, this);
Expand Down Expand Up @@ -389,6 +396,16 @@ void MavsdkImpl::receive_message(mavlink_message_t& message, Connection* connect
}

if (!found_system) {
if (_system_debugging) {
LogWarn() << "Create new system/component " << (int)message.sysid << "/"
<< (int)message.compid;
LogWarn() << "From message " << (int)message.msgid << " with len " << (int)message.len;
std::string bytes = "";
for (unsigned i = 0; i < 12 + message.len; ++i) {
bytes += std::to_string(reinterpret_cast<uint8_t*>(&message)[i]) + ' ';
}
LogWarn() << "Bytes: " << bytes;
}
make_system_with_component(message.sysid, message.compid);
}

Expand Down
1 change: 1 addition & 0 deletions src/mavsdk/core/mavsdk_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class MavsdkImpl {

bool _message_logging_on{false};
bool _callback_debugging{false};
bool _system_debugging{false};

mutable std::mutex _intercept_callback_mutex{};
std::function<bool(mavlink_message_t&)> _intercept_incoming_messages_callback{nullptr};
Expand Down

0 comments on commit 0a825ac

Please sign in to comment.