SparkFun Iridium 9604  v1.0.0
Library for the Iridium 9604 Hybrid LTE-M Cellular + Iridium Satellite (SBD) + GNSS IoT module
Loading...
Searching...
No Matches
SparkFun_Iridium_9604::nmeaMessage Class Reference

The base class for the NMEA messages. Each message stores its latest copy and a ring buffer of copies for the callback. More...

#include <nmeaMessage.h>

Inheritance diagram for SparkFun_Iridium_9604::nmeaMessage:

Classes

struct  nmeaField
 One entry per field in the message payload. More...
 

Public Member Functions

 nmeaMessage (void)
 Construct a new, unregistered nmeaMessage object. More...
 
virtual ~nmeaMessage (void)
 Destroy this nmeaMessage, freeing any lazily-allocated storage. More...
 
bool amI (const char *msgId) const
 Check whether this message object represents the given NMEA message identifier. More...
 
bool initStorage (void)
 Lazily allocate this message's raw payload storage (_storage), if not already done. More...
 
bool initCallbackStorage (void)
 Lazily allocate this message's callback ring-buffer storage (_callbackStorage), if not already done. More...
 
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. More...
 
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. More...
 

Public Attributes

const char * _msgId = nullptr
 The message ID, e.g. "GGA". More...
 
uint8_t _messageLength = 0
 The maximum message length in bytes. Messages could be less than this. More...
 
uint8_t _numCallbackCopies = 0
 Number of ring-buffer slots in _callbackStorage - 1 for most messages, 54 for GSV - see the GNSS v4 AGENTS.md "Adding support for NMEA GSV messages". More...
 
uint8_t * _storage = nullptr
 Raw payload storage - nullptr until initStorage() is called. More...
 
uint8_t _numFields = 0
 Number of entries in _fields (header + footer fields only - excludes _numBlockFields) More...
 
bool _moduleQueried = false
 true when fresh data has arrived. Cleared by getNMEA(). More...
 
const void * _fields = nullptr
 Points at the subclass's own, permanently-lived nmeaFields[] table. More...
 
const void * _blockFields = nullptr
 Points at the subclass's own nmeaBlockFields[] table; nullptr => no repeated blocks. More...
 
uint8_t _numBlockFields = 0
 Number of entries in _blockFields. More...
 
uint8_t _numHeaderFields = 0
 Number of header fields before the first repeated block (also the field-table position of the first footer field) More...
 
uint8_t _maxNumBlocks = 0
 Upper bound on the number of repeated blocks (e.g. GSV's 4) More...
 
uint8_t * _callbackStorage = nullptr
 Ring buffer of _numCallbackCopies slots, each _messageLength bytes - nullptr until initCallbackStorage() is called. More...
 
uint8_t _callbackHead = 0
 Next free slot the write side will write into. More...
 
uint8_t _callbackTail = 0
 Next fresh slot checkCallbacks() will read and dispatch. More...
 
uint8_t _callbackCount = 0
 How many slots currently hold fresh, undelivered data (replaces the old single _callbackDataValid bool) More...
 
uint8_t _callbackReadIndex = 0
 Set by checkCallbacks() to _callbackTail immediately before each callback firing, so getNmeaMessageFieldCallback()/getNmeaMessageBlockFieldCallback() know which slot to read. More...
 
void(* _callbackPtr )(nmeaCallbackDataCommon_t *) = nullptr
 The user callback. More...
 
bool _urcEnabled = false
 Has the module been told to output this message as a +UUGNMEA URC? (AT+UGNMEA <output> bit 1) More...
 
bool _memoryEnabled = false
 Has the module been told to store this message in its internal buffer? (AT+UGNMEA <output> bit 0) More...
 

Detailed Description

The base class for the NMEA messages. Each message stores its latest copy and a ring buffer of copies for the callback.

Constructor & Destructor Documentation

◆ nmeaMessage()

SparkFun_Iridium_9604::nmeaMessage::nmeaMessage ( void  )
inline

Construct a new, unregistered nmeaMessage object.

Leaves every field at its default (no msgId, no field table, no storage allocated). A subclass calls addNMEA() from its own constructor to actually register its identity and metadata - see addNMEA() below.

◆ ~nmeaMessage()

virtual SparkFun_Iridium_9604::nmeaMessage::~nmeaMessage ( void  )
inlinevirtual

Destroy this nmeaMessage, freeing any lazily-allocated storage.

Frees _storage and _callbackStorage if they were ever allocated (via initStorage() / initCallbackStorage()). Safe to call even if neither was ever allocated, since each is nullptr until first use.

Member Function Documentation

◆ addNMEA()

void SparkFun_Iridium_9604::nmeaMessage::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 
)
inline

