/*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// Novatel/Tersus/ComNav GPS driver for ArduPilot.16// Code by Michael Oborne17// Derived from https://hexagondownloads.blob.core.windows.net/public/Novatel/assets/Documents/Manuals/om-20000129/om-20000129.pdf1819#pragma once2021#include "AP_GPS.h"22#include "GPS_Backend.h"2324#if AP_GPS_NOVA_ENABLED25class AP_GPS_NOVA : public AP_GPS_Backend26{27public:28AP_GPS_NOVA(AP_GPS &_gps, AP_GPS::Params &_params, AP_GPS::GPS_State &_state, AP_HAL::UARTDriver *_port);2930AP_GPS::GPS_Status highest_supported_status(void) override { return AP_GPS::GPS_OK_FIX_3D_RTK_FIXED; }3132// Methods33bool read() override;3435const char *name() const override { return "NOVA"; }3637private:3839bool parse(uint8_t temp);40bool process_message();4142static const uint8_t NOVA_PREAMBLE1 = 0xaa;43static const uint8_t NOVA_PREAMBLE2 = 0x44;44static const uint8_t NOVA_PREAMBLE3 = 0x12;4546// do we have new position information?47bool _new_position:1;48// do we have new speed information?49bool _new_speed:1;5051uint32_t _last_vel_time;5253uint8_t _init_blob_index = 0;54uint32_t _init_blob_time = 0;55static const char* const _initialisation_blob[4];5657uint32_t crc_error_counter = 0;5859struct PACKED nova_header60{61// 062uint8_t preamble[3];63// 364uint8_t headerlength;65// 466uint16_t messageid;67// 668uint8_t messagetype;69//770uint8_t portaddr;71//872uint16_t messagelength;73//1074uint16_t sequence;75//1276uint8_t idletime;77//1378uint8_t timestatus;79//1480uint16_t week;81//1682uint32_t tow;83//2084uint32_t recvstatus;85// 2486uint16_t resv;87//2688uint16_t recvswver;89};9091static const uint8_t NOVA_PSRDOP = 174;92struct PACKED psrdop93{94float gdop;95float pdop;96float hdop;97float htdop;98float tdop;99float cutoff;100uint32_t svcount;101// extra data for individual prns102};103104static const uint8_t NOVA_BESTPOS = 42;105struct PACKED bestpos106{107uint32_t solstat; ///< Solution status108uint32_t postype; ///< Position type109double lat; ///< latitude (deg)110double lng; ///< longitude (deg)111double hgt; ///< height above mean sea level (m)112float undulation; ///< relationship between the geoid and the ellipsoid (m)113uint32_t datumid; ///< datum id number114float latsdev; ///< latitude standard deviation (m)115float lngsdev; ///< longitude standard deviation (m)116float hgtsdev; ///< height standard deviation (m)117// 4 bytes118uint8_t stnid[4]; ///< base station id119float diffage; ///< differential position age (sec)120float sol_age; ///< solution age (sec)121uint8_t svstracked; ///< number of satellites tracked122uint8_t svsused; ///< number of satellites used in solution123uint8_t svsl1; ///< number of GPS plus GLONASS L1 satellites used in solution124uint8_t svsmultfreq; ///< number of GPS plus GLONASS L2 satellites used in solution125uint8_t resv; ///< reserved126uint8_t extsolstat; ///< extended solution status - OEMV and greater only127uint8_t galbeisigmask;128uint8_t gpsglosigmask;129};130131static const uint8_t NOVA_BESTVEL = 99;132struct PACKED bestvel133{134uint32_t solstat;135uint32_t veltype;136float latency;137float age;138double horspd;139double trkgnd;140// + up141double vertspd;142float resv;143};144145union PACKED msgbuffer {146bestvel bestvelu;147bestpos bestposu;148psrdop psrdopu;149uint8_t bytes[256];150};151152union PACKED msgheader {153nova_header nova_headeru;154uint8_t data[28];155};156157struct PACKED nova_msg_parser158{159enum160{161PREAMBLE1 = 0,162PREAMBLE2,163PREAMBLE3,164HEADERLENGTH,165HEADERDATA,166DATA,167CRC1,168CRC2,169CRC3,170CRC4,171} nova_state;172173msgbuffer data;174uint32_t crc;175msgheader header;176uint16_t read;177} nova_msg;178};179#endif180181182