gnss
gnss.h@6:56eda66d585b, 2017-06-14 (annotated)
- Committer:
- rob.meades@u-blox.com
- Date:
- Wed Jun 14 20:44:42 2017 +0100
- Revision:
- 6:56eda66d585b
- Parent:
- 5:af4baf3c67f3
- Child:
- 8:720841961804
Test passing on C027 and C030 platforms.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rob.meades@u-blox.com | 1:ef70a58a6c98 | 1 | /* mbed Microcontroller Library |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 2 | * Copyright (c) 2017 u-blox |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 3 | * |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 5 | * you may not use this file except in compliance with the License. |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 6 | * You may obtain a copy of the License at |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 7 | * |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 9 | * |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 10 | * Unless required by applicable law or agreed to in writing, software |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 13 | * See the License for the specific language governing permissions and |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 14 | * limitations under the License. |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 15 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 16 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 17 | #ifndef GNSS_H |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 18 | #define GNSS_H |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 19 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 20 | /** |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 21 | * @file gnss.h |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 22 | * This file defines a class that communicates with a u-blox GNSS chip. |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 23 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 24 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 25 | #include "mbed.h" |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 26 | #include "pipe.h" |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 27 | #include "serial_pipe.h" |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 28 | |
rob.meades@u-blox.com | 4:82308d600690 | 29 | #if defined (TARGET_UBLOX_C030) || defined (TARGET_UBLOX_C027) |
RobMeades | 2:b10ca4aa2e5e | 30 | # define GNSS_IF(onboard, shield) onboard |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 31 | #else |
RobMeades | 2:b10ca4aa2e5e | 32 | # define GNSS_IF(onboard, shield) shield |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 33 | #endif |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 34 | |
RobMeades | 5:af4baf3c67f3 | 35 | #ifdef TARGET_UBLOX_C027 |
rob.meades@u-blox.com | 6:56eda66d585b | 36 | # define GNSSEN GPSEN |
rob.meades@u-blox.com | 6:56eda66d585b | 37 | # define GNSSTXD GPSTXD |
rob.meades@u-blox.com | 6:56eda66d585b | 38 | # define GNSSRXD GPSRXD |
rob.meades@u-blox.com | 6:56eda66d585b | 39 | # define GNSSBAUD GPSBAUD |
RobMeades | 5:af4baf3c67f3 | 40 | #endif |
RobMeades | 5:af4baf3c67f3 | 41 | |
rob.meades@u-blox.com | 4:82308d600690 | 42 | /** Basic GNSS parser class. |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 43 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 44 | class GnssParser |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 45 | { |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 46 | public: |
rob.meades@u-blox.com | 4:82308d600690 | 47 | /** Constructor. |
rob.meades@u-blox.com | 4:82308d600690 | 48 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 49 | GnssParser(); |
rob.meades@u-blox.com | 4:82308d600690 | 50 | /** Destructor. |
rob.meades@u-blox.com | 4:82308d600690 | 51 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 52 | virtual ~GnssParser(void); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 53 | |
rob.meades@u-blox.com | 4:82308d600690 | 54 | /** Power-on/wake-up the GNSS. |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 55 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 56 | virtual bool init(PinName pn) = 0; |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 57 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 58 | enum { |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 59 | // getLine Responses |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 60 | WAIT = -1, //!< wait for more incoming data (the start of a message was found, or no data available) |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 61 | NOT_FOUND = 0, //!< a parser concluded the the current offset of the pipe doe not contain a valid message |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 62 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 63 | #define LENGTH(x) (x & 0x00FFFF) //!< extract/mask the length |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 64 | #define PROTOCOL(x) (x & 0xFF0000) //!< extract/mask the type |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 65 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 66 | UNKNOWN = 0x000000, //!< message type is unknown |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 67 | UBX = 0x100000, //!< message if of protocol NMEA |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 68 | NMEA = 0x200000 //!< message if of protocol UBX |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 69 | }; |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 70 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 71 | /** Get a line from the physical interface. This function |
rob.meades@u-blox.com | 4:82308d600690 | 72 | * needs to be implemented in the inherited class. |
rob.meades@u-blox.com | 4:82308d600690 | 73 | * @param buf the buffer to store it. |
rob.meades@u-blox.com | 4:82308d600690 | 74 | * @param len size of the buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 75 | * @return type and length if something was found, |
rob.meades@u-blox.com | 4:82308d600690 | 76 | * WAIT if not enough data is available, |
rob.meades@u-blox.com | 4:82308d600690 | 77 | * NOT_FOUND if nothing was found |
rob.meades@u-blox.com | 4:82308d600690 | 78 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 79 | virtual int getMessage(char* buf, int len) = 0; |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 80 | |
rob.meades@u-blox.com | 4:82308d600690 | 81 | /** Send a buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 82 | * @param buf the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 83 | * @param len size of the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 84 | * @return bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 85 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 86 | virtual int send(const char* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 87 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 88 | /** send a NMEA message, this function just takes the |
rob.meades@u-blox.com | 4:82308d600690 | 89 | * payload and calculates and adds checksum. ($ and *XX\r\n will be added). |
rob.meades@u-blox.com | 4:82308d600690 | 90 | * @param buf the message payload to write. |
rob.meades@u-blox.com | 4:82308d600690 | 91 | * @param len size of the message payload to write. |
rob.meades@u-blox.com | 4:82308d600690 | 92 | * @return total bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 93 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 94 | virtual int sendNmea(const char* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 95 | |
rob.meades@u-blox.com | 4:82308d600690 | 96 | /** Send a UBX message, this function just takes the |
rob.meades@u-blox.com | 4:82308d600690 | 97 | * payload and calculates and adds checksum. |
rob.meades@u-blox.com | 4:82308d600690 | 98 | * @param cls the UBX class id. |
rob.meades@u-blox.com | 4:82308d600690 | 99 | * @param id the UBX message id. |
rob.meades@u-blox.com | 4:82308d600690 | 100 | * @param buf the message payload to write. |
rob.meades@u-blox.com | 4:82308d600690 | 101 | * @param len size of the message payload to write. |
rob.meades@u-blox.com | 4:82308d600690 | 102 | * @return total bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 103 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 104 | virtual int sendUbx(unsigned char cls, unsigned char id, |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 105 | const void* buf = NULL, int len = 0); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 106 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 107 | /** Power off the GNSS, it can be again woken up by an |
rob.meades@u-blox.com | 4:82308d600690 | 108 | * edge on the serial port on the external interrupt pin. |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 109 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 110 | void powerOff(void); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 111 | |
rob.meades@u-blox.com | 4:82308d600690 | 112 | /** get the first character of a NMEA field. |
rob.meades@u-blox.com | 4:82308d600690 | 113 | * @param ix the index of the field to find. |
rob.meades@u-blox.com | 4:82308d600690 | 114 | * @param start the start of the buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 115 | * @param end the end of the buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 116 | * @return the pointer to the first character of the field. |
rob.meades@u-blox.com | 4:82308d600690 | 117 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 118 | static const char* findNmeaItemPos(int ix, const char* start, const char* end); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 119 | |
rob.meades@u-blox.com | 4:82308d600690 | 120 | /** Extract a double value from a buffer containing a NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 121 | * @param ix the index of the field to extract. |
rob.meades@u-blox.com | 4:82308d600690 | 122 | * @param buf the NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 123 | * @param len the size of the NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 124 | * @param val the extracted value. |
rob.meades@u-blox.com | 4:82308d600690 | 125 | * @return true if successful, false otherwise. |
rob.meades@u-blox.com | 4:82308d600690 | 126 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 127 | static bool getNmeaItem(int ix, char* buf, int len, double& val); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 128 | |
rob.meades@u-blox.com | 4:82308d600690 | 129 | /** Extract a interger value from a buffer containing a NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 130 | * @param ix the index of the field to extract. |
rob.meades@u-blox.com | 4:82308d600690 | 131 | * @param buf the NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 132 | * @param len the size of the NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 133 | * @param val the extracted value. |
rob.meades@u-blox.com | 4:82308d600690 | 134 | * @param base the numeric base to be used (e.g. 8, 10 or 16). |
rob.meades@u-blox.com | 4:82308d600690 | 135 | * @return true if successful, false otherwise. |
rob.meades@u-blox.com | 4:82308d600690 | 136 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 137 | static bool getNmeaItem(int ix, char* buf, int len, int& val, int base/*=10*/); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 138 | |
rob.meades@u-blox.com | 4:82308d600690 | 139 | /** Extract a char value from a buffer containing a NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 140 | * @param ix the index of the field to extract. |
rob.meades@u-blox.com | 4:82308d600690 | 141 | * @param buf the NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 142 | * @param len the size of the NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 143 | * @param val the extracted value. |
rob.meades@u-blox.com | 4:82308d600690 | 144 | * @return true if successful, false otherwise. |
rob.meades@u-blox.com | 4:82308d600690 | 145 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 146 | static bool getNmeaItem(int ix, char* buf, int len, char& val); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 147 | |
rob.meades@u-blox.com | 4:82308d600690 | 148 | /** Extract a latitude/longitude value from a buffer containing a NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 149 | * @param ix the index of the field to extract (will extract ix and ix + 1), |
rob.meades@u-blox.com | 4:82308d600690 | 150 | * @param buf the NMEA message, |
rob.meades@u-blox.com | 4:82308d600690 | 151 | * @param len the size of the NMEA message, |
rob.meades@u-blox.com | 4:82308d600690 | 152 | * @param val the extracted latitude or longitude, |
rob.meades@u-blox.com | 4:82308d600690 | 153 | * @return true if successful, false otherwise. |
rob.meades@u-blox.com | 4:82308d600690 | 154 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 155 | static bool getNmeaAngle(int ix, char* buf, int len, double& val); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 156 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 157 | protected: |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 158 | /** Power on the GNSS module. |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 159 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 160 | void _powerOn(void); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 161 | |
rob.meades@u-blox.com | 4:82308d600690 | 162 | /** Get a line from the physical interface. |
rob.meades@u-blox.com | 4:82308d600690 | 163 | * @param pipe the receiveing pipe to parse messages . |
rob.meades@u-blox.com | 4:82308d600690 | 164 | * @param buf the buffer to store it. |
rob.meades@u-blox.com | 4:82308d600690 | 165 | * @param len size of the buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 166 | * @return type and length if something was found, |
rob.meades@u-blox.com | 4:82308d600690 | 167 | * WAIT if not enough data is available, |
rob.meades@u-blox.com | 4:82308d600690 | 168 | * NOT_FOUND if nothing was found. |
rob.meades@u-blox.com | 4:82308d600690 | 169 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 170 | static int _getMessage(Pipe<char>* pipe, char* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 171 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 172 | /** Check if the current offset of the pipe contains a NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 173 | * @param pipe the receiveing pipe to parse messages. |
rob.meades@u-blox.com | 4:82308d600690 | 174 | * @param len numer of bytes to parse at maximum. |
rob.meades@u-blox.com | 4:82308d600690 | 175 | * @return length if something was found (including the NMEA frame), |
rob.meades@u-blox.com | 4:82308d600690 | 176 | * WAIT if not enough data is available, |
rob.meades@u-blox.com | 4:82308d600690 | 177 | * NOT_FOUND if nothing was found. |
rob.meades@u-blox.com | 4:82308d600690 | 178 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 179 | static int _parseNmea(Pipe<char>* pipe, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 180 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 181 | /** Check if the current offset of the pipe contains a UBX message. |
rob.meades@u-blox.com | 4:82308d600690 | 182 | * @param pipe the receiveing pipe to parse messages. |
rob.meades@u-blox.com | 4:82308d600690 | 183 | * @param len numer of bytes to parse at maximum. |
rob.meades@u-blox.com | 4:82308d600690 | 184 | * @return length if something was found (including the UBX frame), |
rob.meades@u-blox.com | 4:82308d600690 | 185 | * WAIT if not enough data is available, |
rob.meades@u-blox.com | 4:82308d600690 | 186 | * NOT_FOUND if nothing was found. |
rob.meades@u-blox.com | 4:82308d600690 | 187 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 188 | static int _parseUbx(Pipe<char>* pipe, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 189 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 190 | /** Write bytes to the physical interface. This function |
rob.meades@u-blox.com | 4:82308d600690 | 191 | * needs to be implemented by the inherited class. |
rob.meades@u-blox.com | 4:82308d600690 | 192 | * @param buf the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 193 | * @param len size of the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 194 | * @return bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 195 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 196 | virtual int _send(const void* buf, int len) = 0; |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 197 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 198 | static const char _toHex[16]; //!< num to hex conversion |
rob.meades@u-blox.com | 4:82308d600690 | 199 | DigitalInOut *_gnssEnable; //!< IO pin that enables GNSS |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 200 | }; |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 201 | |
rob.meades@u-blox.com | 4:82308d600690 | 202 | /** GNSS class which uses a serial port as physical interface. |
rob.meades@u-blox.com | 4:82308d600690 | 203 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 204 | class GnssSerial : public SerialPipe, public GnssParser |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 205 | { |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 206 | public: |
rob.meades@u-blox.com | 4:82308d600690 | 207 | /** Constructor. |
rob.meades@u-blox.com | 4:82308d600690 | 208 | * @param tx is the serial ports transmit pin (GNSS to CPU). |
rob.meades@u-blox.com | 4:82308d600690 | 209 | * @param rx is the serial ports receive pin (CPU to GNSS). |
rob.meades@u-blox.com | 4:82308d600690 | 210 | * @param baudrate the baudrate of the GNSS use 9600. |
rob.meades@u-blox.com | 4:82308d600690 | 211 | * @param rxSize the size of the serial rx buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 212 | * @param txSize the size of the serial tx buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 213 | */ |
RobMeades | 2:b10ca4aa2e5e | 214 | GnssSerial(PinName tx GNSS_IF( = GNSSTXD, = D8 /* = D8 */), // resistor on shield not populated |
RobMeades | 2:b10ca4aa2e5e | 215 | PinName rx GNSS_IF( = GNSSRXD, = D9 /* = D9 */), // resistor on shield not populated |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 216 | int baudrate GNSS_IF( = GNSSBAUD, = 9600 ), |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 217 | int rxSize = 256 , |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 218 | int txSize = 128 ); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 219 | |
rob.meades@u-blox.com | 4:82308d600690 | 220 | /** Destructor. |
rob.meades@u-blox.com | 4:82308d600690 | 221 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 222 | virtual ~GnssSerial(void); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 223 | |
rob.meades@u-blox.com | 4:82308d600690 | 224 | /** Initialise the GNSS device. |
rob.meades@u-blox.com | 4:82308d600690 | 225 | * @param pn NOT USED. |
rob.meades@u-blox.com | 4:82308d600690 | 226 | * @return true if successful, otherwise false. |
rob.meades@u-blox.com | 4:82308d600690 | 227 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 228 | virtual bool init(PinName pn = NC); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 229 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 230 | /** Get a line from the physical interface. |
rob.meades@u-blox.com | 4:82308d600690 | 231 | * @param buf the buffer to store it. |
rob.meades@u-blox.com | 4:82308d600690 | 232 | * @param len size of the buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 233 | * @return type and length if something was found, |
rob.meades@u-blox.com | 4:82308d600690 | 234 | * WAIT if not enough data is available, |
rob.meades@u-blox.com | 4:82308d600690 | 235 | * NOT_FOUND if nothing was found. |
rob.meades@u-blox.com | 4:82308d600690 | 236 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 237 | virtual int getMessage(char* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 238 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 239 | protected: |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 240 | /** Write bytes to the physical interface. |
rob.meades@u-blox.com | 4:82308d600690 | 241 | * @param buf the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 242 | * @param len size of the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 243 | * @return bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 244 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 245 | virtual int _send(const void* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 246 | }; |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 247 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 248 | /** GNSS class which uses a i2c as physical interface. |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 249 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 250 | class GnssI2C : public I2C, public GnssParser |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 251 | { |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 252 | public: |
rob.meades@u-blox.com | 4:82308d600690 | 253 | /** Constructor. |
rob.meades@u-blox.com | 4:82308d600690 | 254 | * @param sda is the I2C SDA pin (between CPU and GNSS). |
rob.meades@u-blox.com | 4:82308d600690 | 255 | * @param scl is the I2C SCL pin (CPU to GNSS). |
rob.meades@u-blox.com | 4:82308d600690 | 256 | * @param adr the I2C address of the GNSS set to (66<<1). |
rob.meades@u-blox.com | 4:82308d600690 | 257 | * @param rxSize the size of the serial rx buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 258 | */ |
RobMeades | 2:b10ca4aa2e5e | 259 | GnssI2C(PinName sda GNSS_IF( = NC, = /* D16 TODO */ NC ), |
RobMeades | 2:b10ca4aa2e5e | 260 | PinName scl GNSS_IF( = NC, = /* D17 TODO */ NC ), |
RobMeades | 2:b10ca4aa2e5e | 261 | unsigned char i2cAdr GNSS_IF( = (66<<1), = (66<<1) ), |
RobMeades | 2:b10ca4aa2e5e | 262 | int rxSize = 256 ); |
rob.meades@u-blox.com | 4:82308d600690 | 263 | /** Destructor |
rob.meades@u-blox.com | 4:82308d600690 | 264 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 265 | virtual ~GnssI2C(void); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 266 | |
rob.meades@u-blox.com | 4:82308d600690 | 267 | /** Helper function to probe the i2c device. |
rob.meades@u-blox.com | 4:82308d600690 | 268 | * @param pn the power-on pin for the chip. |
rob.meades@u-blox.com | 4:82308d600690 | 269 | * @return true if successfully detected the GNSS chip. |
rob.meades@u-blox.com | 4:82308d600690 | 270 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 271 | virtual bool init(PinName pn = GNSS_IF( NC, NC /* D7 resistor R67 on shield not mounted */)); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 272 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 273 | /** Get a line from the physical interface. |
rob.meades@u-blox.com | 4:82308d600690 | 274 | * @param buf the buffer to store it. |
rob.meades@u-blox.com | 4:82308d600690 | 275 | * @param len size of the buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 276 | * @return type and length if something was found, |
rob.meades@u-blox.com | 4:82308d600690 | 277 | * WAIT if not enough data is available, |
rob.meades@u-blox.com | 4:82308d600690 | 278 | * NOT_FOUND if nothing was found. |
rob.meades@u-blox.com | 4:82308d600690 | 279 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 280 | virtual int getMessage(char* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 281 | |
rob.meades@u-blox.com | 4:82308d600690 | 282 | /** Send a buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 283 | * @param buf the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 284 | * @param len size of the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 285 | * @return bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 286 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 287 | virtual int send(const char* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 288 | |
rob.meades@u-blox.com | 4:82308d600690 | 289 | /** Send an NMEA message, this function just takes the |
rob.meades@u-blox.com | 4:82308d600690 | 290 | * payload and calculates and adds checksum ($ and *XX\r\n will be added). |
rob.meades@u-blox.com | 4:82308d600690 | 291 | * @param buf the message payload to write. |
rob.meades@u-blox.com | 4:82308d600690 | 292 | * @param len size of the message payload to write. |
rob.meades@u-blox.com | 4:82308d600690 | 293 | * @return total bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 294 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 295 | virtual int sendNmea(const char* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 296 | |
rob.meades@u-blox.com | 4:82308d600690 | 297 | /** Send a UBX message, this function just takes the |
rob.meades@u-blox.com | 4:82308d600690 | 298 | * payload and calculates and adds checksum. |
rob.meades@u-blox.com | 4:82308d600690 | 299 | * @param cls the UBX class id. |
rob.meades@u-blox.com | 4:82308d600690 | 300 | * @param id the UBX message id. |
rob.meades@u-blox.com | 4:82308d600690 | 301 | * @param buf the message payload to write. |
rob.meades@u-blox.com | 4:82308d600690 | 302 | * @param len size of the message payload to write. |
rob.meades@u-blox.com | 4:82308d600690 | 303 | * @return total bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 304 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 305 | virtual int sendUbx(unsigned char cls, unsigned char id, |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 306 | const void* buf = NULL, int len = 0); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 307 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 308 | protected: |
rob.meades@u-blox.com | 4:82308d600690 | 309 | /** Check if the port is writeable (like SerialPipe) |
rob.meades@u-blox.com | 4:82308d600690 | 310 | * @return true if writeable |
rob.meades@u-blox.com | 4:82308d600690 | 311 | */ |
rob.meades@u-blox.com | 4:82308d600690 | 312 | bool writeable(void) {return true;} |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 313 | |
rob.meades@u-blox.com | 4:82308d600690 | 314 | /** Write a character (like SerialPipe). |
rob.meades@u-blox.com | 4:82308d600690 | 315 | * @param c the character to write. |
rob.meades@u-blox.com | 4:82308d600690 | 316 | * @return true if succesffully written . |
rob.meades@u-blox.com | 4:82308d600690 | 317 | */ |
rob.meades@u-blox.com | 4:82308d600690 | 318 | bool putc(int c) {char ch = c; return send(&ch, 1);} |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 319 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 320 | /** Write bytes to the physical interface. |
rob.meades@u-blox.com | 4:82308d600690 | 321 | * @param buf the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 322 | * @param len size of the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 323 | * @return bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 324 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 325 | virtual int _send(const void* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 326 | |
rob.meades@u-blox.com | 4:82308d600690 | 327 | /** Read bytes from the physical interface. |
rob.meades@u-blox.com | 4:82308d600690 | 328 | * @param buf the buffer to read into. |
rob.meades@u-blox.com | 4:82308d600690 | 329 | * @param len size of the read buffer . |
rob.meades@u-blox.com | 4:82308d600690 | 330 | * @return bytes read. |
rob.meades@u-blox.com | 4:82308d600690 | 331 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 332 | int _get(char* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 333 | |
rob.meades@u-blox.com | 4:82308d600690 | 334 | Pipe<char> _pipe; //!< the rx pipe. |
rob.meades@u-blox.com | 4:82308d600690 | 335 | unsigned char _i2cAdr; //!< the i2c address. |
rob.meades@u-blox.com | 4:82308d600690 | 336 | static const char REGLEN; //!< the length i2c register address. |
rob.meades@u-blox.com | 4:82308d600690 | 337 | static const char REGSTREAM;//!< the stream i2c register address. |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 338 | }; |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 339 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 340 | #endif |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 341 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 342 | // End Of File |