2017-07-08 21:24:43 -03:00
|
|
|
#include "GCS.h"
|
2019-04-26 01:44:34 -03:00
|
|
|
|
2019-08-29 06:26:05 -03:00
|
|
|
#include <AC_Fence/AC_Fence.h>
|
2019-04-26 01:44:34 -03:00
|
|
|
#include <AP_BoardConfig/AP_BoardConfig.h>
|
2019-04-04 07:49:44 -03:00
|
|
|
#include <AP_Logger/AP_Logger.h>
|
2019-06-13 19:57:04 -03:00
|
|
|
#include <AP_BattMonitor/AP_BattMonitor.h>
|
2019-04-26 01:44:34 -03:00
|
|
|
#include <AP_Scheduler/AP_Scheduler.h>
|
2019-06-26 23:32:25 -03:00
|
|
|
#include <AP_Baro/AP_Baro.h>
|
2019-08-27 17:07:42 -03:00
|
|
|
#include <AP_AHRS/AP_AHRS.h>
|
2019-11-12 02:16:53 -04:00
|
|
|
#include <AP_GPS/AP_GPS.h>
|
2019-12-17 18:32:57 -04:00
|
|
|
#include <AP_Arming/AP_Arming.h>
|
2017-07-08 21:24:43 -03:00
|
|
|
|
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
2019-02-13 21:59:00 -04:00
|
|
|
void GCS::get_sensor_status_flags(uint32_t &present,
|
|
|
|
uint32_t &enabled,
|
|
|
|
uint32_t &health)
|
|
|
|
{
|
|
|
|
update_sensor_status_flags();
|
|
|
|
|
|
|
|
present = control_sensors_present;
|
|
|
|
enabled = control_sensors_enabled;
|
|
|
|
health = control_sensors_health;
|
|
|
|
}
|
|
|
|
|
2019-04-28 23:52:02 -03:00
|
|
|
MissionItemProtocol_Waypoints *GCS::_missionitemprotocol_waypoints;
|
|
|
|
MissionItemProtocol_Rally *GCS::_missionitemprotocol_rally;
|
2019-04-29 00:05:59 -03:00
|
|
|
MissionItemProtocol_Fence *GCS::_missionitemprotocol_fence;
|
2019-04-28 23:52:02 -03:00
|
|
|
|
|
|
|
const MAV_MISSION_TYPE GCS_MAVLINK::supported_mission_types[] = {
|
|
|
|
MAV_MISSION_TYPE_MISSION,
|
|
|
|
MAV_MISSION_TYPE_RALLY,
|
2019-04-29 00:05:59 -03:00
|
|
|
MAV_MISSION_TYPE_FENCE,
|
2019-04-28 23:52:02 -03:00
|
|
|
};
|
|
|
|
|
2017-07-08 21:24:43 -03:00
|
|
|
/*
|
|
|
|
send a text message to all GCS
|
|
|
|
*/
|
2017-08-01 02:13:34 -03:00
|
|
|
void GCS::send_textv(MAV_SEVERITY severity, const char *fmt, va_list arg_list)
|
2017-07-08 21:24:43 -03:00
|
|
|
{
|
2019-12-17 21:00:33 -04:00
|
|
|
uint8_t mask = GCS_MAVLINK::active_channel_mask() | GCS_MAVLINK::streaming_channel_mask();
|
|
|
|
if (!update_send_has_been_called) {
|
|
|
|
// we have not yet initialised the streaming-channel-mask,
|
|
|
|
// which is done as part of the update() call. So just send
|
|
|
|
// it to all channels:
|
|
|
|
mask = (1<<_num_gcs)-1;
|
|
|
|
}
|
2020-01-12 22:08:14 -04:00
|
|
|
send_textv(severity, fmt, arg_list, mask);
|
2017-08-01 02:13:34 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void GCS::send_text(MAV_SEVERITY severity, const char *fmt, ...)
|
|
|
|
{
|
2017-07-08 21:24:43 -03:00
|
|
|
va_list arg_list;
|
|
|
|
va_start(arg_list, fmt);
|
2017-08-01 02:13:34 -03:00
|
|
|
send_textv(severity, fmt, arg_list);
|
2017-07-08 21:24:43 -03:00
|
|
|
va_end(arg_list);
|
|
|
|
}
|
2017-07-08 03:26:34 -03:00
|
|
|
|
2018-11-06 22:11:08 -04:00
|
|
|
void GCS::send_to_active_channels(uint32_t msgid, const char *pkt)
|
|
|
|
{
|
|
|
|
const mavlink_msg_entry_t *entry = mavlink_get_msg_entry(msgid);
|
|
|
|
if (entry == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (uint8_t i=0; i<num_gcs(); i++) {
|
2018-12-10 03:56:32 -04:00
|
|
|
GCS_MAVLINK &c = *chan(i);
|
2018-11-06 22:11:08 -04:00
|
|
|
if (!c.is_active()) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-09-12 03:14:55 -03:00
|
|
|
if (entry->max_msg_len + c.packet_overhead() > c.txspace()) {
|
2018-11-06 22:11:08 -04:00
|
|
|
// no room on this channel
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
c.send_message(pkt, entry);
|
|
|
|
}
|
|
|
|
}
|
2017-07-08 03:26:34 -03:00
|
|
|
|
2018-05-15 02:20:30 -03:00
|
|
|
void GCS::send_named_float(const char *name, float value) const
|
|
|
|
{
|
2018-11-06 22:11:08 -04:00
|
|
|
|
2019-10-16 21:52:53 -03:00
|
|
|
mavlink_named_value_float_t packet {};
|
2018-11-06 22:11:08 -04:00
|
|
|
packet.time_boot_ms = AP_HAL::millis();
|
|
|
|
packet.value = value;
|
|
|
|
memcpy(packet.name, name, MIN(strlen(name), (uint8_t)MAVLINK_MSG_NAMED_VALUE_FLOAT_FIELD_NAME_LEN));
|
|
|
|
|
|
|
|
gcs().send_to_active_channels(MAVLINK_MSG_ID_NAMED_VALUE_FLOAT,
|
|
|
|
(const char *)&packet);
|
2018-05-15 02:20:30 -03:00
|
|
|
}
|
|
|
|
|
2018-03-25 07:45:48 -03:00
|
|
|
/*
|
|
|
|
install an alternative protocol handler. This allows another
|
|
|
|
protocol to take over the link if MAVLink goes idle. It is used to
|
|
|
|
allow for the AP_BLHeli pass-thru protocols to run on hal.uartA
|
|
|
|
*/
|
|
|
|
bool GCS::install_alternative_protocol(mavlink_channel_t c, GCS_MAVLINK::protocol_handler_fn_t handler)
|
|
|
|
{
|
|
|
|
if (c >= num_gcs()) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-12-10 03:56:32 -04:00
|
|
|
if (chan(c)->alternative.handler && handler) {
|
2018-03-25 07:45:48 -03:00
|
|
|
// already have one installed - we may need to add support for
|
|
|
|
// multiple alternative handlers
|
|
|
|
return false;
|
|
|
|
}
|
2018-12-10 03:56:32 -04:00
|
|
|
chan(c)->alternative.handler = handler;
|
2018-03-25 07:45:48 -03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-19 19:01:16 -04:00
|
|
|
void GCS::update_sensor_status_flags()
|
|
|
|
{
|
|
|
|
control_sensors_present = 0;
|
|
|
|
control_sensors_enabled = 0;
|
|
|
|
control_sensors_health = 0;
|
|
|
|
|
|
|
|
AP_AHRS &ahrs = AP::ahrs();
|
|
|
|
const AP_InertialSensor &ins = AP::ins();
|
|
|
|
|
|
|
|
control_sensors_present |= MAV_SYS_STATUS_AHRS;
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_AHRS;
|
|
|
|
if (!ahrs.initialised() || ahrs.healthy()) {
|
|
|
|
if (!ahrs.have_inertial_nav() || ins.accel_calibrated_ok_all()) {
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_AHRS;
|
|
|
|
}
|
|
|
|
}
|
2019-04-13 20:34:58 -03:00
|
|
|
|
|
|
|
const Compass &compass = AP::compass();
|
|
|
|
if (AP::compass().enabled()) {
|
|
|
|
control_sensors_present |= MAV_SYS_STATUS_SENSOR_3D_MAG;
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_3D_MAG;
|
|
|
|
}
|
|
|
|
if (compass.enabled() && compass.healthy() && ahrs.use_compass()) {
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_SENSOR_3D_MAG;
|
|
|
|
}
|
2019-02-19 19:01:16 -04:00
|
|
|
|
|
|
|
const AP_Baro &barometer = AP::baro();
|
|
|
|
control_sensors_present |= MAV_SYS_STATUS_SENSOR_ABSOLUTE_PRESSURE;
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_ABSOLUTE_PRESSURE;
|
|
|
|
if (barometer.all_healthy()) {
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_SENSOR_ABSOLUTE_PRESSURE;
|
|
|
|
}
|
|
|
|
|
2019-11-08 02:58:57 -04:00
|
|
|
const AP_GPS &gps = AP::gps();
|
|
|
|
if (gps.status() > AP_GPS::NO_GPS) {
|
|
|
|
control_sensors_present |= MAV_SYS_STATUS_SENSOR_GPS;
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_GPS;
|
|
|
|
}
|
|
|
|
if (gps.is_healthy() && gps.status() >= min_status_for_gps_healthy()) {
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_SENSOR_GPS;
|
|
|
|
}
|
|
|
|
|
2019-02-19 19:01:16 -04:00
|
|
|
const AP_BattMonitor &battery = AP::battery();
|
|
|
|
control_sensors_present |= MAV_SYS_STATUS_SENSOR_BATTERY;
|
|
|
|
if (battery.num_instances() > 0) {
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_BATTERY;
|
|
|
|
}
|
|
|
|
if (battery.healthy() && !battery.has_failsafed()) {
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_SENSOR_BATTERY;
|
|
|
|
}
|
|
|
|
|
|
|
|
control_sensors_present |= MAV_SYS_STATUS_SENSOR_3D_GYRO;
|
|
|
|
control_sensors_present |= MAV_SYS_STATUS_SENSOR_3D_ACCEL;
|
|
|
|
if (!ins.calibrating()) {
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_3D_ACCEL;
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_3D_GYRO;
|
|
|
|
if (ins.get_accel_health_all()) {
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_SENSOR_3D_ACCEL;
|
|
|
|
}
|
|
|
|
if (ins.get_gyro_health_all() && ins.gyro_calibrated_ok_all()) {
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_SENSOR_3D_GYRO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const AP_Logger &logger = AP::logger();
|
2019-11-12 02:16:53 -04:00
|
|
|
if (logger.logging_present() || gps.logging_present()) { // primary logging only (usually File)
|
2019-02-19 19:01:16 -04:00
|
|
|
control_sensors_present |= MAV_SYS_STATUS_LOGGING;
|
|
|
|
}
|
2019-11-12 02:16:53 -04:00
|
|
|
if (logger.logging_enabled() || gps.logging_enabled()) {
|
2019-02-19 19:01:16 -04:00
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_LOGGING;
|
|
|
|
}
|
2019-11-12 02:16:53 -04:00
|
|
|
if (!logger.logging_failed() && !gps.logging_failed()) {
|
2019-02-19 19:01:16 -04:00
|
|
|
control_sensors_health |= MAV_SYS_STATUS_LOGGING;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set motors outputs as enabled if safety switch is not disarmed (i.e. either NONE or ARMED)
|
|
|
|
control_sensors_present |= MAV_SYS_STATUS_SENSOR_MOTOR_OUTPUTS;
|
|
|
|
if (hal.util->safety_switch_state() != AP_HAL::Util::SAFETY_DISARMED) {
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_SENSOR_MOTOR_OUTPUTS;
|
|
|
|
}
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_SENSOR_MOTOR_OUTPUTS;
|
|
|
|
|
2019-06-21 22:26:30 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
|
|
|
if (ahrs.get_ekf_type() == 10) {
|
|
|
|
// always show EKF type 10 as healthy. This prevents spurious error
|
|
|
|
// messages in xplane and other simulators that use EKF type 10
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_AHRS | MAV_SYS_STATUS_SENSOR_GPS | MAV_SYS_STATUS_SENSOR_3D_ACCEL | MAV_SYS_STATUS_SENSOR_3D_GYRO;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-29 06:26:05 -03:00
|
|
|
const AC_Fence *fence = AP::fence();
|
|
|
|
if (fence != nullptr) {
|
|
|
|
if (fence->sys_status_enabled()) {
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_GEOFENCE;
|
|
|
|
}
|
|
|
|
if (fence->sys_status_present()) {
|
|
|
|
control_sensors_present |= MAV_SYS_STATUS_GEOFENCE;
|
|
|
|
}
|
|
|
|
if (!fence->sys_status_failed()) {
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_GEOFENCE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 18:32:57 -04:00
|
|
|
// give GCS status of prearm checks. This is enabled if any arming checks are enabled.
|
|
|
|
// it is healthy if armed or checks are passing
|
|
|
|
control_sensors_present |= MAV_SYS_STATUS_PREARM_CHECK;
|
|
|
|
if (AP::arming().get_enabled_checks()) {
|
|
|
|
control_sensors_enabled |= MAV_SYS_STATUS_PREARM_CHECK;
|
|
|
|
if (hal.util->get_soft_armed() || AP_Notify::flags.pre_arm_check) {
|
|
|
|
control_sensors_health |= MAV_SYS_STATUS_PREARM_CHECK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-19 19:01:16 -04:00
|
|
|
update_vehicle_sensor_status_flags();
|
|
|
|
}
|
2019-04-26 01:44:34 -03:00
|
|
|
|
|
|
|
bool GCS::out_of_time() const
|
|
|
|
{
|
|
|
|
// while we are in the delay callback we are never out of time:
|
|
|
|
if (hal.scheduler->in_delay_callback()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we always want to be able to send messages out while in the error loop:
|
2019-11-06 18:23:03 -04:00
|
|
|
if (AP_BoardConfig::in_config_error()) {
|
2019-04-26 01:44:34 -03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (min_loop_time_remaining_for_message_send_us() <= AP::scheduler().time_available_usec()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|