From 48fc7d6c9549513d9b1da3f99f449fc7de27821f Mon Sep 17 00:00:00 2001 From: tao_z <tzj0429@163.com> Date: Fri, 10 Jun 2022 19:23:26 +0800 Subject: [PATCH] 修改信息打印标准 增加数据写入功能 --- Shifter.py | 64 +++++++++++++++++++++++-------- 1 files changed, 47 insertions(+), 17 deletions(-) diff --git a/Shifter.py b/Shifter.py index fb8f852..9cf09ee 100644 --- a/Shifter.py +++ b/Shifter.py @@ -1,17 +1,16 @@ - from ShifterDefine import * import struct from udsoncan import DidCodec import configparser +from dbc import * class AsciiCodec(DidCodec): def __init__(self, string_len=None): if string_len is None: - raise ValueError( - "You must provide a length to the AsciiCodec") + raise ValueError("You must provide a length to the AsciiCodec") self.string_len = string_len def encode(self, string_ascii): @@ -36,6 +35,7 @@ class PartNumberCodec(DidCodec): + def __init__(self, byte_len=None): if byte_len is None: raise ValueError( @@ -68,6 +68,7 @@ class PartNumberVersionCodec(DidCodec): + def __init__(self, byte_len=None): if byte_len is None: raise ValueError( @@ -115,7 +116,7 @@ data = bytearray() for i in range(self.byte_len): - part = string_ascii[2 * i: 2 * i + 2] + part = string_ascii[2 * i:2 * i + 2] data.append(int(part, 16)) return data @@ -131,28 +132,46 @@ return self.byte_len +UnlockButton_dic = {"Unlock Button No Request": 0, "Unlock Button Request": 1} + + class ShifterClass(): + def __init__(self): self.position = ShifterPosition(0) self.Pbutton = 0 self.UnlockButton = 0 self.Voltage = 0 self.canid = ShifterCANID() + self.did_config = { + 0x2100: PartNumberCodec(1), + 0x2101: PartNumberCodec(1), + 0x2103: AsciiCodec(8), + 0x2104: AsciiCodec(4), + 0x2105: AsciiCodec(16), + 0x2106: PartNumberCodec(1), + 0xF187: AsciiCodec(16), + 0x2108: AsciiCodec(18), + 0xF18A: AsciiCodec(10), + 0x210B: BCDCodec(4), + 0xF18C: AsciiCodec(14), 0xF190: AsciiCodec(17), - 0xF1B1: AsciiCodec(9), - 0xF1B2: AsciiCodec(16), - - 0xF1D0: PartNumberCodec(4), - 0xF1D1: PartNumberVersionCodec(2), - 0xF1D2: PartNumberCodec(4), - 0xF1D3: PartNumberVersionCodec(2), - 0xF0DF: PartNumberVersionCodec(1), - - 0xF187: AsciiCodec(21), - 0xF195: AsciiCodec(16), - 0xF198: BCDCodec(8), - 0xF199: BCDCodec(4), + 0xF193: AsciiCodec(26), + 0xF195: AsciiCodec(28), + 0x2110: AsciiCodec(8), + 0x2111: AsciiCodec(16), + 0x2112: BCDCodec(4), + 0x2113: BCDCodec(4), + 0x2116: PartNumberCodec(2), + 0x2118: PartNumberCodec(1), + 0x2119: PartNumberCodec(1), + 0x211A: PartNumberCodec(1), + 0x211B: PartNumberCodec(1), + 0x211c: PartNumberCodec(2), + 0xF197: AsciiCodec(8), + 0xF15a: AsciiCodec(10), + 0xF15B: AsciiCodec(10), } try: config = configparser.ConfigParser() @@ -166,3 +185,14 @@ self.canid.phy_rxId = 0x742 self.canid.fun_rxId = 0x7df self.canid.normalid = 0x420 + self.dbc = DBC("DBC/DFLZM.dbc") + + def FramUnpack(self, id=0x420, frame=[]): + data = ' '.join(['{:0<2x}'.format(a).upper() for a in list(frame)]) + unpackframe = self.dbc.analyzer(msgid=0x420, data=str(data)) + # print(unpackframe[5]['value']['raw']) + self.Pbutton = unpackframe[5]['value']['phy'] + # print(unpackframe[6]['value']['raw']) + self.UnlockButton = unpackframe[4]['value']['phy'] + # print(unpackframe[4]['value']['raw']) + self.position = unpackframe[7]['value']['phy'] -- Gitblit v1.8.0