Merge pull request #11245 from dextero/8bit-sms

AT_CellularSMS: allow configuring SMS encoding (7-bit/8-bit) at initialization
pull/11309/head
Martin Kojtal 2019-08-23 13:51:59 +02:00 committed by GitHub
commit a1540c5f77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 6 deletions

View File

@ -71,7 +71,8 @@ nsapi_error_t AT_CellularSMS::set_csdh(int show_header)
return NSAPI_ERROR_OK;
}
nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode)
nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode,
CellularSMSEncoding encoding)
{
return NSAPI_ERROR_OK;
}

View File

@ -62,6 +62,11 @@ public:
CellularSMSMmodeText
};
enum CellularSMSEncoding {
CellularSMSEncoding7Bit,
CellularSMSEncoding8Bit,
};
/** Does all the necessary initializations needed for receiving and sending SMS.
*
* @param mode enumeration for choosing the correct mode: text/pdu
@ -69,7 +74,8 @@ public:
* NSAPI_ERROR_NO_MEMORY on memory failure
* NSAPI_ERROR_DEVICE_ERROR on other failures
*/
virtual nsapi_error_t initialize(CellularSMSMmode mode) = 0;
virtual nsapi_error_t initialize(CellularSMSMmode mode,
CellularSMSEncoding encoding = CellularSMSEncoding::CellularSMSEncoding7Bit) = 0;
/** Send the SMS with the given parameters
*

View File

@ -245,8 +245,11 @@ nsapi_error_t AT_CellularSMS::set_csdh(int show_header)
return _at.at_cmd_discard("+CSDH", "=", "%d", show_header);
}
nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode)
nsapi_error_t AT_CellularSMS::initialize(CellularSMSMmode mode,
CellularSMSEncoding encoding)
{
_use_8bit_encoding = (encoding == CellularSMSEncoding8Bit);
_at.set_urc_handler("+CMTI:", callback(this, &AT_CellularSMS::cmti_urc));
_at.set_urc_handler("+CMT:", callback(this, &AT_CellularSMS::cmt_urc));
@ -292,8 +295,11 @@ char *AT_CellularSMS::create_pdu(const char *phone_number, const char *message,
// there might be need for padding so some more space
totalPDULength += 2;
// message 7-bit padded and it will be converted to hex so it will take twice as much space
totalPDULength += (message_length - (message_length / 8)) * 2;
// 8-bit message, converted to hex so it will take twice as much space
totalPDULength += message_length * 2;
// terminating nullbyte, because callers use strlen() to find out PDU size
totalPDULength += 1;
char *pdu = new char[totalPDULength];
memset(pdu, 0, totalPDULength);

View File

@ -39,7 +39,8 @@ public:
public:
// from CellularSMS
virtual nsapi_error_t initialize(CellularSMSMmode mode);
virtual nsapi_error_t initialize(CellularSMSMmode mode,
CellularSMSEncoding encoding = CellularSMSEncoding7Bit);
virtual nsapi_size_or_error_t send_sms(const char *phone_number, const char *message, int msg_len);