• 大小: 8KB
    文件类型: .gz
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: C/C++
  • 标签: dbc  CAN  

资源简介

将can消息描述的**.dbc文件转换成c++代码来读取,不需要自己动手编解码做移位拼接操作 将can消息描述的**.dbc文件转换成c++代码来读取,不需要自己动手编解码 将can消息描述的**.dbc文件转换成c++代码来读取,不需要自己动手编解码

资源截图

代码片段和文件信息

#!/usr/bin/env python
import re
import json
import pprint
from  pprint import pprint
import canmatrix
from  canmatrix import convert

class frame():
    def __init__(selffr_nameid):
        self.fr_name = fr_name
        self.id = id



class DBC_to_M():
    account = {}
    def __init__(selfdbc_pathm_path):
        self.dbc_path = str(dbc_path)
        self.m_path = str(m_path)

    def Read_DBC(self):
        with open(self.dbc_path) as f:
            self.dbc_file = f

    def parse_dbc(self):
        for line in self.dbc_file:
            mes = []
            l = line.strip()
            if l.__len__() == 0:
                continue
            if(l.startswith(“SG_ “)):
                pass
            elif (l.startswith(“BO_“)):
                pattern = re.compile(“BO\_ (\w+) (\w+) *: (\w+) (\w+)“)
                regex = re.match(pattern)
                if regex:
                    frame_name = regex.group(2)
                    frame_id = regex.group(1)
                    frame_len = regex.group(3)
                    frame_io = regex.group(4)

class can_frame():
    sig_list = list()
    # sig_conv_list = list()
    sig_conv = {}
    def __init__(self):
        pass
    def set_id(selfid):
        self.id = id
    def set_name(selfname):
        self.name = name
    def add_signal(selfsignal):
        self.sig_list.append(signal)
        self._parse_signal(signal)
    def _parse_signal(selfsignal):
        start_bit = (signal[“start_bit“] )
        signal_length = signal[“bit_length“]
        signal_isbigendian = signal[“is_big_endian“]
        Sbit_data_num Sbit_bit_num = self._start_bit_position(start_bit)
        Ebit_data_num Ebit_bit_num = self._end_bit_to_data_pos(Sbit_data_numSbit_bit_numsignal_lengthsignal_isbigendian)
        #operation = self._parse_bits(Sbit_data_numSbit_bit_numEbit_data_numEbit_bit_numsignal[“name“])
        # operation = self._descripe_bits(Sbit_data_numSbit_bit_numEbit_data_numEbit_bit_numsignal[“name“])
        self.sig_conv[str(signal[“name“])] = {“St_Bit“: (Sbit_data_numSbit_bit_num) “End_Bit“:(Ebit_data_numEbit_bit_num)}
        #self.sig_conv[str(signal[“name“])] = operation


    def _start_bit_position(selfstart_bit):
        Sbit_bit_num = start_bit % 8
        Sbit_data_num = start_bit // 8
        return Sbit_data_numSbit_bit_num
    def _end_bit_to_data_pos(selfSbit_data_numSbit_bit_numdata_lengthis_big_endian): # give the  data_length and data_position of each signal  calculate
        Ebit_data_num = Sbit_data_num
        Ebit_bit_num = Sbit_bit_num                                                                            #end_bit‘s position
        for count in range(data_length - 1):
            print(count)
            if Ebit_bit_num < 8:
                Ebit_bit_num = Ebit_bit_num + 1
            elif Ebit_bit_num == 8:
                Ebit_bit_num = 1
                if Ebit_data_num < 8:
                    if is_big_endian == True:
                    

评论

共有 条评论