NetworkSocketAPI / C027_Support

Dependents:   C027Interface C027Interface C027_SupportTest

Fork of C027_Support by u-blox

Files at this revision

API Documentation at this revision

Comitter:
mazgch
Date:
Fri Oct 25 17:50:17 2013 +0000
Parent:
3:c7cd4887560d
Child:
5:5362073f2689
Commit message:
small fix

Changed in this revision

GPS.cpp Show annotated file Show diff for this revision Revisions of this file
GPS.h Show annotated file Show diff for this revision Revisions of this file
--- a/GPS.cpp	Fri Oct 25 09:45:55 2013 +0000
+++ b/GPS.cpp	Fri Oct 25 17:50:17 2013 +0000
@@ -35,6 +35,7 @@
     pipe->start();
     if (++ix > len)                     return WAIT;
     if ('$' != pipe->next())            return NOT_FOUND;
+    // this needs to be extended by crc checking 
     for (;;)
     {
         if (++ix > len)                 return WAIT;
@@ -75,6 +76,11 @@
     return o;
 }
 
+int GPSParser::send(const char* buf, int len)
+{
+    return _send(buf, len);
+}
+
 int GPSParser::sendNmea(const char* buf, int len)
 {
     char head[1] = { '$' };
@@ -83,11 +89,11 @@
     int crc = 0;
     for (i = 0; i < len; i ++)
         crc ^= *buf++;
-    i  = send(head, sizeof(head));
-    i += send(buf, len);
+    i  = _send(head, sizeof(head));
+    i += _send(buf, len);
     tail[1] = toHex[(crc > 4) & 0xF0];
     tail[2] = toHex[(crc > 0) & 0x0F];
-    i += send(tail, sizeof(tail));
+    i += _send(tail, sizeof(tail));
     return i;
 }
 
@@ -108,11 +114,11 @@
         ca += ((char*)buf)[i];
         cb += ca;
     }
-    i  = send(head, sizeof(head));
-    i += send(buf, len);
+    i  = _send(head, sizeof(head));
+    i += _send(buf, len);
     crc[0] = ca & 0xFF;
     crc[1] = cb & 0xFF;
-    i += send(crc,  sizeof(crc));
+    i += _send(crc,  sizeof(crc));
     return i;
 }
 
@@ -209,7 +215,7 @@
     return _pipe.next(); 
 }
 
-int GPSSerial::send(const void* buf, int len)   
+int GPSSerial::_send(const void* buf, int len)   
 { 
     for (int i = 0; i < len; i ++)
         putc(((char*)buf)[i]); 
@@ -246,6 +252,19 @@
     return _getMessage(&_pipe, buf, len);   
 }
 
+int GPSI2C::send(const char* buf, int len)
+{
+    int sent = 0;
+    if (len) 
+    {
+        if (!I2C::write(GPSADR,&REGSTREAM,sizeof(REGSTREAM),true))
+            sent = _send(buf, len);
+        found = len == sent;
+        stop();
+    }
+    return sent;
+}
+
 int GPSI2C::sendNmea(const char* buf, int len)
 { 
     int sent = 0;
@@ -298,7 +317,7 @@
     return _pipe.next(); 
 }
 
-int GPSI2C::send(const void* buf, int len)
+int GPSI2C::_send(const void* buf, int len)
 { 
     return !I2C::write(GPSADR,(const char*)buf,len,true) ? len : 0; 
 }
--- a/GPS.h	Fri Oct 25 09:45:55 2013 +0000
+++ b/GPS.h	Fri Oct 25 17:50:17 2013 +0000
@@ -17,8 +17,9 @@
     #define PROTOCOL(x) (x & 0xFF0000)
 
     virtual int getMessage(char* buf, int len) = 0; 
-    virtual int sendNmea(const char* buf, int len) = 0;
-    virtual int sendUbx(unsigned char cls, unsigned char id, const void* buf, int len) = 0;
+    virtual int send(const char* buf, int len);
+    virtual int sendNmea(const char* buf, int len);
+    virtual int sendUbx(unsigned char cls, unsigned char id, const void* buf, int len);
     
     static const char* findNmeaItemPos(int ix, const char* start, const char* end);
     static bool getNmeaItem(int ix, char* buf, int len, double& val);
@@ -28,7 +29,7 @@
     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);
-    virtual int send(const void* buf, int len) = 0;
+    virtual int _send(const void* buf, int len) = 0;
     static const char toHex[16];
 };
 
@@ -42,7 +43,7 @@
 protected:
     void serialRxIrq(void);
     virtual char next(void);
-    virtual int send(const void* buf, int len);
+    virtual int _send(const void* buf, int len);
     Pipe<char> _pipe;
 };
 
@@ -53,11 +54,12 @@
     bool detect(void);
     
     virtual int getMessage(char* buf, int len);
+    virtual int send(const char* buf, int len);
     virtual int sendNmea(const char* buf, int len);
     virtual int sendUbx(unsigned char cls, unsigned char id, const void* buf, int len);
 protected:
     virtual char next(void);
-    virtual int send(const void* buf, int len);
+    virtual int _send(const void* buf, int len);
     int _get(char* buf, int len);                 // read the NMEA or UBX stream
     
     Pipe<char> _pipe;