@@ -419,6 +419,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
419419 return NSAPI_ERROR_PARAMETER;
420420 }
421421
422+ _at.set_at_timeout (10s);
422423 _at.lock ();
423424
424425 int write_size = 0 ;
@@ -438,6 +439,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
438439 _at.cmd_start (ESC);
439440 _at.cmd_stop ();
440441 _at.unlock ();
442+ _at.restore_at_timeout ();
441443 return write_size;
442444 }
443445 // <ctrl-Z> (IRA 26) must be used to indicate the ending of the message body.
@@ -483,6 +485,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
483485 sms_count, i + 1 , header_len);
484486 if (!pdu_str) {
485487 _at.unlock ();
488+ _at.restore_at_timeout ();
486489 return NSAPI_ERROR_NO_MEMORY;
487490 }
488491 pdu_len = strlen (pdu_str);
@@ -510,6 +513,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
510513 _at.cmd_start (ESC);
511514 _at.cmd_stop ();
512515 _at.unlock ();
516+ _at.restore_at_timeout ();
513517 delete [] pdu_str;
514518 return msg_write_len;
515519 }
@@ -523,14 +527,19 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
523527 delete [] pdu_str;
524528 remaining_len -= concatenated_sms_length;
525529 if (_at.get_last_error () != NSAPI_ERROR_OK) {
526- return _at.unlock_return_error ();
530+ nsapi_error_t ret = _at.get_last_error ();
531+ _at.unlock ();
532+ _at.restore_at_timeout ();
533+ return ret;
527534 }
528535 }
529536 }
530537
531538 _sms_message_ref_number++;
532539 nsapi_error_t ret = _at.get_last_error ();
533540 _at.unlock ();
541+ _at.restore_at_timeout ();
542+ _at.clear_error ();
534543
535544 return (ret == NSAPI_ERROR_OK) ? msg_len : ret;
536545}
@@ -696,6 +705,7 @@ nsapi_size_or_error_t AT_CellularSMS::get_sms(char *buf, uint16_t len, char *pho
696705 return NSAPI_ERROR_PARAMETER;
697706 }
698707
708+ _at.set_at_timeout (10s);
699709 _at.lock ();
700710
701711 nsapi_size_or_error_t err = list_messages ();
@@ -735,6 +745,7 @@ nsapi_size_or_error_t AT_CellularSMS::get_sms(char *buf, uint16_t len, char *pho
735745 free_linked_list ();
736746
737747 _at.unlock ();
748+ _at.restore_at_timeout ();
738749
739750 // update error only when there really was an error, otherwise we return the length
740751 if (_at.get_last_error ()) {
@@ -1027,6 +1038,7 @@ nsapi_error_t AT_CellularSMS::list_messages()
10271038 int index = 0 ;
10281039 int length = 0 ;
10291040 char *pdu = NULL ;
1041+ char buffer[32 ]; // 32 > SMS_STATUS_SIZE, SMS_MAX_PHONE_NUMBER_SIZE, SMS_MAX_TIME_STAMP_SIZE
10301042
10311043 _at.resp_start (" +CMGL:" );
10321044 while (_at.info_resp ()) {
@@ -1049,8 +1061,18 @@ nsapi_error_t AT_CellularSMS::list_messages()
10491061 // +CMGL: <index>,<stat>,<oa/da>,[<alpha>],[<scts>][,<tooa/toda>,<length>]<CR><LF><data>[<CR><LF>
10501062 // +CMGL: <index>,<stat>,<da/oa>,[<alpha>],[<scts>][,<tooa/toda>,<length>]<CR><LF><data>[...]]
10511063 index = _at.read_int ();
1052- (void )_at.consume_to_stop_tag (); // consume until <CR><LF>
1053- (void )_at.consume_to_stop_tag (); // consume until <CR><LF>
1064+ _at.read_string (buffer, SMS_STATUS_SIZE);
1065+ _at.read_string (buffer, SMS_MAX_PHONE_NUMBER_SIZE);
1066+ _at.skip_param (); // <alpha>
1067+ _at.read_string (buffer, SMS_MAX_TIME_STAMP_SIZE);
1068+ _at.read_int ();
1069+ int size = _at.read_int (); // length
1070+ _at.consume_to_stop_tag (); // consume until <CR><LF> end of header
1071+ if (size > 0 ) {
1072+ // we can not use skip param because we already consumed stop tag
1073+ _at.skip_param_bytes (size, 1 );
1074+ }
1075+ _at.consume_to_stop_tag_even_stop_tag_found (); // consume until <CR><LF> -> data
10541076 }
10551077
10561078 if (index >= 0 ) {
0 commit comments