AP_SerialManager: add device ID getter

This commit is contained in:
Iampete1
2026-08-27 10:59:59 +10:00
committed by Peter Barker
parent c2a49d2d03
commit aca2000bbb
2 changed files with 66 additions and 0 deletions
@@ -908,6 +908,60 @@ void AP_SerialManager::registered_ports_log()
#endif // AP_SERIALMANAGER_REGISTER_ENABLED
// Return a device id for this port
uint32_t AP_SerialManager::UARTState::get_device_id() const
{
#if AP_SERIALMANAGER_REGISTER_ENABLED
if (idx >= AP_SERIALMANAGER_SCR_PORT_1) {
// Scripting port
return AP_HAL::Device::make_bus_id(
AP_HAL::Device::BUS_TYPE_SERIAL,
0,
idx - AP_SERIALMANAGER_SCR_PORT_1,
uint8_t(DeviceType::SCRIPTING)
);
}
if (idx >= AP_SERIALMANAGER_CAN_D2_PORT_1) {
// CAN D2 port
return AP_HAL::Device::make_bus_id(
AP_HAL::Device::BUS_TYPE_SERIAL,
1,
idx - AP_SERIALMANAGER_CAN_D2_PORT_1,
uint8_t(DeviceType::CANBUS)
);
}
if (idx >= AP_SERIALMANAGER_CAN_D1_PORT_1) {
// CAN D1 port
return AP_HAL::Device::make_bus_id(
AP_HAL::Device::BUS_TYPE_SERIAL,
0,
idx - AP_SERIALMANAGER_CAN_D1_PORT_1,
uint8_t(DeviceType::CANBUS)
);
}
if (idx >= AP_SERIALMANAGER_NET_PORT_1) {
// Networking port
return AP_HAL::Device::make_bus_id(
AP_HAL::Device::BUS_TYPE_SERIAL,
0,
idx - AP_SERIALMANAGER_NET_PORT_1,
uint8_t(DeviceType::NETWORKING)
);
}
#endif // AP_SERIALMANAGER_REGISTER_ENABLED
// Standard port
return AP_HAL::Device::make_bus_id(
AP_HAL::Device::BUS_TYPE_SERIAL,
0,
idx,
uint8_t(DeviceType::UART)
);
}
namespace AP {
AP_SerialManager &serialmanager()
@@ -229,6 +229,18 @@ public:
#if HAL_LOGGING_ENABLED && HAL_UART_STATS_ENABLED
AP_HAL::UARTDriver::StatsTracker stats;
#endif
// Enum for device type used in get_device_id
enum class DeviceType {
UNKNOWN,
UART,
NETWORKING,
CANBUS,
SCRIPTING,
};
// Return a device id for this port
uint32_t get_device_id() const;
};
// get a state from serial index