![](/media/cache/profiles/b5c4ec91390a6fbccf8d918d443563ed.jpg.50x50_q85.jpg)
aconno gnss simple example for U-blox gnss dev board.
Fork of gnss by
Diff: gnss.cpp
- Revision:
- 6:56eda66d585b
- Parent:
- 5:af4baf3c67f3
- Child:
- 7:bfbe9d5d6f56
diff -r af4baf3c67f3 -r 56eda66d585b gnss.cpp --- a/gnss.cpp Sun Jun 11 13:45:56 2017 +0000 +++ b/gnss.cpp Wed Jun 14 20:44:42 2017 +0100 @@ -45,7 +45,7 @@ void GnssParser::powerOff(void) { - // set the GNSS into backup mode using the command RMX-LPREQ + // Set the GNSS 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)); } @@ -103,7 +103,7 @@ char ch; if (++o > len) return WAIT; if ('$' != pipe->next()) return NOT_FOUND; - // this needs to be extended by crc checking + // This needs to be extended by crc checking for (;;) { if (++o > len) return WAIT; @@ -203,13 +203,13 @@ const char* GnssParser::findNmeaItemPos(int ix, const char* start, const char* end) { - // find the start + // Find the start for (; (start < end) && (ix > 0); start ++) { if (*start == ',') ix --; } - // found and check bounds + // Found and check bounds if ((ix == 0) && (start < end) && (*start != ',') && (*start != '*') && (*start != '\r') && (*start != '\n')) return start; @@ -221,11 +221,11 @@ { char* end = &buf[len]; const char* pos = findNmeaItemPos(ix, buf, end); - // find the start + // Find the start if (!pos) return false; val = strtod(pos, &end); - // restore the last character + // Restore the last character return (end > pos); } @@ -233,7 +233,7 @@ { char* end = &buf[len]; const char* pos = findNmeaItemPos(ix, buf, end); - // find the start + // Find the start if (!pos) return false; val = (int)strtol(pos, &end, base); @@ -244,13 +244,13 @@ { const char* end = &buf[len]; const char* pos = findNmeaItemPos(ix, buf, end); - // find the start + // Find the start if (!pos) return false; - // skip leading spaces + // Skip leading spaces while ((pos < end) && isspace(*pos)) pos++; - // check bound + // Check bound if ((pos < end) && (*pos != ',') && (*pos != '*') && (*pos != '\r') && (*pos != '\n')) { @@ -296,20 +296,25 @@ bool GnssSerial::init(PinName pn) { + Timer timer; + int size; + // Unused (kept only for compatibility with the I2C version) (void)pn; // Power up and enable the module _powerOn(); - // send a byte to wakup the device again + // Send a byte to wakup the device again putc(0xFF); - // wait until we get some bytes - int size = _pipeRx.size(); - Timer timer; + // Wait until we get some bytes + size = _pipeRx.size(); timer.start(); - while ((100 > timer.read_ms()) && (size == _pipeRx.size())) - /* nothing / just wait */; + while ((timer.read_ms() < 1000) && (size == _pipeRx.size())) { + /* Nothing, just wait */ + } + timer.stop(); + return (size != _pipeRx.size()); } @@ -357,13 +362,13 @@ int GnssI2C::getMessage(char* buf, int len) { - // fill the pipe + // Fill the pipe int sz = _pipe.free(); if (sz) sz = _get(buf, sz); if (sz) _pipe.put(buf, sz); - // now parse it + // Now parse it return _getMessage(&_pipe, buf, len); }