import struct 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 def read_chestnut_state(handle, gpu_state=None): msg = messaging.new_message('chestnutState') if gpu_state is not None: msg.chestnutState = gpu_state state = msg.chestnutState try: raw = handle.controlRead(0xC0, 0xC0, 0, 0, 5, timeout=100) state.supplyVoltage, state.supplyCurrent, state.supplyFault = struct.unpack('