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