DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
nmea0183.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file nmea0183.h
6 * @brief NMEA 0183 sentence codec (DETWS_ENABLE_NMEA0183) - the marine / GPS ASCII protocol.
7 *
8 * NMEA 0183 sentences look like `$GPGGA,123519,4807.038,N,...*47<CR><LF>`: a `$` (or `!` for
9 * AIS-encapsulated), a comma-separated field list whose first field is the 5-char address
10 * (2-char talker id + 3-char sentence type), a `*`, and a two-hex-digit XOR checksum. This
11 * codec builds a sentence (adding the `$`, checksum, and CR/LF) and parses one (validating the
12 * checksum and splitting the fields), with `det_strtof` / `det_strtol` field-value helpers.
13 *
14 * GPS / marine receivers are cheap UART breakouts, so on an ESP32 this is a plain
15 * `HardwareSerial` link (commonly 4800 or 9600 baud); the UART is the application's. Pure
16 * codec, host-tested. Bridge position / wind / depth data onto Wi-Fi.
17 *
18 * @author Douglas Quigg (dstroy0)
19 * @date 2026
20 */
21
22#ifndef DETERMINISTICESPASYNCWEBSERVER_NMEA0183_H
23#define DETERMINISTICESPASYNCWEBSERVER_NMEA0183_H
24
25#include "ServerConfig.h"
26
27#if DETWS_ENABLE_NMEA0183
28
29#include <stddef.h>
30#include <stdint.h>
31
32/** @brief A parsed NMEA 0183 sentence. Field pointers reference the caller's buffer. */
33struct Nmea0183
34{
35 char talker[3]; ///< 2-char talker id (e.g. "GP") + NUL
36 char type[4]; ///< 3-char sentence type (e.g. "GGA") + NUL
37 uint8_t field_count; ///< number of fields, including field 0 (the address)
38 const char *fields[DETWS_NMEA0183_MAX_FIELDS]; ///< field 0 is the address; data is 1..n
39 uint8_t field_len[DETWS_NMEA0183_MAX_FIELDS]; ///< each field's length (0 for an empty field)
40};
41
42/** @brief XOR checksum over @p len octets (the sentence body between `$` and `*`). */
43uint8_t nmea0183_checksum(const char *s, size_t len);
44
45/**
46 * @brief Build a sentence from @p body (e.g. "GPGGA,123519,..."): writes `$<body>*HH\r\n` and
47 * NUL-terminates. Returns the length (excluding the NUL) or 0 on overflow.
48 */
49size_t nmea0183_build(char *buf, size_t cap, const char *body);
50
51/**
52 * @brief Parse a sentence: requires a leading `$`/`!`, validates the `*HH` XOR checksum, and
53 * splits the comma-separated fields. Fills @p out (field 0 is the address; talker / type are
54 * derived from it). Returns false on a bad frame or checksum.
55 */
56bool nmea0183_parse(const char *s, size_t len, Nmea0183 *out);
57
58/** @brief Decode field @p idx as a float (false if absent / empty / non-numeric). */
59bool nmea0183_field_float(const Nmea0183 *m, uint8_t idx, float *out);
60
61/** @brief Decode field @p idx as a long integer (false if absent / empty / non-numeric). */
62bool nmea0183_field_int(const Nmea0183 *m, uint8_t idx, long *out);
63
64#endif // DETWS_ENABLE_NMEA0183
65#endif // DETERMINISTICESPASYNCWEBSERVER_NMEA0183_H
User-facing configuration for DeterministicESPAsyncWebServer.