我收到了类似PDU的消息,但我只收到消息"C824"
PDU example, 040C9119898392752300008010610014412202C834
04 - first octet
0C - phone number length
91 - phone number type
198983927523 - phone number
00 - protocol identifier
00 - data coding scheme
80106100144122 - time stamp
02 - message length
C834 - message, i.e. "Hi"
Run Code Online (Sandbox Code Playgroud)
我需要知道格式是什么格式("C834")转换为"Hi".我怎么可能把它翻译成人类可读的语言?
最好的祝福,
SMS消息是7位ASCII打包成8位流.您可以阅读规范第6.1节中的格式(pdf)
在您的示例中,"C8 34"等于:
Hex Binary
C8 11001000
34 00110100
Run Code Online (Sandbox Code Playgroud)
使用文档中的规则拆分时,它看起来像这样:
Hex Binary
48 1001000 most significant bit is moved to next char's least significant bit
69 1101001
00 00
Run Code Online (Sandbox Code Playgroud)
要解析这个你想要做这样的事情:
bytes = (0xC8, 0xF7, 0x1D, 0x14, 0x96, 0x97, 0x41, 0xF9, 0x77, 0xFD, 0x07)
number = 0
bitcount = 0
output = ''
for byte in bytes:
# add data on to the end
number = number + (byte << bitcount)
# increase the counter
bitcount = bitcount + 1
# output the first 7 bits
output = output + '%c' % (number % 128)
# then throw them away
number = number >> 7
# every 7th letter you have an extra one in the buffer
if bitcount == 7:
output = output + '%c' % (number)
bitcount = 0
number = 0
print output
Run Code Online (Sandbox Code Playgroud)
不是最优雅的解决方案,但它应该工作.这是一个JavaScript实现,也可能有所帮助.