Skip to content

Commit

Permalink
GCS_MAVLink: Add FLIGHT_INFORMATION message
Browse files Browse the repository at this point in the history
  • Loading branch information
nexton-winjeel committed Aug 4, 2024
1 parent b7e8c0d commit cbce03d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libraries/GCS_MAVLink/GCS.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,13 @@ class GCS_MAVLINK
void send_uavionix_adsb_out_status() const;
void send_autopilot_state_for_gimbal_device() const;

struct {
MAV_LANDED_STATE last_landed_state;
uint64_t takeoff_time_us;
} flight_info;

void send_flight_information();

// lock a channel, preventing use by MAVLink
void lock(bool _lock) {
_locked = _lock;
Expand Down
55 changes: 55 additions & 0 deletions libraries/GCS_MAVLink/GCS_Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5964,6 +5964,56 @@ void GCS_MAVLINK::send_autopilot_state_for_gimbal_device() const
#endif // AP_AHRS_ENABLED
}

void GCS_MAVLINK::send_flight_information()
{
const uint32_t time_boot_us = AP_HAL::millis64();

// This field is misnamed as `arming_time_utc` in MAVLink. However, it is
// not a UTC time, it is the microseconds since boot.
const uint64_t arm_time_us = AP::arming().arm_time_us();

const MAV_LANDED_STATE current_landed_state = landed_state();
if (flight_info.last_landed_state != current_landed_state) {
switch (current_landed_state) {
case MAV_LANDED_STATE_IN_AIR:
case MAV_LANDED_STATE_TAKEOFF:
case MAV_LANDED_STATE_LANDING: {
if (!flight_info.takeoff_time_us) {
flight_info.takeoff_time_us = time_boot_us;
}
break;
}

case MAV_LANDED_STATE_ON_GROUND: {
flight_info.takeoff_time_us = 0;
break;
}

case MAV_LANDED_STATE_UNDEFINED:
case MAV_LANDED_STATE_ENUM_END: {
break;
}
}

flight_info.last_landed_state = current_landed_state;
}

// This field is misnamed as `takeoff_time_utc` in MAVLink. However, it is
// not a UTC time, it is the microseconds since boot.
uint64_t takeoff_time_us = flight_info.takeoff_time_us;

// This field is misnamed as `flight_uuid` in MAVLink.
const uint64_t flight_number = 0;

mavlink_msg_flight_information_send(
chan,
time_boot_us,
arm_time_us,
takeoff_time_us,
flight_number
);
}

void GCS_MAVLINK::send_received_message_deprecation_warning(const char * message)
{
// we're not expecting very many of these ever, so a tiny bit of
Expand Down Expand Up @@ -6395,6 +6445,11 @@ bool GCS_MAVLINK::try_send_message(const enum ap_message id)
break;
#endif

case MSG_FLIGHT_INFORMATION:
CHECK_PAYLOAD_SIZE(FLIGHT_INFORMATION);
send_flight_information();
break;

default:
// try_send_message must always at some stage return true for
// a message, or we will attempt to infinitely retry the
Expand Down
1 change: 1 addition & 0 deletions libraries/GCS_MAVLink/ap_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,6 @@ enum ap_message : uint8_t {
#if AP_MAVLINK_MSG_HIGHRES_IMU_ENABLED
MSG_HIGHRES_IMU,
#endif
MSG_FLIGHT_INFORMATION,
MSG_LAST // MSG_LAST must be the last entry in this enum
};

0 comments on commit cbce03d

Please sign in to comment.