mirror of
https://github.com/infiniteCable2/panda.git
synced 2026-06-08 07:45:00 +08:00
Sync: commaai/panda:master → sunnypilot/panda:master
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# python library to interface with panda
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import usb1
|
||||
@@ -42,6 +43,15 @@ def calculate_checksum(data):
|
||||
res ^= b
|
||||
return res
|
||||
|
||||
def _parse_c_struct(path, name):
|
||||
type_to_format = {"uint8_t": "B", "uint16_t": "H", "uint32_t": "I", "float": "f"}
|
||||
with open(path) as f:
|
||||
lines = [l.strip() for l in f.read().split(f"struct __attribute__((packed)) {name} {{", 1)[1].split("};", 1)[0].splitlines() if l.strip()]
|
||||
fields = [re.fullmatch(rf"({'|'.join(type_to_format)})\s+\w+;", l) for l in lines]
|
||||
if not all(fields):
|
||||
raise ValueError(f"unsupported {name} layout in {path}")
|
||||
return struct.Struct("<" + "".join(type_to_format[m[1]] for m in fields))
|
||||
|
||||
def pack_can_buffer(arr, chunk=False, fd=False):
|
||||
snds = [bytearray(), ]
|
||||
for address, dat, bus in arr:
|
||||
@@ -128,7 +138,7 @@ class Panda:
|
||||
|
||||
CAN_PACKET_VERSION = compute_version_hash(os.path.join(opendbc.INCLUDE_PATH, "opendbc/safety/can.h"))
|
||||
HEALTH_PACKET_VERSION = compute_version_hash(os.path.join(BASEDIR, "board/health.h"))
|
||||
HEALTH_STRUCT = struct.Struct("<IIIIIIIIBBBBBHBBBHfBBHHHBH")
|
||||
HEALTH_STRUCT = _parse_c_struct(os.path.join(BASEDIR, "board/health.h"), "health_t")
|
||||
CAN_HEALTH_STRUCT = struct.Struct("<BIBBBBBBBBIIIIIIIHHBBBIIII")
|
||||
|
||||
H7_DEVICES = [HW_TYPE_RED_PANDA, HW_TYPE_TRES, HW_TYPE_CUATRO, HW_TYPE_BODY]
|
||||
|
||||
Reference in New Issue
Block a user