Skip to content

Commit a1540c5

Browse files
authored
Merge pull request #11245 from dextero/8bit-sms
AT_CellularSMS: allow configuring SMS encoding (7-bit/8-bit) at initialization
2 parents b9a6251 + f3e9501 commit a1540c5

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

UNITTESTS/stubs/AT_CellularSMS_stub.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ nsapi_error_t AT_CellularSMS::set_csdh(int show_header)
7171
return NSAPI_ERROR_OK;
7272
}
7373

74-
nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode)
74+
nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode,
75+
CellularSMSEncoding encoding)
7576
{
7677
return NSAPI_ERROR_OK;
7778
}

features/cellular/framework/API/CellularSMS.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,20 @@ class CellularSMS {
6262
CellularSMSMmodeText
6363
};
6464

65+
enum CellularSMSEncoding {
66+
CellularSMSEncoding7Bit,
67+
CellularSMSEncoding8Bit,
68+
};
69+
6570
/** Does all the necessary initializations needed for receiving and sending SMS.
6671
*
6772
* @param mode enumeration for choosing the correct mode: text/pdu
6873
* @return NSAPI_ERROR_OK on success
6974
* NSAPI_ERROR_NO_MEMORY on memory failure
7075
* NSAPI_ERROR_DEVICE_ERROR on other failures
7176
*/
72-
virtual nsapi_error_t initialize(CellularSMSMmode mode) = 0;
77+
virtual nsapi_error_t initialize(CellularSMSMmode mode,
78+
CellularSMSEncoding encoding = CellularSMSEncoding::CellularSMSEncoding7Bit) = 0;
7379

7480
/** Send the SMS with the given parameters
7581
*

features/cellular/framework/AT/AT_CellularSMS.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,11 @@ nsapi_error_t AT_CellularSMS::set_csdh(int show_header)
245245
return _at.at_cmd_discard("+CSDH", "=", "%d", show_header);
246246
}
247247

248-
nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode)
248+
nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode,
249+
CellularSMSEncoding encoding)
249250
{
251+
_use_8bit_encoding = (encoding == CellularSMSEncoding8Bit);
252+
250253
_at.set_urc_handler("+CMTI:", callback(this, &AT_CellularSMS::cmti_urc));
251254
_at.set_urc_handler("+CMT:", callback(this, &AT_CellularSMS::cmt_urc));
252255

@@ -292,8 +295,11 @@ char *AT_CellularSMS::create_pdu(const char *phone_number, const char *message,
292295
// there might be need for padding so some more space
293296
totalPDULength += 2;
294297

295-
// message 7-bit padded and it will be converted to hex so it will take twice as much space
296-
totalPDULength += (message_length - (message_length / 8)) * 2;
298+
// 8-bit message, converted to hex so it will take twice as much space
299+
totalPDULength += message_length * 2;
300+
301+
// terminating nullbyte, because callers use strlen() to find out PDU size
302+
totalPDULength += 1;
297303

298304
char *pdu = new char[totalPDULength];
299305
memset(pdu, 0, totalPDULength);

features/cellular/framework/AT/AT_CellularSMS.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class AT_CellularSMS: public CellularSMS, public AT_CellularBase {
3939
public:
4040
// from CellularSMS
4141

42-
virtual nsapi_error_t initialize(CellularSMSMmode mode);
42+
virtual nsapi_error_t initialize(CellularSMSMmode mode,
43+
CellularSMSEncoding encoding = CellularSMSEncoding7Bit);
4344

4445
virtual nsapi_size_or_error_t send_sms(const char *phone_number, const char *message, int msg_len);
4546

0 commit comments

Comments
 (0)