2014-03-28 16:52:27 -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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
GPS driver backend class
|
|
|
|
*/
|
2016-02-17 21:25:23 -04:00
|
|
|
#pragma once
|
2014-03-28 16:52:27 -03:00
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
2018-06-22 02:28:11 -03:00
|
|
|
#include <AP_RTC/JitterCorrection.h>
|
2015-08-11 03:28:43 -03:00
|
|
|
#include "AP_GPS.h"
|
2014-06-06 18:58:11 -03:00
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
class AP_GPS_Backend
|
|
|
|
{
|
|
|
|
public:
|
2017-04-18 17:05:56 -03:00
|
|
|
AP_GPS_Backend(AP_GPS &_gps, AP_GPS::GPS_State &_state, AP_HAL::UARTDriver *_port);
|
2014-03-28 16:52:27 -03:00
|
|
|
|
2014-03-31 16:11:55 -03:00
|
|
|
// we declare a virtual destructor so that GPS drivers can
|
|
|
|
// override with a custom destructor if need be.
|
|
|
|
virtual ~AP_GPS_Backend(void) {}
|
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
// The read() method is the only one needed in each driver. It
|
|
|
|
// should return true when the backend has successfully received a
|
|
|
|
// valid packet from the GPS.
|
|
|
|
virtual bool read() = 0;
|
|
|
|
|
2014-06-06 18:58:11 -03:00
|
|
|
// Highest status supported by this GPS.
|
|
|
|
// Allows external system to identify type of receiver connected.
|
|
|
|
virtual AP_GPS::GPS_Status highest_supported_status(void) { return AP_GPS::GPS_OK_FIX_3D; }
|
|
|
|
|
2021-02-23 16:18:17 -04:00
|
|
|
virtual bool is_configured(void) const { return true; }
|
2016-02-02 03:58:33 -04:00
|
|
|
|
2017-04-18 17:05:56 -03:00
|
|
|
virtual void inject_data(const uint8_t *data, uint16_t len);
|
2016-02-02 03:58:33 -04:00
|
|
|
|
2014-06-06 18:58:11 -03:00
|
|
|
//MAVLink methods
|
2020-08-13 19:09:12 -03:00
|
|
|
virtual bool supports_mavlink_gps_rtk_message() const { return false; }
|
2017-06-30 10:45:24 -03:00
|
|
|
virtual void send_mavlink_gps_rtk(mavlink_channel_t chan);
|
2014-06-06 18:58:11 -03:00
|
|
|
|
2016-04-12 00:16:20 -03:00
|
|
|
virtual void broadcast_configuration_failure_reason(void) const { return ; }
|
|
|
|
|
2019-04-30 07:22:48 -03:00
|
|
|
virtual void handle_msg(const mavlink_message_t &msg) { return ; }
|
2020-09-03 06:15:35 -03:00
|
|
|
#if HAL_MSP_GPS_ENABLED
|
|
|
|
virtual void handle_msp(const MSP::msp_gps_data_message_t &pkt) { return; }
|
|
|
|
#endif
|
2020-12-28 18:42:14 -04:00
|
|
|
#if HAL_EXTERNAL_AHRS_ENABLED
|
|
|
|
virtual void handle_external(const AP_ExternalAHRS::gps_data_message_t &pkt) { return; }
|
|
|
|
#endif
|
|
|
|
|
2017-05-24 14:42:03 -03:00
|
|
|
// driver specific lag, returns true if the driver is confident in the provided lag
|
|
|
|
virtual bool get_lag(float &lag) const { lag = 0.2f; return true; }
|
2016-12-18 19:31:28 -04:00
|
|
|
|
2017-09-21 22:22:22 -03:00
|
|
|
// driver specific health, returns true if the driver is healthy
|
|
|
|
virtual bool is_healthy(void) const { return true; }
|
2019-11-12 02:16:26 -04:00
|
|
|
// returns true if the GPS is doing any logging it is expected to
|
|
|
|
virtual bool logging_healthy(void) const { return true; }
|
2017-09-21 22:22:22 -03:00
|
|
|
|
2016-08-01 08:58:23 -03:00
|
|
|
virtual const char *name() const = 0;
|
|
|
|
|
2016-08-01 21:30:12 -03:00
|
|
|
void broadcast_gps_type() const;
|
2019-01-18 00:23:42 -04:00
|
|
|
virtual void Write_AP_Logger_Log_Startup_messages() const;
|
2016-08-01 21:30:12 -03:00
|
|
|
|
2017-10-19 22:15:11 -03:00
|
|
|
virtual bool prepare_for_arming(void) { return true; }
|
|
|
|
|
2019-11-16 00:26:28 -04:00
|
|
|
// optional support for retrieving RTCMv3 data from a moving baseline base
|
|
|
|
virtual bool get_RTCMV3(const uint8_t *&bytes, uint16_t &len) { return false; }
|
|
|
|
virtual void clear_RTCMV3(void) {};
|
|
|
|
|
2021-02-23 16:18:17 -04:00
|
|
|
virtual bool get_error_codes(uint32_t &error_codes) const { return false; }
|
|
|
|
|
2020-09-03 08:48:47 -03:00
|
|
|
// return iTOW of last message, or zero if not supported
|
|
|
|
uint32_t get_last_itow(void) const {
|
|
|
|
return _last_itow;
|
|
|
|
}
|
|
|
|
|
2021-02-07 20:51:19 -04:00
|
|
|
enum DriverOptions : int16_t {
|
|
|
|
UBX_MBUseUart2 = (1 << 0U),
|
|
|
|
SBF_UseBaseForYaw = (1 << 1U),
|
|
|
|
};
|
|
|
|
|
2014-03-28 16:52:27 -03:00
|
|
|
protected:
|
|
|
|
AP_HAL::UARTDriver *port; ///< UART we are attached to
|
|
|
|
AP_GPS &gps; ///< access to frontend (for parameters)
|
|
|
|
AP_GPS::GPS_State &state; ///< public state for this instance
|
|
|
|
|
|
|
|
// common utility functions
|
|
|
|
int32_t swap_int32(int32_t v) const;
|
|
|
|
int16_t swap_int16(int16_t v) const;
|
|
|
|
|
|
|
|
/*
|
|
|
|
fill in 3D velocity from 2D components
|
|
|
|
*/
|
|
|
|
void fill_3d_velocity(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
fill in time_week_ms and time_week from BCD date and time components
|
|
|
|
assumes MTK19 millisecond form of bcd_time
|
|
|
|
*/
|
|
|
|
void make_gps_time(uint32_t bcd_date, uint32_t bcd_milliseconds);
|
2016-08-01 21:30:12 -03:00
|
|
|
|
|
|
|
void _detection_message(char *buffer, uint8_t buflen) const;
|
2017-06-27 05:12:45 -03:00
|
|
|
|
2019-02-11 04:19:08 -04:00
|
|
|
bool should_log() const;
|
2018-05-15 22:16:01 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
set a timestamp based on arrival time on uart at current byte,
|
|
|
|
assuming the message started nbytes ago
|
|
|
|
*/
|
|
|
|
void set_uart_timestamp(uint16_t nbytes);
|
2018-06-19 19:35:41 -03:00
|
|
|
|
|
|
|
void check_new_itow(uint32_t itow, uint32_t msg_length);
|
2020-04-03 00:54:15 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
access to driver option bits
|
|
|
|
*/
|
2020-09-29 17:34:57 -03:00
|
|
|
DriverOptions driver_options(void) const {
|
|
|
|
return DriverOptions(gps._driver_options.get());
|
2020-04-03 00:54:15 -03:00
|
|
|
}
|
|
|
|
|
2020-09-29 16:47:37 -03:00
|
|
|
#if GPS_MOVING_BASELINE
|
|
|
|
bool calculate_moving_base_yaw(const float reported_heading_deg, const float reported_distance, const float reported_D);
|
|
|
|
#endif //GPS_MOVING_BASELINE
|
|
|
|
|
2020-11-11 19:04:14 -04:00
|
|
|
// get GPS type, for subtype config
|
|
|
|
AP_GPS::GPS_Type get_type() const {
|
|
|
|
return gps.get_type(state.instance);
|
|
|
|
}
|
|
|
|
|
2018-06-19 19:35:41 -03:00
|
|
|
private:
|
|
|
|
// itow from previous message
|
|
|
|
uint32_t _last_itow;
|
2018-06-22 02:28:11 -03:00
|
|
|
uint64_t _pseudo_itow;
|
|
|
|
uint32_t _last_ms;
|
|
|
|
uint32_t _rate_ms;
|
|
|
|
uint32_t _last_rate_ms;
|
|
|
|
uint16_t _rate_counter;
|
|
|
|
|
|
|
|
JitterCorrection jitter_correction;
|
2014-03-28 16:52:27 -03:00
|
|
|
};
|