95 const char fieldName[20];
131 bool amI(
const char *msgId)
const
133 return (strcmp(
_msgId, msgId) == 0);
219 const void *fieldsOverride =
nullptr, uint8_t numFieldsOverride = 0,
220 uint16_t blockIndex = 0)
const
222 if (buffer ==
nullptr)
236 if ((fieldsOverride !=
nullptr) && (blockIndex >=
_maxNumBlocks))
247 uint16_t actualBlockCount = 0;
250 uint16_t totalFields = 0;
251 for (
int y = 1; y < (int)strlen((
const char *)buffer); y++)
253 if ((buffer[y] ==
',') || (buffer[y] ==
'*'))
264 if ((fieldsOverride !=
nullptr) && (blockIndex >= actualBlockCount))
273 uint8_t numFieldsToSearch = fieldsOverride ? numFieldsOverride :
_numFields;
274 for (uint8_t i = 0; i < numFieldsToSearch; i++)
276 if (strncmp(fields[i].fieldName, fieldName,
sizeof(fields[i].fieldName)) != 0)
287 if (fieldsOverride !=
nullptr)
303 const uint8_t *fieldStart = buffer;
304 const uint8_t *fieldEnd = buffer + 1;
309 const int bufferLength = (int)strlen((
const char *)buffer);
310 for (x = 1; x < bufferLength; x++)
312 if ((buffer[x] ==
',') || (buffer[x] ==
'*'))
314 fieldEnd = &buffer[x];
317 if (commaCount == trueFieldNumber)
323 fieldStart = &buffer[x];
328 if (x == bufferLength)
335 if ((fieldEnd - fieldStart) <= 1)
341 switch (fields[i].nmeaDataType)
352 while (fieldStart < fieldEnd)
354 value += (char)*fieldStart;
363 double field = (double)(*fieldStart++ -
'0') * 10.0;
364 field += (double)(*fieldStart++ -
'0') * 1.0;
365 field += (double)(*fieldStart++ -
'0') / 6.0;
366 field += (double)(*fieldStart++ -
'0') / 60.0;
368 if (*fieldStart ==
'.')
371 double multiplier = 1.0 / 600.0;
372 while (fieldStart < fieldEnd)
374 field += (double)(*fieldStart++ -
'0') * multiplier;
379 sfe_string_from_double(value, field, numDPs);
386 double field = (double)(*fieldStart++ -
'0') * 100.0;
387 field += (double)(*fieldStart++ -
'0') * 10.0;
388 field += (double)(*fieldStart++ -
'0') * 1.0;
389 field += (double)(*fieldStart++ -
'0') / 6.0;
390 field += (double)(*fieldStart++ -
'0') / 60.0;
392 if (*fieldStart ==
'.')
395 double multiplier = 1.0 / 600.0;
396 while (fieldStart < fieldEnd)
398 field += (double)(*fieldStart++ -
'0') * multiplier;
403 sfe_string_from_double(value, field, numDPs);
410 value += (char)*fieldStart;
417 bool isNegative =
false;
418 if (*fieldStart ==
'-')
423 double field = (double)(*fieldStart++ -
'0');
424 while ((*fieldStart !=
'.') && (fieldStart < fieldEnd))
427 field += (double)(*fieldStart++ -
'0');
430 if ((*fieldStart ==
'.') && (fieldStart < fieldEnd))
433 double multiplier = 1.0 / 10.0;
434 while (fieldStart < fieldEnd)
436 field += (double)(*fieldStart++ -
'0') * multiplier;
443 sfe_string_from_double(value, field, numDPs);
482 void addNMEA(
const char *msgId, uint8_t messageLength, uint8_t numCallbackCopies, uint8_t numFields,
483 const void *nmeaFields,
484 const void *blockFields =
nullptr, uint8_t numBlockFields = 0,
485 uint8_t numHeaderFields = 0, uint8_t maxNumBlocks = 0)
The base class for the NMEA messages. Each message stores its latest copy and a ring buffer of copies...
Definition: nmeaMessage.h:88
uint8_t _numCallbackCopies
Number of ring-buffer slots in _callbackStorage - 1 for most messages, 54 for GSV - see the GNSS v4 A...
Definition: nmeaMessage.h:510
void(* _callbackPtr)(nmeaCallbackDataCommon_t *)
The user callback.
Definition: nmeaMessage.h:539
uint8_t _numFields
Number of entries in _fields (header + footer fields only - excludes _numBlockFields)
Definition: nmeaMessage.h:512
uint8_t * _callbackStorage
Ring buffer of _numCallbackCopies slots, each _messageLength bytes - nullptr until initCallbackStorag...
Definition: nmeaMessage.h:526
bool initCallbackStorage(void)
Lazily allocate this message's callback ring-buffer storage (_callbackStorage), if not already done.
Definition: nmeaMessage.h:170
bool initStorage(void)
Lazily allocate this message's raw payload storage (_storage), if not already done.
Definition: nmeaMessage.h:150
uint8_t * _storage
Raw payload storage - nullptr until initStorage() is called.
Definition: nmeaMessage.h:511
bool _moduleQueried
true when fresh data has arrived. Cleared by getNMEA().
Definition: nmeaMessage.h:515
uint8_t _messageLength
The maximum message length in bytes. Messages could be less than this.
Definition: nmeaMessage.h:509
nmeaMessage(void)
Construct a new, unregistered nmeaMessage object.
Definition: nmeaMessage.h:107
uint8_t _callbackTail
Next fresh slot checkCallbacks() will read and dispatch.
Definition: nmeaMessage.h:535
bool _urcEnabled
Has the module been told to output this message as a +UUGNMEA URC? (AT+UGNMEA <output> bit 1)
Definition: nmeaMessage.h:540
void addNMEA(const char *msgId, uint8_t messageLength, uint8_t numCallbackCopies, uint8_t numFields, const void *nmeaFields, const void *blockFields=nullptr, uint8_t numBlockFields=0, uint8_t numHeaderFields=0, uint8_t maxNumBlocks=0)
Register this message's identity, field table and metadata with the base class.
Definition: nmeaMessage.h:482
uint8_t _callbackReadIndex
Set by checkCallbacks() to _callbackTail immediately before each callback firing, so getNmeaMessageFi...
Definition: nmeaMessage.h:537
uint8_t _callbackHead
Next free slot the write side will write into.
Definition: nmeaMessage.h:534
bool _memoryEnabled
Has the module been told to store this message in its internal buffer? (AT+UGNMEA <output> bit 0)
Definition: nmeaMessage.h:541
const void * _fields
Points at the subclass's own, permanently-lived nmeaFields[] table.
Definition: nmeaMessage.h:516
bool extractFieldFrom(const uint8_t *buffer, const char *fieldName, sfe_string_t &value, const void *fieldsOverride=nullptr, uint8_t numFieldsOverride=0, uint16_t blockIndex=0) const
Look up one field of this message, by name, in a given NMEA sentence buffer.
Definition: nmeaMessage.h:218
uint8_t _numHeaderFields
Number of header fields before the first repeated block (also the field-table position of the first f...
Definition: nmeaMessage.h:524
const char * _msgId
The message ID, e.g. "GGA".
Definition: nmeaMessage.h:508
uint8_t _numBlockFields
Number of entries in _blockFields.
Definition: nmeaMessage.h:523
uint8_t _callbackCount
How many slots currently hold fresh, undelivered data (replaces the old single _callbackDataValid boo...
Definition: nmeaMessage.h:536
virtual ~nmeaMessage(void)
Destroy this nmeaMessage, freeing any lazily-allocated storage.
Definition: nmeaMessage.h:116
const void * _blockFields
Points at the subclass's own nmeaBlockFields[] table; nullptr => no repeated blocks.
Definition: nmeaMessage.h:522
bool amI(const char *msgId) const
Check whether this message object represents the given NMEA message identifier.
Definition: nmeaMessage.h:131
uint8_t _maxNumBlocks
Upper bound on the number of repeated blocks (e.g. GSV's 4)
Definition: nmeaMessage.h:525
Definition: nmeaMessage.h:30
const uint8_t NMEA_GST_MAX_LENGTH
The maximum length of the NMEA GST message (bytes).
Definition: nmeaMessage.h:41
const uint8_t NMEA_GBS_MAX_LENGTH
The maximum length of the NMEA GBS message (bytes).
Definition: nmeaMessage.h:35
const uint8_t NMEA_MAX_LENGTH
The largest of the above. The URC parser uses this.
Definition: nmeaMessage.h:47
const uint8_t NMEA_GRS_MAX_LENGTH
The maximum length of the NMEA GRS message (bytes).
Definition: nmeaMessage.h:39
const uint8_t NMEA_VTG_MAX_LENGTH
The maximum length of the NMEA VTG message (bytes).
Definition: nmeaMessage.h:45
const uint8_t NMEA_GSA_MAX_LENGTH
The maximum length of the NMEA GSA message (bytes).
Definition: nmeaMessage.h:40
const uint8_t NMEA_ZDA_MAX_LENGTH
The maximum length of the NMEA ZDA message (bytes).
Definition: nmeaMessage.h:46
const uint8_t NMEA_VLW_MAX_LENGTH
The maximum length of the NMEA VLW message (bytes).
Definition: nmeaMessage.h:44
const uint8_t NMEA_GSV_MAX_LENGTH
Variable length - up to 4 satellite blocks.
Definition: nmeaMessage.h:42
nmeaFieldFormats_t
NMEA message field formats.
Definition: nmeaMessage.h:64
@ nmeaDataTypeChar
A single ASCII character: e.g. N S E W M.
Definition: nmeaMessage.h:69
@ nmeaDataTypeDDDMM
Degrees Minutes for Longitude: 3 digit degrees, 2 digit minutes. Could have a variable number of deci...
Definition: nmeaMessage.h:68
@ nmeaDataTypeDigit
A single ASCII digit: 0-9.
Definition: nmeaMessage.h:70
@ nmeaDataTypeTime
Time in the format HHMMSS. Could have a variable number of decimal places: HHMMSS....
Definition: nmeaMessage.h:66
@ nmeaDataTypeString
An array of ASCII char.
Definition: nmeaMessage.h:65
@ nmeaDataTypeNumeric
A numeric: could be integer or floating point; could be negative.
Definition: nmeaMessage.h:71
@ nmeaDataTypeDDMM
Degrees Minutes for Latitude: 2 digit degrees, 2 digit minutes. Could have a variable number of decim...
Definition: nmeaMessage.h:67
const uint8_t NMEA_RMC_MAX_LENGTH
The maximum length of the NMEA RMC message (bytes).
Definition: nmeaMessage.h:43
const uint8_t NMEA_DTM_MAX_LENGTH
The maximum length of the NMEA DTM message (bytes).
Definition: nmeaMessage.h:34
const uint8_t NMEA_GNS_MAX_LENGTH
The maximum length of the NMEA GNS message (bytes).
Definition: nmeaMessage.h:38
const uint8_t NMEA_GGA_MAX_LENGTH
The maximum length of the NMEA GGA message (bytes).
Definition: nmeaMessage.h:36
nmea_status_e
Status codes returned by the nmeaMessageVector methods (replaces GNSS v4's sfe_ublox_status_e)
Definition: nmeaMessage.h:53
@ NMEA_STATUS_SUCCESS
Definition: nmeaMessage.h:54
@ NMEA_STATUS_INVALID_ARG
Definition: nmeaMessage.h:55
@ NMEA_STATUS_MEM_ERR
Definition: nmeaMessage.h:56
const uint8_t NMEA_GLL_MAX_LENGTH
The maximum length of the NMEA GLL message (bytes).
Definition: nmeaMessage.h:37
Forward declaration - see nmeaCallbackDataCommon_t below.
Definition: nmeaMessage.h:80
nmeaMessage * messagePtr
Opaque - do not dereference directly. Use getNmeaMessagePtr() /.
Definition: nmeaMessage.h:82
One entry per field in the message payload.
Definition: nmeaMessage.h:94
const uint8_t fieldNumber
Field number, starting from the Message ID.
Definition: nmeaMessage.h:97
const uint8_t nmeaDataType
8-bit type tag, from nmeaFieldFormats_t - see above
Definition: nmeaMessage.h:96