This class provides an API to communicate with a u-blox GNSS chip. The files here were originally part of the C027_Support library (https://developer.mbed.org/teams/ublox/code/C027_Support/ at revision 138:dafbbf31bf76) but have been separated out, primarily for use on the u-blox C030 board where the cellular interace portion of the C027_Support library will instead be provided through the new mbed Cellular API.

Dependents:   example-ublox-at-cellular-interface-ext example-low-power-sleep example-C030-out-of-box-demo example-C030-out-of-box-demo ... more

Committer:
wajahat.abbas@u-blox.com
Date:
Mon Jul 29 14:24:22 2019 +0500
Revision:
34:d6a65d4c902a
Parent:
33:75163fa7e453
Fixed build error on generic applications

Who changed what in which revision?

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