@@ -420,6 +420,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
420
420
}
421
421
422
422
_at.lock ();
423
+ _at.set_at_timeout (10s);
423
424
424
425
int write_size = 0 ;
425
426
@@ -437,6 +438,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
437
438
// sending can be cancelled by giving <ESC> character (IRA 27).
438
439
_at.cmd_start (ESC);
439
440
_at.cmd_stop ();
441
+ _at.restore_at_timeout ();
440
442
_at.unlock ();
441
443
return write_size;
442
444
}
@@ -482,6 +484,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
482
484
pdu_str = create_pdu (phone_number, message + i * concatenated_sms_length, pdu_len,
483
485
sms_count, i + 1 , header_len);
484
486
if (!pdu_str) {
487
+ _at.restore_at_timeout ();
485
488
_at.unlock ();
486
489
return NSAPI_ERROR_NO_MEMORY;
487
490
}
@@ -509,6 +512,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char *phone_number, const c
509
512
// sending can be cancelled by giving <ESC> character (IRA 27).
510
513
_at.cmd_start (ESC);
511
514
_at.cmd_stop ();
515
+ _at.restore_at_timeout ();
512
516
_at.unlock ();
513
517
delete [] pdu_str;
514
518
return msg_write_len;
@@ -523,13 +527,15 @@ 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) {
530
+ _at.restore_at_timeout ();
526
531
return _at.unlock_return_error ();
527
532
}
528
533
}
529
534
}
530
535
531
536
_sms_message_ref_number++;
532
537
nsapi_error_t ret = _at.get_last_error ();
538
+ _at.restore_at_timeout ();
533
539
_at.unlock ();
534
540
535
541
return (ret == NSAPI_ERROR_OK) ? msg_len : ret;
@@ -697,6 +703,7 @@ nsapi_size_or_error_t AT_CellularSMS::get_sms(char *buf, uint16_t len, char *pho
697
703
}
698
704
699
705
_at.lock ();
706
+ _at.set_at_timeout (10s);
700
707
701
708
nsapi_size_or_error_t err = list_messages ();
702
709
if (err == NSAPI_ERROR_OK) {
@@ -710,6 +717,7 @@ nsapi_size_or_error_t AT_CellularSMS::get_sms(char *buf, uint16_t len, char *pho
710
717
*buf_size = info->msg_size ;
711
718
}
712
719
free_linked_list ();
720
+ _at.restore_at_timeout ();
713
721
_at.unlock ();
714
722
return NSAPI_ERROR_PARAMETER;
715
723
}
@@ -734,6 +742,7 @@ nsapi_size_or_error_t AT_CellularSMS::get_sms(char *buf, uint16_t len, char *pho
734
742
735
743
free_linked_list ();
736
744
745
+ _at.restore_at_timeout ();
737
746
_at.unlock ();
738
747
739
748
// update error only when there really was an error, otherwise we return the length
@@ -1027,6 +1036,7 @@ nsapi_error_t AT_CellularSMS::list_messages()
1027
1036
int index = 0 ;
1028
1037
int length = 0 ;
1029
1038
char *pdu = NULL ;
1039
+ char buffer[32 ]; // 32 > SMS_STATUS_SIZE, SMS_MAX_PHONE_NUMBER_SIZE, SMS_MAX_TIME_STAMP_SIZE
1030
1040
1031
1041
_at.resp_start (" +CMGL:" );
1032
1042
while (_at.info_resp ()) {
@@ -1049,8 +1059,18 @@ nsapi_error_t AT_CellularSMS::list_messages()
1049
1059
// +CMGL: <index>,<stat>,<oa/da>,[<alpha>],[<scts>][,<tooa/toda>,<length>]<CR><LF><data>[<CR><LF>
1050
1060
// +CMGL: <index>,<stat>,<da/oa>,[<alpha>],[<scts>][,<tooa/toda>,<length>]<CR><LF><data>[...]]
1051
1061
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>
1062
+ _at.read_string (buffer, SMS_STATUS_SIZE);
1063
+ _at.read_string (buffer, SMS_MAX_PHONE_NUMBER_SIZE);
1064
+ _at.skip_param (); // <alpha>
1065
+ _at.read_string (buffer, SMS_MAX_TIME_STAMP_SIZE);
1066
+ _at.read_int ();
1067
+ int size = _at.read_int (); // length
1068
+ _at.consume_to_stop_tag (); // consume until <CR><LF> end of header
1069
+ if (size > 0 ) {
1070
+ // we can not use skip param because we already consumed stop tag
1071
+ _at.skip_param_bytes (size, 1 );
1072
+ }
1073
+ _at.consume_to_stop_tag_even_found (); // consume until <CR><LF> -> data
1054
1074
}
1055
1075
1056
1076
if (index >= 0 ) {
0 commit comments