support library for C027 helper functions for Buffer Pipes, Buffered Serial Port (rtos capable) and GPS parsing. It includes modem APIs for USSD, SMS and Sockets.

Dependents:   HTTPClient_Cellular_HelloWorld Cellular_HelloMQTT MbedSmartRestMain Car_Bon_car_module ... more

This library is intended to be used with u-blox products such as the C027 or a shield with u-blox cellular and GPS modules like the cellular and positioning shield from Embedded Artist.

For 2G/GSM and 3G/UMTS you need to:

  • have a SIM card and know its PIN number
  • need to know you network operators APN setting These setting should be passed to the connect or init and join functions. You can also extend the APN database in MDMAPN.h.

For CDMA products you need to make sure that you have provisioned and activated the modem with either Sprint or Verizon.

Committer:
mazgch
Date:
Thu May 15 22:20:42 2014 +0000
Revision:
74:208e3e32d263
Parent:
51:e7b81c31baec
Child:
75:ce6e12067d0c
initial version of restructured u-blox library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mazgch 1:f41579f4e2ed 1 #pragma once
mazgch 1:f41579f4e2ed 2
mazgch 2:b6012cd91657 3 #include "mbed.h"
mazgch 2:b6012cd91657 4 #include "Pipe.h"
mazgch 1:f41579f4e2ed 5 #include "SerialPipe.h"
mazgch 2:b6012cd91657 6
mazgch 19:2b5d097ca15d 7 #ifdef TARGET_UBLOX_C027
mazgch 74:208e3e32d263 8 #define _IF(onboard, shield) onboard
mazgch 19:2b5d097ca15d 9 #else
mazgch 74:208e3e32d263 10 #define _IF(onboard, shield) shield
mazgch 19:2b5d097ca15d 11 #endif
mazgch 9:e7a5959ffae1 12
mazgch 38:e6cab4632d84 13 /** basic gps parser class
mazgch 38:e6cab4632d84 14 */
mazgch 2:b6012cd91657 15 class GPSParser
mazgch 2:b6012cd91657 16 {
mazgch 2:b6012cd91657 17 public:
mazgch 74:208e3e32d263 18
mazgch 74:208e3e32d263 19 //! Constructor
mazgch 74:208e3e32d263 20 ~GPSParser(void);
mazgch 74:208e3e32d263 21
mazgch 74:208e3e32d263 22 /** Power on / Wake up the gps
mazgch 74:208e3e32d263 23 */
mazgch 74:208e3e32d263 24 virtual bool init(void) = 0;
mazgch 74:208e3e32d263 25
mazgch 51:e7b81c31baec 26 enum {
mazgch 51:e7b81c31baec 27 // getLine Responses
mazgch 51:e7b81c31baec 28 WAIT = -1, //!< wait for more incoming data (the start of a message was found, or no data available)
mazgch 51:e7b81c31baec 29 NOT_FOUND = 0, //!< a parser concluded the the current offset of the pipe doe not contain a valid message
mazgch 39:9b4b9433e220 30
mazgch 51:e7b81c31baec 31 #define LENGTH(x) (x & 0x00FFFF) //!< extract/mask the length
mazgch 51:e7b81c31baec 32 #define PROTOCOL(x) (x & 0xFF0000) //!< extract/mask the type
mazgch 39:9b4b9433e220 33
mazgch 51:e7b81c31baec 34 UNKNOWN = 0x000000, //!< message type is unknown
mazgch 51:e7b81c31baec 35 UBX = 0x100000, //!< message if of protocol NMEA
mazgch 51:e7b81c31baec 36 NMEA = 0x200000 //!< message if of protocol UBX
mazgch 51:e7b81c31baec 37 };
mazgch 51:e7b81c31baec 38
mazgch 39:9b4b9433e220 39 /** Get a line from the physical interface. This fucntion
mazgch 39:9b4b9433e220 40 needs to be implemented in the inherited class.
mazgch 39:9b4b9433e220 41 \param buf the buffer to store it
mazgch 39:9b4b9433e220 42 \param len size of the buffer
mazgch 39:9b4b9433e220 43 \return type and length if something was found,
mazgch 39:9b4b9433e220 44 WAIT if not enough data is available
mazgch 39:9b4b9433e220 45 NOT_FOUND if nothing was found
mazgch 39:9b4b9433e220 46 */
mazgch 39:9b4b9433e220 47 virtual int getMessage(char* buf, int len) = 0;
mazgch 2:b6012cd91657 48
mazgch 39:9b4b9433e220 49 /** send a buffer
mazgch 39:9b4b9433e220 50 \param buf the buffer to write
mazgch 39:9b4b9433e220 51 \param len size of the buffer to write
mazgch 39:9b4b9433e220 52 \return bytes written
mazgch 39:9b4b9433e220 53 */
mazgch 4:c959dd4c5fe8 54 virtual int send(const char* buf, int len);
mazgch 39:9b4b9433e220 55
mazgch 39:9b4b9433e220 56 /** send a NMEA message, this function just takes the
mazgch 39:9b4b9433e220 57 payload and calculates and adds checksum. ($ and *XX\r\n will be added)
mazgch 39:9b4b9433e220 58 \param buf the message payload to write
mazgch 39:9b4b9433e220 59 \param len size of the message payload to write
mazgch 39:9b4b9433e220 60 \return total bytes written
mazgch 39:9b4b9433e220 61 */
mazgch 4:c959dd4c5fe8 62 virtual int sendNmea(const char* buf, int len);
mazgch 39:9b4b9433e220 63
mazgch 39:9b4b9433e220 64 /** send a UBX message, this function just takes the
mazgch 39:9b4b9433e220 65 payload and calculates and adds checksum.
mazgch 39:9b4b9433e220 66 \param cls the UBX class id
mazgch 39:9b4b9433e220 67 \param id the UBX message id
mazgch 39:9b4b9433e220 68 \param buf the message payload to write
mazgch 39:9b4b9433e220 69 \param len size of the message payload to write
mazgch 39:9b4b9433e220 70 \return total bytes written
mazgch 39:9b4b9433e220 71 */
mazgch 40:295099ff5338 72 virtual int sendUbx(unsigned char cls, unsigned char id,
mazgch 40:295099ff5338 73 const void* buf = NULL, int len = 0);
mazgch 74:208e3e32d263 74
mazgch 39:9b4b9433e220 75 /** Power off the gps, it can be again woken up by an
mazgch 39:9b4b9433e220 76 edge on the serial port on the external interrupt pin.
mazgch 39:9b4b9433e220 77 */
mazgch 31:a0bed6c1e05d 78 void powerOff(void);
mazgch 2:b6012cd91657 79
mazgch 39:9b4b9433e220 80 /** get the first character of a NMEA field
mazgch 39:9b4b9433e220 81 \param ix the index of the field to find
mazgch 39:9b4b9433e220 82 \param start the start of the buffer
mazgch 39:9b4b9433e220 83 \param end the end of the buffer
mazgch 39:9b4b9433e220 84 \return the pointer to the first character of the field.
mazgch 39:9b4b9433e220 85 */
mazgch 2:b6012cd91657 86 static const char* findNmeaItemPos(int ix, const char* start, const char* end);
mazgch 39:9b4b9433e220 87
mazgch 39:9b4b9433e220 88 /** extract a double value from a buffer containing a NMEA message
mazgch 39:9b4b9433e220 89 \param ix the index of the field to extract
mazgch 39:9b4b9433e220 90 \param buf the NMEA message
mazgch 39:9b4b9433e220 91 \param len the size of the NMEA message
mazgch 39:9b4b9433e220 92 \param val the extracted value
mazgch 39:9b4b9433e220 93 \return true if successful, false otherwise
mazgch 39:9b4b9433e220 94 */
mazgch 2:b6012cd91657 95 static bool getNmeaItem(int ix, char* buf, int len, double& val);
mazgch 39:9b4b9433e220 96
mazgch 39:9b4b9433e220 97 /** extract a interger value from a buffer containing a NMEA message
mazgch 39:9b4b9433e220 98 \param ix the index of the field to extract
mazgch 39:9b4b9433e220 99 \param buf the NMEA message
mazgch 39:9b4b9433e220 100 \param len the size of the NMEA message
mazgch 39:9b4b9433e220 101 \param val the extracted value
mazgch 39:9b4b9433e220 102 \param base the numeric base to be used (e.g. 8, 10 or 16)
mazgch 39:9b4b9433e220 103 \return true if successful, false otherwise
mazgch 39:9b4b9433e220 104 */
mazgch 2:b6012cd91657 105 static bool getNmeaItem(int ix, char* buf, int len, int& val, int base/*=10*/);
mazgch 39:9b4b9433e220 106
mazgch 39:9b4b9433e220 107 /** extract a char value from a buffer containing a NMEA message
mazgch 39:9b4b9433e220 108 \param ix the index of the field to extract
mazgch 39:9b4b9433e220 109 \param buf the NMEA message
mazgch 39:9b4b9433e220 110 \param len the size of the NMEA message
mazgch 39:9b4b9433e220 111 \param val the extracted value
mazgch 39:9b4b9433e220 112 \return true if successful, false otherwise
mazgch 39:9b4b9433e220 113 */
mazgch 2:b6012cd91657 114 static bool getNmeaItem(int ix, char* buf, int len, char& val);
mazgch 39:9b4b9433e220 115
mazgch 39:9b4b9433e220 116 /** extract a latitude/longitude value from a buffer containing a NMEA message
mazgch 39:9b4b9433e220 117 \param ix the index of the field to extract (will extract ix and ix + 1)
mazgch 39:9b4b9433e220 118 \param buf the NMEA message
mazgch 39:9b4b9433e220 119 \param len the size of the NMEA message
mazgch 39:9b4b9433e220 120 \param val the extracted latitude or longitude
mazgch 39:9b4b9433e220 121 \return true if successful, false otherwise
mazgch 39:9b4b9433e220 122 */
mazgch 20:535ef78655df 123 static bool getNmeaAngle(int ix, char* buf, int len, double& val);
mazgch 39:9b4b9433e220 124
mazgch 2:b6012cd91657 125 protected:
mazgch 39:9b4b9433e220 126 /** Get a line from the physical interface.
mazgch 39:9b4b9433e220 127 \param pipe the receiveing pipe to parse messages
mazgch 39:9b4b9433e220 128 \param buf the buffer to store it
mazgch 39:9b4b9433e220 129 \param len size of the buffer
mazgch 39:9b4b9433e220 130 \return type and length if something was found,
mazgch 39:9b4b9433e220 131 WAIT if not enough data is available
mazgch 39:9b4b9433e220 132 NOT_FOUND if nothing was found
mazgch 39:9b4b9433e220 133 */
mazgch 2:b6012cd91657 134 static int _getMessage(Pipe<char>* pipe, char* buf, int len);
mazgch 39:9b4b9433e220 135
mazgch 39:9b4b9433e220 136 /** Check if the current offset of the pipe contains a NMEA message.
mazgch 39:9b4b9433e220 137 \param pipe the receiveing pipe to parse messages
mazgch 39:9b4b9433e220 138 \param len numer of bytes to parse at maximum
mazgch 39:9b4b9433e220 139 \return length if something was found (including the NMEA frame)
mazgch 39:9b4b9433e220 140 WAIT if not enough data is available
mazgch 39:9b4b9433e220 141 NOT_FOUND if nothing was found
mazgch 39:9b4b9433e220 142 */
mazgch 2:b6012cd91657 143 static int _parseNmea(Pipe<char>* pipe, int len);
mazgch 39:9b4b9433e220 144
mazgch 39:9b4b9433e220 145 /** Check if the current offset of the pipe contains a UBX message.
mazgch 39:9b4b9433e220 146 \param pipe the receiveing pipe to parse messages
mazgch 39:9b4b9433e220 147 \param len numer of bytes to parse at maximum
mazgch 39:9b4b9433e220 148 \return length if something was found (including the UBX frame)
mazgch 39:9b4b9433e220 149 WAIT if not enough data is available
mazgch 39:9b4b9433e220 150 NOT_FOUND if nothing was found
mazgch 39:9b4b9433e220 151 */
mazgch 2:b6012cd91657 152 static int _parseUbx(Pipe<char>* pipe, int len);
mazgch 39:9b4b9433e220 153
mazgch 39:9b4b9433e220 154 /** Write bytes to the physical interface. This function
mazgch 39:9b4b9433e220 155 needs to be implemented by the inherited class.
mazgch 39:9b4b9433e220 156 \param buf the buffer to write
mazgch 39:9b4b9433e220 157 \param len size of the buffer to write
mazgch 39:9b4b9433e220 158 \return bytes written
mazgch 39:9b4b9433e220 159 */
mazgch 4:c959dd4c5fe8 160 virtual int _send(const void* buf, int len) = 0;
mazgch 39:9b4b9433e220 161
mazgch 39:9b4b9433e220 162 static const char toHex[16]; //!< num to hex conversion
mazgch 74:208e3e32d263 163 #ifdef TARGET_UBLOX_C027
mazgch 74:208e3e32d263 164 bool _onboard;
mazgch 74:208e3e32d263 165 #endif
mazgch 2:b6012cd91657 166 };
mazgch 2:b6012cd91657 167
mazgch 38:e6cab4632d84 168 /** gps class which uses a serial port
mazgch 38:e6cab4632d84 169 as physical interface.
mazgch 38:e6cab4632d84 170 */
mazgch 9:e7a5959ffae1 171 class GPSSerial : public SerialPipe, public GPSParser
mazgch 1:f41579f4e2ed 172 {
mazgch 1:f41579f4e2ed 173 public:
mazgch 38:e6cab4632d84 174 /** Constructor
mazgch 38:e6cab4632d84 175 \param tx is the serial ports transmit pin (gps to CPU)
mazgch 38:e6cab4632d84 176 \param rx is the serial ports receive pin (CPU to gps)
mazgch 38:e6cab4632d84 177 \param baudrate the baudrate of the gps use 9600
mazgch 38:e6cab4632d84 178 \param rxSize the size of the serial rx buffer
mazgch 38:e6cab4632d84 179 \param txSize the size of the serial tx buffer
mazgch 38:e6cab4632d84 180 */
mazgch 74:208e3e32d263 181 GPSSerial(PinName tx _IF( = GPSTXD, /* = D8 */), // resistor on shield not populated
mazgch 74:208e3e32d263 182 PinName rx _IF( = GPSRXD, /* = D9 */), // resistor on shield not populated
mazgch 74:208e3e32d263 183 int baudrate _IF( = GPSBAUD, = 9600 ),
mazgch 19:2b5d097ca15d 184 int rxSize = 256 ,
mazgch 19:2b5d097ca15d 185 int txSize = 128 );
mazgch 39:9b4b9433e220 186
mazgch 74:208e3e32d263 187 virtual bool init(void);
mazgch 74:208e3e32d263 188
mazgch 38:e6cab4632d84 189 /** Get a line from the physical interface.
mazgch 38:e6cab4632d84 190 \param buf the buffer to store it
mazgch 38:e6cab4632d84 191 \param len size of the buffer
mazgch 38:e6cab4632d84 192 \return type and length if something was found,
mazgch 38:e6cab4632d84 193 WAIT if not enough data is available
mazgch 38:e6cab4632d84 194 NOT_FOUND if nothing was found
mazgch 38:e6cab4632d84 195 */
mazgch 2:b6012cd91657 196 virtual int getMessage(char* buf, int len);
mazgch 39:9b4b9433e220 197
mazgch 2:b6012cd91657 198 protected:
mazgch 38:e6cab4632d84 199 /** Write bytes to the physical interface.
mazgch 38:e6cab4632d84 200 \param buf the buffer to write
mazgch 38:e6cab4632d84 201 \param len size of the buffer to write
mazgch 38:e6cab4632d84 202 \return bytes written
mazgch 38:e6cab4632d84 203 */
mazgch 4:c959dd4c5fe8 204 virtual int _send(const void* buf, int len);
mazgch 1:f41579f4e2ed 205 };
mazgch 2:b6012cd91657 206
mazgch 38:e6cab4632d84 207 /** gps class which uses a i2c as physical interface.
mazgch 38:e6cab4632d84 208 */
mazgch 2:b6012cd91657 209 class GPSI2C : public I2C, public GPSParser
mazgch 2:b6012cd91657 210 {
mazgch 2:b6012cd91657 211 public:
mazgch 38:e6cab4632d84 212 /** Constructor
mazgch 38:e6cab4632d84 213 \param sda is the I2C SDA pin (between CPU and GPS)
mazgch 38:e6cab4632d84 214 \param scl is the I2C SCL pin (CPU to GPS)
mazgch 38:e6cab4632d84 215 \param adr the I2C address of the GPS set to (66<<1)
mazgch 38:e6cab4632d84 216 \param rxSize the size of the serial rx buffer
mazgch 38:e6cab4632d84 217 */
mazgch 74:208e3e32d263 218 GPSI2C(PinName sda _IF( = GPSSDA, = D14 ),
mazgch 74:208e3e32d263 219 PinName scl _IF( = GPSSCL, = D15 ),
mazgch 74:208e3e32d263 220 unsigned char i2cAdr _IF( = GPSADR, = (66<<1) ),
mazgch 19:2b5d097ca15d 221 int rxSize = 256 );
mazgch 74:208e3e32d263 222
mazgch 38:e6cab4632d84 223 /** helper function to probe the i2c device
mazgch 38:e6cab4632d84 224 \return true if successfully detected the gps.
mazgch 38:e6cab4632d84 225 */
mazgch 74:208e3e32d263 226 virtual bool init(void);
mazgch 2:b6012cd91657 227
mazgch 38:e6cab4632d84 228 /** Get a line from the physical interface.
mazgch 38:e6cab4632d84 229 \param buf the buffer to store it
mazgch 38:e6cab4632d84 230 \param len size of the buffer
mazgch 38:e6cab4632d84 231 \return type and length if something was found,
mazgch 38:e6cab4632d84 232 WAIT if not enough data is available
mazgch 38:e6cab4632d84 233 NOT_FOUND if nothing was found
mazgch 38:e6cab4632d84 234 */
mazgch 2:b6012cd91657 235 virtual int getMessage(char* buf, int len);
mazgch 38:e6cab4632d84 236
mazgch 38:e6cab4632d84 237 /** send a buffer
mazgch 38:e6cab4632d84 238 \param buf the buffer to write
mazgch 38:e6cab4632d84 239 \param len size of the buffer to write
mazgch 38:e6cab4632d84 240 \return bytes written
mazgch 38:e6cab4632d84 241 */
mazgch 4:c959dd4c5fe8 242 virtual int send(const char* buf, int len);
mazgch 38:e6cab4632d84 243
mazgch 38:e6cab4632d84 244 /** send a NMEA message, this function just takes the
mazgch 38:e6cab4632d84 245 payload and calculates and adds checksum. ($ and *XX\r\n will be added)
mazgch 38:e6cab4632d84 246 \param buf the message payload to write
mazgch 38:e6cab4632d84 247 \param len size of the message payload to write
mazgch 38:e6cab4632d84 248 \return total bytes written
mazgch 38:e6cab4632d84 249 */
mazgch 3:c7cd4887560d 250 virtual int sendNmea(const char* buf, int len);
mazgch 38:e6cab4632d84 251
mazgch 38:e6cab4632d84 252 /** send a UBX message, this function just takes the
mazgch 38:e6cab4632d84 253 payload and calculates and adds checksum.
mazgch 38:e6cab4632d84 254 \param cls the UBX class id
mazgch 38:e6cab4632d84 255 \param id the UBX message id
mazgch 38:e6cab4632d84 256 \param buf the message payload to write
mazgch 38:e6cab4632d84 257 \param len size of the message payload to write
mazgch 38:e6cab4632d84 258 \return total bytes written
mazgch 38:e6cab4632d84 259 */
mazgch 39:9b4b9433e220 260 virtual int sendUbx(unsigned char cls, unsigned char id,
mazgch 39:9b4b9433e220 261 const void* buf = NULL, int len = 0);
mazgch 39:9b4b9433e220 262
mazgch 2:b6012cd91657 263 protected:
mazgch 38:e6cab4632d84 264 /** check if the port is writeable (like SerialPipe)
mazgch 38:e6cab4632d84 265 \return true if writeable
mazgch 38:e6cab4632d84 266 */
mazgch 9:e7a5959ffae1 267 bool writeable(void) { return true; }
mazgch 39:9b4b9433e220 268
mazgch 38:e6cab4632d84 269 /** Write a character (like SerialPipe)
mazgch 38:e6cab4632d84 270 \param c the character to write
mazgch 38:e6cab4632d84 271 \return true if succesffully written
mazgch 38:e6cab4632d84 272 */
mazgch 9:e7a5959ffae1 273 bool putc(int c) { char ch = c; return send(&ch, 1); }
mazgch 39:9b4b9433e220 274
mazgch 38:e6cab4632d84 275 /** Write bytes to the physical interface.
mazgch 38:e6cab4632d84 276 \param buf the buffer to write
mazgch 38:e6cab4632d84 277 \param len size of the buffer to write
mazgch 38:e6cab4632d84 278 \return bytes written
mazgch 38:e6cab4632d84 279 */
mazgch 4:c959dd4c5fe8 280 virtual int _send(const void* buf, int len);
mazgch 39:9b4b9433e220 281
mazgch 38:e6cab4632d84 282 /** read bytes from the physical interface.
mazgch 38:e6cab4632d84 283 \param buf the buffer to read into
mazgch 38:e6cab4632d84 284 \param len size of the read buffer
mazgch 38:e6cab4632d84 285 \return bytes read
mazgch 38:e6cab4632d84 286 */
mazgch 38:e6cab4632d84 287 int _get(char* buf, int len);
mazgch 3:c7cd4887560d 288
mazgch 38:e6cab4632d84 289 Pipe<char> _pipe; //!< the rx pipe
mazgch 38:e6cab4632d84 290 unsigned char _i2cAdr; //!< the i2c address
mazgch 38:e6cab4632d84 291 static const char REGLEN; //!< the length i2c register address
mazgch 38:e6cab4632d84 292 static const char REGSTREAM;//!< the stream i2c register address
mazgch 2:b6012cd91657 293 };