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.
Dependents: C027Interface C027Interface C027_SupportTest
Fork of C027_Support by
Diff: GPS.cpp
- Revision:
- 74:208e3e32d263
- Parent:
- 46:8ce9169e0747
- Child:
- 75:ce6e12067d0c
diff -r 2b32e0a21df2 -r 208e3e32d263 GPS.cpp
--- 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,®STREAM,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,®STREAM,sizeof(REGSTREAM));
}
int GPSI2C::getMessage(char* buf, int len)
@@ -294,7 +329,6 @@
{
if (!I2C::write(_i2cAdr,®STREAM,sizeof(REGSTREAM),true))
sent = send(buf, len);
- found = (len == sent);
stop();
}
return sent;
@@ -305,7 +339,6 @@
int sent = 0;
if (!I2C::write(_i2cAdr,®STREAM,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,®STREAM,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;
}
