Ví dụ:
"Hello" -- mã hoá --> C8 32 9B FD 06 (mã hex)
"I love DIY" --------> 49 10 FB 6D 2F 83 88 C9 2C
Hình vẽ sau đây minh hoạ cho cách mã hoá 7 bits chuỗi ký tự "Hello":
------------ Chương trình C --------------
void Nokia_iPackSMS(char *decode, char *input)
{
unsigned char c, w;
int n, shift, x;
int len;
len = strlen(input);
shift = 0;
decode[0] = 0;
/* Decode into 7 bit characters */
for (n = 0; n < len; ++n)
{
c = input[n] & 0x7f;
c >>= shift;
w = input[n+1] & 0x7f;
w <<= (7-shift);
shift += 1;
c = c | w;
if (shift == 7)
{
shift = 0x00;
n++;
}
x = strlen(decode);
decode[x] = c;
decode[x+1] = 0;
}
}
Ví dụ gọi:
char message[255];
char* sms = "Hello";
Nokia_iPackSMS (message, sms);
Kết quả message[]: 0xC8, 0x32, 0x9B, 0xFD, 0x06
Mã hoá PDU Message online: http://twit88.com/home/utility/sms-pdu-encode-decode
Không có nhận xét nào:
Đăng nhận xét