@@ -419,6 +419,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
419
419
return NSAPI_ERROR_PARAMETER;
420
420
}
421
421
422
+ _at.set_at_timeout (10s);
422
423
_at.lock ();
423
424
424
425
int write_size = 0 ;
@@ -438,6 +439,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
438
439
_at.cmd_start (ESC);
439
440
_at.cmd_stop ();
440
441
_at.unlock ();
442
+ _at.restore_at_timeout ();
441
443
return write_size;
442
444
}
443
445
// <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
483
485
sms_count, i + 1 , header_len);
484
486
if (!pdu_str) {
485
487
_at.unlock ();
488
+ _at.restore_at_timeout ();
486
489
return NSAPI_ERROR_NO_MEMORY;
487
490
}
488
491
pdu_len = strlen (pdu_str);
@@ -510,6 +513,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
510
513
_at.cmd_start (ESC);
511
514
_at.cmd_stop ();
512
515
_at.unlock ();
516
+ _at.restore_at_timeout ();
513
517
delete [] pdu_str;
514
518
return msg_write_len;
515
519
}
@@ -523,14 +527,19 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
523
527
delete [] pdu_str;
524
528
remaining_len -= concatenated_sms_length;
525
529
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;
527
534
}
528
535
}
529
536
}
530
537
531
538
_sms_message_ref_number++;
532
539
nsapi_error_t ret = _at.get_last_error ();
533
540
_at.unlock ();
541
+ _at.restore_at_timeout ();
542
+ _at.clear_error ();
534
543
535
544
return (ret == NSAPI_ERROR_OK) ? msg_len : ret;
536
545
}
@@ -696,6 +705,7 @@ nsapi_size_or_error_t AT_CellularSMS::get_sms(char *buf, uint16_t len, char *pho
696
705
return NSAPI_ERROR_PARAMETER;
697
706
}
698
707
708
+ _at.set_at_timeout (10s);
699
709
_at.lock ();
700
710
701
711
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
735
745
free_linked_list ();
736
746
737
747
_at.unlock ();
748
+ _at.restore_at_timeout ();
738
749
739
750
// update error only when there really was an error, otherwise we return the length
740
751
if (_at.get_last_error ()) {
@@ -1027,6 +1038,7 @@ nsapi_error_t AT_CellularSMS::list_messages()
1027
1038
int index = 0 ;
1028
1039
int length = 0 ;
1029
1040
char *pdu = NULL ;
1041
+ char buffer[32 ]; // 32 > SMS_STATUS_SIZE, SMS_MAX_PHONE_NUMBER_SIZE, SMS_MAX_TIME_STAMP_SIZE
1030
1042
1031
1043
_at.resp_start (" +CMGL:" );
1032
1044
while (_at.info_resp ()) {
@@ -1049,8 +1061,18 @@ nsapi_error_t AT_CellularSMS::list_messages()
1049
1061
// +CMGL: <index>,<stat>,<oa/da>,[<alpha>],[<scts>][,<tooa/toda>,<length>]<CR><LF><data>[<CR><LF>
1050
1062
// +CMGL: <index>,<stat>,<da/oa>,[<alpha>],[<scts>][,<tooa/toda>,<length>]<CR><LF><data>[...]]
1051
1063
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
1054
1076
}
1055
1077
1056
1078
if (index >= 0 ) {
0 commit comments