Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Examples/Base_Test/Base_Test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -164,7 +164,7 @@ void processMessage(SEMP_PARSE_STATE *parse, uint16_t type)
{
displayOnce = false;
Serial.println();
sempPrintParserConfiguration(parse);
sempPrintParserConfiguration(parse, &Serial);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Examples/Mixed_Parser/Mixed_Parser.ino
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void processMessage(SEMP_PARSE_STATE *parse, uint16_t type)
{
displayOnce = false;
Serial.println();
sempPrintParserConfiguration(parse);
sempPrintParserConfiguration(parse, &Serial);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Examples/Multiple_Parsers/Multiple_Parsers.ino
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void nmeaMessage(SEMP_PARSE_STATE *parse, uint16_t type)
{
displayOnce = false;
Serial.println();
sempPrintParserConfiguration(parse);
sempPrintParserConfiguration(parse, &Serial);
}
}

Expand All @@ -261,7 +261,7 @@ void ubloxMessage(SEMP_PARSE_STATE *parse, uint16_t type)
{
displayOnce = false;
Serial.println();
sempPrintParserConfiguration(parse);
sempPrintParserConfiguration(parse, &Serial);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Examples/NMEA_Test/NMEA_Test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void processMessage(SEMP_PARSE_STATE *parse, uint16_t type)
{
displayOnce = false;
Serial.println();
sempPrintParserConfiguration(parse);
sempPrintParserConfiguration(parse, &Serial);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Examples/RTCM_Test/RTCM_Test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void processMessage(SEMP_PARSE_STATE *parse, uint16_t type)
{
displayOnce = false;
Serial.println();
sempPrintParserConfiguration(parse);
sempPrintParserConfiguration(parse, &Serial);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Examples/UBLOX_Test/UBLOX_Test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void processMessage(SEMP_PARSE_STATE *parse, uint16_t type)
{
displayOnce = false;
Serial.println();
sempPrintParserConfiguration(parse);
sempPrintParserConfiguration(parse, &Serial);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Examples/Unicore_Test/Unicore_Test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void processMessage(SEMP_PARSE_STATE *parse, uint16_t type)
{
displayOnce = false;
Serial.println();
sempPrintParserConfiguration(parse);
sempPrintParserConfiguration(parse, &Serial);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Examples/User_Parser/User_Parser.ino
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void userMessage(SEMP_PARSE_STATE *parse, uint16_t type)
{
displayOnce = false;
Serial.println();
sempPrintParserConfiguration(parse);
sempPrintParserConfiguration(parse, &Serial);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Parse_NMEA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
Expand Down
2 changes: 2 additions & 0 deletions src/Parse_RTCM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
Expand Down
2 changes: 2 additions & 0 deletions src/Parse_UBLOX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
Expand Down
2 changes: 2 additions & 0 deletions src/Parse_Unicore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
Expand Down
71 changes: 34 additions & 37 deletions src/SparkFun_Extensible_Message_Parser.cpp
Original file line number Diff line number Diff line change
@@ -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 <malloc.h>
Expand All @@ -21,19 +23,13 @@ SparkFun_Extensible_Message_Parser.cpp

#define SEMP_ALIGN(x) ((x + SEMP_ALIGNMENT_MASK) & (~SEMP_ALIGNMENT_MASK))

//----------------------------------------
// Globals
//----------------------------------------

bool sempPrintErrorMessages;

//----------------------------------------
// Support routines
//----------------------------------------

// Allocate the parse structure
SEMP_PARSE_STATE * sempAllocateParseStructure(
Print *printError,
Print *printDebug,
uint16_t scratchPadBytes,
size_t bufferLength
)
Expand All @@ -43,14 +39,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);
}
Expand All @@ -60,17 +56,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;
Expand All @@ -79,7 +75,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)
Expand All @@ -89,13 +85,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;
}
Expand Down Expand Up @@ -125,28 +121,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));
}
}

Expand Down Expand Up @@ -231,6 +227,7 @@ SEMP_PARSE_STATE *sempBeginParser(
SEMP_EOM_CALLBACK eomCallback,
const char *parserName,
Print *printError,
Print *printDebug,
SEMP_BAD_CRC_CALLBACK badCrc
)
{
Expand Down Expand Up @@ -281,14 +278,15 @@ 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");
break;
}

// Initialize the parser
parse->printError = printError;
parse->parsers = parserTable;
parse->parserCount = parserCount;
parse->parserNames = parserNameTable;
Expand All @@ -298,8 +296,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
Expand Down
7 changes: 5 additions & 2 deletions src/SparkFun_Extensible_Message_Parser.h
Original file line number Diff line number Diff line change
@@ -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__
Expand Down Expand Up @@ -202,6 +204,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
Expand All @@ -223,7 +226,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, ...);
Expand Down