Own fork of C027_Support

Dependents:   MbedSmartRestMain MbedSmartRestMain

Fork of C027_Support by u-blox

Revision:
19:2b5d097ca15d
Parent:
18:e5697801df29
Child:
21:c4d64830bf02
diff -r e5697801df29 -r 2b5d097ca15d GPS.cpp
--- a/GPS.cpp	Fri Mar 14 13:07:48 2014 +0000
+++ b/GPS.cpp	Mon Mar 24 07:38:05 2014 +0000
@@ -206,12 +206,12 @@
 bool GPSParser::getNmeaAngle(int ix, char* buf, int len, double& d)
 {
     char ch;
-    char val;
+    double val;
     if (getNmeaItem(ix,buf,len,val) && getNmeaItem(ix+1,buf,len,ch) && 
         ((ch == 'S') || (ch == 'N') || (ch == 'E') || (ch == 'W')))
     {
         val *= 0.01;
-        int i = (int)d;
+        int i = (int)val;
         val = (val - i) / 0.6 + i;
         if (ch == 'S' || ch == 'W')
             val = -val;
@@ -249,9 +249,10 @@
 // ----------------------------------------------------------------
 
 GPSI2C::GPSI2C(PinName sda /*= GPSSDA*/, PinName scl /*= GPSSCL*/,
-            int rxSize /*= 256*/) : 
+            unsigned char i2cAdr /*=GPSADR*/, int rxSize /*= 256*/) : 
             I2C(sda,scl),
-            _pipe(rxSize)
+            _pipe(rxSize),
+            _i2cAdr(i2cAdr)
 {
     found = false;
 }
@@ -260,7 +261,7 @@
 {
     if (!found)
     {
-        int w = I2C::write(GPSADR,&REGSTREAM,sizeof(REGSTREAM));
+        int w = I2C::write(_i2cAdr,&REGSTREAM,sizeof(REGSTREAM));
         if (w == 0)
             found = true;
     }
@@ -284,7 +285,7 @@
     int sent = 0;
     if (len) 
     {
-        if (!I2C::write(GPSADR,&REGSTREAM,sizeof(REGSTREAM),true))
+        if (!I2C::write(_i2cAdr,&REGSTREAM,sizeof(REGSTREAM),true))
             sent = send(buf, len);
         found = (len == sent);
         stop();
@@ -295,7 +296,7 @@
 int GPSI2C::sendNmea(const char* buf, int len)
 { 
     int sent = 0;
-    if (!I2C::write(GPSADR,&REGSTREAM,sizeof(REGSTREAM),true))
+    if (!I2C::write(_i2cAdr,&REGSTREAM,sizeof(REGSTREAM),true))
         sent = GPSParser::sendNmea(buf, len);
     found = (len == sent);
     stop();
@@ -305,7 +306,7 @@
 int GPSI2C::sendUbx(unsigned char cls, unsigned char id, const void* buf, int len)
 { 
     int sent = 0;
-    if (!I2C::write(GPSADR,&REGSTREAM,sizeof(REGSTREAM),true))
+    if (!I2C::write(_i2cAdr,&REGSTREAM,sizeof(REGSTREAM),true))
         sent = GPSParser::sendUbx(cls, id, buf, len);
     found = (len == sent);
     I2C::stop();
@@ -316,14 +317,14 @@
 {
     int read = 0;
     unsigned char sz[2];
-    if (!I2C::write(GPSADR,&REGLEN,sizeof(REGLEN),true) && 
-        !I2C::read(GPSADR,(char*)sz,sizeof(sz),true))
+    if (!I2C::write(_i2cAdr,&REGLEN,sizeof(REGLEN),true) && 
+        !I2C::read(_i2cAdr,(char*)sz,sizeof(sz),true))
     {
         int size = 256 * (int)sz[0] + sz[1];
         if (size > len)
             size = len;
         if (size > 0)
-            read = !I2C::read(GPSADR,buf,size, true) ? size : 0;
+            read = !I2C::read(_i2cAdr,buf,size, true) ? size : 0;
         found = (read == size);
     }
     else 
@@ -334,7 +335,7 @@
 
 int GPSI2C::_send(const void* buf, int len)
 { 
-    return !I2C::write(GPSADR,(const char*)buf,len,true) ? len : 0; 
+    return !I2C::write(_i2cAdr,(const char*)buf,len,true) ? len : 0; 
 }
 
 const char GPSI2C::REGLEN    = 0xFD;