Skip to content

Commit c765c1c

Browse files
authored
Merge pull request #6 from neomilium/master
Fix last parameter count and comparison using flash
2 parents 8d387f5 + b48f403 commit c765c1c

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
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/CmdCallback.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ template <size_t STORESIZE>
172172
class CmdCallback_P : public _CmdCallback<STORESIZE, CmdParserString_P>
173173
{
174174
/**
175-
* @implement CmdCallbackObject with strcmp_P
175+
* @implement CmdCallbackObject with strcasecmp_P
176176
*/
177177
virtual bool equalStoreCmd(size_t idx, char *cmdStr)
178178
{
179179
if (this->checkStorePos(idx) &&
180-
strcasecmp_P(this->m_cmdList[idx], cmdStr) == 0) {
180+
strcasecmp_P(cmdStr, this->m_cmdList[idx]) == 0) {
181181
return true;
182182
}
183183

@@ -195,7 +195,7 @@ template <size_t STORESIZE>
195195
class CmdCallback : public _CmdCallback<STORESIZE, CmdParserString>
196196
{
197197
/**
198-
* @implement CmdCallbackObject with strcmp_P
198+
* @implement CmdCallbackObject with strcasecmp
199199
*/
200200
virtual bool equalStoreCmd(size_t idx, char *cmdStr)
201201
{

src/CmdParser.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ uint16_t CmdParser::parseCmd(uint8_t *buffer, size_t bufferSize)
2121
bool isString = false;
2222

2323
// init param count
24-
m_paramCount ^= m_paramCount;
24+
m_paramCount = 0;
2525

2626
// buffer is not okay
2727
if (buffer == NULL || bufferSize == 0) {
@@ -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)