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 | 30 +++++++++++++++++------------- 1 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Shifter.py b/Shifter.py index c920bd0..9cf09ee 100644 --- a/Shifter.py +++ b/Shifter.py @@ -1,4 +1,3 @@ - from ShifterDefine import * import struct from udsoncan import DidCodec @@ -11,8 +10,7 @@ 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): @@ -37,6 +35,7 @@ class PartNumberCodec(DidCodec): + def __init__(self, byte_len=None): if byte_len is None: raise ValueError( @@ -69,6 +68,7 @@ class PartNumberVersionCodec(DidCodec): + def __init__(self, byte_len=None): if byte_len is None: raise ValueError( @@ -116,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 @@ -132,7 +132,11 @@ 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 @@ -166,7 +170,6 @@ 0x211B: PartNumberCodec(1), 0x211c: PartNumberCodec(2), 0xF197: AsciiCodec(8), - 0xF15a: AsciiCodec(10), 0xF15B: AsciiCodec(10), } @@ -182,13 +185,14 @@ self.canid.phy_rxId = 0x742 self.canid.fun_rxId = 0x7df self.canid.normalid = 0x420 - self.dbc = DBC("DBC/SX7H.dbc") + self.dbc = DBC("DBC/DFLZM.dbc") def FramUnpack(self, id=0x420, frame=[]): - data = [] - data.append(' '.join(['0x' + - '{:0<2x}'.format(a).upper() for a in list(frame)])) - unpackframe = self.dbc.analyzer(msgid=0x420, data=data) - self.position = ShifterPosition(unpackframe[4]['value']['raw']) - self.Pbutton = unpackframe[5]['value']['raw'] - self.UnlockButton = unpackframe[6]['value']['raw'] + 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