From 20cc603922983f154d10b7d56c6b49e5e02997bd Mon Sep 17 00:00:00 2001
From: tao_z <tzj0429@163.com>
Date: Mon, 06 Jun 2022 00:13:05 +0800
Subject: [PATCH] 初步bootloader实现。dbc解析存在解析值不正确问题。

---
 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