From 945639ac0faa71c337ac0b3f9bd9ee03a1343878 Mon Sep 17 00:00:00 2001 From: Tom Pittenger Date: Fri, 24 Jul 2015 01:10:04 -0700 Subject: [PATCH] Copter: implement try send mission_item_reached clean up unreachable code --- ArduCopter/Copter.h | 2 +- ArduCopter/GCS_Mavlink.cpp | 35 ++++++++++++++++++----------------- ArduCopter/commands_logic.cpp | 19 ++----------------- 3 files changed, 21 insertions(+), 35 deletions(-) diff --git a/ArduCopter/Copter.h b/ArduCopter/Copter.h index 05c73ba70f..eb8767fffa 100644 --- a/ArduCopter/Copter.h +++ b/ArduCopter/Copter.h @@ -588,10 +588,10 @@ private: void send_statustext(mavlink_channel_t chan); bool telemetry_delayed(mavlink_channel_t chan); void gcs_send_message(enum ap_message id); + void gcs_send_mission_item_reached_message(uint16_t mission_index); void gcs_data_stream_send(void); void gcs_check_input(void); void gcs_send_text_P(gcs_severity severity, const prog_char_t *str); - void gcs_send_mission_item_reached(uint16_t seq); void do_erase_logs(void); void Log_Write_AutoTune(uint8_t axis, uint8_t tune_step, float meas_target, float meas_min, float meas_max, float new_gain_rp, float new_gain_rd, float new_gain_sp, float new_ddt); void Log_Write_AutoTuneDetails(float angle_cd, float rate_cds); diff --git a/ArduCopter/GCS_Mavlink.cpp b/ArduCopter/GCS_Mavlink.cpp index 22e7e815a0..4ef8b97e09 100644 --- a/ArduCopter/GCS_Mavlink.cpp +++ b/ArduCopter/GCS_Mavlink.cpp @@ -5,10 +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) -// check if a message will fit in the payload space available -#define HAVE_PAYLOAD_SPACE(chan, id) (comm_get_txspace(chan) >= MAVLINK_NUM_NON_PAYLOAD_BYTES+MAVLINK_MSG_ID_ ## id ## _LEN) -#define CHECK_PAYLOAD_SIZE(id) if (txspace < MAVLINK_NUM_NON_PAYLOAD_BYTES+MAVLINK_MSG_ID_ ## id ## _LEN) return false - void Copter::gcs_send_heartbeat(void) { gcs_send_message(MSG_HEARTBEAT); @@ -518,8 +514,6 @@ bool Copter::telemetry_delayed(mavlink_channel_t chan) // 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 (copter.telemetry_delayed(chan)) { return false; } @@ -738,6 +732,11 @@ bool GCS_MAVLINK::try_send_message(enum ap_message id) send_vibration(copter.ins); break; + case MSG_MISSION_ITEM_REACHED: + CHECK_PAYLOAD_SIZE(MISSION_ITEM_REACHED); + mavlink_msg_mission_item_reached_send(chan, mission_item_reached_index); + break; + case MSG_RETRY_DEFERRED: break; // just here to prevent a warning } @@ -1841,6 +1840,19 @@ void Copter::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 Copter::gcs_send_mission_item_reached_message(uint16_t mission_index) +{ + for (uint8_t i=0; i