2017-07-12 21:20:45 -03:00
|
|
|
/*
|
2019-07-16 23:32:05 -03:00
|
|
|
GCS MAVLink functions related to upload and download of rally
|
|
|
|
points with the ArduPilot-specific protocol comprised of
|
|
|
|
MAVLINK_MSG_ID_RALLY_POINT and MAVLINK_MSG_ID_RALLY_FETCH_POINT.
|
2017-07-12 21:20:45 -03:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "GCS.h"
|
2019-04-04 07:49:44 -03:00
|
|
|
#include <AP_Rally/AP_Rally.h>
|
2019-04-28 23:52:02 -03:00
|
|
|
#include <AP_Logger/AP_Logger.h>
|
2017-07-12 21:20:45 -03:00
|
|
|
|
2019-07-11 05:31:45 -03:00
|
|
|
void GCS_MAVLINK::handle_rally_point(const mavlink_message_t &msg)
|
2017-07-12 21:20:45 -03:00
|
|
|
{
|
2018-12-29 00:48:28 -04:00
|
|
|
AP_Rally *r = AP::rally();
|
2017-07-12 21:20:45 -03:00
|
|
|
if (r == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mavlink_rally_point_t packet;
|
2019-07-11 05:31:45 -03:00
|
|
|
mavlink_msg_rally_point_decode(&msg, &packet);
|
2017-07-12 21:20:45 -03:00
|
|
|
|
|
|
|
if (packet.idx >= r->get_rally_total() ||
|
|
|
|
packet.idx >= r->get_rally_max()) {
|
2017-07-13 20:09:55 -03:00
|
|
|
send_text(MAV_SEVERITY_WARNING,"Bad rally point ID");
|
2017-07-12 21:20:45 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (packet.count != r->get_rally_total()) {
|
2017-07-13 20:09:55 -03:00
|
|
|
send_text(MAV_SEVERITY_WARNING,"Bad rally point count");
|
2017-07-12 21:20:45 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// sanity check location
|
|
|
|
if (!check_latlng(packet.lat, packet.lng)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RallyLocation rally_point;
|
|
|
|
rally_point.lat = packet.lat;
|
|
|
|
rally_point.lng = packet.lng;
|
|
|
|
rally_point.alt = packet.alt;
|
|
|
|
rally_point.break_alt = packet.break_alt;
|
|
|
|
rally_point.land_dir = packet.land_dir;
|
|
|
|
rally_point.flags = packet.flags;
|
|
|
|
|
|
|
|
if (!r->set_rally_point_with_index(packet.idx, rally_point)) {
|
|
|
|
send_text(MAV_SEVERITY_CRITICAL, "Error setting rally point");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-11 05:31:45 -03:00
|
|
|
void GCS_MAVLINK::handle_rally_fetch_point(const mavlink_message_t &msg)
|
2017-07-12 21:20:45 -03:00
|
|
|
{
|
2018-12-29 00:48:28 -04:00
|
|
|
AP_Rally *r = AP::rally();
|
2017-07-12 21:20:45 -03:00
|
|
|
if (r == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mavlink_rally_fetch_point_t packet;
|
2019-07-11 05:31:45 -03:00
|
|
|
mavlink_msg_rally_fetch_point_decode(&msg, &packet);
|
2017-07-12 21:20:45 -03:00
|
|
|
|
|
|
|
if (packet.idx > r->get_rally_total()) {
|
2017-07-13 20:09:55 -03:00
|
|
|
send_text(MAV_SEVERITY_WARNING, "Bad rally point ID");
|
2017-07-12 21:20:45 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RallyLocation rally_point;
|
|
|
|
if (!r->get_rally_point_with_index(packet.idx, rally_point)) {
|
2017-07-13 20:09:55 -03:00
|
|
|
send_text(MAV_SEVERITY_WARNING, "Failed to get rally point");
|
2017-07-12 21:20:45 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-11 05:31:45 -03:00
|
|
|
mavlink_msg_rally_point_send(chan, msg.sysid, msg.compid, packet.idx,
|
2019-04-08 11:16:07 -03:00
|
|
|
r->get_rally_total(), rally_point.lat, rally_point.lng,
|
|
|
|
rally_point.alt, rally_point.break_alt, rally_point.land_dir,
|
|
|
|
rally_point.flags);
|
2017-07-12 21:20:45 -03:00
|
|
|
}
|
|
|
|
|
2019-07-11 05:31:45 -03:00
|
|
|
void GCS_MAVLINK::handle_common_rally_message(const mavlink_message_t &msg)
|
2017-07-12 21:20:45 -03:00
|
|
|
{
|
2019-07-11 05:31:45 -03:00
|
|
|
switch (msg.msgid) {
|
2017-07-12 21:20:45 -03:00
|
|
|
case MAVLINK_MSG_ID_RALLY_POINT:
|
|
|
|
handle_rally_point(msg);
|
|
|
|
break;
|
|
|
|
case MAVLINK_MSG_ID_RALLY_FETCH_POINT:
|
|
|
|
handle_rally_fetch_point(msg);
|
|
|
|
break;
|
|
|
|
default:
|
2019-02-03 20:16:30 -04:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
|
|
|
AP_HAL::panic("Unhandled common rally message");
|
|
|
|
#endif
|
2017-07-12 21:20:45 -03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|