This class provides an API to communicate with a u-blox GNSS chip. The files here were originally part of the C027_Support library (https://developer.mbed.org/teams/ublox/code/C027_Support/ at revision 138:dafbbf31bf76) but have been separated out, primarily for use on the u-blox C030 board where the cellular interace portion of the C027_Support library will instead be provided through the new mbed Cellular API.
Dependents: example-ublox-at-cellular-interface-ext example-low-power-sleep example-C030-out-of-box-demo example-C030-out-of-box-demo ... more
Revision 2:b10ca4aa2e5e, committed 2017-04-13
- Comitter:
- RobMeades
- Date:
- Thu Apr 13 14:45:17 2017 +0000
- Parent:
- 1:ef70a58a6c98
- Child:
- 3:2a1cd49ead85
- Commit message:
- Remove deprecation warnings and warning about lack of bracing around empty else condition. Changed bracing style to ARM standard.
Changed in this revision
--- a/gnss.cpp Mon Apr 10 11:28:24 2017 +0100 +++ b/gnss.cpp Thu Apr 13 14:45:17 2017 +0000 @@ -26,17 +26,29 @@ GnssParser::GnssParser(void) { // Create the power pins but set everything to disabled + _gnssPower = NULL; + _gnssEnable = NULL; + +#if defined GNSSPWR && defined TARGET_UBLOX_C030 /* TODO */ _gnssPower = new DigitalInOut(GNSSPWR, PIN_OUTPUT, OpenDrain, 0); +#endif +#if defined GNSSEN && defined TARGET_UBLOX_C030 /* TODO */ _gnssEnable = new DigitalInOut(GNSSEN, PIN_OUTPUT, PushPullNoPull, 0); +#endif } GnssParser::~GnssParser(void) { // Set the power pins to lowest power state before ending - *_gnssPower = 0; - *_gnssEnable = 0; - delete _gnssPower; - delete _gnssEnable; + if (_gnssPower != NULL) { + *_gnssPower = 0; + delete _gnssPower; + } + + if (_gnssEnable != NULL) { + *_gnssEnable = 0; + delete _gnssEnable; + } } void GnssParser::powerOff(void) @@ -49,9 +61,13 @@ void GnssParser::_powerOn(void) { // Power up and enable the module - *_gnssPower = 1; + if (_gnssPower != NULL) { + *_gnssPower = 1; + } wait_ms (1); - *_gnssEnable = 1; + if (_gnssEnable != NULL) { + *_gnssEnable = 1; + } wait_ms (1); }
--- a/gnss.h Mon Apr 10 11:28:24 2017 +0100 +++ b/gnss.h Thu Apr 13 14:45:17 2017 +0000 @@ -27,9 +27,9 @@ #include "serial_pipe.h" #ifdef TARGET_UBLOX_C030 - #define GNSS_IF(onboard, shield) onboard +# define GNSS_IF(onboard, shield) onboard #else - #define GNSS_IF(onboard, shield) shield +# define GNSS_IF(onboard, shield) shield #endif /** basic GNSS parser class @@ -204,8 +204,8 @@ \param rxSize the size of the serial rx buffer \param txSize the size of the serial tx buffer */ - GnssSerial(PinName tx GNSS_IF( = GNSSTXD, /* = D8 */), // resistor on shield not populated - PinName rx GNSS_IF( = GNSSRXD, /* = D9 */), // resistor on shield not populated + GnssSerial(PinName tx GNSS_IF( = GNSSTXD, = D8 /* = D8 */), // resistor on shield not populated + PinName rx GNSS_IF( = GNSSRXD, = D9 /* = D9 */), // resistor on shield not populated int baudrate GNSS_IF( = GNSSBAUD, = 9600 ), int rxSize = 256 , int txSize = 128 ); @@ -244,10 +244,10 @@ \param adr the I2C address of the GNSS set to (66<<1) \param rxSize the size of the serial rx buffer */ - GnssI2C(PinName sda GNSS_IF( = NC, = D16 ), - PinName scl GNSS_IF( = NC, = D17 ), - unsigned char i2cAdr GNSS_IF( = (66<<1), = (66<<1) ), - int rxSize = 256 ); + GnssI2C(PinName sda GNSS_IF( = NC, = /* D16 TODO */ NC ), + PinName scl GNSS_IF( = NC, = /* D17 TODO */ NC ), + unsigned char i2cAdr GNSS_IF( = (66<<1), = (66<<1) ), + int rxSize = 256 ); //! Destructor virtual ~GnssI2C(void);
--- a/serial_pipe.cpp Mon Apr 10 11:28:24 2017 +0100 +++ b/serial_pipe.cpp Thu Apr 13 14:45:17 2017 +0000 @@ -20,8 +20,9 @@ _pipeRx( (rx!=NC) ? rxSize : 0), _pipeTx( (tx!=NC) ? txSize : 0) { - if (rx!=NC) - attach(this, &SerialPipe::rxIrqBuf, RxIrq); + if (rx!=NC) { + attach(callback(this, &SerialPipe::rxIrqBuf), RxIrq); + } } SerialPipe::~SerialPipe(void) @@ -47,29 +48,28 @@ { int count = length; const char* ptr = (const char*)buffer; - if (count) - { - do - { + if (count) { + do { int written = _pipeTx.put(ptr, count, false); if (written) { ptr += written; count -= written; txStart(); } - else if (!blocking) + else if (!blocking) { + /* nothing / just wait */; break; - /* nothing / just wait */; + } } while (count); } + return (length - count); } void SerialPipe::txCopy(void) { - while (_SerialPipeBase::writeable() && _pipeTx.readable()) - { + while (_SerialPipeBase::writeable() && _pipeTx.readable()) { char c = _pipeTx.getc(); _SerialPipeBase::_base_putc(c); } @@ -79,8 +79,9 @@ { txCopy(); // detach tx isr if we are done - if (!_pipeTx.readable()) + if (!_pipeTx.readable()) { attach(NULL, TxIrq); + } } void SerialPipe::txStart(void) @@ -89,8 +90,9 @@ attach(NULL, TxIrq); txCopy(); // attach the tx isr to handle the remaining data - if (_pipeTx.readable()) - attach(this, &SerialPipe::txIrqBuf, TxIrq); + if (_pipeTx.readable()) { + attach(callback(this, &SerialPipe::txIrqBuf), TxIrq); + } } // rx channel @@ -101,8 +103,10 @@ int SerialPipe::getc(void) { - if (!_pipeRx.readable()) + if (!_pipeRx.readable()) { return EOF; + } + return _pipeRx.getc(); } @@ -116,10 +120,10 @@ while (_SerialPipeBase::readable()) { char c = _SerialPipeBase::_base_getc(); - if (_pipeRx.writeable()) + if (_pipeRx.writeable()) { _pipeRx.putc(c); - else - /* overflow */; + } else { + /* overflow */ + } } } -