gnss
gnss.h@10:bfa9081e1d14, 2018-05-21 (annotated)
- Committer:
- fahim.alavi@u-blox.com
- Date:
- Mon May 21 17:18:35 2018 +0500
- Revision:
- 10:bfa9081e1d14
- Parent:
- 9:cff83b9f5093
- Child:
- 11:514ea8bf1dc8
Retrieve log batch added
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 | |
fahim.alavi@u-blox.com | 8:720841961804 | 42 | #define UBX_FRAME_SIZE 8 |
fahim.alavi@u-blox.com | 8:720841961804 | 43 | #define RETRY 5 |
fahim.alavi@u-blox.com | 8:720841961804 | 44 | #define SYNC_CHAR_INDEX_1 0 |
fahim.alavi@u-blox.com | 8:720841961804 | 45 | #define SYNC_CHAR_INDEX_2 1 |
fahim.alavi@u-blox.com | 8:720841961804 | 46 | #define MSG_CLASS_INDEX 2 |
fahim.alavi@u-blox.com | 8:720841961804 | 47 | #define MSG_ID_INDEX 3 |
fahim.alavi@u-blox.com | 8:720841961804 | 48 | #define UBX_LENGTH_INDEX 4 |
fahim.alavi@u-blox.com | 8:720841961804 | 49 | #define UBX_PAYLOAD_INDEX 6 |
fahim.alavi@u-blox.com | 8:720841961804 | 50 | |
fahim.alavi@u-blox.com | 8:720841961804 | 51 | enum eUBX_MSG_CLASS {NAV = 0x01, ACK = 0x05, LOG = 0x21}; |
fahim.alavi@u-blox.com | 8:720841961804 | 52 | |
fahim.alavi@u-blox.com | 8:720841961804 | 53 | enum eUBX_MESSAGE {UBX_LOG_BATCH, UBX_ACK_ACK, UBX_ACK_NAK, UBX_NAV_ODO, UBX_NAV_PVT, UNKNOWN_UBX}; |
fahim.alavi@u-blox.com | 8:720841961804 | 54 | |
fahim.alavi@u-blox.com | 9:cff83b9f5093 | 55 | typedef struct UBX_ACK_ACK { |
fahim.alavi@u-blox.com | 8:720841961804 | 56 | uint8_t msg_class; |
fahim.alavi@u-blox.com | 8:720841961804 | 57 | uint8_t msg_id; |
fahim.alavi@u-blox.com | 8:720841961804 | 58 | |
fahim.alavi@u-blox.com | 9:cff83b9f5093 | 59 | }tUBX_ACK_ACK; |
fahim.alavi@u-blox.com | 8:720841961804 | 60 | |
fahim.alavi@u-blox.com | 8:720841961804 | 61 | typedef struct UBX_NAV_ODO { |
fahim.alavi@u-blox.com | 8:720841961804 | 62 | uint8_t version; |
fahim.alavi@u-blox.com | 8:720841961804 | 63 | uint8_t reserved[3]; |
fahim.alavi@u-blox.com | 8:720841961804 | 64 | uint32_t itow; |
fahim.alavi@u-blox.com | 8:720841961804 | 65 | uint32_t distance; |
fahim.alavi@u-blox.com | 8:720841961804 | 66 | uint32_t totalDistance; |
fahim.alavi@u-blox.com | 8:720841961804 | 67 | uint32_t distanceSTD; |
fahim.alavi@u-blox.com | 8:720841961804 | 68 | }tUBX_NAV_ODO; |
fahim.alavi@u-blox.com | 8:720841961804 | 69 | |
fahim.alavi@u-blox.com | 8:720841961804 | 70 | typedef struct UBX_NAV_PVT { |
fahim.alavi@u-blox.com | 8:720841961804 | 71 | uint32_t itow; |
fahim.alavi@u-blox.com | 8:720841961804 | 72 | uint16_t year; |
fahim.alavi@u-blox.com | 8:720841961804 | 73 | uint8_t month; |
fahim.alavi@u-blox.com | 8:720841961804 | 74 | uint8_t day; |
fahim.alavi@u-blox.com | 8:720841961804 | 75 | int32_t lon; // scaling 1e-7 |
fahim.alavi@u-blox.com | 8:720841961804 | 76 | int32_t lat; // scaling 1e-7 |
fahim.alavi@u-blox.com | 8:720841961804 | 77 | int32_t height; |
fahim.alavi@u-blox.com | 8:720841961804 | 78 | |
fahim.alavi@u-blox.com | 8:720841961804 | 79 | }tUBX_NAV_PVT; |
fahim.alavi@u-blox.com | 8:720841961804 | 80 | |
fahim.alavi@u-blox.com | 8:720841961804 | 81 | typedef struct UBX_LOG_BATCH { |
fahim.alavi@u-blox.com | 8:720841961804 | 82 | uint32_t itow; |
fahim.alavi@u-blox.com | 8:720841961804 | 83 | int32_t lon; // scaling 1e-7 |
fahim.alavi@u-blox.com | 8:720841961804 | 84 | int32_t lat; // scaling 1e-7 |
fahim.alavi@u-blox.com | 8:720841961804 | 85 | int32_t height; |
fahim.alavi@u-blox.com | 8:720841961804 | 86 | uint32_t distance; |
fahim.alavi@u-blox.com | 8:720841961804 | 87 | uint32_t totalDistance; |
fahim.alavi@u-blox.com | 8:720841961804 | 88 | uint32_t distanceSTD; |
fahim.alavi@u-blox.com | 8:720841961804 | 89 | |
fahim.alavi@u-blox.com | 8:720841961804 | 90 | }tUBX_LOG_BATCH; |
fahim.alavi@u-blox.com | 8:720841961804 | 91 | |
rob.meades@u-blox.com | 4:82308d600690 | 92 | /** Basic GNSS parser class. |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 93 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 94 | class GnssParser |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 95 | { |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 96 | public: |
rob.meades@u-blox.com | 4:82308d600690 | 97 | /** Constructor. |
rob.meades@u-blox.com | 4:82308d600690 | 98 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 99 | GnssParser(); |
rob.meades@u-blox.com | 4:82308d600690 | 100 | /** Destructor. |
rob.meades@u-blox.com | 4:82308d600690 | 101 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 102 | virtual ~GnssParser(void); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 103 | |
rob.meades@u-blox.com | 4:82308d600690 | 104 | /** Power-on/wake-up the GNSS. |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 105 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 106 | virtual bool init(PinName pn) = 0; |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 107 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 108 | enum { |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 109 | // getLine Responses |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 110 | 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 | 111 | 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 | 112 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 113 | #define LENGTH(x) (x & 0x00FFFF) //!< extract/mask the length |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 114 | #define PROTOCOL(x) (x & 0xFF0000) //!< extract/mask the type |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 115 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 116 | UNKNOWN = 0x000000, //!< message type is unknown |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 117 | UBX = 0x100000, //!< message if of protocol NMEA |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 118 | NMEA = 0x200000 //!< message if of protocol UBX |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 119 | }; |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 120 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 121 | /** Get a line from the physical interface. This function |
rob.meades@u-blox.com | 4:82308d600690 | 122 | * needs to be implemented in the inherited class. |
rob.meades@u-blox.com | 4:82308d600690 | 123 | * @param buf the buffer to store it. |
rob.meades@u-blox.com | 4:82308d600690 | 124 | * @param len size of the buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 125 | * @return type and length if something was found, |
rob.meades@u-blox.com | 4:82308d600690 | 126 | * WAIT if not enough data is available, |
rob.meades@u-blox.com | 4:82308d600690 | 127 | * NOT_FOUND if nothing was found |
rob.meades@u-blox.com | 4:82308d600690 | 128 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 129 | virtual int getMessage(char* buf, int len) = 0; |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 130 | |
rob.meades@u-blox.com | 4:82308d600690 | 131 | /** Send a buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 132 | * @param buf the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 133 | * @param len size of the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 134 | * @return bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 135 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 136 | virtual int send(const char* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 137 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 138 | /** send a NMEA message, this function just takes the |
rob.meades@u-blox.com | 4:82308d600690 | 139 | * payload and calculates and adds checksum. ($ and *XX\r\n will be added). |
rob.meades@u-blox.com | 4:82308d600690 | 140 | * @param buf the message payload to write. |
rob.meades@u-blox.com | 4:82308d600690 | 141 | * @param len size of the message payload to write. |
rob.meades@u-blox.com | 4:82308d600690 | 142 | * @return total bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 143 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 144 | virtual int sendNmea(const char* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 145 | |
rob.meades@u-blox.com | 4:82308d600690 | 146 | /** Send a UBX message, this function just takes the |
rob.meades@u-blox.com | 4:82308d600690 | 147 | * payload and calculates and adds checksum. |
rob.meades@u-blox.com | 4:82308d600690 | 148 | * @param cls the UBX class id. |
rob.meades@u-blox.com | 4:82308d600690 | 149 | * @param id the UBX message id. |
rob.meades@u-blox.com | 4:82308d600690 | 150 | * @param buf the message payload to write. |
rob.meades@u-blox.com | 4:82308d600690 | 151 | * @param len size of the message payload to write. |
rob.meades@u-blox.com | 4:82308d600690 | 152 | * @return total bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 153 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 154 | virtual int sendUbx(unsigned char cls, unsigned char id, |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 155 | const void* buf = NULL, int len = 0); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 156 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 157 | /** Power off the GNSS, it can be again woken up by an |
rob.meades@u-blox.com | 4:82308d600690 | 158 | * edge on the serial port on the external interrupt pin. |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 159 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 160 | void powerOff(void); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 161 | |
rob.meades@u-blox.com | 4:82308d600690 | 162 | /** get the first character of a NMEA field. |
rob.meades@u-blox.com | 4:82308d600690 | 163 | * @param ix the index of the field to find. |
rob.meades@u-blox.com | 4:82308d600690 | 164 | * @param start the start of the buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 165 | * @param end the end of the buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 166 | * @return the pointer to the first character of the field. |
rob.meades@u-blox.com | 4:82308d600690 | 167 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 168 | static const char* findNmeaItemPos(int ix, const char* start, const char* end); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 169 | |
rob.meades@u-blox.com | 4:82308d600690 | 170 | /** Extract a double value from a buffer containing a NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 171 | * @param ix the index of the field to extract. |
rob.meades@u-blox.com | 4:82308d600690 | 172 | * @param buf the NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 173 | * @param len the size of the NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 174 | * @param val the extracted value. |
rob.meades@u-blox.com | 4:82308d600690 | 175 | * @return true if successful, false otherwise. |
rob.meades@u-blox.com | 4:82308d600690 | 176 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 177 | static bool getNmeaItem(int ix, char* buf, int len, double& val); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 178 | |
rob.meades@u-blox.com | 4:82308d600690 | 179 | /** Extract a interger value from a buffer containing a NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 180 | * @param ix the index of the field to extract. |
rob.meades@u-blox.com | 4:82308d600690 | 181 | * @param buf the NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 182 | * @param len the size of the NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 183 | * @param val the extracted value. |
rob.meades@u-blox.com | 4:82308d600690 | 184 | * @param base the numeric base to be used (e.g. 8, 10 or 16). |
rob.meades@u-blox.com | 4:82308d600690 | 185 | * @return true if successful, false otherwise. |
rob.meades@u-blox.com | 4:82308d600690 | 186 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 187 | static bool getNmeaItem(int ix, char* buf, int len, int& val, int base/*=10*/); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 188 | |
rob.meades@u-blox.com | 4:82308d600690 | 189 | /** Extract a char value from a buffer containing a NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 190 | * @param ix the index of the field to extract. |
rob.meades@u-blox.com | 4:82308d600690 | 191 | * @param buf the NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 192 | * @param len the size of the NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 193 | * @param val the extracted value. |
rob.meades@u-blox.com | 4:82308d600690 | 194 | * @return true if successful, false otherwise. |
rob.meades@u-blox.com | 4:82308d600690 | 195 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 196 | static bool getNmeaItem(int ix, char* buf, int len, char& val); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 197 | |
rob.meades@u-blox.com | 4:82308d600690 | 198 | /** Extract a latitude/longitude value from a buffer containing a NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 199 | * @param ix the index of the field to extract (will extract ix and ix + 1), |
rob.meades@u-blox.com | 4:82308d600690 | 200 | * @param buf the NMEA message, |
rob.meades@u-blox.com | 4:82308d600690 | 201 | * @param len the size of the NMEA message, |
rob.meades@u-blox.com | 4:82308d600690 | 202 | * @param val the extracted latitude or longitude, |
rob.meades@u-blox.com | 4:82308d600690 | 203 | * @return true if successful, false otherwise. |
rob.meades@u-blox.com | 4:82308d600690 | 204 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 205 | static bool getNmeaAngle(int ix, char* buf, int len, double& val); |
fahim.alavi@u-blox.com | 8:720841961804 | 206 | |
fahim.alavi@u-blox.com | 8:720841961804 | 207 | /** Enable UBX messages. |
fahim.alavi@u-blox.com | 8:720841961804 | 208 | * @param none |
fahim.alavi@u-blox.com | 8:720841961804 | 209 | * @return 0 if successful, false otherwise. |
fahim.alavi@u-blox.com | 8:720841961804 | 210 | */ |
fahim.alavi@u-blox.com | 8:720841961804 | 211 | int enable_ubx(); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 212 | |
fahim.alavi@u-blox.com | 8:720841961804 | 213 | /** GET Message type of receiver UBX message |
fahim.alavi@u-blox.com | 8:720841961804 | 214 | * @param buff the UXB message |
fahim.alavi@u-blox.com | 8:720841961804 | 215 | * @return eUBX_MESSAGE |
fahim.alavi@u-blox.com | 8:720841961804 | 216 | */ |
fahim.alavi@u-blox.com | 8:720841961804 | 217 | eUBX_MESSAGE get_ubx_message(char *); |
fahim.alavi@u-blox.com | 8:720841961804 | 218 | |
fahim.alavi@u-blox.com | 9:cff83b9f5093 | 219 | /** Method to parse contents of UBX ACK-ACK/NAK and return messageid amd class for which ACK is received |
fahim.alavi@u-blox.com | 8:720841961804 | 220 | * @param buff the UXB message |
fahim.alavi@u-blox.com | 9:cff83b9f5093 | 221 | * @return tUBX_ACK_ACK |
fahim.alavi@u-blox.com | 8:720841961804 | 222 | */ |
fahim.alavi@u-blox.com | 9:cff83b9f5093 | 223 | tUBX_ACK_ACK decode_ubx_cfg_ack_nak_msg(char *); |
fahim.alavi@u-blox.com | 8:720841961804 | 224 | |
fahim.alavi@u-blox.com | 8:720841961804 | 225 | /** Method to parse contents of UBX_NAV_ODO and return decoded msg |
fahim.alavi@u-blox.com | 8:720841961804 | 226 | * @param buff the UXB message |
fahim.alavi@u-blox.com | 8:720841961804 | 227 | * @return tUBX_NAV_ODO |
fahim.alavi@u-blox.com | 8:720841961804 | 228 | */ |
fahim.alavi@u-blox.com | 8:720841961804 | 229 | tUBX_NAV_ODO decode_ubx_nav_odo_msg(char *); |
fahim.alavi@u-blox.com | 8:720841961804 | 230 | |
fahim.alavi@u-blox.com | 8:720841961804 | 231 | /** Method to parse contents of UBX_NAV_PVT and return decoded msg |
fahim.alavi@u-blox.com | 8:720841961804 | 232 | * @param buff the UXB message |
fahim.alavi@u-blox.com | 8:720841961804 | 233 | * @return tUBX_NAV_PVT |
fahim.alavi@u-blox.com | 8:720841961804 | 234 | */ |
fahim.alavi@u-blox.com | 8:720841961804 | 235 | tUBX_NAV_PVT decode_ubx_nav_pvt_msg(char *); |
fahim.alavi@u-blox.com | 8:720841961804 | 236 | |
fahim.alavi@u-blox.com | 8:720841961804 | 237 | /** Method to parse contents of UBX_LOG_BATCH and return decoded msg |
fahim.alavi@u-blox.com | 8:720841961804 | 238 | * @param buff the UXB message |
fahim.alavi@u-blox.com | 8:720841961804 | 239 | * @return tUBX_LOG_BATCH |
fahim.alavi@u-blox.com | 8:720841961804 | 240 | */ |
fahim.alavi@u-blox.com | 8:720841961804 | 241 | tUBX_LOG_BATCH decode_ubx_log_batch_msg(char *); |
fahim.alavi@u-blox.com | 8:720841961804 | 242 | |
fahim.alavi@u-blox.com | 10:bfa9081e1d14 | 243 | /** Method to send UBX LOG-RETRIEVEBATCH msg. This message is used to request batched data. |
fahim.alavi@u-blox.com | 10:bfa9081e1d14 | 244 | * @param bool |
fahim.alavi@u-blox.com | 10:bfa9081e1d14 | 245 | * @return int |
fahim.alavi@u-blox.com | 10:bfa9081e1d14 | 246 | */ |
fahim.alavi@u-blox.com | 10:bfa9081e1d14 | 247 | int ubx_request_batched_data(bool sendMonFirst = false); |
fahim.alavi@u-blox.com | 10:bfa9081e1d14 | 248 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 249 | protected: |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 250 | /** Power on the GNSS module. |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 251 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 252 | void _powerOn(void); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 253 | |
rob.meades@u-blox.com | 4:82308d600690 | 254 | /** Get a line from the physical interface. |
rob.meades@u-blox.com | 4:82308d600690 | 255 | * @param pipe the receiveing pipe to parse messages . |
rob.meades@u-blox.com | 4:82308d600690 | 256 | * @param buf the buffer to store it. |
rob.meades@u-blox.com | 4:82308d600690 | 257 | * @param len size of the buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 258 | * @return type and length if something was found, |
rob.meades@u-blox.com | 4:82308d600690 | 259 | * WAIT if not enough data is available, |
rob.meades@u-blox.com | 4:82308d600690 | 260 | * NOT_FOUND if nothing was found. |
rob.meades@u-blox.com | 4:82308d600690 | 261 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 262 | static int _getMessage(Pipe<char>* pipe, char* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 263 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 264 | /** Check if the current offset of the pipe contains a NMEA message. |
rob.meades@u-blox.com | 4:82308d600690 | 265 | * @param pipe the receiveing pipe to parse messages. |
rob.meades@u-blox.com | 4:82308d600690 | 266 | * @param len numer of bytes to parse at maximum. |
rob.meades@u-blox.com | 4:82308d600690 | 267 | * @return length if something was found (including the NMEA frame), |
rob.meades@u-blox.com | 4:82308d600690 | 268 | * WAIT if not enough data is available, |
rob.meades@u-blox.com | 4:82308d600690 | 269 | * NOT_FOUND if nothing was found. |
rob.meades@u-blox.com | 4:82308d600690 | 270 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 271 | static int _parseNmea(Pipe<char>* pipe, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 272 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 273 | /** Check if the current offset of the pipe contains a UBX message. |
rob.meades@u-blox.com | 4:82308d600690 | 274 | * @param pipe the receiveing pipe to parse messages. |
rob.meades@u-blox.com | 4:82308d600690 | 275 | * @param len numer of bytes to parse at maximum. |
rob.meades@u-blox.com | 4:82308d600690 | 276 | * @return length if something was found (including the UBX frame), |
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 | static int _parseUbx(Pipe<char>* pipe, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 281 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 282 | /** Write bytes to the physical interface. This function |
rob.meades@u-blox.com | 4:82308d600690 | 283 | * needs to be implemented by the inherited class. |
rob.meades@u-blox.com | 4:82308d600690 | 284 | * @param buf the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 285 | * @param len size of the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 286 | * @return bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 287 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 288 | virtual int _send(const void* buf, int len) = 0; |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 289 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 290 | static const char _toHex[16]; //!< num to hex conversion |
rob.meades@u-blox.com | 4:82308d600690 | 291 | DigitalInOut *_gnssEnable; //!< IO pin that enables GNSS |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 292 | }; |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 293 | |
rob.meades@u-blox.com | 4:82308d600690 | 294 | /** GNSS class which uses a serial port as physical interface. |
rob.meades@u-blox.com | 4:82308d600690 | 295 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 296 | class GnssSerial : public SerialPipe, public GnssParser |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 297 | { |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 298 | public: |
rob.meades@u-blox.com | 4:82308d600690 | 299 | /** Constructor. |
rob.meades@u-blox.com | 4:82308d600690 | 300 | * @param tx is the serial ports transmit pin (GNSS to CPU). |
rob.meades@u-blox.com | 4:82308d600690 | 301 | * @param rx is the serial ports receive pin (CPU to GNSS). |
rob.meades@u-blox.com | 4:82308d600690 | 302 | * @param baudrate the baudrate of the GNSS use 9600. |
rob.meades@u-blox.com | 4:82308d600690 | 303 | * @param rxSize the size of the serial rx buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 304 | * @param txSize the size of the serial tx buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 305 | */ |
RobMeades | 2:b10ca4aa2e5e | 306 | GnssSerial(PinName tx GNSS_IF( = GNSSTXD, = D8 /* = D8 */), // resistor on shield not populated |
RobMeades | 2:b10ca4aa2e5e | 307 | PinName rx GNSS_IF( = GNSSRXD, = D9 /* = D9 */), // resistor on shield not populated |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 308 | int baudrate GNSS_IF( = GNSSBAUD, = 9600 ), |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 309 | int rxSize = 256 , |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 310 | int txSize = 128 ); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 311 | |
rob.meades@u-blox.com | 4:82308d600690 | 312 | /** Destructor. |
rob.meades@u-blox.com | 4:82308d600690 | 313 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 314 | virtual ~GnssSerial(void); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 315 | |
rob.meades@u-blox.com | 4:82308d600690 | 316 | /** Initialise the GNSS device. |
rob.meades@u-blox.com | 4:82308d600690 | 317 | * @param pn NOT USED. |
rob.meades@u-blox.com | 4:82308d600690 | 318 | * @return true if successful, otherwise false. |
rob.meades@u-blox.com | 4:82308d600690 | 319 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 320 | virtual bool init(PinName pn = NC); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 321 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 322 | /** Get a line from the physical interface. |
rob.meades@u-blox.com | 4:82308d600690 | 323 | * @param buf the buffer to store it. |
rob.meades@u-blox.com | 4:82308d600690 | 324 | * @param len size of the buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 325 | * @return type and length if something was found, |
rob.meades@u-blox.com | 4:82308d600690 | 326 | * WAIT if not enough data is available, |
rob.meades@u-blox.com | 4:82308d600690 | 327 | * NOT_FOUND if nothing was found. |
rob.meades@u-blox.com | 4:82308d600690 | 328 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 329 | virtual int getMessage(char* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 330 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 331 | protected: |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 332 | /** Write bytes to the physical interface. |
rob.meades@u-blox.com | 4:82308d600690 | 333 | * @param buf the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 334 | * @param len size of the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 335 | * @return bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 336 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 337 | virtual int _send(const void* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 338 | }; |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 339 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 340 | /** GNSS class which uses a i2c as physical interface. |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 341 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 342 | class GnssI2C : public I2C, public GnssParser |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 343 | { |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 344 | public: |
rob.meades@u-blox.com | 4:82308d600690 | 345 | /** Constructor. |
rob.meades@u-blox.com | 4:82308d600690 | 346 | * @param sda is the I2C SDA pin (between CPU and GNSS). |
rob.meades@u-blox.com | 4:82308d600690 | 347 | * @param scl is the I2C SCL pin (CPU to GNSS). |
rob.meades@u-blox.com | 4:82308d600690 | 348 | * @param adr the I2C address of the GNSS set to (66<<1). |
rob.meades@u-blox.com | 4:82308d600690 | 349 | * @param rxSize the size of the serial rx buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 350 | */ |
RobMeades | 2:b10ca4aa2e5e | 351 | GnssI2C(PinName sda GNSS_IF( = NC, = /* D16 TODO */ NC ), |
RobMeades | 2:b10ca4aa2e5e | 352 | PinName scl GNSS_IF( = NC, = /* D17 TODO */ NC ), |
RobMeades | 2:b10ca4aa2e5e | 353 | unsigned char i2cAdr GNSS_IF( = (66<<1), = (66<<1) ), |
RobMeades | 2:b10ca4aa2e5e | 354 | int rxSize = 256 ); |
rob.meades@u-blox.com | 4:82308d600690 | 355 | /** Destructor |
rob.meades@u-blox.com | 4:82308d600690 | 356 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 357 | virtual ~GnssI2C(void); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 358 | |
rob.meades@u-blox.com | 4:82308d600690 | 359 | /** Helper function to probe the i2c device. |
rob.meades@u-blox.com | 4:82308d600690 | 360 | * @param pn the power-on pin for the chip. |
rob.meades@u-blox.com | 4:82308d600690 | 361 | * @return true if successfully detected the GNSS chip. |
rob.meades@u-blox.com | 4:82308d600690 | 362 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 363 | virtual bool init(PinName pn = GNSS_IF( NC, NC /* D7 resistor R67 on shield not mounted */)); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 364 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 365 | /** Get a line from the physical interface. |
rob.meades@u-blox.com | 4:82308d600690 | 366 | * @param buf the buffer to store it. |
rob.meades@u-blox.com | 4:82308d600690 | 367 | * @param len size of the buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 368 | * @return type and length if something was found, |
rob.meades@u-blox.com | 4:82308d600690 | 369 | * WAIT if not enough data is available, |
rob.meades@u-blox.com | 4:82308d600690 | 370 | * NOT_FOUND if nothing was found. |
rob.meades@u-blox.com | 4:82308d600690 | 371 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 372 | virtual int getMessage(char* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 373 | |
rob.meades@u-blox.com | 4:82308d600690 | 374 | /** Send a buffer. |
rob.meades@u-blox.com | 4:82308d600690 | 375 | * @param buf the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 376 | * @param len size of the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 377 | * @return bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 378 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 379 | virtual int send(const char* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 380 | |
rob.meades@u-blox.com | 4:82308d600690 | 381 | /** Send an NMEA message, this function just takes the |
rob.meades@u-blox.com | 4:82308d600690 | 382 | * payload and calculates and adds checksum ($ and *XX\r\n will be added). |
rob.meades@u-blox.com | 4:82308d600690 | 383 | * @param buf the message payload to write. |
rob.meades@u-blox.com | 4:82308d600690 | 384 | * @param len size of the message payload to write. |
rob.meades@u-blox.com | 4:82308d600690 | 385 | * @return total bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 386 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 387 | virtual int sendNmea(const char* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 388 | |
rob.meades@u-blox.com | 4:82308d600690 | 389 | /** Send a UBX message, this function just takes the |
rob.meades@u-blox.com | 4:82308d600690 | 390 | * payload and calculates and adds checksum. |
rob.meades@u-blox.com | 4:82308d600690 | 391 | * @param cls the UBX class id. |
rob.meades@u-blox.com | 4:82308d600690 | 392 | * @param id the UBX message id. |
rob.meades@u-blox.com | 4:82308d600690 | 393 | * @param buf the message payload to write. |
rob.meades@u-blox.com | 4:82308d600690 | 394 | * @param len size of the message payload to write. |
rob.meades@u-blox.com | 4:82308d600690 | 395 | * @return total bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 396 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 397 | virtual int sendUbx(unsigned char cls, unsigned char id, |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 398 | const void* buf = NULL, int len = 0); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 399 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 400 | protected: |
rob.meades@u-blox.com | 4:82308d600690 | 401 | /** Check if the port is writeable (like SerialPipe) |
rob.meades@u-blox.com | 4:82308d600690 | 402 | * @return true if writeable |
rob.meades@u-blox.com | 4:82308d600690 | 403 | */ |
rob.meades@u-blox.com | 4:82308d600690 | 404 | bool writeable(void) {return true;} |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 405 | |
rob.meades@u-blox.com | 4:82308d600690 | 406 | /** Write a character (like SerialPipe). |
rob.meades@u-blox.com | 4:82308d600690 | 407 | * @param c the character to write. |
rob.meades@u-blox.com | 4:82308d600690 | 408 | * @return true if succesffully written . |
rob.meades@u-blox.com | 4:82308d600690 | 409 | */ |
rob.meades@u-blox.com | 4:82308d600690 | 410 | bool putc(int c) {char ch = c; return send(&ch, 1);} |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 411 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 412 | /** Write bytes to the physical interface. |
rob.meades@u-blox.com | 4:82308d600690 | 413 | * @param buf the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 414 | * @param len size of the buffer to write. |
rob.meades@u-blox.com | 4:82308d600690 | 415 | * @return bytes written. |
rob.meades@u-blox.com | 4:82308d600690 | 416 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 417 | virtual int _send(const void* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 418 | |
rob.meades@u-blox.com | 4:82308d600690 | 419 | /** Read bytes from the physical interface. |
rob.meades@u-blox.com | 4:82308d600690 | 420 | * @param buf the buffer to read into. |
rob.meades@u-blox.com | 4:82308d600690 | 421 | * @param len size of the read buffer . |
rob.meades@u-blox.com | 4:82308d600690 | 422 | * @return bytes read. |
rob.meades@u-blox.com | 4:82308d600690 | 423 | */ |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 424 | int _get(char* buf, int len); |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 425 | |
rob.meades@u-blox.com | 4:82308d600690 | 426 | Pipe<char> _pipe; //!< the rx pipe. |
rob.meades@u-blox.com | 4:82308d600690 | 427 | unsigned char _i2cAdr; //!< the i2c address. |
rob.meades@u-blox.com | 4:82308d600690 | 428 | static const char REGLEN; //!< the length i2c register address. |
rob.meades@u-blox.com | 4:82308d600690 | 429 | static const char REGSTREAM;//!< the stream i2c register address. |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 430 | }; |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 431 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 432 | #endif |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 433 | |
rob.meades@u-blox.com | 1:ef70a58a6c98 | 434 | // End Of File |