Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of C027_Support_Plus_Dialing by
Diff: GPS.cpp
- 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,®STREAM,sizeof(REGSTREAM)); + int w = I2C::write(_i2cAdr,®STREAM,sizeof(REGSTREAM)); if (w == 0) found = true; } @@ -284,7 +285,7 @@ int sent = 0; if (len) { - if (!I2C::write(GPSADR,®STREAM,sizeof(REGSTREAM),true)) + if (!I2C::write(_i2cAdr,®STREAM,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,®STREAM,sizeof(REGSTREAM),true)) + if (!I2C::write(_i2cAdr,®STREAM,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,®STREAM,sizeof(REGSTREAM),true)) + if (!I2C::write(_i2cAdr,®STREAM,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,®LEN,sizeof(REGLEN),true) && - !I2C::read(GPSADR,(char*)sz,sizeof(sz),true)) + if (!I2C::write(_i2cAdr,®LEN,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;