There is a serious problem in the class library implemented a few days ago. The received ASCII code and the 7-bit SMS read text message content is garbled, so that the control cannot be used. The reason is that there is no corresponding decoding in the class library.Program, All are decoded by USC2 encoding. Add the program described in this article to this PartCodeTo solve this problem, the previous project file updates this part at the same time. You are welcome to download this part.
Let's take a look at the 7bit encoding of the PDU:
For more information about PDU encoding, see the implementation of the sms cat Software (C #) <3> Analysis of PDU text messages
English code: 7-bit code, which shifts the last few digits of the next digit to the front to form a new 8-bit code.
Example: Test
T: 01010100 E: 01100101 S: 01110011 T: 01110100
Go to the highest digit 0 and change it to 7 digits
T: 1010100 E: 1100101 S: 1110011 T: 1110100
Move the back low to the front to Form 8-bit encoding
Test: 11010100111100101001110000001110
UD: d4f29c0e udl: 04
DecodingAlgorithm: Use a loop; read a single-digit group (saved in the byte buffer) cyclically at a time; convert it to a binary string, and combine the low position with the remaining binary digits of the corresponding previous one-digit group to form a 7bit ASCII code, add the result array.
1:Private stringPdu7bitdecoder (StringUserdata)
2:{
3:StringResult =String. Empty;
4:Byte[] B =New byte[100];
5:StringTemp =String. Empty;
6:
7:For(IntI = 0; I <userdata. length; I + = 2)
8:{
9:B [I/2] = (Byte)Convert. Tobyte (userdata [I]. tostring () + userdata [I + 1]. tostring (), 16 );
10:}
11:
12:IntJ = 0;// While count
13:IntTMP = 1;// Number of binary characters in temp
14:While(J <userdata. Length/2-1)
15:{
16:StringS =String. Empty;
17:
18:S =Convert. Tostring (B [J], 2 );
19:
20:While(S. Length <8)// If the number of bytes converted by the complement of 8 bytes is less than 8 bits, decoding will lead to an error.
21:{
22:S ="0"+ S;
23:}
24:
25:Result + = (Char)Convert. Toint32 (S. substring (TMP) + temp, 2 );// Add a character to the result set temp and the remaining one in the previous group
26:
27:Temp = S. substring (0, TMP );// Multiple parts in the previous group
28:
29:If(TMP> 6)// Add a character when the excess part is 7 characters long.
30:{
31:Result + = (Char)Convert. Toint32 (temp, 2 );
32:Temp =String. Empty;
33:TMP = 0;
34:}
35:
36:TMP ++;
37:J ++;
38:
39:If(J = userdata. Length/2-1)// The last character
40:{
41:Result + = (Char)Convert. Toint32 (Convert. Tostring (B [J], 2) + temp, 2 );
42:}
43:}
44:ReturnResult;
45:}