资源简介
将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:
相关资源
- MFC sql server的ADO及ODBC连接操作
- 使用MFC ODBC连接数据库(access)
- C语言实现canny边缘检测
- 一个完整的C++ odbc连接数据库
- DBSCAN聚类算法C++代码实现
- CAN通讯C++源代码以及软件,自己写的
- OpenCV边缘检测程序 by浅墨
- CAN总线通讯VC++源码
- DBC的C++解析源码
- MFC连接MySql数据库
- scanner程序 网络扫描
- ControlCAN C++动态库 64位_32位
- 聚类算法DBScanC++实现代码及简单
- 用Canny算子提取边缘Visual C++源代码
- FDCAN实验(CAN总线的使用)
- An implementation of the ISO-TP (ISO15765-2)
- stm32 can bootloader
- LED点亮CAN通信程序
- 树莓派CAN通讯(c语言)
- stm32cubeIDE hul库freertos can中断收发,
- STM32-CAN模块通讯实验(正常工作模式
- 335X can总线
- 发动机CAN总线通讯
- 基于飞思卡尔MC9s单片机的CAN通信代码
- stc12c5608ad_ad_da_转换
- STM32中的CAN模块使用程序
- 基于AUTOSAR标准的CAN网络管理研究
- 基于STM32F103C8T6的RS485和CAN
- 室内定位 WIFI Scan 源代码.rar
- USBcan Vc
评论
共有 条评论