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:
74:208e3e32d263
Parent:
46:8ce9169e0747
Child:
75:ce6e12067d0c
--- a/GPS.cpp	Thu May 15 08:25:45 2014 +0000
+++ b/GPS.cpp	Thu May 15 22:20:42 2014 +0000
@@ -1,6 +1,26 @@
 #include "mbed.h"
 #include <ctype.h>
 #include "GPS.h"
+#include "Relax.h"
+#ifdef TARGET_UBLOX_C027
+ #include "C027_api.h"
+#endif
+
+GPSParser::~GPSParser(void) 
+{ 
+    powerOff(); 
+#ifdef TARGET_UBLOX_C027
+    if (_onboard)
+         c027_gps_powerOff();
+#endif
+}
+    
+void GPSParser::powerOff(void)
+{
+    // set the gps into backup mode using the command RMX-LPREQ
+    struct { unsigned long dur; unsigned long flags; } msg = {0/*endless*/,0/*backup*/};
+    sendUbx(0x02, 0x41, &msg, sizeof(msg));
+}
 
 int GPSParser::_getMessage(Pipe<char>* pipe, char* buf, int len)
 {
@@ -104,13 +124,6 @@
     return _send(buf, len);
 }
 
-void GPSParser::powerOff(void)
-{
-    // set the gps into backup mode using the command RMX-LPREQ
-    struct { unsigned long dur; unsigned long flags; } msg = {0/*endless*/,0/*backup*/};
-    sendUbx(0x02, 0x41, &msg, sizeof(msg));
-}
-
 int GPSParser::sendNmea(const char* buf, int len)
 {
     char head[1] = { '$' };
@@ -238,6 +251,26 @@
             SerialPipe(tx, rx, rxSize, txSize)
 {
     baud(baudrate);
+#ifdef TARGET_UBLOX_C027
+    _onboard = (tx == GPSTXD) || (rx == GPSRXD);
+    if (_onboard)
+        c027_gps_powerOn(); 
+#endif
+}
+
+bool GPSSerial::init(void)
+{
+    // send a byte to wakup the device again
+    putc(0);
+    // wait until we get some bytes
+    int size = _pipeRx.size();
+    int i = 30;
+    while (i--) {
+        RELAX_MS(10);
+        if(size != _pipeRx.size())
+            break;
+    }   
+    return (i >= 0);
 }
 
 int GPSSerial::getMessage(char* buf, int len)
@@ -261,18 +294,20 @@
             _i2cAdr(i2cAdr)
 {
     frequency(100000);
-    found = false;
+#ifdef TARGET_UBLOX_C027
+    _onboard = (sda == GPSSDA) && (scl == GPSSCL);
+    if (_onboard)
+        c027_gps_powerOn(); 
+#endif
 }
 
-bool GPSI2C::detect(void)
+bool GPSI2C::init(void)
 {
-    if (!found)
-    {
-        int w = I2C::write(_i2cAdr,&REGSTREAM,sizeof(REGSTREAM));
-        if (w == 0)
-            found = true;
-    }
-    return found;
+    DigitalOut pin(GPSINT, 0);
+    wait_us(1);
+    pin = 1;
+    RELAX_MS(100);
+    return !I2C::write(_i2cAdr,&REGSTREAM,sizeof(REGSTREAM));
 }
 
 int GPSI2C::getMessage(char* buf, int len)
@@ -294,7 +329,6 @@
     {
         if (!I2C::write(_i2cAdr,&REGSTREAM,sizeof(REGSTREAM),true))
             sent = send(buf, len);
-        found = (len == sent);
         stop();
     }
     return sent;
@@ -305,7 +339,6 @@
     int sent = 0;
     if (!I2C::write(_i2cAdr,&REGSTREAM,sizeof(REGSTREAM),true))
         sent = GPSParser::sendNmea(buf, len);
-    found = (len == sent);
     stop();
     return sent;
 }
@@ -315,7 +348,6 @@
     int sent = 0;
     if (!I2C::write(_i2cAdr,&REGSTREAM,sizeof(REGSTREAM),true))
         sent = GPSParser::sendUbx(cls, id, buf, len);
-    found = (len == sent);
     I2C::stop();
     return sent;
 }
@@ -336,12 +368,8 @@
                 !I2C::read(_i2cAdr,buf,size)) {
                 read = size;
             }
-            else 
-                found = false;
         }
     }
-    else 
-        found = false;
     return read;
 }