RTCM 协议数据解析

RTCM 协议数据简易解析

源码

import tkinter.filedialog
import numpy as np 
import matplotlib.pyplot as plt
import struct
import string
import re
#import crc as CRC

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)
    #print(msg_id)
    msg_numb.append(msg_id)
    #print(msg_numb)
    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(n = bit_1008.get_bit(8,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(m = 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[msg_id]
    fu = RTCM_Msg.get(msg_id,default)
    
    #if(NONE != fu):
    fu(pack,pack_len)
    #print('msg_ok!')

    #print(fu)


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_ID(rtcm_package_buf)
                    RTCM_Msg_Proccess(rtcm_package_buf,pack_len)
                    rtcm_package_buf.clear()
                    pack_len = 0
                    pack_len_temp = 0

Data_process()

  • 2
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值