Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_GPS/AP_GPS_SBP2.h
Views: 1798
/*1This program is free software: you can redistribute it and/or modify2it under the terms of the GNU General Public License as published by3the Free Software Foundation, either version 3 of the License, or4(at your option) any later version.56This program is distributed in the hope that it will be useful,7but WITHOUT ANY WARRANTY; without even the implied warranty of8MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9GNU General Public License for more details.1011You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/1415//16// Swift Navigation SBP GPS driver for ArduPilot.17// Code by Niels Joubert18//19// Swift Binary Protocol format: http://docs.swift-nav.com/20//21#pragma once2223#include "AP_GPS.h"24#include "GPS_Backend.h"2526#if AP_GPS_SBP2_ENABLED27class AP_GPS_SBP2 : public AP_GPS_Backend28{29public:30AP_GPS_SBP2(AP_GPS &_gps, AP_GPS::Params &_params, AP_GPS::GPS_State &_state, AP_HAL::UARTDriver *_port);3132AP_GPS::GPS_Status highest_supported_status(void) override { return AP_GPS::GPS_OK_FIX_3D_RTK_FIXED; }3334// Methods35bool read() override;3637void inject_data(const uint8_t *data, uint16_t len) override;3839static bool _detect(struct SBP2_detect_state &state, uint8_t data);4041const char *name() const override { return "SBP2"; }4243private:4445// ************************************************************************46// Swift Navigation SBP protocol types and definitions47// ************************************************************************4849struct sbp_parser_state_t {50enum {51WAITING = 0,52GET_TYPE = 1,53GET_SENDER = 2,54GET_LEN = 3,55GET_MSG = 4,56GET_CRC = 557} state:8;58uint16_t msg_type;59uint16_t sender_id;60uint16_t crc;61uint8_t msg_len;62uint8_t n_read;63uint8_t msg_buff[256];64} parser_state;6566static const uint8_t SBP_PREAMBLE = 0x55;6768// Message types supported by this driver69static const uint16_t SBP_STARTUP_MSGTYPE = 0xFF00;70static const uint16_t SBP_HEARTBEAT_MSGTYPE = 0xFFFF;71static const uint16_t SBP_GPS_TIME_MSGTYPE = 0x0102;72static const uint16_t SBP_DOPS_MSGTYPE = 0x0208;73static const uint16_t SBP_POS_ECEF_MSGTYPE = 0x0209;74static const uint16_t SBP_POS_LLH_MSGTYPE = 0x020A;75static const uint16_t SBP_BASELINE_ECEF_MSGTYPE = 0x020B;76static const uint16_t SBP_BASELINE_NED_MSGTYPE = 0x020C;77static const uint16_t SBP_VEL_ECEF_MSGTYPE = 0x020D;78static const uint16_t SBP_VEL_NED_MSGTYPE = 0x020E;79static const uint16_t SBP_TRACKING_STATE_MSGTYPE = 0x0013;80static const uint16_t SBP_IAR_STATE_MSGTYPE = 0x0019;81static const uint16_t SBP_EXT_EVENT_MSGTYPE = 0x0101;8283// Heartbeat84struct PACKED sbp_heartbeat_t {85bool sys_error : 1;86bool io_error : 1;87bool nap_error : 1;88uint8_t res : 5;89uint8_t protocol_minor : 8;90uint8_t protocol_major : 8;91uint8_t res2 : 6;92bool ext_antenna_short : 1;93bool ext_antenna : 1;94}; // 4 bytes9596// GPS Time97struct PACKED sbp_gps_time_t {98uint16_t wn; //< GPS week number (unit: weeks)99uint32_t tow; //< GPS Time of Week rounded to the nearest ms (unit: ms)100int32_t ns; //< Nanosecond remainder of rounded tow (unit: ns)101struct PACKED flags {102uint8_t time_src:3; //< Fix mode (0: invalid, 1: GNSS Solution, 2: Propagated103uint8_t res:5; //< Reserved104} flags;105}; // 11 bytes106107// Dilution of Precision108struct PACKED sbp_dops_t {109uint32_t tow; //< GPS Time of Week (unit: ms)110uint16_t gdop; //< Geometric Dilution of Precision (unit: 0.01)111uint16_t pdop; //< Position Dilution of Precision (unit: 0.01)112uint16_t tdop; //< Time Dilution of Precision (unit: 0.01)113uint16_t hdop; //< Horizontal Dilution of Precision (unit: 0.01)114uint16_t vdop; //< Vertical Dilution of Precision (unit: 0.01)115struct PACKED flags {116uint8_t fix_mode:3; //< Fix mode (0: invalid, 1: SPP, 2: DGNSS, 3: Float RTX, 4: Fixed RTX, 5: Undefined, 6: SBAS Position117uint8_t res:4; //< Reserved118bool raim_repair:1; //< Solution from RAIM?119} flags;120}; // 15 bytes121122// Geodetic position solution.123struct PACKED sbp_pos_llh_t {124uint32_t tow; //< GPS Time of Week (unit: ms)125double lat; //< Latitude (unit: degrees)126double lon; //< Longitude (unit: degrees)127double height; //< Height (unit: meters)128uint16_t h_accuracy; //< Horizontal position accuracy estimate (unit: mm)129uint16_t v_accuracy; //< Vertical position accuracy estimate (unit: mm)130uint8_t n_sats; //< Number of satellites used in solution131struct PACKED flags {132uint8_t fix_mode:3; //< Fix mode (0: invalid, 1: SPP, 2: DGNSS, 3: Float RTX, 4: Fixed RTX, 5: Dead Reckoning, 6: SBAS Position133uint8_t ins_mode:2; //< Inertial navigation mode (0: none, 1: INS used)134uint8_t res:3; //< Reserved135} flags;136}; // 34 bytes137138// Velocity in NED Velocity in local North East Down (NED) coordinates.139struct PACKED sbp_vel_ned_t {140uint32_t tow; //< GPS Time of Week (unit: ms)141int32_t n; //< Velocity North coordinate (unit: mm/s)142int32_t e; //< Velocity East coordinate (unit: mm/s)143int32_t d; //< Velocity Down coordinate (unit: mm/s)144uint16_t h_accuracy; //< Horizontal velocity accuracy estimate (unit: mm/s)145uint16_t v_accuracy; //< Vertical velocity accuracy estimate (unit: mm/s)146uint8_t n_sats; //< Number of satellites used in solution147struct PACKED flags {148uint8_t vel_mode:3; //< Velocity mode (0: Invalid, 1: Measured Doppler derived, 2: Computed Doppler derived, 3: Dead reckoning)149uint8_t ins_mode:2; //< Inertial navigation mode (0: none, 1: INS used)150uint8_t res:3; //< Reserved151} flags;152}; // 22 bytes153154// Messages reporting accurately-timestamped external events, e.g. camera shutter time.155struct PACKED sbp_ext_event_t {156uint16_t wn; //< GPS week number (unit: weeks)157uint32_t tow; //< GPS Time of Week (unit: ms)158int32_t ns_residual; //< Nanosecond residual of millisecond-rounded TOW (ranges from -500000 to 500000)159struct PACKED flags {160uint8_t level:1; //< New level of pin values (0: Low (falling edge), 1: High (rising edge))161uint8_t quality:1; //< Time quality values (0: Unknown - don't have nav solution, 1: Good (< 1 microsecond))162uint8_t res:6; //< Reserved163} flags;164uint8_t pin; //< Pin number (0-9)165}; // 12 bytes166167void _sbp_process();168void _sbp_process_message();169bool _attempt_state_update();170171// ************************************************************************172// Internal Received Messages State173// ************************************************************************174uint32_t last_heartbeat_received_ms;175uint32_t last_injected_data_ms;176177struct sbp_heartbeat_t last_heartbeat;178struct sbp_gps_time_t last_gps_time;179struct sbp_dops_t last_dops;180struct sbp_pos_llh_t last_pos_llh;181struct sbp_vel_ned_t last_vel_ned;182struct sbp_ext_event_t last_event;183184uint32_t last_full_update_tow;185uint16_t last_full_update_wn;186187// ************************************************************************188// Monitoring and Performance Counting189// ************************************************************************190191uint32_t crc_error_counter;192193// ************************************************************************194// Logging to AP_Logger195// ************************************************************************196197void logging_log_full_update();198void logging_ext_event();199void logging_log_raw_sbp(uint16_t msg_type, uint16_t sender_id, uint8_t msg_len, uint8_t *msg_buff);200201int32_t distMod(int32_t tow1_ms, int32_t tow2_ms, int32_t mod);202203};204#endif205206207