This class provides an API to communicate with a u-blox GNSS chip. The files here were originally part of the C027_Support library (https://developer.mbed.org/teams/ublox/code/C027_Support/ at revision 138:dafbbf31bf76) but have been separated out, primarily for use on the u-blox C030 board where the cellular interace portion of the C027_Support library will instead be provided through the new mbed Cellular API.

Dependents:   example-ublox-at-cellular-interface-ext example-low-power-sleep example-C030-out-of-box-demo example-C030-out-of-box-demo ... more

Revision:
33:75163fa7e453
Parent:
30:de9fcdbc4d06
--- a/gnss.h	Wed Apr 24 17:55:48 2019 +0500
+++ b/gnss.h	Wed May 29 16:45:00 2019 +0500
@@ -53,68 +53,68 @@
 enum eUBX_MESSAGE  {UBX_LOG_BATCH, UBX_ACK_ACK, UBX_ACK_NAK, UBX_NAV_ODO, UBX_NAV_PVT, UBX_NAV_STATUS, UBX_NAV_SAT, UNKNOWN_UBX};
 
 typedef struct UBX_ACK_ACK {
-	uint8_t msg_class;
-	uint8_t msg_id;
+    uint8_t msg_class;
+    uint8_t msg_id;
 
-}tUBX_ACK_ACK;
+} tUBX_ACK_ACK;
 
 typedef struct UBX_NAV_ODO {
-	uint8_t version;
-	uint8_t reserved[3];
-	uint32_t itow;
-	uint32_t distance;
-	uint32_t totalDistance;
-	uint32_t distanceSTD;
-}tUBX_NAV_ODO;
+    uint8_t version;
+    uint8_t reserved[3];
+    uint32_t itow;
+    uint32_t distance;
+    uint32_t totalDistance;
+    uint32_t distanceSTD;
+} tUBX_NAV_ODO;
 
 typedef struct UBX_NAV_PVT {
-	uint32_t itow;
-	uint16_t year;
-	uint8_t month;
-	uint8_t day;
-	uint8_t fixType;
+    uint32_t itow;
+    uint16_t year;
+    uint8_t month;
+    uint8_t day;
+    uint8_t fixType;
     uint8_t flag1; // gnssFixOK, diffSoln, psmState, headVehValid and carrSoln.
-	int32_t lon; // scaling 1e-7
-	int32_t lat; // scaling 1e-7
-	int32_t height;
-	int32_t speed;
+    int32_t lon; // scaling 1e-7
+    int32_t lat; // scaling 1e-7
+    int32_t height;
+    int32_t speed;
 
-}tUBX_NAV_PVT;
+} tUBX_NAV_PVT;
 
 typedef struct UBX_LOG_BATCH {
-	uint32_t itow;
-	int32_t lon; // scaling 1e-7
-	int32_t lat; // scaling 1e-7
-	int32_t height;
-	uint32_t distance;
-	uint32_t totalDistance;
-	uint32_t distanceSTD;
+    uint32_t itow;
+    int32_t lon; // scaling 1e-7
+    int32_t lat; // scaling 1e-7
+    int32_t height;
+    uint32_t distance;
+    uint32_t totalDistance;
+    uint32_t distanceSTD;
 
-}tUBX_LOG_BATCH;
+} tUBX_LOG_BATCH;
 
 typedef struct UBX_CFG_BATCH {
-	uint32_t version;
-	uint8_t flags;
-	uint32_t bufSize;
-	uint32_t notifThrs;
-	uint8_t pioId;
-	uint8_t reserved1;
+    uint32_t version;
+    uint8_t flags;
+    uint32_t bufSize;
+    uint32_t notifThrs;
+    uint8_t pioId;
+    uint8_t reserved1;
 
-}tUBX_CFG_BATCH;
+} tUBX_CFG_BATCH;
 
-typedef struct UBX_NAV_STATUS{
-	uint32_t itow;
-	uint8_t fix;
-	uint8_t flags;
-	uint32_t ttff;
-	uint32_t msss;
+typedef struct UBX_NAV_STATUS {
+    uint32_t itow;
+    uint8_t fix;
+    uint8_t flags;
+    uint32_t ttff;
+    uint32_t msss;
 
-}tUBX_NAV_STATUS;
+} tUBX_NAV_STATUS;
 
-typedef struct UBX_NAV_SAT{
-	bool status;
+typedef struct UBX_NAV_SAT {
+    bool status;
 
-}tUBX_NAV_SAT;
+} tUBX_NAV_SAT;
 
 /** Basic GNSS parser class.
 */
