Hardware-independent NMEA framing and utilities shared by receiver classes. Receive storage is borrowed, with no heap allocation. Each instance has its own receive state and timestamps; callers must synchronize concurrent use.
Feed one byte into this receiver's bounded sentence buffer.
- Parameters
-
| byte | Received byte, including any CR/LF characters. |
| receivedAtMs | Receive time in milliseconds, such as millis(). |
- Returns
- INCOMPLETE until LF completes a line, then its validation status. OVERFLOW discards a line that cannot fit including LF and NUL. BAD_FORMAT also indicates invalid storage supplied to the constructor.
Ignore bytes before '$' or '!'. Either start marker restarts assembly, including after overflow. Overflow is reported once; subsequent bytes are ignored until another start marker. Partial and overflowing lines preserve the previous complete line and its timestamps.
Every complete, non-overflowed line replaces lastSentence(), even if its format or checksum is invalid. Its raw text includes LF and is followed by a NUL terminator. The caller must consume each line promptly; there is no queue. No transport access, allocation, or sentence copying occurs.
| nmea_sentence_t Adafruit_NMEA::validate |
( |
const char * |
data, |
|
|
size_t |
length |
|
) |
| |
|
static |
Validate a complete, length-bounded NMEA sentence without copying it.
- Parameters
-
| data | Readable input buffer; no NUL terminator is required. |
| length | Number of bytes to inspect, excluding any NUL terminator. |
- Returns
- Status and borrowed spans. Address and fields are absent on failure. Raw text remains available unless data is NULL, which gives absent spans.
Accepts '$' or '!', an ASCII alphanumeric address, optional comma-separated fields, '*', two hex checksum digits, optional CR, and optional LF, in that order. A valid but unknown address is accepted. Embedded start markers, control characters, non-ASCII bytes, and extra trailer bytes are rejected. Missing or invalid hex digits are BAD_FORMAT; a mismatch is BAD_CHECKSUM.
A zero-field message such as "$PQTMVERNO*58" has absent fields. A comma immediately followed by '*' denotes one empty field, with non-NULL data and zero length. Returned views require the input to remain unchanged. This function allocates no memory and has no shared or per-instance state.
Return the next field and advance a bounded field cursor.
- Parameters
-
| remaining | Start with a copy of a VALID sentence's fields span. Updated in place to refer to the fields after the next comma, or to an absent span after the last field. Its input storage must remain readable. |
- Returns
- Borrowed field text, excluding the comma. Non-NULL data with zero length means an empty field; NULL data means there are no fields left.
Leading, consecutive, and trailing commas preserve empty fields. An absent cursor stays absent on subsequent calls. No text is copied or modified, and no NUL terminator is required. Only the supplied length is inspected. Iterate each cursor in order for one forward scan of its fields.
To mark a cursor exhausted, set remaining.data to NULL. Setting only remaining.length to zero still yields one empty field if data is non-NULL.
Convert a complete field to an exact signed decimal value.
- Parameters
-
| field | Borrowed readable text, with no NUL terminator required. |
- Returns
- Status, integer coefficient, and decimal-place count. Both numeric members are zero on failure. NULL data is MISSING; zero length is EMPTY.
Accepts an optional sign, digits, and at most one decimal point. At least one digit is required. Whitespace, exponents, and non-digit suffixes are rejected. The supplied fractional digit count is retained, including zeros. Coefficients must fit int64_t and decimal-place counts must fit uint8_t. Malformed syntax takes precedence over overflow. No rounding, floating-point conversion, allocation, or input modification occurs.
| size_t Adafruit_NMEA::buildCommand |
( |
char * |
output, |
|
|
size_t |
capacity, |
|
|
const char * |
body, |
|
|
size_t |
bodyLength |
|
) |
| |
|
static |
Build a checksummed command in caller-provided storage.
- Parameters
-
| output | Writable buffer for the complete command and NUL terminator. |
| capacity | Size of output in bytes, including space for NUL. |
| body | Readable address and optional comma-separated fields, without '$', '!', '*', control characters, or non-ASCII bytes. No NUL is required. |
| bodyLength | Number of bytes in body, excluding any NUL terminator. |
- Returns
- Bytes written excluding NUL, or zero on invalid input, overlapping buffers, or insufficient capacity. On failure, output[0] is cleared if output is non-NULL and capacity is nonzero; no other output bytes are changed.
Produces "$<body>*HH\r\n" followed by NUL, using uppercase checksum digits. Requires bodyLength + NMEA_COMMAND_OVERHEAD bytes of storage. The address must be nonempty and ASCII alphanumeric. Zero-field commands are allowed. Arguments, capacity, and body syntax are checked before constructing output. No heap allocation or transport I/O occurs.