adsb: add support for callsign

This commit is contained in:
Igor Misic
2022-12-19 12:16:26 +01:00
committed by Beat Küng
parent 678607117a
commit 52275923ad
2 changed files with 69 additions and 2 deletions
+23
View File
@@ -226,3 +226,26 @@ PARAM_DEFINE_INT32(ADSB_GPS_OFF_LAT, 0);
* @group ADSB
*/
PARAM_DEFINE_INT32(ADSB_GPS_OFF_LON, 0);
/**
* First 4 characters of CALLSIGN
*
* Sets first 4 characters of a total of 8. Valid characters are A-Z, 0-9, " ". Example "PX4 " -> 1347957792
* For CALLSIGN shorter than 8 characters use the null terminator at the end '\0'.
*
* @reboot_required true
* @group ADSB
*/
PARAM_DEFINE_INT32(ADSB_CALLSIGN_1, 0);
/**
* Second 4 characters of CALLSIGN
*
* Sets second 4 characters of a total of 8. Valid characters are A-Z, 0-9, " " only. Example "TEST" -> 1413829460
* For CALLSIGN shorter than 8 characters use the null terminator at the end '\0'.
*
* @reboot_required true
* @group ADSB
*/
PARAM_DEFINE_INT32(ADSB_CALLSIGN_2, 0);
@@ -66,6 +66,27 @@ private:
_stall_speed = static_cast<uint16_t>(fw_airspd_stall * 100.0f); // convert [m/s] to [cm/s]
}
}
int32_t callsign_part1 = _adsb_callsign_part1.get();
int32_t callsign_part2 = _adsb_callsign_part2.get();
bool success = false;
if (copy_and_check_callsign(_callsign, callsign_part1)) {
if (copy_and_check_callsign(_callsign + sizeof(int32_t), callsign_part2)) {
success = true;
}
}
if (success) {
_callsign[sizeof(_callsign) - 1] = '\0';
} else {
_callsign[0] = '\0';
events::send(events::ID("uavionix_adsb_out_cfg_unsupported_callsign_format"),
events::Log::Critical, "Unsupported callsign format");
}
}
DEFINE_PARAMETERS(
@@ -73,10 +94,32 @@ private:
(ParamInt<px4::params::ADSB_LEN_WIDTH>) _adsb_len_width,
(ParamInt<px4::params::ADSB_EMIT_TYPE>) _adsb_emit_type,
(ParamInt<px4::params::ADSB_GPS_OFF_LAT>) _adsb_gps_offset_lat,
(ParamInt<px4::params::ADSB_GPS_OFF_LON>) _adsb_gps_offset_lon
(ParamInt<px4::params::ADSB_GPS_OFF_LON>) _adsb_gps_offset_lon,
(ParamInt<px4::params::ADSB_CALLSIGN_1>) _adsb_callsign_part1,
(ParamInt<px4::params::ADSB_CALLSIGN_2>) _adsb_callsign_part2
);
uint16_t _stall_speed{0}; // [cm/s]
char _callsign[9];
bool copy_and_check_callsign(char *ptr_callsign, int32_t part)
{
for (uint8_t i = 0; i < sizeof(int32_t); ++i) {
char character = static_cast<char>(part >>(i * 8));
if ((character >= 'A' && character <= 'Z') || (character >= '0' && character <= '9') || character == ' '
|| character == '\0') {
ptr_callsign[sizeof(int32_t) - i - 1] = character;
} else {
return false;
}
}
return true;
}
bool send() override
{
@@ -92,7 +135,8 @@ private:
.rfSelect = UAVIONIX_ADSB_OUT_RF_SELECT_TX_ENABLED
};
//memcpy(cfg_msg.callsign, "PX4 UAV ", sizeof(cfg_msg.callsign)); //TODO: add support for callsign
static_assert(sizeof(cfg_msg.callsign) == sizeof(_callsign), "Size mismatch");
memcpy(cfg_msg.callsign, _callsign, sizeof(cfg_msg.callsign));
mavlink_msg_uavionix_adsb_out_cfg_send_struct(_mavlink->get_channel(), &cfg_msg);