.NET platform mobile phone management software development (11) - SMS section VB.NET encoding PDU

xiaoxiao2021-03-06  41

(11) SMS section - VB.NET encoding PDU

The working principle of the encoder of the PDU is the inverse process of the decoder. The encoder is required to encode the transmitted PDU code as needed, and the work is relatively simple. This article explains the coding idea, please refer to the PDUEncoder section in Blog in the specific code.

I divide the PDU code into two parts, SMS and EMS. EMS section I only provide the encoder of ConcatenatedShortMessage. This is the coding of the ultra-long SMS and is used up to.

SMS coding

Encoding an SMS generally requires the following information:

TP_DATA_CODING_SCHEME TP_UD encoding method

TP_DESTINATION_ADDRESS other party number

TP_MESSAGE_REGERENCE reference number

TP_STATUS_REPORT_REQUEST status report

TP_USER_DATA user information

TP_VALIDITY_PRIOD validity period

ServiceCenterNumber SMS Center Number

Therefore, there is more attributes in the encoder, and the processing code is added to the SET, and the readable information is converted into a corresponding hexadecimal information.

Special note is the TP_USER_DATA property, which can automatically set TP_UDL according to user data encoding. For pure English codes, TP_UDL is all the number of characters; for Unicode encoding, since a character is represented by two bytes, TP_UDL is all of the characters * 2. Note The length of TP_USER_DATA is checked, and the TP_UD length after SMS cannot exceed 140 bytes. That is to say English 160 characters (140/7 * 8), 70 characters in Chinese.

The encoding of TP_UD is also described in the decoder, and details are not described herein.

I also designed a few enumerations:

ENUM_TP_DCS encoding method

ENUM_TP_SRI Status Report

ENUM_TP_VALID_PERID Validity

ENUM_TP_VPF Time Format

These enumeration variables can simplify input and are also exposed in the future.

When the above content is set, the substantially a SMS is coming out. At this point, GetSMSPDucode is called, and simply puts the hexadecimal splicing to form a complete PDU code.

EMS - ConcatenatedShortMessage section

The encoding EMS is complicated than SMS, but the foundation of each EMS is still SMS, so I directly inherited the SMS class. The difference is mainly to handle TP_UD and IE. For ConcatenatedShortMessage, because its IE and TP_UDHL occupy some space of TP_UD, each SMS can only hold 133 characters, Chinese 66 characters. We can get the number of SMS through this information.

If tp_dcs is Unicode encoding, the SMS entry is: totalMessages = (TP_UD.LENGTH / 4) / 66 ((TP_UD.LENGTH / 4 MOD 66) = 0) 1

If it is 7bit, it is:

TotalMessages = (TP_UD.LENGTH / 266) - ((TP_UD.LENGTH MOD 266) = 0) 1

Note that I didn't add one in order to simplify future array operations.

The TP_UD of each SMS can be extracted after the number of SMS will be extracted.

SELECT CASE TP_DCS

Case enum_tp_dcs.ucs2

TMPTP_UD = MID (TP_UD, I * 66 * 4 1, 66 * 4) 'When TP_UDL IS ODD, The Max Length of An Unicode String in PDU Code IS 66 Charactor.see [3GPP TS 23.040 V6.5.0

(2004-09] 9.2.3.24.1

Case enum_tp_dcs.defaultalphabet

TMPTP_UD = MID (TP_UD, I * 133 * 2 1, 133 * 2)

End SELECT

Thereafter, the IE section is also required, and the key code is the value of the TP_UDL. It is more complicated for TP_DCs to 7bit, and it is easy to make more mistakes.

IF tp_dcs = enum_tp_dcs.us2 then

TP_UDL = TMPTP_UD.LENGTH / 2 6 1 '6: Length Of IE

END IF

IF tp_dcs = enum_tp_dcs.defaultalphabet then

TP_UDL = FIX ((TMPTP_UD.LENGTH 7 * 2) * 4/7) '6: Length of IE

END IF

The handler of the EMS PDU can then be written in accordance with the structure of the EMS in 3GPP. See the original code for details.

If you need to extend EMS to accommodate more types of EMS, you can refer to 3GPP to write more powerful encoders. But the most critical is still to handle IE and TP_UDL.

转载请注明原文地址:https://www.9cbs.com/read-56067.html

New Post(0)