mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-29 03:30:48 +08:00
refactor(mavlink): share the _INT frame mapping across mission and receiver
The mission manager and two receiver handlers each had their own way of treating the deprecated MAV_FRAME_*_INT frames as synonyms of the plain global frames. Use one helper, so a handler cannot check the plain frame and forget its _INT spelling. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Beniamino Pozzan <beniamino.pozzan@auterion.com>
This commit is contained in:
1 parent
721226063b
commit
84bb25a78b
3 files changed
+33
-27
No files matched your search
@@ -169,6 +169,21 @@ static inline bool int_param_is_unset(int32_t v)
|
||||
return v == INT32_MAX || v == INT32_MIN;
|
||||
}
|
||||
|
||||
// MAV_FRAME_*_INT are deprecated MAVLink synonyms of the plain global frames. They are
|
||||
// accepted on the link, but mapped to the plain frame so the rest of PX4 only sees that.
|
||||
static constexpr uint8_t frame_without_int(uint8_t frame)
|
||||
{
|
||||
switch (frame) {
|
||||
case 5: return 0; // MAV_FRAME_GLOBAL_INT -> MAV_FRAME_GLOBAL
|
||||
|
||||
case 6: return 3; // MAV_FRAME_GLOBAL_RELATIVE_ALT_INT -> MAV_FRAME_GLOBAL_RELATIVE_ALT
|
||||
|
||||
case 11: return 10; // MAV_FRAME_GLOBAL_TERRAIN_ALT_INT -> MAV_FRAME_GLOBAL_TERRAIN_ALT
|
||||
|
||||
default: return frame;
|
||||
}
|
||||
}
|
||||
|
||||
// Vehicle type bitmask for per-vehicle parameter support.
|
||||
// bit 0 = fixed-wing (FW), bit 1 = multicopter (MC), bit 2 = VTOL, bit 3 = rover.
|
||||
enum VehicleType : uint8_t {
|
||||
|
||||
@@ -1443,28 +1443,19 @@ MavlinkMissionManager::handle_mission_clear_all(const mavlink_message_t *msg)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MAV_FRAME_*_INT frames are deprecated MAVLink synonyms of the plain global frames.
|
||||
* They are accepted on the link, but only the plain frame is stored and used internally.
|
||||
*/
|
||||
static uint8_t mav_frame_without_int(uint8_t frame)
|
||||
{
|
||||
switch (frame) {
|
||||
case MAV_FRAME_GLOBAL_INT: return MAV_FRAME_GLOBAL;
|
||||
|
||||
case MAV_FRAME_GLOBAL_RELATIVE_ALT_INT: return MAV_FRAME_GLOBAL_RELATIVE_ALT;
|
||||
|
||||
case MAV_FRAME_GLOBAL_TERRAIN_ALT_INT: return MAV_FRAME_GLOBAL_TERRAIN_ALT;
|
||||
|
||||
default: return frame;
|
||||
}
|
||||
}
|
||||
// mavlink_command_params.hpp uses raw frame values to stay self-contained: check them against the MAVLink enum
|
||||
static_assert(mavlink_cmd_params::frame_without_int(MAV_FRAME_GLOBAL_INT) == MAV_FRAME_GLOBAL, "");
|
||||
static_assert(mavlink_cmd_params::frame_without_int(MAV_FRAME_GLOBAL_RELATIVE_ALT_INT) == MAV_FRAME_GLOBAL_RELATIVE_ALT,
|
||||
"");
|
||||
static_assert(mavlink_cmd_params::frame_without_int(MAV_FRAME_GLOBAL_TERRAIN_ALT_INT) == MAV_FRAME_GLOBAL_TERRAIN_ALT,
|
||||
"");
|
||||
static_assert(mavlink_cmd_params::frame_without_int(MAV_FRAME_GLOBAL) == MAV_FRAME_GLOBAL, "");
|
||||
|
||||
int
|
||||
MavlinkMissionManager::parse_mavlink_mission_item(const mavlink_mission_item_int_t *mavlink_mission_item,
|
||||
struct mission_item_s *mission_item)
|
||||
{
|
||||
const uint8_t frame = mav_frame_without_int(mavlink_mission_item->frame);
|
||||
const uint8_t frame = mavlink_cmd_params::frame_without_int(mavlink_mission_item->frame);
|
||||
|
||||
if (frame == MAV_FRAME_GLOBAL || frame == MAV_FRAME_GLOBAL_RELATIVE_ALT) {
|
||||
// This is a mission item with a global coordinate
|
||||
@@ -2000,7 +1991,7 @@ uint32_t MavlinkMissionManager::crc32_for_mission_item(const mavlink_mission_ite
|
||||
memcpy(&y_bits, &mission_item.y, sizeof(y_bits));
|
||||
|
||||
// Hash the plain frame so a mission gets the same ID whether it was uploaded with the *_INT synonyms or not
|
||||
u.item.frame = mav_frame_without_int(mission_item.frame);
|
||||
u.item.frame = mavlink_cmd_params::frame_without_int(mission_item.frame);
|
||||
u.item.command = mission_item.command;
|
||||
u.item.autocontinue = mission_item.autocontinue;
|
||||
u.item.params[0] = mission_item.param1;
|
||||
|
||||
@@ -722,11 +722,12 @@ MavlinkReceiver::handle_message_command_int(mavlink_message_t *msg)
|
||||
// current position is used (MAV_BOOL_TRUE). Other param1 values are denied by Commander.
|
||||
if (cmd_mavlink.command == MAV_CMD_DO_SET_HOME && fabsf(cmd_mavlink.param1) < FLT_EPSILON
|
||||
&& evaluate_target_ok(vcmd.command, vcmd.target_system, vcmd.target_component)) {
|
||||
if (cmd_mavlink.frame == MAV_FRAME_GLOBAL || cmd_mavlink.frame == MAV_FRAME_GLOBAL_INT) {
|
||||
const uint8_t frame = mavlink_cmd_params::frame_without_int(cmd_mavlink.frame);
|
||||
|
||||
if (frame == MAV_FRAME_GLOBAL) {
|
||||
// already AMSL
|
||||
|
||||
} else if (cmd_mavlink.frame == MAV_FRAME_GLOBAL_RELATIVE_ALT
|
||||
|| cmd_mavlink.frame == MAV_FRAME_GLOBAL_RELATIVE_ALT_INT) {
|
||||
} else if (frame == MAV_FRAME_GLOBAL_RELATIVE_ALT) {
|
||||
home_position_s home_position{};
|
||||
_home_position_sub.copy(&home_position);
|
||||
|
||||
@@ -1419,12 +1420,12 @@ MavlinkReceiver::handle_message_set_position_target_global_int(mavlink_message_t
|
||||
const double lon = target_global_int.lon_int / 1e7;
|
||||
global_local_proj_ref.project(lat, lon, setpoint.position[0], setpoint.position[1]);
|
||||
|
||||
if (target_global_int.coordinate_frame == MAV_FRAME_GLOBAL
|
||||
|| target_global_int.coordinate_frame == MAV_FRAME_GLOBAL_INT) {
|
||||
const uint8_t frame = mavlink_cmd_params::frame_without_int(target_global_int.coordinate_frame);
|
||||
|
||||
if (frame == MAV_FRAME_GLOBAL) {
|
||||
setpoint.position[2] = local_pos.ref_alt - target_global_int.alt;
|
||||
|
||||
} else if (target_global_int.coordinate_frame == MAV_FRAME_GLOBAL_RELATIVE_ALT
|
||||
|| target_global_int.coordinate_frame == MAV_FRAME_GLOBAL_RELATIVE_ALT_INT) {
|
||||
} else if (frame == MAV_FRAME_GLOBAL_RELATIVE_ALT) {
|
||||
home_position_s home_position{};
|
||||
_home_position_sub.copy(&home_position);
|
||||
|
||||
@@ -1437,8 +1438,7 @@ MavlinkReceiver::handle_message_set_position_target_global_int(mavlink_message_t
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (target_global_int.coordinate_frame == MAV_FRAME_GLOBAL_TERRAIN_ALT
|
||||
|| target_global_int.coordinate_frame == MAV_FRAME_GLOBAL_TERRAIN_ALT_INT) {
|
||||
} else if (frame == MAV_FRAME_GLOBAL_TERRAIN_ALT) {
|
||||
vehicle_global_position_s vehicle_global_position{};
|
||||
_vehicle_global_position_sub.copy(&vehicle_global_position);
|
||||
|
||||
|
||||
Reference in new issue
Block a user