123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- #pragma once
- #include "AP_GPS.h"
- #include "GPS_Backend.h"
- class AP_GPS_SBP2 : public AP_GPS_Backend
- {
- public:
- AP_GPS_SBP2(AP_GPS &_gps, AP_GPS::GPS_State &_state, AP_HAL::UARTDriver *_port);
- AP_GPS::GPS_Status highest_supported_status(void) override { return AP_GPS::GPS_OK_FIX_3D_RTK_FIXED; }
-
- bool read() override;
- void inject_data(const uint8_t *data, uint16_t len) override;
- static bool _detect(struct SBP2_detect_state &state, uint8_t data);
- const char *name() const override { return "SBP2"; }
- private:
-
-
-
- struct sbp_parser_state_t {
- enum {
- WAITING = 0,
- GET_TYPE = 1,
- GET_SENDER = 2,
- GET_LEN = 3,
- GET_MSG = 4,
- GET_CRC = 5
- } state:8;
- uint16_t msg_type;
- uint16_t sender_id;
- uint16_t crc;
- uint8_t msg_len;
- uint8_t n_read;
- uint8_t msg_buff[256];
- } parser_state;
- static const uint8_t SBP_PREAMBLE = 0x55;
-
- static const uint16_t SBP_STARTUP_MSGTYPE = 0xFF00;
- static const uint16_t SBP_HEARTBEAT_MSGTYPE = 0xFFFF;
- static const uint16_t SBP_GPS_TIME_MSGTYPE = 0x0102;
- static const uint16_t SBP_DOPS_MSGTYPE = 0x0208;
- static const uint16_t SBP_POS_ECEF_MSGTYPE = 0x0209;
- static const uint16_t SBP_POS_LLH_MSGTYPE = 0x020A;
- static const uint16_t SBP_BASELINE_ECEF_MSGTYPE = 0x020B;
- static const uint16_t SBP_BASELINE_NED_MSGTYPE = 0x020C;
- static const uint16_t SBP_VEL_ECEF_MSGTYPE = 0x020D;
- static const uint16_t SBP_VEL_NED_MSGTYPE = 0x020E;
- static const uint16_t SBP_TRACKING_STATE_MSGTYPE = 0x0013;
- static const uint16_t SBP_IAR_STATE_MSGTYPE = 0x0019;
- static const uint16_t SBP_EXT_EVENT_MSGTYPE = 0x0101;
-
- struct PACKED sbp_heartbeat_t {
- bool sys_error : 1;
- bool io_error : 1;
- bool nap_error : 1;
- uint8_t res : 5;
- uint8_t protocol_minor : 8;
- uint8_t protocol_major : 8;
- uint8_t res2 : 6;
- bool ext_antenna_short : 1;
- bool ext_antenna : 1;
- };
-
- struct PACKED sbp_gps_time_t {
- uint16_t wn;
- uint32_t tow;
- int32_t ns;
- struct PACKED flags {
- uint8_t time_src:3;
- uint8_t res:5;
- } flags;
- };
-
- struct PACKED sbp_dops_t {
- uint32_t tow;
- uint16_t gdop;
- uint16_t pdop;
- uint16_t tdop;
- uint16_t hdop;
- uint16_t vdop;
- struct PACKED flags {
- uint8_t fix_mode:3;
- uint8_t res:4;
- bool raim_repair:1;
- } flags;
- };
-
- struct PACKED sbp_pos_llh_t {
- uint32_t tow;
- double lat;
- double lon;
- double height;
- uint16_t h_accuracy;
- uint16_t v_accuracy;
- uint8_t n_sats;
- struct PACKED flags {
- uint8_t fix_mode:3;
- uint8_t ins_mode:2;
- uint8_t res:3;
- } flags;
- };
-
- struct PACKED sbp_vel_ned_t {
- uint32_t tow;
- int32_t n;
- int32_t e;
- int32_t d;
- uint16_t h_accuracy;
- uint16_t v_accuracy;
- uint8_t n_sats;
- struct PACKED flags {
- uint8_t vel_mode:3;
- uint8_t ins_mode:2;
- uint8_t res:3;
- } flags;
- };
-
- struct PACKED sbp_ext_event_t {
- uint16_t wn;
- uint32_t tow;
- int32_t ns_residual;
- struct PACKED flags {
- uint8_t level:1;
- uint8_t quality:1;
- uint8_t res:6;
- } flags;
- uint8_t pin;
- };
- void _sbp_process();
- void _sbp_process_message();
- bool _attempt_state_update();
-
-
-
- uint32_t last_heartbeat_received_ms;
- uint32_t last_injected_data_ms;
- struct sbp_heartbeat_t last_heartbeat;
- struct sbp_gps_time_t last_gps_time;
- struct sbp_dops_t last_dops;
- struct sbp_pos_llh_t last_pos_llh;
- struct sbp_vel_ned_t last_vel_ned;
- struct sbp_ext_event_t last_event;
- uint32_t last_full_update_tow;
- uint16_t last_full_update_wn;
-
-
-
- uint32_t crc_error_counter;
-
-
-
- void logging_log_full_update();
- void logging_ext_event();
- void logging_log_raw_sbp(uint16_t msg_type, uint16_t sender_id, uint8_t msg_len, uint8_t *msg_buff);
- int32_t distMod(int32_t tow1_ms, int32_t tow2_ms, int32_t mod);
- };
|