@@ -279,7 +279,7 @@ void AT_CellularSMS::set_extra_sim_wait_time(int sim_wait_time)
279
279
}
280
280
281
281
char * AT_CellularSMS::create_pdu (const char * phone_number, const char * message, uint8_t message_length, uint8_t msg_parts,
282
- uint8_t msg_part_number)
282
+ uint8_t msg_part_number, uint8_t & header_size )
283
283
{
284
284
int totalPDULength = 0 ;
285
285
int number_len = strlen (phone_number);
@@ -418,6 +418,7 @@ char* AT_CellularSMS::create_pdu(const char* phone_number, const char* message,
418
418
419
419
// now we know the correct length of the UDL (User Data Length)
420
420
int_to_hex_str (message_length + udhlen, pdu+lengthPos);
421
+ header_size = x;
421
422
422
423
return pdu;
423
424
}
@@ -480,17 +481,20 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char* phone_number, const c
480
481
481
482
int remaining_len = msg_len;
482
483
int pdu_len;
484
+ int msg_write_len = 0 ;
485
+ uint8_t header_len;
483
486
char *pdu_str;
484
- for (int i = 0 ; i< sms_count; i++) {
487
+ for (int i = 0 ; i < sms_count; i++) {
485
488
489
+ header_len = 0 ;
486
490
if (sms_count == 1 ) {
487
491
pdu_len = msg_len;
488
492
} else {
489
493
pdu_len = remaining_len > concatenated_sms_length ? concatenated_sms_length : remaining_len;
490
494
}
491
495
492
496
pdu_str = create_pdu (phone_number+remove_plus_sign, message + i*concatenated_sms_length, pdu_len,
493
- sms_count, i+1 );
497
+ sms_count, i+1 , header_len );
494
498
if (!pdu_str) {
495
499
_at.unlock ();
496
500
return NSAPI_ERROR_NO_MEMORY;
@@ -508,13 +512,21 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char* phone_number, const c
508
512
if (_at.get_last_error () == NSAPI_ERROR_OK) {
509
513
write_size = _at.write_bytes ((uint8_t *)pdu_str, pdu_len);
510
514
if (write_size < pdu_len) {
515
+ // calculate exact size of what we have send
516
+ if (write_size <= header_len) {
517
+ // managed only to write header or some of it so actual msg write size in this iteration is 0
518
+ write_size = 0 ;
519
+ } else {
520
+ write_size = (write_size - header_len)/2 ; // as hex encoded so divide by two
521
+ }
522
+ msg_write_len += write_size;
523
+
511
524
// sending can be cancelled by giving <ESC> character (IRA 27).
512
525
_at.cmd_start (ESC);
513
526
_at.cmd_stop ();
514
527
_at.unlock ();
515
528
free (pdu_str);
516
- // TODO: Fix this (might be bigger value than msg_len!)
517
- return write_size;
529
+ return msg_write_len;
518
530
}
519
531
520
532
// <ctrl-Z> (IRA 26) must be used to indicate the ending of the message body.
@@ -535,8 +547,7 @@ nsapi_size_or_error_t AT_CellularSMS::send_sms(const char* phone_number, const c
535
547
nsapi_error_t ret = _at.get_last_error ();
536
548
_at.unlock ();
537
549
538
- // TODO: fix this also: msg_len should be returned instead of write_size!
539
- return (ret == NSAPI_ERROR_OK) ? write_size : ret;
550
+ return (ret == NSAPI_ERROR_OK) ? msg_len : ret;
540
551
}
541
552
542
553
void AT_CellularSMS::set_sms_callback (Callback<void ()> func)
0 commit comments