@@ -112,28 +112,22 @@ class Panda:
112112
113113 # from https://github.com/commaai/openpilot/blob/103b4df18cbc38f4129555ab8b15824d1a672bdf/cereal/log.capnp#L648
114114 HW_TYPE_UNKNOWN = b'\x00 '
115- HW_TYPE_WHITE = b'\x01 '
116- HW_TYPE_BLACK = b'\x03 '
117115 HW_TYPE_RED_PANDA = b'\x07 '
118116 HW_TYPE_TRES = b'\x09 '
119117 HW_TYPE_CUATRO = b'\x0a '
118+ HW_TYPE_BODY = b'\xb1 '
120119
121120 CAN_PACKET_VERSION = 4
122121 HEALTH_PACKET_VERSION = 17
123122 CAN_HEALTH_PACKET_VERSION = 5
124123 HEALTH_STRUCT = struct .Struct ("<IIIIIIIIBBBBBHBBBHfBBHHHB" )
125124 CAN_HEALTH_STRUCT = struct .Struct ("<BIBBBBBBBBIIIIIIIHHBBBIIII" )
126125
127- H7_DEVICES = [HW_TYPE_RED_PANDA , HW_TYPE_TRES , HW_TYPE_CUATRO ]
126+ H7_DEVICES = [HW_TYPE_RED_PANDA , HW_TYPE_TRES , HW_TYPE_CUATRO , HW_TYPE_BODY ]
128127 SUPPORTED_DEVICES = H7_DEVICES
129128
130129 INTERNAL_DEVICES = (HW_TYPE_TRES , HW_TYPE_CUATRO )
131130
132- MAX_FAN_RPMs = {
133- HW_TYPE_TRES : 6600 ,
134- HW_TYPE_CUATRO : 5000 ,
135- }
136-
137131 HARNESS_STATUS_NC = 0
138132 HARNESS_STATUS_NORMAL = 1
139133 HARNESS_STATUS_FLIPPED = 2
@@ -147,11 +141,10 @@ def __init__(self, serial: str | None = None, claim: bool = True, disable_checks
147141 self ._can_speed_kbps = can_speed_kbps
148142
149143 if cli and serial is None :
150- self ._connect_serial = self ._cli_select_panda ()
144+ self ._connect_serial = self ._cli_select_panda ()
151145 else :
152- self ._connect_serial = serial
146+ self ._connect_serial = serial
153147
154- # connect and set mcu type
155148 self .connect (claim )
156149
157150 def _cli_select_panda (self ):
@@ -208,14 +201,9 @@ def connect(self, claim=True, wait=False):
208201 self ._serial = serial
209202 self ._connect_serial = serial
210203 self ._handle_open = True
211- self ._mcu_type = self .get_mcu_type ()
212204 self .health_version , self .can_version , self .can_health_version = self .get_packets_versions ()
213205 logger .debug ("connected" )
214206
215- hw_type = self .get_type ()
216- if hw_type not in self .SUPPORTED_DEVICES :
217- print ("WARNING: Using deprecated HW" )
218-
219207 # disable openpilot's heartbeat checks
220208 if self ._disable_checks :
221209 self .set_heartbeat_disabled ()
@@ -286,7 +274,7 @@ def usb_connect(cls, serial, claim=True, no_error=False):
286274 handle = device .open ()
287275 if sys .platform not in ("win32" , "cygwin" , "msys" , "darwin" ):
288276 handle .setAutoDetachKernelDriver (True )
289- if claim :
277+ if claim or sys . platform == "darwin" :
290278 handle .claimInterface (0 )
291279 # handle.setInterfaceAltSetting(0, 0) # Issue in USB stack
292280
@@ -342,6 +330,9 @@ def spi_list(cls):
342330 return []
343331
344332 def reset (self , enter_bootstub = False , enter_bootloader = False , reconnect = True ):
333+ if enter_bootstub or enter_bootloader :
334+ assert (hw_type := self .get_type ()) in self .SUPPORTED_DEVICES , f"Unknown HW: { hw_type } "
335+
345336 # no response is expected since it resets right away
346337 timeout = 5000 if isinstance (self ._handle , PandaSpiHandle ) else 15000
347338 try :
@@ -371,7 +362,7 @@ def reconnect(self):
371362 # wait up to 15 seconds
372363 for _ in range (15 * 10 ):
373364 try :
374- self .connect (wait = True )
365+ self .connect (claim = False , wait = True )
375366 success = True
376367 break
377368 except Exception :
@@ -421,16 +412,14 @@ def flash_static(handle, code, mcu_type):
421412 pass
422413
423414 def flash (self , fn = None , code = None , reconnect = True ):
415+ assert (hw_type := self .get_type ()) in self .SUPPORTED_DEVICES , f"Unknown HW: { hw_type } "
416+
424417 if self .up_to_date (fn = fn ):
425418 logger .info ("flash: already up to date" )
426419 return
427420
428- hw_type = self .get_type ()
429- if hw_type not in self .SUPPORTED_DEVICES :
430- raise RuntimeError (f"HW type { hw_type .hex ()} is deprecated and can no longer be flashed." )
431-
432421 if not fn :
433- fn = os .path .join (FW_PATH , self . _mcu_type .config .app_fn )
422+ fn = os .path .join (FW_PATH , McuType . H7 .config .app_fn )
434423 assert os .path .isfile (fn )
435424 logger .debug ("flash: main version is %s" , self .get_version ())
436425 if not self .bootstub :
@@ -445,7 +434,7 @@ def flash(self, fn=None, code=None, reconnect=True):
445434 logger .debug ("flash: bootstub version is %s" , self .get_version ())
446435
447436 # do flash
448- Panda .flash_static (self ._handle , code , mcu_type = self . _mcu_type )
437+ Panda .flash_static (self ._handle , code , mcu_type = McuType . H7 )
449438
450439 # reconnect
451440 if reconnect :
@@ -496,7 +485,7 @@ def wait_for_panda(cls, serial: str | None, timeout: int) -> bool:
496485 def up_to_date (self , fn = None ) -> bool :
497486 current = self .get_signature ()
498487 if fn is None :
499- fn = os .path .join (FW_PATH , self . get_mcu_type () .config .app_fn )
488+ fn = os .path .join (FW_PATH , McuType . H7 .config .app_fn )
500489 expected = Panda .get_signature_from_firmware (fn )
501490 return (current == expected )
502491
@@ -608,12 +597,6 @@ def get_packets_versions(self):
608597 else :
609598 return (0 , 0 , 0 )
610599
611- def get_mcu_type (self ) -> McuType :
612- hw_type = self .get_type ()
613- if hw_type in Panda .H7_DEVICES :
614- return McuType .H7
615- raise ValueError (f"unknown HW type: { hw_type } " )
616-
617600 def is_internal (self ):
618601 return self .get_type () in Panda .INTERNAL_DEVICES
619602
@@ -634,7 +617,7 @@ def get_usb_serial(self):
634617 return self ._serial
635618
636619 def get_dfu_serial (self ):
637- return PandaDFU .st_serial_to_dfu_serial (self ._serial , self . _mcu_type )
620+ return PandaDFU .st_serial_to_dfu_serial (self ._serial , McuType . H7 )
638621
639622 def get_uid (self ):
640623 """
@@ -694,10 +677,6 @@ def set_uart_parity(self, uart, parity):
694677 def set_uart_callback (self , uart , install ):
695678 self ._handle .controlWrite (Panda .REQUEST_OUT , 0xe3 , uart , int (install ), b'' )
696679
697- # LED stuff
698- def set_led (self , led , state ):
699- self ._handle .controlWrite (Panda .REQUEST_OUT , 0xe9 , led , state , b'' )
700-
701680 # ******************* can *******************
702681
703682 # The panda will NAK CAN writes when there is CAN congestion.
@@ -742,15 +721,6 @@ def can_clear(self, bus):
742721
743722 """
744723 self ._handle .controlWrite (Panda .REQUEST_OUT , 0xf1 , bus , 0 , b'' )
745-
746- def get_can_rx_slots (self ):
747- """Returns the number of empty RX slots in the internal CAN ringbuffer.
748-
749- Returns:
750- int: number of empty RX slots.
751- """
752- dat = self ._handle .controlRead (Panda .REQUEST_IN , 0xc7 , 0 , 0 , 2 )
753- return struct .unpack ("H" , dat )[0 ]
754724
755725 # ******************* serial *******************
756726
0 commit comments