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:
- 9:e7a5959ffae1
- Parent:
- 7:9aa830f5811e
- Child:
- 10:3f1c13a8763d
--- a/GPS.cpp Sat Nov 09 13:31:49 2013 +0000 +++ b/GPS.cpp Sun Nov 10 16:39:42 2013 +0000 @@ -6,26 +6,34 @@ { int unkn = 0; int sz = pipe->size(); + int fr = pipe->free(); if (len > sz) len = sz; while (len > 0) { // NMEA protocol int nmea = _parseNmea(pipe,len); - if ((nmea != NOT_FOUND) && (unkn > 0)) return unkn; - if (nmea == WAIT) return WAIT; - if (nmea > 0) return NMEA | pipe->get(buf,nmea); + if ((nmea != NOT_FOUND) && (unkn > 0)) + return unkn; + if (nmea == WAIT && fr) + return WAIT; + if (nmea > 0) + return NMEA | pipe->get(buf,nmea); // UBX protocol int ubx = _parseUbx(pipe,len); - if ((ubx != NOT_FOUND) && (unkn > 0)) return unkn; - if (ubx == WAIT) return WAIT; - if (ubx > 0) return UBX | pipe->get(buf,ubx); + if ((ubx != NOT_FOUND) && (unkn > 0)) + return unkn; + if (ubx == WAIT && fr) + return WAIT; + if (ubx > 0) + return UBX | pipe->get(buf,ubx); // UNKNOWN *buf++ = pipe->getc(); unkn ++; len--; } - if (unkn != NOT_FOUND) return unkn; + if (unkn != NOT_FOUND) + return unkn; return WAIT; } @@ -201,48 +209,36 @@ // Serial Implementation // ---------------------------------------------------------------- -GPSSerial::GPSSerial(PinName tx /*= GPSTXD*/, PinName rx /*= GPSRXD*/, int baudrate /*= GPSBAUD*/) : - Serial(tx, rx, "gps"), _pipe(256) +GPSSerial::GPSSerial(PinName tx /*= GPSTXD*/, PinName rx /*= GPSRXD*/, int baudrate /*= GPSBAUD*/, + int rxSize /*= 256*/, int txSize /*= 128*/) : + SerialPipe(tx, rx, rxSize, txSize, "gps") { - attach(this, &GPSSerial::serialRxIrq, RxIrq); baud(baudrate); } -GPSSerial::~GPSSerial(void) -{ - attach(NULL, RxIrq); -} - -void GPSSerial::serialRxIrq(void) -{ - while (serial_readable(&_serial)) - _pipe.putc(serial_getc(&_serial)); -} - int GPSSerial::getMessage(char* buf, int len) { - return _getMessage(&_pipe, buf, len); + return _getMessage(&_pipeRx, buf, len); } char GPSSerial::next(void) { - return _pipe.next(); + return _pipeRx.next(); } int GPSSerial::_send(const void* buf, int len) { - for (int i = 0; i < len; i ++) - putc(((char*)buf)[i]); - return len; + return put((const char*)buf, len, true/*=blocking*/); } // ---------------------------------------------------------------- // I2C Implementation // ---------------------------------------------------------------- -GPSI2C::GPSI2C(PinName sda /*= GPSSDA*/, PinName scl /*= GPSSCL*/) : +GPSI2C::GPSI2C(PinName sda /*= GPSSDA*/, PinName scl /*= GPSSCL*/, + int rxSize /*= 256*/) : I2C(sda,scl), - _pipe(256) + _pipe(rxSize) { found = false; }