From 1c5feb550ac67ab01a837f6286d1b5a9adeafeba Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Tue, 30 Jan 2024 17:07:06 -1000 Subject: [PATCH 1/3] Pass debugPrint to sempBeginParser, show parse & scratchPad allocations --- src/SparkFun_Extensible_Message_Parser.cpp | 27 +++++++++++----------- src/SparkFun_Extensible_Message_Parser.h | 1 + 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/SparkFun_Extensible_Message_Parser.cpp b/src/SparkFun_Extensible_Message_Parser.cpp index 9226bb8..afa10da 100644 --- a/src/SparkFun_Extensible_Message_Parser.cpp +++ b/src/SparkFun_Extensible_Message_Parser.cpp @@ -33,7 +33,7 @@ bool sempPrintErrorMessages; // Allocate the parse structure SEMP_PARSE_STATE * sempAllocateParseStructure( - Print *printError, + Print *printDebug, uint16_t scratchPadBytes, size_t bufferLength ) @@ -43,14 +43,14 @@ SEMP_PARSE_STATE * sempAllocateParseStructure( int parseBytes; // Print the scratchPad area size - sempPrintf(printError, "scratchPadBytes: 0x%04x (%d) bytes", + sempPrintf(printDebug, "scratchPadBytes: 0x%04x (%d) bytes", scratchPadBytes, scratchPadBytes); // Align the scratch patch area if (scratchPadBytes < SEMP_ALIGN(scratchPadBytes)) { scratchPadBytes = SEMP_ALIGN(scratchPadBytes); - sempPrintf(printError, + sempPrintf(printDebug, "scratchPadBytes: 0x%04x (%d) bytes after alignment", scratchPadBytes, scratchPadBytes); } @@ -60,17 +60,17 @@ SEMP_PARSE_STATE * sempAllocateParseStructure( if (scratchPadBytes < length) { scratchPadBytes = length; - sempPrintf(printError, + sempPrintf(printDebug, "scratchPadBytes: 0x%04x (%d) bytes after mimimum size adjustment", scratchPadBytes, scratchPadBytes); } parseBytes = SEMP_ALIGN(sizeof(SEMP_PARSE_STATE)); - sempPrintf(printError, "parseBytes: 0x%04x (%d)", parseBytes, parseBytes); + sempPrintf(printDebug, "parseBytes: 0x%04x (%d)", parseBytes, parseBytes); // Verify the minimum bufferLength if (bufferLength < SEMP_MINIMUM_BUFFER_LENGTH) { - sempPrintf(printError, + sempPrintf(printDebug, "SEMP: Increasing bufferLength from %d to %d bytes, minimum size adjustment", bufferLength, SEMP_MINIMUM_BUFFER_LENGTH); bufferLength = SEMP_MINIMUM_BUFFER_LENGTH; @@ -79,7 +79,7 @@ SEMP_PARSE_STATE * sempAllocateParseStructure( // Allocate the parser length = parseBytes + scratchPadBytes; parse = (SEMP_PARSE_STATE *)malloc(length + bufferLength); - sempPrintf(printError, "parse: %p", parse); + sempPrintf(printDebug, "parse: %p", parse); // Initialize the parse structure if (parse) @@ -89,13 +89,13 @@ SEMP_PARSE_STATE * sempAllocateParseStructure( // Set the scratch pad area address parse->scratchPad = ((void *)parse) + parseBytes; - parse->printError = printError; - sempPrintf(parse->printError, "parse->scratchPad: %p", parse->scratchPad); + parse->printDebug = printDebug; + sempPrintf(parse->printDebug, "parse->scratchPad: %p", parse->scratchPad); // Set the buffer address and length parse->bufferLength = bufferLength; parse->buffer = (uint8_t *)(parse->scratchPad + scratchPadBytes); - sempPrintf(parse->printError, "parse->buffer: %p", parse->buffer); + sempPrintf(parse->printDebug, "parse->buffer: %p", parse->buffer); } return parse; } @@ -231,6 +231,7 @@ SEMP_PARSE_STATE *sempBeginParser( SEMP_EOM_CALLBACK eomCallback, const char *parserName, Print *printError, + Print *printDebug, SEMP_BAD_CRC_CALLBACK badCrc ) { @@ -281,7 +282,7 @@ SEMP_PARSE_STATE *sempBeginParser( } // Validate the parser address is not nullptr - parse = sempAllocateParseStructure(printError, scratchPadBytes, bufferLength); + parse = sempAllocateParseStructure(printDebug, scratchPadBytes, bufferLength); if (!parse) { sempPrintln(printError, "SEMP: Failed to allocate the parse structure"); @@ -289,6 +290,7 @@ SEMP_PARSE_STATE *sempBeginParser( } // Initialize the parser + parse->printError = printError; parse->parsers = parserTable; parse->parserCount = parserCount; parse->parserNames = parserNameTable; @@ -298,8 +300,7 @@ SEMP_PARSE_STATE *sempBeginParser( parse->badCrc = badCrc; // Display the parser configuration - if (sempPrintErrorMessages) - sempPrintParserConfiguration(parse); + sempPrintParserConfiguration(parse, parse->printDebug); } while (0); // Return the parse structure address diff --git a/src/SparkFun_Extensible_Message_Parser.h b/src/SparkFun_Extensible_Message_Parser.h index 8162ca7..bc00224 100644 --- a/src/SparkFun_Extensible_Message_Parser.h +++ b/src/SparkFun_Extensible_Message_Parser.h @@ -202,6 +202,7 @@ SEMP_PARSE_STATE * sempBeginParser(const SEMP_PARSE_ROUTINE *parseTable, \ SEMP_EOM_CALLBACK eomCallback, \ const char *name, \ Print *printError = &Serial, + Print *printDebug = (Print *)nullptr, SEMP_BAD_CRC_CALLBACK badCrcCallback = (SEMP_BAD_CRC_CALLBACK)nullptr); // Only parsers should call the routine sempFirstByte when an unexpected From 93e4ab0072ea70e951523b9eaa005980af2970ef Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Tue, 30 Jan 2024 20:34:25 -1000 Subject: [PATCH 2/3] Pass Print * to sempPrintParserConfiguration --- Examples/Base_Test/Base_Test.ino | 4 +- Examples/Mixed_Parser/Mixed_Parser.ino | 2 +- .../Multiple_Parsers/Multiple_Parsers.ino | 4 +- Examples/NMEA_Test/NMEA_Test.ino | 2 +- Examples/RTCM_Test/RTCM_Test.ino | 2 +- Examples/UBLOX_Test/UBLOX_Test.ino | 2 +- Examples/Unicore_Test/Unicore_Test.ino | 2 +- Examples/User_Parser/User_Parser.ino | 2 +- src/SparkFun_Extensible_Message_Parser.cpp | 40 ++++++++----------- src/SparkFun_Extensible_Message_Parser.h | 2 +- 10 files changed, 28 insertions(+), 34 deletions(-) diff --git a/Examples/Base_Test/Base_Test.ino b/Examples/Base_Test/Base_Test.ino index 9adde1f..900ae19 100644 --- a/Examples/Base_Test/Base_Test.ino +++ b/Examples/Base_Test/Base_Test.ino @@ -112,7 +112,7 @@ void setup() // Display the parser configuration Serial.printf("&parserTable: %p\r\n", parserTable); Serial.printf("&parserNames: %p\r\n", parserNames); - sempPrintParserConfiguration(parse); + sempPrintParserConfiguration(parse, &Serial); // Display the parse state Serial.printf("Parse State: %s\r\n", sempGetStateName(parse)); @@ -164,7 +164,7 @@ void processMessage(SEMP_PARSE_STATE *parse, uint16_t type) { displayOnce = false; Serial.println(); - sempPrintParserConfiguration(parse); + sempPrintParserConfiguration(parse, &Serial); } } diff --git a/Examples/Mixed_Parser/Mixed_Parser.ino b/Examples/Mixed_Parser/Mixed_Parser.ino index 8971e36..fb1b492 100644 --- a/Examples/Mixed_Parser/Mixed_Parser.ino +++ b/Examples/Mixed_Parser/Mixed_Parser.ino @@ -229,7 +229,7 @@ void processMessage(SEMP_PARSE_STATE *parse, uint16_t type) { displayOnce = false; Serial.println(); - sempPrintParserConfiguration(parse); + sempPrintParserConfiguration(parse, &Serial); } } diff --git a/Examples/Multiple_Parsers/Multiple_Parsers.ino b/Examples/Multiple_Parsers/Multiple_Parsers.ino index 9519653..2702bd2 100644 --- a/Examples/Multiple_Parsers/Multiple_Parsers.ino +++ b/Examples/Multiple_Parsers/Multiple_Parsers.ino @@ -238,7 +238,7 @@ void nmeaMessage(SEMP_PARSE_STATE *parse, uint16_t type) { displayOnce = false; Serial.println(); - sempPrintParserConfiguration(parse); + sempPrintParserConfiguration(parse, &Serial); } } @@ -261,7 +261,7 @@ void ubloxMessage(SEMP_PARSE_STATE *parse, uint16_t type) { displayOnce = false; Serial.println(); - sempPrintParserConfiguration(parse); + sempPrintParserConfiguration(parse, &Serial); } } diff --git a/Examples/NMEA_Test/NMEA_Test.ino b/Examples/NMEA_Test/NMEA_Test.ino index 3c5020c..bb6806e 100644 --- a/Examples/NMEA_Test/NMEA_Test.ino +++ b/Examples/NMEA_Test/NMEA_Test.ino @@ -138,7 +138,7 @@ void processMessage(SEMP_PARSE_STATE *parse, uint16_t type) { displayOnce = false; Serial.println(); - sempPrintParserConfiguration(parse); + sempPrintParserConfiguration(parse, &Serial); } } diff --git a/Examples/RTCM_Test/RTCM_Test.ino b/Examples/RTCM_Test/RTCM_Test.ino index 39a57d8..c1d9ab2 100644 --- a/Examples/RTCM_Test/RTCM_Test.ino +++ b/Examples/RTCM_Test/RTCM_Test.ino @@ -132,7 +132,7 @@ void processMessage(SEMP_PARSE_STATE *parse, uint16_t type) { displayOnce = false; Serial.println(); - sempPrintParserConfiguration(parse); + sempPrintParserConfiguration(parse, &Serial); } } diff --git a/Examples/UBLOX_Test/UBLOX_Test.ino b/Examples/UBLOX_Test/UBLOX_Test.ino index 3e1ec3f..e60633a 100644 --- a/Examples/UBLOX_Test/UBLOX_Test.ino +++ b/Examples/UBLOX_Test/UBLOX_Test.ino @@ -174,7 +174,7 @@ void processMessage(SEMP_PARSE_STATE *parse, uint16_t type) { displayOnce = false; Serial.println(); - sempPrintParserConfiguration(parse); + sempPrintParserConfiguration(parse, &Serial); } } diff --git a/Examples/Unicore_Test/Unicore_Test.ino b/Examples/Unicore_Test/Unicore_Test.ino index 1281e27..a85da1c 100644 --- a/Examples/Unicore_Test/Unicore_Test.ino +++ b/Examples/Unicore_Test/Unicore_Test.ino @@ -180,7 +180,7 @@ void processMessage(SEMP_PARSE_STATE *parse, uint16_t type) { displayOnce = false; Serial.println(); - sempPrintParserConfiguration(parse); + sempPrintParserConfiguration(parse, &Serial); } } diff --git a/Examples/User_Parser/User_Parser.ino b/Examples/User_Parser/User_Parser.ino index 9f24640..624779d 100644 --- a/Examples/User_Parser/User_Parser.ino +++ b/Examples/User_Parser/User_Parser.ino @@ -220,7 +220,7 @@ void userMessage(SEMP_PARSE_STATE *parse, uint16_t type) { displayOnce = false; Serial.println(); - sempPrintParserConfiguration(parse); + sempPrintParserConfiguration(parse, &Serial); } } diff --git a/src/SparkFun_Extensible_Message_Parser.cpp b/src/SparkFun_Extensible_Message_Parser.cpp index afa10da..6387ff1 100644 --- a/src/SparkFun_Extensible_Message_Parser.cpp +++ b/src/SparkFun_Extensible_Message_Parser.cpp @@ -21,12 +21,6 @@ SparkFun_Extensible_Message_Parser.cpp #define SEMP_ALIGN(x) ((x + SEMP_ALIGNMENT_MASK) & (~SEMP_ALIGNMENT_MASK)) -//---------------------------------------- -// Globals -//---------------------------------------- - -bool sempPrintErrorMessages; - //---------------------------------------- // Support routines //---------------------------------------- @@ -125,28 +119,28 @@ const char * sempGetTypeName(SEMP_PARSE_STATE *parse, uint16_t type) } // Print the parser's configuration -void sempPrintParserConfiguration(SEMP_PARSE_STATE *parse) +void sempPrintParserConfiguration(SEMP_PARSE_STATE *parse, Print *print) { - if (parse->printError) + if (print) { - sempPrintln(parse->printError, "SparkFun Extensible Message Parser"); - sempPrintf(parse->printError, " Name: %p (%s)", parse->parserName, parse->parserName); - sempPrintf(parse->printError, " parsers: %p", parse->parsers); - sempPrintf(parse->printError, " parserNames: %p", parse->parserNames); - sempPrintf(parse->printError, " parserCount: %d", parse->parserCount); - sempPrintf(parse->printError, " printError: %p", parse->printError); - sempPrintf(parse->printError, " printDebug: %p", parse->printDebug); - sempPrintf(parse->printError, " Scratch Pad: %p (%d bytes)", + sempPrintln(print, "SparkFun Extensible Message Parser"); + sempPrintf(print, " Name: %p (%s)", parse->parserName, parse->parserName); + sempPrintf(print, " parsers: %p", parse->parsers); + sempPrintf(print, " parserNames: %p", parse->parserNames); + sempPrintf(print, " parserCount: %d", parse->parserCount); + sempPrintf(print, " printError: %p", parse->printError); + sempPrintf(print, " printDebug: %p", parse->printDebug); + sempPrintf(print, " Scratch Pad: %p (%d bytes)", (void *)parse->scratchPad, parse->buffer - (uint8_t *)parse->scratchPad); - sempPrintf(parse->printError, " computeCrc: %p", (void *)parse->computeCrc); - sempPrintf(parse->printError, " crc: 0x%08x", parse->crc); - sempPrintf(parse->printError, " State: %p%s", (void *)parse->state, + sempPrintf(print, " computeCrc: %p", (void *)parse->computeCrc); + sempPrintf(print, " crc: 0x%08x", parse->crc); + sempPrintf(print, " State: %p%s", (void *)parse->state, (parse->state == sempFirstByte) ? " (sempFirstByte)" : ""); - sempPrintf(parse->printError, " EomCallback: %p", (void *)parse->eomCallback); - sempPrintf(parse->printError, " Buffer: %p (%d bytes)", + sempPrintf(print, " EomCallback: %p", (void *)parse->eomCallback); + sempPrintf(print, " Buffer: %p (%d bytes)", (void *)parse->buffer, parse->bufferLength); - sempPrintf(parse->printError, " length: %d message bytes", parse->length); - sempPrintf(parse->printError, " type: %d (%s)", parse->type, sempGetTypeName(parse, parse->type)); + sempPrintf(print, " length: %d message bytes", parse->length); + sempPrintf(print, " type: %d (%s)", parse->type, sempGetTypeName(parse, parse->type)); } } diff --git a/src/SparkFun_Extensible_Message_Parser.h b/src/SparkFun_Extensible_Message_Parser.h index bc00224..d376df0 100644 --- a/src/SparkFun_Extensible_Message_Parser.h +++ b/src/SparkFun_Extensible_Message_Parser.h @@ -224,7 +224,7 @@ void sempParseNextByte(SEMP_PARSE_STATE *parse, uint8_t data); void sempStopParser(SEMP_PARSE_STATE **parse); // Print the contents of the parser data structure -void sempPrintParserConfiguration(SEMP_PARSE_STATE *parse); +void sempPrintParserConfiguration(SEMP_PARSE_STATE *parse, Print *print); // Format and print a line of text void sempPrintf(Print *print, const char *format, ...); From d108461266406f7ac979b0e365cf4ea7ec75741f Mon Sep 17 00:00:00 2001 From: Lee Leahy Date: Wed, 31 Jan 2024 10:53:35 -1000 Subject: [PATCH 3/3] Add license line to source files --- src/Parse_NMEA.cpp | 2 ++ src/Parse_RTCM.cpp | 2 ++ src/Parse_UBLOX.cpp | 2 ++ src/Parse_Unicore.cpp | 2 ++ src/SparkFun_Extensible_Message_Parser.cpp | 4 +++- src/SparkFun_Extensible_Message_Parser.h | 4 +++- 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Parse_NMEA.cpp b/src/Parse_NMEA.cpp index e10d8cb..1c13e9f 100644 --- a/src/Parse_NMEA.cpp +++ b/src/Parse_NMEA.cpp @@ -9,6 +9,8 @@ proceed the routine use and eliminates the need for forward declaration. Removing the forward declaration helps reduce the exposure of the routines to the application layer. As such only the preamble routine should need to be listed in SparkFun_Extensible_Message_Parser.h. + +License: MIT. Please see LICENSE.md for more details ------------------------------------------------------------------------------*/ #include diff --git a/src/Parse_RTCM.cpp b/src/Parse_RTCM.cpp index 62d1a45..d179880 100644 --- a/src/Parse_RTCM.cpp +++ b/src/Parse_RTCM.cpp @@ -9,6 +9,8 @@ proceed the routine use and eliminates the need for forward declaration. Removing the forward declaration helps reduce the exposure of the routines to the application layer. As such only the preamble routine should need to be listed in SparkFun_Extensible_Message_Parser.h. + +License: MIT. Please see LICENSE.md for more details ------------------------------------------------------------------------------*/ #include diff --git a/src/Parse_UBLOX.cpp b/src/Parse_UBLOX.cpp index bc9f2df..44e3e80 100644 --- a/src/Parse_UBLOX.cpp +++ b/src/Parse_UBLOX.cpp @@ -9,6 +9,8 @@ proceed the routine use and eliminates the need for forward declaration. Removing the forward declaration helps reduce the exposure of the routines to the application layer. As such only the preamble routine should need to be listed in SparkFun_Extensible_Message_Parser.h. + +License: MIT. Please see LICENSE.md for more details ------------------------------------------------------------------------------*/ #include diff --git a/src/Parse_Unicore.cpp b/src/Parse_Unicore.cpp index 8e33156..58f8596 100644 --- a/src/Parse_Unicore.cpp +++ b/src/Parse_Unicore.cpp @@ -9,6 +9,8 @@ proceed the routine use and eliminates the need for forward declaration. Removing the forward declaration helps reduce the exposure of the routines to the application layer. As such only the preamble routine should need to be listed in SparkFun_Extensible_Message_Parser.h. + +License: MIT. Please see LICENSE.md for more details ------------------------------------------------------------------------------*/ #include diff --git a/src/SparkFun_Extensible_Message_Parser.cpp b/src/SparkFun_Extensible_Message_Parser.cpp index 6387ff1..f15645a 100644 --- a/src/SparkFun_Extensible_Message_Parser.cpp +++ b/src/SparkFun_Extensible_Message_Parser.cpp @@ -1,7 +1,9 @@ /*------------------------------------------------------------------------------ SparkFun_Extensible_Message_Parser.cpp - Parse messages from GNSS radios +Parse messages from GNSS radios + +License: MIT. Please see LICENSE.md for more details ------------------------------------------------------------------------------*/ #include diff --git a/src/SparkFun_Extensible_Message_Parser.h b/src/SparkFun_Extensible_Message_Parser.h index d376df0..a2bcf0b 100644 --- a/src/SparkFun_Extensible_Message_Parser.h +++ b/src/SparkFun_Extensible_Message_Parser.h @@ -1,7 +1,9 @@ /*------------------------------------------------------------------------------ SparkFun_Extensible_Message_Parser.h - Constant and routine declarations for the extensible message parser. +Constant and routine declarations for the extensible message parser. + +License: MIT. Please see LICENSE.md for more details ------------------------------------------------------------------------------*/ #ifndef __SPARKFUN_EXTENSIBLE_MESSAGE_PARSER_H__