Simple driver for GNSS functions on BG96 module.

Dependents:   mbed-os-example-cellular-gps-bg96

Note: this is early version

BG96 module needs to be already running to use this. Configuration only inside of this class. (hardcoded values)

Revision:
2:8b0663001935
Parent:
1:c3a5d3a0b437
Child:
3:98d27fc2eed5
--- a/BG96_GNSS.h	Wed Feb 19 16:34:28 2020 +0100
+++ b/BG96_GNSS.h	Tue Mar 03 14:27:09 2020 +0100
@@ -2,6 +2,7 @@
 #define BG96_GNSS_H
 
 #include "mbed.h"
+#include "CellularNonIPSocket.h"
 
 #define SUCCESS 0
 #define FAILURE 1
@@ -9,35 +10,79 @@
 #define BG96_AT_TIMEOUT      1000
 #define BG96_GPS_FIX_TIMEOUT 15000
 
+/* for mode=2 */
 typedef struct gps_data_t {
-    float utc;      // hhmmss.sss
-    float lat;      // latitude. (-)dd.ddddd
-    float lon;      // longitude. (-)dd.ddddd
-    float hdop;     // Horizontal precision: 0.5-99.9
-    float altitude; // altitude of antenna from sea level (meters) 
-    int fix;        // GNSS position mode 2=2D, 3=3D
-    float cog;      // Course Over Ground ddd.mm
-    float spkm;     // Speed over ground (Km/h) xxxx.x
-    float spkn;     // Speed over ground (knots) xxxx.x
-    char date[7];   // data: ddmmyy
-    int nsat;       // number of satellites 0-12
+    // char header[9];    // +QGPSLOC:
+    char utc[20];      // hhmmss.sss
+    char lat[8];       // latitude. (-)dd.ddddd
+    char lon[8];       // longitude. (-)dd.ddddd
+    char hdop[5];      // Horizontal precision: 0.5-99.9
+    char altitude[10];  // altitude of antenna from sea level (meters) 
+    char fix[2];       // GNSS position mode 2=2D, 3=3D
+    char cog[6];       // Course Over Ground ddd.mm
+    char spkm[6];      // Speed over ground (Km/h) xxxx.x
+    char spkn[6];      // Speed over ground (knots) xxxx.x
+    char date[7];      // data: ddmmyy
+    char nsat[2];      // number of satellites 0-12
 } gps_data;
 
 class BG96_GNSS 
 {
 private:
-    ATCmdParser *_parser;
-    UARTSerial  *_serial;
+    ATHandler  *_bg96_at_handler; // taken from CellularInterface
+    ATHandler  *_bg96_instance;
+    EventQueue *_dummy_eventqueue;
+
+    /** Getting instance of BG96 Cellular Interface.
+     *  Needed for not interfering communication using same AThandler as Cellular.
+     *  Note: needs to be closed with _close_instance() after using.
+     *
+     *  @return     SUCCESS if got instance, FAILURE otherwise
+     */
+    uint8_t _get_instance();    
+    
+    /** Closing instance and seting ATHandler to NULL.
+     *
+     *  @return     SUCCESS if closed instance, FAILURE otherwise
+     */
+    uint8_t _close_instance();    
+    
+    /** Reading GPS from BG96 module using AT commands.
+     *
+     *  @param  *data   gps data structure for passing data (gps_data)
+     *  @return         SUCCESS if data read, FAILURE otherwise
+     */
+    uint8_t _read_gps(gps_data *data);
 
 public:
+    /** Constructor.
+     *  Taking CellularInterface default instance.
+     */
     BG96_GNSS();
 
-    /* init methods */
-    int check_if_ready(void);
-    int set_gps_power(bool state);
+    /** Power ON/OFF GPS module on BG96.
+     *  Note: needs to be called before reading GPS data.
+     *
+     *  @param  *state  true for Power ON, false for Power OFF
+     *  @return         SUCCESS if succedded, SUCCESS otherwise
+     */
+    uint8_t set_gps_power(bool state);
+ 
+    /** Send AT commands to GPS module for GPS data.
+     *  Note: Need some time after power ON to fix position.
+     *
+     *  @param  *data   gps data structure for passing data (gps_data)
+     *  @return         SUCCESS if succedded, FAILURE otherwise
+     */
+    uint8_t get_gps_data(gps_data *data);
 
-    /* data acquisition methods */
-    int get_gps_data(gps_data *data);
+    /** Print GPS data structure.
+     *
+     *  @param  *data   gps data structure for passing data (gps_data)
+     */
+    void print_gps_data(gps_data *data);
+
+
 };
 
 #endif /* BG96_GNSS_H */