1010from functools import wraps , partial
1111from itertools import accumulate
1212
13+ import opendbc
1314from opendbc .car .structs import CarParams
1415
1516from .base import BaseHandle
16- from .constants import FW_PATH , McuType
17+ from .constants import BASEDIR , FW_PATH , McuType , compute_version_hash
1718from .dfu import PandaDFU
1819from .spi import PandaSpiHandle , PandaSpiException , PandaProtocolMismatch
1920from .usb import PandaUsbHandle
@@ -104,7 +105,6 @@ def wrapper(self, *args, **kwargs):
104105 return fn (self , * args , ** kwargs )
105106 return wrapper
106107ensure_can_packet_version = partial (ensure_version , "CAN" , "CAN_PACKET_VERSION" , "can_version" )
107- ensure_can_health_packet_version = partial (ensure_version , "CAN health" , "CAN_HEALTH_PACKET_VERSION" , "can_health_version" )
108108ensure_health_packet_version = partial (ensure_version , "health" , "HEALTH_PACKET_VERSION" , "health_version" )
109109
110110
@@ -126,9 +126,8 @@ class Panda:
126126 HW_TYPE_CUATRO = b'\x0a '
127127 HW_TYPE_BODY = b'\xb1 '
128128
129- CAN_PACKET_VERSION = 4
130- HEALTH_PACKET_VERSION = 18
131- CAN_HEALTH_PACKET_VERSION = 5
129+ CAN_PACKET_VERSION = compute_version_hash (os .path .join (opendbc .INCLUDE_PATH , "opendbc/safety/can.h" ))
130+ HEALTH_PACKET_VERSION = compute_version_hash (os .path .join (BASEDIR , "board/health.h" ))
132131 HEALTH_STRUCT = struct .Struct ("<IIIIIIIIBBBBBHBBBHfBBHHHBH" )
133132 CAN_HEALTH_STRUCT = struct .Struct ("<BIBBBBBBBBIIIIIIIHHBBBIIII" )
134133
@@ -210,7 +209,7 @@ def connect(self, claim=True, wait=False):
210209 self ._serial = serial
211210 self ._connect_serial = serial
212211 self ._handle_open = True
213- self .health_version , self .can_version , self . can_health_version = self .get_packets_versions ()
212+ self .health_version , self .can_version = self .get_packets_versions ()
214213 logger .debug ("connected" )
215214
216215 # disable openpilot's heartbeat checks
@@ -536,7 +535,7 @@ def health(self):
536535 "sound_output_level" : a [25 ],
537536 }
538537
539- @ensure_can_health_packet_version
538+ @ensure_health_packet_version
540539 def can_health (self , can_number ):
541540 LEC_ERROR_CODE = {
542541 0 : "No error" ,
@@ -598,14 +597,11 @@ def get_signature(self) -> bytes:
598597 def get_type (self ):
599598 return self ._handle .controlRead (Panda .REQUEST_IN , 0xc1 , 0 , 0 , 0x40 )
600599
601- # Returns tuple with health packet version and CAN packet/USB packet version
602600 def get_packets_versions (self ):
603- dat = self ._handle .controlRead (Panda .REQUEST_IN , 0xdd , 0 , 0 , 3 )
604- if dat and len (dat ) == 3 :
605- a = struct .unpack ("BBB" , dat )
606- return (a [0 ], a [1 ], a [2 ])
607- else :
608- return (0 , 0 , 0 )
601+ dat = self ._handle .controlRead (Panda .REQUEST_IN , 0xdd , 0 , 0 , 8 )
602+ if dat and len (dat ) == 8 :
603+ return struct .unpack ("<II" , dat )
604+ return (0 , 0 )
609605
610606 def is_internal (self ):
611607 return self .get_type () in Panda .INTERNAL_DEVICES
0 commit comments