@@ -131,45 +131,45 @@
     /** Power-on/wake-up the GNSS.
     */
     virtual bool init(PinName pn) = 0;
-    
-    enum { 
+
+    enum {
         // getLine Responses
         WAIT      = -1, //!< wait for more incoming data (the start of a message was found, or no data available)
         NOT_FOUND =  0, //!< a parser concluded the the current offset of the pipe doe not contain a valid message
-    
-        #define LENGTH(x)   (x & 0x00FFFF)  //!< extract/mask the length
-        #define PROTOCOL(x) (x & 0xFF0000)  //!< extract/mask the type
 
-        UNKNOWN   = 0x000000,       //!< message type is unknown 
+#define LENGTH(x)   (x & 0x00FFFF)  //!< extract/mask the length
+#define PROTOCOL(x) (x & 0xFF0000)  //!< extract/mask the type
+
+        UNKNOWN   = 0x000000,       //!< message type is unknown
         UBX       = 0x100000,       //!< message if of protocol NMEA
         NMEA      = 0x200000        //!< message if of protocol UBX
     };
-    
+
     /** Get a line from the physical interface. This function
      * needs to be implemented in the inherited class.
      * @param buf the buffer to store it.
      * @param len size of the buffer.
-     * @return type and length if something was found, 
+     * @return type and length if something was found,
      *         WAIT if not enough data is available,
      *         NOT_FOUND if nothing was found
-     */ 
+     */
     virtual int getMessage(char* buf, int len) = 0;
-    
+
     /** Send a buffer.
      * @param buf the buffer to write.
      * @param len size of the buffer to write.
      * @return bytes written.
      */
     virtual int send(const char* buf, int len);
-    
-    /** send a NMEA message, this function just takes the 
+
+    /** send a NMEA message, this function just takes the
      * payload and calculates and adds checksum. ($ and *XX\r\n will be added).
      * @param buf the message payload to write.
      * @param len size of the message payload to write.
      * @return total bytes written.
      */
     virtual int sendNmea(const char* buf, int len);
-    
+
     /** Send a UBX message, this function just takes the
      * payload and calculates and adds checksum.
      * @param cls the UBX class id.
@@ -178,27 +178,27 @@
      * @param len size of the message payload to write.
      * @return total bytes written.
      */
-    virtual int sendUbx(unsigned char cls, unsigned char id, 
+    virtual int sendUbx(unsigned char cls, unsigned char id,
                         const void* buf = NULL, int len = 0);
-    
+
     /** Power off the GNSS, it can be again woken up by an
-     * edge on the serial port on the external interrupt pin. 
+     * edge on the serial port on the external interrupt pin.
     */
     void powerOff(void);
-	
-	/** Cuts off the power supply of GNSS by disabling gnssEnable pin
-	* 	Backup supply is provided, can turn it on again by enabling PA15
-	*/
+
+    /** Cuts off the power supply of GNSS by disabling gnssEnable pin
+    * 	Backup supply is provided, can turn it on again by enabling PA15
+    */
     void cutOffPower(void);
-    
+
     /** get the first character of a NMEA field.
      * @param ix the index of the field to find.
      * @param start the start of the buffer.
      * @param end the end of the buffer.
-     * @return the pointer to the first character of the field. 
+     * @return the pointer to the first character of the field.
      */
     static const char* findNmeaItemPos(int ix, const char* start, const char* end);
-    
+
     /** Extract a double value from a buffer containing a NMEA message.
      * @param ix the index of the field to extract.
      * @param buf the NMEA message.
@@ -207,7 +207,7 @@
      * @return true if successful, false otherwise.
      */
     static bool getNmeaItem(int ix, char* buf, int len, double& val);
-    
+
     /** Extract a interger value from a buffer containing a NMEA message.
      * @param ix the index of the field to extract.
      * @param buf the NMEA message.
@@ -217,7 +217,7 @@
      * @return true if successful, false otherwise.
      */
     static bool getNmeaItem(int ix, char* buf, int len, int& val, int base/*=10*/);
-    
+
     /** Extract a char value from a buffer containing a NMEA message.
      * @param ix the index of the field to extract.
      * @param buf the NMEA message.
@@ -226,7 +226,7 @@
      * @return true if successful, false otherwise.
      */
     static bool getNmeaItem(int ix, char* buf, int len, char& val);
-    
+
     /** Extract a latitude/longitude value from a buffer containing a NMEA message.
      * @param ix the index of the field to extract (will extract ix and ix + 1),
      * @param buf the NMEA message,
@@ -237,11 +237,11 @@
     static bool getNmeaAngle(int ix, char* buf, int len, double& val);
 
     /** Enable UBX messages.
-	 * @param none
-	 * @return 1 if successful, false otherwise.
-	 */
+     * @param none
+     * @return 1 if successful, false otherwise.
+     */
     int enable_ubx();
-    
+
     /** GET Message type of receiver UBX message
      * @param buff the UXB message
      * @return eUBX_MESSAGE
@@ -261,33 +261,33 @@
     tUBX_NAV_ODO decode_ubx_nav_odo_msg(char *);
 
     /** Method to parse contents of UBX_NAV_PVT and return decoded msg
-	 * @param buff the UXB message
-	 * @return tUBX_NAV_PVT
-	 */
+     * @param buff the UXB message
+     * @return tUBX_NAV_PVT
+     */
     tUBX_NAV_PVT decode_ubx_nav_pvt_msg(char *);
 
     /** Method to parse contents of UBX_LOG_BATCH and return decoded msg
-	 * @param buff the UXB message
-	 * @return tUBX_LOG_BATCH
-	 */
+     * @param buff the UXB message
+     * @return tUBX_LOG_BATCH
+     */
     tUBX_LOG_BATCH decode_ubx_log_batch_msg(char *);
 
     /** Method to parse contents of UBX_NAV_STATUS and return decoded msg
-	 * @param buff the UXB message
-	 * @return tUBX_NAV_STATUS
-	 */
+     * @param buff the UXB message
+     * @return tUBX_NAV_STATUS
+     */
     tUBX_NAV_STATUS decode_ubx_nav_status_msg(char *);
 
     /** Method to parse contents of UBX_NAV_SAT and return decoded msg
-	 * @param buff the UXB message, int length
-	 * @return tUBX_NAV_SAT
-	 */
+     * @param buff the UXB message, int length
+     * @return tUBX_NAV_SAT
+     */
     tUBX_NAV_SAT decode_ubx_nav_sat_msg(char *, int);
 
     /** Method to send UBX LOG-RETRIEVEBATCH msg. This message is used to request batched data.
-	 * @param bool
-	 * @return int
-	 */
+     * @param bool
+     * @return int
+     */
     int ubx_request_batched_data(bool sendMonFirst = false);
 
 protected:
@@ -299,43 +299,43 @@
      * @param pipe the receiveing pipe to parse messages .
      * @param buf the buffer to store it.
      * @param len size of the buffer.
-     * @return type and length if something was found, 
+     * @return type and length if something was found,
      *         WAIT if not enough data is available,
      *         NOT_FOUND if nothing was found.
-     */ 
+     */
     static int _getMessage(Pipe<char>* pipe, char* buf, int len);
-    
+
     /** Check if the current offset of the pipe contains a NMEA message.
      * @param pipe the receiveing pipe to parse messages.
      * @param len numer of bytes to parse at maximum.
      * @return length if something was found (including the NMEA frame),
      *         WAIT if not enough data is available,
      *         NOT_FOUND if nothing was found.
-     */ 
+     */
     static int _parseNmea(Pipe<char>* pipe, int len);
-    
+
     /** Check if the current offset of the pipe contains a UBX message.
      * @param pipe the receiveing pipe to parse messages.
      * @param len numer of bytes to parse at maximum.
      * @return length if something was found (including the UBX frame),
      *         WAIT if not enough data is available,
      *         NOT_FOUND if nothing was found.
-     */ 
+     */
     static int _parseUbx(Pipe<char>* pipe, int len);
-    
-    /** Write bytes to the physical interface. This function 
-     * needs to be implemented by the inherited class. 
+
+    /** Write bytes to the physical interface. This function
+     * needs to be implemented by the inherited class.
      * @param buf the buffer to write.
      * @param len size of the buffer to write.
      * @return bytes written.
      */
     virtual int _send(const void* buf, int len) = 0;
-    
+
     static const char _toHex[16]; //!< num to hex conversion
     DigitalInOut *_gnssEnable;    //!< IO pin that enables GNSS
 };
 
-/** GNSS class which uses a serial port as physical interface. 
+/** GNSS class which uses a serial port as physical interface.
  */
 class GnssSerial : public SerialPipe, public GnssParser
 {
@@ -350,29 +350,29 @@
     GnssSerial(PinName tx    GNSS_IF( = GNSSTXD, = D8 /* = D8 */), // resistor on shield not populated
                PinName rx    GNSS_IF( = GNSSRXD, = D9 /* = D9 */), // resistor on shield not populated
                int baudrate  GNSS_IF( = GNSSBAUD, = 9600 ),
-               int rxSize    = 512 ,
+               int rxSize    = 512,
                int txSize    = 512 );
-              
+
     /** Destructor.
      */
     virtual ~GnssSerial(void);
-    
+
     /** Initialise the GNSS device.
      * @param pn  NOT USED.
      * @param baudrate
      * @return true if successful, otherwise false.
      */
     virtual bool init(PinName pn = NC);
-    
-    /** Get a line from the physical interface. 
+
+    /** Get a line from the physical interface.
      * @param buf the buffer to store it.
      * @param len size of the buffer.
-     * @return type and length if something was found, 
+     * @return type and length if something was found,
      *         WAIT if not enough data is available,
      *         NOT_FOUND if nothing was found.
-     */ 
+     */
     virtual int getMessage(char* buf, int len);
-    
+
 protected:
     /** Write bytes to the physical interface.
      * @param buf the buffer to write.
@@ -386,7 +386,7 @@
 */
 class GnssI2C : public I2C, public GnssParser
 {
-public: 
+public:
     /** Constructor.
      * @param sda is the I2C SDA pin (between CPU and GNSS).
      * @param scl is the I2C SCL pin (CPU to GNSS).
@@ -400,38 +400,38 @@
     /** Destructor
      */
     virtual ~GnssI2C(void);
-    
+
     /** Helper function to probe the i2c device.
      * @param pn  the power-on pin for the chip.
      * @return true if successfully detected the GNSS chip.
-     */ 
+     */
     virtual bool init(PinName pn = GNSS_IF( NC, NC /* D7 resistor R67 on shield not mounted */));
-    
-    /** Get a line from the physical interface. 
+
+    /** Get a line from the physical interface.
      * @param buf the buffer to store it.
      * @param len size of the buffer.
-     * @return type and length if something was found, 
+     * @return type and length if something was found,
      *         WAIT if not enough data is available,
      *         NOT_FOUND if nothing was found.
-     */ 
+     */
     virtual int getMessage(char* buf, int len);
-    
+
     /** Send a buffer.
      *  @param buf the buffer to write.
      *  @param len size of the buffer to write.
      *  @return bytes written.
      */
     virtual int send(const char* buf, int len);
-    
-    /** Send an NMEA message, this function just takes the 
+
+    /** Send an NMEA message, this function just takes the
      * payload and calculates and adds checksum ($ and *XX\r\n will be added).
      * @param buf the message payload to write.
      * @param len size of the message payload to write.
      * @return total bytes written.
      */
     virtual int sendNmea(const char* buf, int len);
-    
-    /** Send a UBX message, this function just takes the 
+
+    /** Send a UBX message, this function just takes the
      * payload and calculates and adds checksum.
      * @param cls the UBX class id.
      * @param id the UBX message id.
@@ -439,35 +439,40 @@
      * @param len size of the message payload to write.
      * @return total bytes written.
      */
-    virtual int sendUbx(unsigned char cls, unsigned char id, 
+    virtual int sendUbx(unsigned char cls, unsigned char id,
                         const void* buf = NULL, int len = 0);
-                        
+
 protected:
     /** Check if the port is writeable (like SerialPipe)
-     * @return true if writeable        
+     * @return true if writeable
      */
-    bool writeable(void) {return true;}
-    
+    bool writeable(void) {
+        return true;
+    }
+
     /** Write a character (like SerialPipe).
      * @param c  the character to write.
      * @return true if succesffully written .
      */
-    bool putc(int c) {char ch = c; return send(&ch, 1);}
-    
+    bool putc(int c) {
+        char ch = c;
+        return send(&ch, 1);
+    }
+
     /** Write bytes to the physical interface.
      * @param buf the buffer to write.
      * @param len size of the buffer to write.
      * @return bytes written.
      */
     virtual int _send(const void* buf, int len);
-    
+
     /** Read bytes from the physical interface.
      * @param buf the buffer to read into.
      * @param len size of the read buffer .
      * @return bytes read.
      */
     int _get(char* buf, int len);
-    
+
     Pipe<char> _pipe;           //!< the rx pipe.
     unsigned char _i2cAdr;      //!< the i2c address.
     static const char REGLEN;   //!< the length i2c register address.