Register this message's identity, field table and metadata with the base class.

Called once, from the subclass's own constructor, to populate every _* member below with the subclass's message identifier, field table(s) and configuration keys, and to reset all storage pointers and callback bookkeeping to their initial "nothing allocated yet" state.

Parameters
msgIdThe 3-character NMEA message identifier (e.g. "GGA").
messageLengthMaximum message length in bytes (an actual received sentence may be shorter).
numCallbackCopiesNumber of ring-buffer slots to allocate for callback storage.
numFieldsNumber of entries in 'nmeaFields' (header + footer fields only - excludes 'numBlockFields').
nmeaFieldsPointer to this message's own, permanently-lived field table.
blockFieldsOptional field table describing one repeated block, for a variable-length message (e.g. NMEA GSV's per-satellite blocks). Defaults to nullptr (no repeated blocks).
numBlockFieldsNumber of entries in 'blockFields'. Defaults to 0.
numHeaderFieldsNumber of header fields before the first repeated block (also the field-table position of the first footer field). Defaults to 0.
maxNumBlocksUpper bound on the number of repeated blocks. Defaults to 0.

◆ amI()

bool SparkFun_Iridium_9604::nmeaMessage::amI ( const char *  msgId) const
inline

Check whether this message object represents the given NMEA message identifier.

Parameters
msgIdThe 3-character NMEA message identifier to test against (e.g. "GGA").
Returns
true if this object's registered _msgId matches, false otherwise.

◆ extractFieldFrom()

bool SparkFun_Iridium_9604::nmeaMessage::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
inline

Look up one field of this message, by name, in a given NMEA sentence buffer.

Walks the comma-delimited sentence in 'buffer' to find field 'fieldName' and returns its text, converted according to that field's nmeaDataType (see nmeaFieldFormats_t above). Shared core used both for a live/polled read (from this object's own _storage) and for a callback read (from _callbackStorage) - see getNmeaMessageField() and getNmeaMessageBlockField()/getNmeaMessageBlockFieldCallback() in Iridium_9604_GNSS.cpp.

