Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move MAVLink fence-message handling up #10408

Merged
merged 9 commits into from
Feb 8, 2019
19 changes: 0 additions & 19 deletions APMrover2/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,19 +686,6 @@ MAV_RESULT GCS_MAVLINK_Rover::handle_command_long_packet(const mavlink_command_l
}
return MAV_RESULT_UNSUPPORTED;

case MAV_CMD_DO_FENCE_ENABLE:
switch ((uint16_t)packet.param1) {
case 0:
rover.g2.fence.enable(false);
return MAV_RESULT_ACCEPTED;
case 1:
rover.g2.fence.enable(true);
return MAV_RESULT_ACCEPTED;
default:
break;
}
return MAV_RESULT_FAILED;

case MAV_CMD_DO_CHANGE_SPEED:
// param1 : unused
// param2 : new speed in m/s
Expand Down Expand Up @@ -1142,12 +1129,6 @@ void GCS_MAVLINK_Rover::handleMessage(mavlink_message_t* msg)
break;
}

// send or receive fence points with GCS
case MAVLINK_MSG_ID_FENCE_POINT: // MAV ID: 160
case MAVLINK_MSG_ID_FENCE_FETCH_POINT:
rover.g2.fence.handle_msg(*this, msg);
break;

case MAVLINK_MSG_ID_DISTANCE_SENSOR:
rover.rangefinder.handle_msg(msg);
rover.g2.proximity.handle_msg(msg);
Expand Down
22 changes: 0 additions & 22 deletions ArduCopter/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,20 +799,6 @@ MAV_RESULT GCS_MAVLINK_Copter::handle_command_long_packet(const mavlink_command_
}
return MAV_RESULT_FAILED;

#if AC_FENCE == ENABLED
case MAV_CMD_DO_FENCE_ENABLE:
switch ((uint16_t)packet.param1) {
case 0:
copter.fence.enable(false);
return MAV_RESULT_ACCEPTED;
case 1:
copter.fence.enable(true);
return MAV_RESULT_ACCEPTED;
default:
return MAV_RESULT_FAILED;
}
#endif

#if PARACHUTE == ENABLED
case MAV_CMD_DO_PARACHUTE:
// configure or release parachute
Expand Down Expand Up @@ -1355,14 +1341,6 @@ void GCS_MAVLINK_Copter::handleMessage(mavlink_message_t* msg)
break;
#endif

#if AC_FENCE == ENABLED
// send or receive fence points with GCS
case MAVLINK_MSG_ID_FENCE_POINT: // MAV ID: 160
case MAVLINK_MSG_ID_FENCE_FETCH_POINT:
copter.fence.handle_msg(*this, msg);
break;
#endif // AC_FENCE == ENABLED

case MAVLINK_MSG_ID_TERRAIN_DATA:
case MAVLINK_MSG_ID_TERRAIN_CHECK:
#if AP_TERRAIN_AVAILABLE && AC_TERRAIN
Expand Down
23 changes: 0 additions & 23 deletions ArduSub/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,21 +791,6 @@ MAV_RESULT GCS_MAVLINK_Sub::handle_command_long_packet(const mavlink_command_lon
}
return MAV_RESULT_FAILED;

#if AC_FENCE == ENABLED
case MAV_CMD_DO_FENCE_ENABLE:
switch ((uint16_t)packet.param1) {
case 0:
sub.fence.enable(false);
return MAV_RESULT_ACCEPTED;
case 1:
sub.fence.enable(true);
return MAV_RESULT_ACCEPTED;
default:
break;
}
return MAV_RESULT_FAILED;
#endif

case MAV_CMD_DO_MOTOR_TEST:
// param1 : motor sequence number (a number from 1 to max number of motors on the vehicle)
// param2 : throttle type (0=throttle percentage, 1=PWM, 2=pilot throttle channel pass-through. See MOTOR_TEST_THROTTLE_TYPE enum)
Expand Down Expand Up @@ -1065,14 +1050,6 @@ void GCS_MAVLINK_Sub::handleMessage(mavlink_message_t* msg)
break;
}

