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
27 changes: 14 additions & 13 deletions src/SparkFun_Extensible_Message_Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool sempPrintErrorMessages;

// Allocate the parse structure
SEMP_PARSE_STATE * sempAllocateParseStructure(
Print *printError,
Print *printDebug,
uint16_t scratchPadBytes,
size_t bufferLength
)
Expand All @@ -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);
}
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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;
}
Expand Down Expand Up @@ -231,6 +231,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 +282,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 +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
Expand Down
1 change: 1 addition & 0 deletions src/SparkFun_Extensible_Message_Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down