Skip to content

Commit e98f23f

Browse files
fixup! [WIP] Improving parse function in modem class
1 parent 051a711 commit e98f23f

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

libraries/WiFiS3/src/Modem.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,16 @@ ModemClass::ParseResult ModemClass::buf_read(const string &prompt, string &data_
141141
* + "+COMMAND: 4| 123OK<CR><LF>"
142142
*/
143143
enum class at_parse_state_t {
144-
Begin,
145-
Cmd,
146-
Data,
147-
Sized,
148-
ResWaitLF,
149-
Res,
150-
Error,
151-
ParseError,
152-
Ok,
153-
Completed,
144+
Begin = 0,
145+
Cmd = 1,
146+
Data = 2,
147+
Sized = 3,
148+
ResWaitLF = 4,
149+
Res = 5,
150+
Error = 6,
151+
ParseError = 7,
152+
Ok = 8,
153+
Completed = 9,
154154
};
155155

156156
at_parse_state_t state = at_parse_state_t::Begin;
@@ -189,6 +189,9 @@ ModemClass::ParseResult ModemClass::buf_read(const string &prompt, string &data_
189189
} else {
190190
_serial_debug->print(c);
191191
}
192+
} else if(_serial_debug && _debug_level >= 2) {
193+
_serial_debug->print(" State ");
194+
_serial_debug->println((int)state);
192195
}
193196

194197
switch(state) {
@@ -289,9 +292,11 @@ ModemClass::ParseResult ModemClass::buf_read(const string &prompt, string &data_
289292
} if(c == RESULT_OK[0]) { // OK response
290293
res = Ok;
291294
state = at_parse_state_t::Ok;
295+
result_parse = 1;
292296
} else if(c == RESULT_ERROR[0]) { // Error response
293297
res = Error;
294298
state = at_parse_state_t::Error;
299+
result_parse = 1;
295300
}
296301
// if we uncomment this we can force strict response matching
297302
// else {
@@ -303,8 +308,7 @@ ModemClass::ParseResult ModemClass::buf_read(const string &prompt, string &data_
303308
* In this state we want to match the exact 'K<CR><LF>' response
304309
*/
305310

306-
if(c != RESULT_OK[++result_parse]) {
307-
_serial_debug->println("pippo");
311+
if(c != RESULT_OK[result_parse++]) {
308312
state = at_parse_state_t::ParseError;
309313
}
310314

@@ -317,7 +321,7 @@ ModemClass::ParseResult ModemClass::buf_read(const string &prompt, string &data_
317321
* In this state we want to match the exact 'RROR<CR><LF>' response
318322
*/
319323

320-
if(c != RESULT_ERROR[++result_parse]) {
324+
if(c != RESULT_ERROR[result_parse++]) {
321325
state = at_parse_state_t::ParseError;
322326
}
323327

0 commit comments

Comments
 (0)