Skip to content

Commit 3630fe5

Browse files
committed
Fix last parameter count
While parsing, last parameter was not always count. e.g. with Parser.ino example: * getParamCount() on "START \"Hallo world\" sensor" should return 3 but was returning 2 * getParamCount() on "START \"Hallo world\" sensor " (note: space at eol) will return 3 as expected This commit fixes this behaviour and always count the last parameter.
1 parent 8d387f5 commit 3630fe5

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

examples/Parser/Parser.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void loop()
7474
Serial.println(cmdParser.getParamCount());
7575

7676
const size_t count = cmdParser.getParamCount();
77-
for (size_t i = 0; i <= count; i++) {
77+
for (size_t i = 0; i < count; i++) {
7878

7979
Serial.print("Param ");
8080
Serial.print(i);

src/CmdParser.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ uint16_t CmdParser::parseCmd(uint8_t *buffer, size_t bufferSize)
3838

3939
// end
4040
if (buffer[i] == 0x00 || m_paramCount == 0xFFFE) {
41+
if (i > 0 && buffer[i - 1] != 0x00) {
42+
m_paramCount++;
43+
}
4144
return m_paramCount;
4245
}
4346
// is string "xy zyx" / only the quote option is disabled

0 commit comments

Comments
 (0)