From 86e3116fb6cc1ee160edd929f49bff8cb470f8ef Mon Sep 17 00:00:00 2001 From: Tom Pittenger Date: Sun, 19 Jul 2015 23:11:34 -0700 Subject: [PATCH] Plane: implement try send mission_item_reached clean up unreachable code --- ArduPlane/GCS_Mavlink.cpp | 25 ++++++++++++++++++------- ArduPlane/Plane.h | 1 + ArduPlane/commands_logic.cpp | 12 ++++++++---- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/ArduPlane/GCS_Mavlink.cpp b/ArduPlane/GCS_Mavlink.cpp index f428e8cffd..3a5da5e799 100644 --- a/ArduPlane/GCS_Mavlink.cpp +++ b/ArduPlane/GCS_Mavlink.cpp @@ -5,8 +5,6 @@ // default sensors are present and healthy: gyro, accelerometer, barometer, rate_control, attitude_stabilization, yaw_position, altitude control, x/y position control, motor_control #define MAVLINK_SENSOR_PRESENT_DEFAULT (MAV_SYS_STATUS_SENSOR_3D_GYRO | MAV_SYS_STATUS_SENSOR_3D_ACCEL | MAV_SYS_STATUS_SENSOR_ABSOLUTE_PRESSURE | MAV_SYS_STATUS_SENSOR_ANGULAR_RATE_CONTROL | MAV_SYS_STATUS_SENSOR_ATTITUDE_STABILIZATION | MAV_SYS_STATUS_SENSOR_YAW_POSITION | MAV_SYS_STATUS_SENSOR_Z_ALTITUDE_CONTROL | MAV_SYS_STATUS_SENSOR_XY_POSITION_CONTROL | MAV_SYS_STATUS_SENSOR_MOTOR_OUTPUTS | MAV_SYS_STATUS_AHRS) -#define HAVE_PAYLOAD_SPACE(chan, id) (comm_get_txspace(chan) >= MAVLINK_NUM_NON_PAYLOAD_BYTES+MAVLINK_MSG_ID_ ## id ## _LEN) - void Plane::send_heartbeat(mavlink_channel_t chan) { uint8_t base_mode = MAV_MODE_FLAG_CUSTOM_MODE_ENABLED; @@ -570,15 +568,10 @@ bool Plane::telemetry_delayed(mavlink_channel_t chan) return true; } -// check if a message will fit in the payload space available -#define CHECK_PAYLOAD_SIZE(id) if (txspace < MAVLINK_NUM_NON_PAYLOAD_BYTES+MAVLINK_MSG_ID_ ## id ## _LEN) return false -#define CHECK_PAYLOAD_SIZE2(id) if (!HAVE_PAYLOAD_SPACE(chan, id)) return false // try to send a message, return false if it won't fit in the serial tx buffer bool GCS_MAVLINK::try_send_message(enum ap_message id) { - uint16_t txspace = comm_get_txspace(chan); - if (plane.telemetry_delayed(chan)) { return false; } @@ -802,6 +795,11 @@ bool GCS_MAVLINK::try_send_message(enum ap_message id) case MSG_RPM: // unused break; + + case MSG_MISSION_ITEM_REACHED: + CHECK_PAYLOAD_SIZE(MISSION_ITEM_REACHED); + mavlink_msg_mission_item_reached_send(chan, mission_item_reached_index); + break; } return true; } @@ -1797,6 +1795,19 @@ void Plane::gcs_send_message(enum ap_message id) } } +/* + * send a mission item reached message and load the index before the send attempt in case it may get delayed + */ +void Plane::gcs_send_mission_item_reached_message(uint16_t mission_index) +{ + for (uint8_t i=0; i