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)

Committer:
Pawel Zarembski
Date:
Tue Mar 03 14:27:09 2020 +0100
Revision:
2:8b0663001935
Parent:
1:c3a5d3a0b437
Child:
3:98d27fc2eed5
redo for interfacing with cellular device, without blocking

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pawel Zarembski 0:6a2a480672be 1 #ifndef BG96_GNSS_H
Pawel Zarembski 0:6a2a480672be 2 #define BG96_GNSS_H
Pawel Zarembski 0:6a2a480672be 3
Pawel Zarembski 0:6a2a480672be 4 #include "mbed.h"
Pawel Zarembski 2:8b0663001935 5 #include "CellularNonIPSocket.h"
Pawel Zarembski 0:6a2a480672be 6
Pawel Zarembski 0:6a2a480672be 7 #define SUCCESS 0
Pawel Zarembski 0:6a2a480672be 8 #define FAILURE 1
Pawel Zarembski 0:6a2a480672be 9
Pawel Zarembski 1:c3a5d3a0b437 10 #define BG96_AT_TIMEOUT 1000
Pawel Zarembski 1:c3a5d3a0b437 11 #define BG96_GPS_FIX_TIMEOUT 15000
Pawel Zarembski 1:c3a5d3a0b437 12
Pawel Zarembski 2:8b0663001935 13 /* for mode=2 */
Pawel Zarembski 1:c3a5d3a0b437 14 typedef struct gps_data_t {
Pawel Zarembski 2:8b0663001935 15 // char header[9]; // +QGPSLOC:
Pawel Zarembski 2:8b0663001935 16 char utc[20]; // hhmmss.sss
Pawel Zarembski 2:8b0663001935 17 char lat[8]; // latitude. (-)dd.ddddd
Pawel Zarembski 2:8b0663001935 18 char lon[8]; // longitude. (-)dd.ddddd
Pawel Zarembski 2:8b0663001935 19 char hdop[5]; // Horizontal precision: 0.5-99.9
Pawel Zarembski 2:8b0663001935 20 char altitude[10]; // altitude of antenna from sea level (meters)
Pawel Zarembski 2:8b0663001935 21 char fix[2]; // GNSS position mode 2=2D, 3=3D
Pawel Zarembski 2:8b0663001935 22 char cog[6]; // Course Over Ground ddd.mm
Pawel Zarembski 2:8b0663001935 23 char spkm[6]; // Speed over ground (Km/h) xxxx.x
Pawel Zarembski 2:8b0663001935 24 char spkn[6]; // Speed over ground (knots) xxxx.x
Pawel Zarembski 2:8b0663001935 25 char date[7]; // data: ddmmyy
Pawel Zarembski 2:8b0663001935 26 char nsat[2]; // number of satellites 0-12
Pawel Zarembski 1:c3a5d3a0b437 27 } gps_data;
Pawel Zarembski 0:6a2a480672be 28
Pawel Zarembski 0:6a2a480672be 29 class BG96_GNSS
Pawel Zarembski 0:6a2a480672be 30 {
Pawel Zarembski 1:c3a5d3a0b437 31 private:
Pawel Zarembski 2:8b0663001935 32 ATHandler *_bg96_at_handler; // taken from CellularInterface
Pawel Zarembski 2:8b0663001935 33 ATHandler *_bg96_instance;
Pawel Zarembski 2:8b0663001935 34 EventQueue *_dummy_eventqueue;
Pawel Zarembski 2:8b0663001935 35
Pawel Zarembski 2:8b0663001935 36 /** Getting instance of BG96 Cellular Interface.
Pawel Zarembski 2:8b0663001935 37 * Needed for not interfering communication using same AThandler as Cellular.
Pawel Zarembski 2:8b0663001935 38 * Note: needs to be closed with _close_instance() after using.
Pawel Zarembski 2:8b0663001935 39 *
Pawel Zarembski 2:8b0663001935 40 * @return SUCCESS if got instance, FAILURE otherwise
Pawel Zarembski 2:8b0663001935 41 */
Pawel Zarembski 2:8b0663001935 42 uint8_t _get_instance();
Pawel Zarembski 2:8b0663001935 43
Pawel Zarembski 2:8b0663001935 44 /** Closing instance and seting ATHandler to NULL.
Pawel Zarembski 2:8b0663001935 45 *
Pawel Zarembski 2:8b0663001935 46 * @return SUCCESS if closed instance, FAILURE otherwise
Pawel Zarembski 2:8b0663001935 47 */
Pawel Zarembski 2:8b0663001935 48 uint8_t _close_instance();
Pawel Zarembski 2:8b0663001935 49
Pawel Zarembski 2:8b0663001935 50 /** Reading GPS from BG96 module using AT commands.
Pawel Zarembski 2:8b0663001935 51 *
Pawel Zarembski 2:8b0663001935 52 * @param *data gps data structure for passing data (gps_data)
Pawel Zarembski 2:8b0663001935 53 * @return SUCCESS if data read, FAILURE otherwise
Pawel Zarembski 2:8b0663001935 54 */
Pawel Zarembski 2:8b0663001935 55 uint8_t _read_gps(gps_data *data);
Pawel Zarembski 1:c3a5d3a0b437 56
Pawel Zarembski 0:6a2a480672be 57 public:
Pawel Zarembski 2:8b0663001935 58 /** Constructor.
Pawel Zarembski 2:8b0663001935 59 * Taking CellularInterface default instance.
Pawel Zarembski 2:8b0663001935 60 */
Pawel Zarembski 1:c3a5d3a0b437 61 BG96_GNSS();
Pawel Zarembski 0:6a2a480672be 62
Pawel Zarembski 2:8b0663001935 63 /** Power ON/OFF GPS module on BG96.
Pawel Zarembski 2:8b0663001935 64 * Note: needs to be called before reading GPS data.
Pawel Zarembski 2:8b0663001935 65 *
Pawel Zarembski 2:8b0663001935 66 * @param *state true for Power ON, false for Power OFF
Pawel Zarembski 2:8b0663001935 67 * @return SUCCESS if succedded, SUCCESS otherwise
Pawel Zarembski 2:8b0663001935 68 */
Pawel Zarembski 2:8b0663001935 69 uint8_t set_gps_power(bool state);
Pawel Zarembski 2:8b0663001935 70
Pawel Zarembski 2:8b0663001935 71 /** Send AT commands to GPS module for GPS data.
Pawel Zarembski 2:8b0663001935 72 * Note: Need some time after power ON to fix position.
Pawel Zarembski 2:8b0663001935 73 *
Pawel Zarembski 2:8b0663001935 74 * @param *data gps data structure for passing data (gps_data)
Pawel Zarembski 2:8b0663001935 75 * @return SUCCESS if succedded, FAILURE otherwise
Pawel Zarembski 2:8b0663001935 76 */
Pawel Zarembski 2:8b0663001935 77 uint8_t get_gps_data(gps_data *data);
Pawel Zarembski 0:6a2a480672be 78
Pawel Zarembski 2:8b0663001935 79 /** Print GPS data structure.
Pawel Zarembski 2:8b0663001935 80 *
Pawel Zarembski 2:8b0663001935 81 * @param *data gps data structure for passing data (gps_data)
Pawel Zarembski 2:8b0663001935 82 */
Pawel Zarembski 2:8b0663001935 83 void print_gps_data(gps_data *data);
Pawel Zarembski 2:8b0663001935 84
Pawel Zarembski 2:8b0663001935 85
Pawel Zarembski 1:c3a5d3a0b437 86 };
Pawel Zarembski 0:6a2a480672be 87
Pawel Zarembski 1:c3a5d3a0b437 88 #endif /* BG96_GNSS_H */