C027_SupportTest_xively_locationで使用しているC027用ライブラリ

Fork of C027_Support by u-blox

下記のプログラムC027_SupportTest_xively_locationで使用しているC027用ライブラリです。

Import programC027_SupportTest_xively_location

インターフェース2014年10月号のu-blox C027で3G通信する記事で使用したプログラム。   CQ publishing Interface 2014.10 issue, C027 3G test program.

オリジナルのライブラリは下記を参照してください。

Import libraryC027_Support

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.

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;
 }