@@ -235,12 +235,15 @@ ModemClass::ParseResult ModemClass::buf_read(const string &prompt, string &data_
235235 if (c == ' :' || c == ' =' ) {
236236 commandName += c; // prompt includes also ':'
237237
238- if (commandName != DO_NOT_CHECK_CMD && commandName != prompt) {
239- // state = at_parse_state_t::Begin; // TODO decide whether to return ParseError or realign
238+ if (prompt != DO_NOT_CHECK_CMD && commandName != prompt) {
239+ // the response we got is not the one we were expecting, parse the wrong response till the end
240+ // and start the parse of the next response
240241 restart = true ;
241- } else {
242- state = at_parse_state_t ::Data;
242+ commandName = " " ;
243243 }
244+ state = at_parse_state_t ::Data;
245+
246+ data_res = " " ;
244247 // state = at_parse_state_t::Data;
245248 } else if (c != ' ' ) { // FIXME should we keep the space?
246249 commandName += c;
@@ -330,6 +333,7 @@ ModemClass::ParseResult ModemClass::buf_read(const string &prompt, string &data_
330333
331334 if (restart) {
332335 state = at_parse_state_t ::Begin;
336+ restart = false ;
333337 } else {
334338 state = at_parse_state_t ::Completed;
335339 }
@@ -349,6 +353,7 @@ ModemClass::ParseResult ModemClass::buf_read(const string &prompt, string &data_
349353
350354 if (restart) {
351355 state = at_parse_state_t ::Begin;
356+ restart = false ;
352357 } else {
353358 state = at_parse_state_t ::Completed;
354359 }
@@ -358,6 +363,7 @@ ModemClass::ParseResult ModemClass::buf_read(const string &prompt, string &data_
358363 res = ParseError;
359364 if (restart) {
360365 state = at_parse_state_t ::Begin;
366+ restart = false ;
361367 } else {
362368 state = at_parse_state_t ::Completed;
363369 }
0 commit comments