From c1c3837ba69b246a793b9504dce21d3257f5f79d Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Thu, 12 Sep 2024 21:01:12 +0200 Subject: [PATCH] allow overriding of sentence structure defines This is needed for NMEA-like protocols that add extensions with longer-than-expected sentences, or new longer type words. Users that need to, can now define their own limits or use the default defines. --- src/nmea/nmea.c | 4 ++-- src/nmea/nmea.h | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/nmea/nmea.c b/src/nmea/nmea.c index a21c4db..54419ea 100644 --- a/src/nmea/nmea.c +++ b/src/nmea/nmea.c @@ -161,7 +161,7 @@ nmea_validate(const char *sentence, size_t length, int check_checksum) /* should have a 5 letter, uppercase word */ n = sentence; - while (++n < sentence + 6) { + while (++n <= sentence + NMEA_PREFIX_LENGTH) { if (*n < 'A' || *n > 'Z') { /* not uppercase letter */ return -1; @@ -169,7 +169,7 @@ nmea_validate(const char *sentence, size_t length, int check_checksum) } /* should have a comma after the type word */ - if (',' != sentence[6]) { + if (',' != sentence[NMEA_PREFIX_LENGTH+1]) { return -1; } diff --git a/src/nmea/nmea.h b/src/nmea/nmea.h index 99e6ca1..7e874ba 100644 --- a/src/nmea/nmea.h +++ b/src/nmea/nmea.h @@ -43,14 +43,22 @@ typedef struct { } nmea_position; /* NMEA sentence max length, including \r\n (chars) */ +#ifndef NMEA_MAX_LENGTH #define NMEA_MAX_LENGTH 82 +#endif /* NMEA sentence endings, should be \r\n according the NMEA 0183 standard */ +#ifndef NMEA_END_CHAR_1 #define NMEA_END_CHAR_1 '\r' +#endif +#ifndef NMEA_END_CHAR_2 #define NMEA_END_CHAR_2 '\n' +#endif /* NMEA sentence prefix length (num chars), Ex: GPGLL */ +#ifndef NMEA_PREFIX_LENGTH #define NMEA_PREFIX_LENGTH 5 +#endif #ifdef __cplusplus extern "C" {