#if AC_FENCE == ENABLED
// send or receive fence points with GCS
case MAVLINK_MSG_ID_FENCE_POINT: // MAV ID: 160
case MAVLINK_MSG_ID_FENCE_FETCH_POINT:
sub.fence.handle_msg(*this, msg);
break;
#endif // AC_FENCE == ENABLED

case MAVLINK_MSG_ID_TERRAIN_DATA:
case MAVLINK_MSG_ID_TERRAIN_CHECK:
#if AP_TERRAIN_AVAILABLE && AC_TERRAIN
Expand Down
2 changes: 2 additions & 0 deletions libraries/GCS_MAVLink/GCS.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ class GCS_MAVLINK
void handle_rally_fetch_point(mavlink_message_t *msg);
void handle_rally_point(mavlink_message_t *msg);
virtual void handle_mount_message(const mavlink_message_t *msg);
void handle_fence_message(mavlink_message_t *msg);
void handle_param_value(mavlink_message_t *msg);
void handle_radio_status(mavlink_message_t *msg, AP_Logger &dataflash, bool log_radio);
void handle_serial_control(const mavlink_message_t *msg);
Expand Down Expand Up @@ -404,6 +405,7 @@ class GCS_MAVLINK
MAV_RESULT handle_command_do_gripper(const mavlink_command_long_t &packet);
MAV_RESULT handle_command_do_set_mode(const mavlink_command_long_t &packet);
MAV_RESULT handle_command_get_home_position(const mavlink_command_long_t &packet);
MAV_RESULT handle_command_do_fence_enable(const mavlink_command_long_t &packet);

// vehicle-overridable message send function
virtual bool try_send_message(enum ap_message id);
Expand Down
9 changes: 9 additions & 0 deletions libraries/GCS_MAVLink/GCS_Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2992,6 +2992,11 @@ void GCS_MAVLINK::handle_common_message(mavlink_message_t *msg)
handle_command_int(msg);
break;

case MAVLINK_MSG_ID_FENCE_POINT:
case MAVLINK_MSG_ID_FENCE_FETCH_POINT:
handle_fence_message(msg);
break;

case MAVLINK_MSG_ID_GIMBAL_REPORT:
handle_mount_message(msg);
break;
Expand Down Expand Up @@ -3443,6 +3448,10 @@ MAV_RESULT GCS_MAVLINK::handle_command_long_packet(const mavlink_command_long_t
result = handle_command_do_send_banner(packet);
break;

case MAV_CMD_DO_FENCE_ENABLE:
result = handle_command_do_fence_enable(packet);
break;

case MAV_CMD_PREFLIGHT_REBOOT_SHUTDOWN:
result = handle_preflight_reboot(packet);
break;
Expand Down
39 changes: 39 additions & 0 deletions libraries/GCS_MAVLink/GCS_Fence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@

#include <AC_Fence/AC_Fence.h>

MAV_RESULT GCS_MAVLINK::handle_command_do_fence_enable(const mavlink_command_long_t &packet)
{
AC_Fence *fence = AP::fence();
if (fence == nullptr) {
return MAV_RESULT_UNSUPPORTED;
}

switch ((uint16_t)packet.param1) {
case 0:
fence->enable(false);
return MAV_RESULT_ACCEPTED;
case 1:
fence->enable(true);
return MAV_RESULT_ACCEPTED;
default:
return MAV_RESULT_FAILED;
}
}

void GCS_MAVLINK::handle_fence_message(mavlink_message_t *msg)
{
AC_Fence *fence = AP::fence();
if (fence == nullptr) {
return;
}
// send or receive fence points with GCS
switch (msg->msgid) {
case MAVLINK_MSG_ID_FENCE_POINT:
case MAVLINK_MSG_ID_FENCE_FETCH_POINT:
fence->handle_msg(*this, msg);
break;
default:
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
AP_HAL::panic("Unhandled common fence message");
#endif
break;
}
}

// fence_send_mavlink_status - send fence status to ground station
void GCS_MAVLINK::send_fence_status() const
{
Expand Down
3 changes: 3 additions & 0 deletions libraries/GCS_MAVLink/GCS_Rally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ void GCS_MAVLINK::handle_common_rally_message(mavlink_message_t *msg)
handle_rally_fetch_point(msg);
break;
default:
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
AP_HAL::panic("Unhandled common rally message");
#endif
break;
}
}
Expand Down