Skip to content

Commit 7cbd8e5

Browse files
authored
Merge pull request #2748 from mavlink/pr-log-annoyance
Clean up debug messages on discovery a bit
2 parents 5a8f934 + 70997e6 commit 7cbd8e5

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

src/mavsdk/core/mavsdk_impl.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,9 +1075,6 @@ void MavsdkImpl::make_system_with_component(uint8_t system_id, uint8_t comp_id)
10751075

10761076
if (static_cast<int>(system_id) == 0 && static_cast<int>(comp_id) == 0) {
10771077
LogDebug() << "Initializing connection to remote system...";
1078-
} else {
1079-
LogDebug() << "New system ID: " << static_cast<int>(system_id)
1080-
<< " Comp ID: " << static_cast<int>(comp_id);
10811078
}
10821079

10831080
// Make a system with its first component

src/mavsdk/core/system_impl.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,14 @@ void SystemImpl::process_heartbeat(const mavlink_message_t& message)
324324
LogErr() << "type received in HEARTBEAT was not recognized";
325325
} else {
326326
const auto new_vehicle_type = static_cast<MAV_TYPE>(heartbeat.type);
327-
if (heartbeat.autopilot != MAV_AUTOPILOT_INVALID && _vehicle_type != new_vehicle_type &&
328-
new_vehicle_type != MAV_TYPE_GENERIC) {
329-
LogWarn() << "Vehicle type changed (new type: " << static_cast<unsigned>(heartbeat.type)
330-
<< ", old type: " << static_cast<unsigned>(_vehicle_type) << ")";
327+
if (heartbeat.autopilot != MAV_AUTOPILOT_INVALID && new_vehicle_type != MAV_TYPE_GENERIC) {
328+
if (_vehicle_type_set && _vehicle_type != new_vehicle_type) {
329+
LogWarn() << "Vehicle type changed (new type: "
330+
<< static_cast<unsigned>(heartbeat.type)
331+
<< ", old type: " << static_cast<unsigned>(_vehicle_type) << ")";
332+
}
331333
_vehicle_type = new_vehicle_type;
334+
_vehicle_type_set = true;
332335
}
333336
}
334337

@@ -490,8 +493,8 @@ void SystemImpl::add_new_component(uint8_t component_id)
490493
component_type(component_id), component_id, [this](const auto& func) {
491494
call_user_callback(func);
492495
});
493-
LogDebug() << "Component " << component_name(component_id) << " (" << int(component_id)
494-
<< ") added.";
496+
LogDebug() << "Component " << component_name(component_id)
497+
<< " (component ID: " << int(component_id) << ") added.";
495498
}
496499
}
497500

@@ -610,7 +613,8 @@ void SystemImpl::set_connected()
610613
{
611614
std::lock_guard<std::mutex> lock(_components_mutex);
612615
if (!_components.empty()) {
613-
LogDebug() << "Discovered " << _components.size() << " component(s)";
616+
LogDebug() << "Discovered " << _components.size()
617+
<< (_components.size() == 1 ? " component" : " components");
614618
}
615619
}
616620

src/mavsdk/core/system_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ class SystemImpl {
437437
std::unordered_map<const void*, ParamChangedCallback> _param_changed_callbacks{};
438438

439439
MAV_TYPE _vehicle_type{MAV_TYPE::MAV_TYPE_GENERIC};
440+
bool _vehicle_type_set{false};
440441

441442
std::atomic<FlightMode> _flight_mode{FlightMode::Unknown};
442443

src/mavsdk/core/udp_connection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void UdpConnection::add_remote_impl(
261261
// by MAVSDK. As such, it should not be advertised as a newly discovered system.
262262
if (static_cast<int>(remote_sysid) != 0) {
263263
LogInfo() << "New system on: " << new_remote.ip << ":" << new_remote.port_number
264-
<< " (with system ID: " << static_cast<int>(remote_sysid) << ")";
264+
<< " (system ID: " << static_cast<int>(remote_sysid) << ")";
265265
}
266266
_remotes.push_back(new_remote);
267267
} else {

0 commit comments

Comments
 (0)