support library for C027 helper functions for Buffer Pipes, Buffered Serial Port (rtos capable) and GPS parsing. It includes modem APIs for USSD, SMS and Sockets.

Dependents:   HTTPClient_Cellular_HelloWorld Cellular_HelloMQTT MbedSmartRestMain Car_Bon_car_module ... more

This library is intended to be used with u-blox products such as the C027 or a shield with u-blox cellular and GPS modules like the cellular and positioning shield from Embedded Artist.

For 2G/GSM and 3G/UMTS you need to:

  • have a SIM card and know its PIN number
  • need to know you network operators APN setting These setting should be passed to the connect or init and join functions. You can also extend the APN database in MDMAPN.h.

For CDMA products you need to make sure that you have provisioned and activated the modem with either Sprint or Verizon.

Revision:
2:b6012cd91657
Parent:
1:f41579f4e2ed
Child:
3:c7cd4887560d
--- a/GPS.h	Mon Oct 21 19:46:34 2013 +0000
+++ b/GPS.h	Fri Oct 25 08:47:22 2013 +0000
@@ -1,12 +1,74 @@
 #pragma once 
 
+#include "mbed.h"
+#include "Pipe.h"
 #include "SerialPipe.h"
+#include "C027_PinNames.h"
+
+class GPSParser
+{
+public:
+    #define WAIT      -1
+    #define NOT_FOUND  0
+    
+    #define UBX         0x100000
+    #define NMEA        0x200000
+    #define LENGTH(x)   (x & 0x00FFFF)
+    #define PROTOCOL(x) (x & 0xFF0000)
 
-class GPS : public SerialPipe
+    virtual int getMessage(char* buf, int len) = 0; 
+    virtual int putNmea(const char* buf, int len) = 0;
+    virtual int putUbx(const unsigned char cls, unsigned char id, unsigned char* buf, int len) = 0;
+    
+    static const char* findNmeaItemPos(int ix, const char* start, const char* end);
+    static bool getNmeaItem(int ix, char* buf, int len, double& val);
+    static bool getNmeaItem(int ix, char* buf, int len, int& val, int base/*=10*/);
+    static bool getNmeaItem(int ix, char* buf, int len, char& val);
+protected:
+    static int _getMessage(Pipe<char>* pipe, char* buf, int len);
+    static int _parseNmea(Pipe<char>* pipe, int len);
+    static int _parseUbx(Pipe<char>* pipe, int len);
+    static int _putNmea(Stream* stream, const char* buf, int len);
+    static int _putUbx(Stream* stream, const unsigned char cls, unsigned char id, unsigned char* buf, int len);
+    static const char toHex[16];
+};
+
+class GPSSerial : public Serial, public GPSParser
 {
 public:
-    GPS() : SerialPipe(GPSTXD, GPSRXD, 256, "gps")
-    {
-        baud(GPSBAUD);
-    }
+    GPSSerial(PinName tx = GPSTXD, PinName rx = GPSRXD, int baudrate = GPSBAUD);
+    virtual ~GPSSerial(void);
+    
+    virtual int getMessage(char* buf, int len);
+    virtual int putNmea(const char* buf, int len)
+        { return _putNmea(this, buf, len); }
+    virtual int putUbx(const unsigned char cls, unsigned char id, unsigned char* buf, int len)
+        { return _putUbx(this, cls, id, buf, len); }
+protected:
+    void serialRxIrq(void);
+    virtual char next(void) { return _pipe.next(); }
+    Pipe<char> _pipe;
 };
+
+class GPSI2C : public I2C, public GPSParser
+{
+public: 
+    GPSI2C(PinName sda = GPSSDA, PinName scl = GPSSCL);
+    bool detect(void);
+    
+    virtual int getMessage(char* buf, int len);
+    // 
+    virtual int putNmea(const char* buf, int len)
+        { return 0/*_putNmea(NULL, buf, len)*/; }
+    virtual int putUbx(const unsigned char cls, unsigned char id, unsigned char* buf, int len)
+        { return 0/*_putUbx(NULL, cls, id, buf, len)*/; }
+protected:
+    virtual char next(void) { return _pipe.next(); }
+    int _get(char* buf, int len);          // read the NMEA or UBX stream
+    int _put(const char* buf, int len);    // Write the NMEA or UBX stream
+
+    Pipe<char> _pipe; 
+    bool found;
+    static const char REGLEN;
+    static const char REGSTREAM;
+};