mirror of
https://jihulab.com/mr-one/openpilot.git
synced 2026-10-27 04:53:44 +08:00
fix: release chestnut USB handle while modeld loads
This commit is contained in:
@@ -5,6 +5,7 @@ import usb1
|
||||
import openpilot.cereal.messaging as messaging
|
||||
from openpilot.cereal.services import SERVICE_LIST
|
||||
from openpilot.common.hardware.usb import CHESTNUT_USB_PRODUCT, get_usb_state, is_chestnut_usb_id
|
||||
from openpilot.common.params import Params
|
||||
|
||||
|
||||
def read_chestnut_state(handle, gpu_state=None):
|
||||
@@ -26,11 +27,18 @@ def read_chestnut_state(handle, gpu_state=None):
|
||||
def chestnut_state_thread(end_event):
|
||||
pm = messaging.PubMaster(['chestnutState'])
|
||||
sm = messaging.SubMaster(['chestnutGpuState'])
|
||||
params = Params()
|
||||
with usb1.USBContext() as context:
|
||||
handle = None
|
||||
try:
|
||||
while not end_event.is_set():
|
||||
if handle is None:
|
||||
# modeld owns the chestnut USB interface while loading/running the big model.
|
||||
# Do not hold a second libusb handle: libusb_set_configuration returns EBUSY.
|
||||
modeld_owns_usb = params.get_bool("ChestnutLoading") or params.get_bool("ChestnutActive")
|
||||
if handle is not None and modeld_owns_usb:
|
||||
handle.close()
|
||||
handle = None
|
||||
if handle is None and not modeld_owns_usb:
|
||||
devices = [d for d in get_usb_state() if is_chestnut_usb_id(d['vendorId'], d['productId']) and
|
||||
d['product'] == CHESTNUT_USB_PRODUCT]
|
||||
if len(devices) == 1:
|
||||
|
||||
Reference in New Issue
Block a user