Parameters
bufferThe NMEA sentence bytes to search (this message's _storage, or its _callbackStorage), which must start with '$'.
fieldNameName of the field to find, matched against each entry's fieldName.
valueOut parameter: filled in with the field's text (converted per its data type), or cleared to an empty String on failure.
fieldsOverrideOptional field table to search instead of this object's own _fields - used to search a repeated block's own field table (see _blockFields, e.g. NMEA GSV's per-satellite blocks). Defaults to nullptr (search _fields).
numFieldsOverrideNumber of entries in 'fieldsOverride'; ignored when 'fieldsOverride' is nullptr.
blockIndexWhich repeated block a block-field lookup should read; ignored unless 'fieldsOverride' is given. Defaults to 0.
Returns
true if 'fieldName' was found (and *value filled in); false if 'buffer' is null, malformed, too short, 'blockIndex' is out of range, or the field name was not found.

◆ initCallbackStorage()

bool SparkFun_Iridium_9604::nmeaMessage::initCallbackStorage ( void  )
inline

Lazily allocate this message's callback ring-buffer storage (_callbackStorage), if not already done.

Allocates _numCallbackCopies slots of _messageLength bytes each, the first time a callback is registered for this message. Subsequent calls are a no-op.

Returns
true if _callbackStorage is non-null after the call, false if the allocation failed.

◆ initStorage()

bool SparkFun_Iridium_9604::nmeaMessage::initStorage ( void  )
inline

Lazily allocate this message's raw payload storage (_storage), if not already done.

Allocates and zero-fills a buffer of _messageLength bytes on first call; subsequent calls are a no-op. This is what lets a message that is never instantiated/used avoid consuming any RAM for its payload - see the class-level comment above for the "delete the header, save the RAM" design intent.

Returns
true if _storage is non-null after the call (already allocated, or successfully allocated now); false if the allocation failed.

Member Data Documentation

◆ _blockFields

const void* SparkFun_Iridium_9604::nmeaMessage::_blockFields = nullptr

Points at the subclass's own nmeaBlockFields[] table; nullptr => no repeated blocks.

◆ _callbackCount

uint8_t SparkFun_Iridium_9604::nmeaMessage::_callbackCount = 0

How many slots currently hold fresh, undelivered data (replaces the old single _callbackDataValid bool)

◆ _callbackHead

uint8_t SparkFun_Iridium_9604::nmeaMessage::_callbackHead = 0

Next free slot the write side will write into.

◆ _callbackPtr

void(* SparkFun_Iridium_9604::nmeaMessage::_callbackPtr) (nmeaCallbackDataCommon_t *) = nullptr

The user callback.

◆ _callbackReadIndex

uint8_t SparkFun_Iridium_9604::nmeaMessage::_callbackReadIndex = 0

Set by checkCallbacks() to _callbackTail immediately before each callback firing, so getNmeaMessageFieldCallback()/getNmeaMessageBlockFieldCallback() know which slot to read.

◆ _callbackStorage

uint8_t* SparkFun_Iridium_9604::nmeaMessage::_callbackStorage = nullptr

Ring buffer of _numCallbackCopies slots, each _messageLength bytes - nullptr until initCallbackStorage() is called.

◆ _callbackTail

uint8_t SparkFun_Iridium_9604::nmeaMessage::_callbackTail = 0

Next fresh slot checkCallbacks() will read and dispatch.

◆ _fields

const void* SparkFun_Iridium_9604::nmeaMessage::_fields = nullptr

Points at the subclass's own, permanently-lived nmeaFields[] table.

◆ _maxNumBlocks

uint8_t SparkFun_Iridium_9604::nmeaMessage::_maxNumBlocks = 0

Upper bound on the number of repeated blocks (e.g. GSV's 4)

◆ _memoryEnabled

bool SparkFun_Iridium_9604::nmeaMessage::_memoryEnabled = false

Has the module been told to store this message in its internal buffer? (AT+UGNMEA <output> bit 0)

◆ _messageLength

uint8_t SparkFun_Iridium_9604::nmeaMessage::_messageLength = 0

The maximum message length in bytes. Messages could be less than this.

◆ _moduleQueried

bool SparkFun_Iridium_9604::nmeaMessage::_moduleQueried = false

true when fresh data has arrived. Cleared by getNMEA().

◆ _msgId

const char* SparkFun_Iridium_9604::nmeaMessage::_msgId = nullptr

The message ID, e.g. "GGA".

◆ _numBlockFields

uint8_t SparkFun_Iridium_9604::nmeaMessage::_numBlockFields = 0

Number of entries in _blockFields.

◆ _numCallbackCopies

uint8_t SparkFun_Iridium_9604::nmeaMessage::_numCallbackCopies = 0

Number of ring-buffer slots in _callbackStorage - 1 for most messages, 54 for GSV - see the GNSS v4 AGENTS.md "Adding support for NMEA GSV messages".

◆ _numFields

uint8_t SparkFun_Iridium_9604::nmeaMessage::_numFields = 0

Number of entries in _fields (header + footer fields only - excludes _numBlockFields)

◆ _numHeaderFields

uint8_t SparkFun_Iridium_9604::nmeaMessage::_numHeaderFields = 0

Number of header fields before the first repeated block (also the field-table position of the first footer field)

◆ _storage

uint8_t* SparkFun_Iridium_9604::nmeaMessage::_storage = nullptr

Raw payload storage - nullptr until initStorage() is called.

◆ _urcEnabled

bool SparkFun_Iridium_9604::nmeaMessage::_urcEnabled = false

Has the module been told to output this message as a +UUGNMEA URC? (AT+UGNMEA <output> bit 1)


The documentation for this class was generated from the following file: