RTCM 协议数据简易解析
源码
import tkinter.filedialog
import numpy as np
import matplotlib.pyplot as plt
import struct
import string
import re
fr=tkinter.filedialog.askopenfilename(title='选择一个文件',
filetypes=[('所有文件','.*'),('文本文件','.txt')])
fd = open(fr,'rb')
rtcm_data = fd.read()
msg_numb = []
msg_len = []
def Rtcm_Msg_ID(pack):
msg_id = pack[3]
msg_id = (msg_id << 4) ^ (pack[4] >> 4)
msg_numb.append(msg_id)
pack_len_temp = pack[1] & 0x03
pack_len_temp = (pack_len_temp << 8) ^ pack[2]
msg_len.append(pack_len_temp)
def msg_id_get(msg):
msg_temp = msg_numb
msg_id = list(set(msg_temp))
print(msg_id)
msg_len_temp = msg_len
msg_len_temp = list(set(msg_len_temp))
print(msg_len_temp)
class Bit:
def __init__(self,bit_t):
self.bit_step = bit_t
def get_bit(self,bit,data,data_len):
data_temp = 0
bit_temp = bit
data_t = list(data)
for i in range(bit_temp) :
data_temp <<= 1
data_temp = data_temp | (data[self.bit_step // 8] >> ( 7 - (self.bit_step % 8)) & 0x01)
self.bit_step += 1
if self.bit_step // 8 > data_len:
return 0
return data_temp
def Get_Bit_test():
pack = Bit(0)
data = [0xF1,0x11,0x22,0x33]
data_t0 = pack.get_bit(4,data,4)
print(data_t0)
data_t0 = pack.get_bit(5,data,4)
print(data_t0)
data_t0 = pack.get_bit(7,data,4)
print(data_t0)
data_t0 = pack.get_bit(8,data,4)
print(data_t0)
def pack_1006(pack,pack_len):
bit_1006 = Bit(0)
pack_temp = pack[3:]
print('RTCM' +' '+ str(bit_1006.get_bit(12,pack_temp,pack_len))
+' '+ str(bit_1006.get_bit(12,pack_temp,pack_len))
+' '+ str(bit_1006.get_bit(6,pack_temp,pack_len))
+' '+ str(bit_1006.get_bit(1,pack_temp,pack_len))
+' '+ str(bit_1006.get_bit(1,pack_temp,pack_len))
+' '+ str(bit_1006.get_bit(1,pack_temp,pack_len))
+' '+ str(bit_1006.get_bit(1,pack_temp,pack_len))
+' '+ str(bit_1006.get_bit(38,pack_temp,pack_len))
+' '+ str(bit_1006.get_bit(1,pack_temp,pack_len))
+' '+ str(bit_1006.get_bit(1,pack_temp,pack_len))
+' '+ str(bit_1006.get_bit(38,pack_temp,pack_len))
+' '+ str(bit_1006.get_bit(2,pack_temp,pack_len))
+' '+ str(bit_1006.get_bit(38,pack_temp,pack_len))
+' '+ str(bit_1006.get_bit(16,pack_temp,pack_len))
)
def pack_1008(pack,pack_len):
bit_1008 = Bit(0)
pack_temp = pack[3:]
n = 0
m = 0
print('RTCM' +' '+ str(bit_1008.get_bit(12,pack_temp,pack_len))
+' '+ str(bit_1008.get_bit(12,pack_temp,pack_len))
+' '+ str(bit_1008.get_bit(8 * n,pack_temp,pack_len))
+' '+ str(bit_1008.get_bit(8,pack_temp,pack_len))
+' '+ str(bit_1008.get_bit(8 * m,pack_temp,pack_len))
)
def pack_1074(pack,pack_len):
bit_1074 = Bit(0)
pack_temp = pack[3:]
def pack_1084(pack,pack_len):
bit_1084 = Bit(0)
pack_temp = pack[3:]
def pack_1124(pack,pack_len):
bit_1124 = Bit(0)
pack_temp = pack[3:]
def pack_1013(pack,pack_len):
bit_1013 = Bit(0)
pack_temp = pack[3:]
def pack_1032(pack,pack_len):
bit_1032 = Bit(0)
pack_temp = pack[3:]
def pack_1033(pack,pack_len):
bit_1033 = Bit(0)
pack_temp = pack[3:]
def default(pack,pack_len):
msg_id = pack[3]
msg_id = (msg_id << 4) ^ (pack[4] >> 4)
print('no msg' + str(msg_id))
RTCM_Msg = {1006:pack_1006
,1008:pack_1008
,1074:pack_1074
,1084:pack_1084
,1124:pack_1124
,1013:pack_1013
,1032:pack_1032
,1033:pack_1033
}
def RTCM_Msg_Proccess(pack,pack_len):
msg_id = pack[3]
msg_id = (msg_id << 4) ^ (pack[4] >> 4)
fu = RTCM_Msg.get(msg_id,default)
fu(pack,pack_len)
def Data_process():
rtcm_package_buf = []
pack_len_temp = 0;
pack_len = 0
for data in rtcm_data:
rtcm_package_buf.append(data)
pack_len += 1
if rtcm_package_buf[0] != 0xD3:
rtcm_package_buf.clear()
pack_len = 0;
else :
if pack_len > 2:
pack_len_temp = rtcm_package_buf[1] & 0x03
pack_len_temp = (pack_len_temp << 8) ^ rtcm_package_buf[2]
if pack_len_temp + 6 == pack_len:
RTCM_Msg_Proccess(rtcm_package_buf,pack_len)
rtcm_package_buf.clear()
pack_len = 0
pack_len_temp = 0
Data_process()