def wrapper(panda_type=None, **kwargs): # Change panda_types to a list if panda_type is not None: if not isinstance(panda_type, list): panda_type = [panda_type] # If not done already, get panda serials and their type global _panda_serials if _panda_serials == None: _panda_serials = [] for serial in Panda.list(): p = Panda(serial=serial) _panda_serials.append((serial, p.get_type())) p.close() # Find a panda with the correct types and add the corresponding serial serials = [] for p_type in panda_type: found = False for serial, pt in _panda_serials: # Never take the same panda twice if (pt == p_type) and (serial not in serials): serials.append(serial) found = True break if not found: raise IOError( "No unused panda found for type: {}".format(p_type)) return fn(serials, **kwargs)
def panda_sort_cmp(a: Panda, b: Panda): a_type = a.get_type() b_type = b.get_type() # make sure the internal one is always first if a.is_internal() and not b.is_internal(): return -1 if not a.is_internal() and b.is_internal(): return 1 # sort by hardware type if a_type != b_type: return a_type < b_type # last resort: sort by serial number return a.get_usb_serial() < b.get_usb_serial()
def init_panda_serials(): global panda_jungle, _panda_serials _panda_serials = [] panda_jungle.set_panda_power(True) time.sleep(5) for serial in Panda.list(): p = Panda(serial=serial) _panda_serials.append((serial, p.get_type())) p.close() print('Found', str(len(_panda_serials)), 'pandas')
def init_panda_serials(): global panda_jungle, _panda_serials _panda_serials = [] panda_jungle.set_panda_power(True) time.sleep(5) for serial in Panda.list(): if serial not in PANDAS_EXCLUDE: p = Panda(serial=serial) _panda_serials.append((serial, p.get_type())) p.close() print(f"Found {len(_panda_serials)} pandas")
if JUNGLE_SERIAL: panda_jungle = PandaJungle(JUNGLE_SERIAL) panda_jungle.set_panda_power(False) time.sleep(2) panda_jungle.set_panda_power(True) time.sleep(4) #panda_jungle.set_can_enable(0, False) #panda_jungle.set_can_enable(1, False) #panda_jungle.set_can_enable(2, False) for serial in Panda.list(): if serial not in H7_PANDAS_EXCLUDE: p = Panda(serial=serial) if p.get_type() in H7_HW_TYPES: _panda_serials.append(serial) p.close() if len(_panda_serials) < 2: print("Minimum two H7 type pandas should be connected.") assert False def canfd_test(p_send, p_recv): for _ in range(500): sent_msgs = defaultdict(set) to_send = [] for _ in range(200): bus = random.randrange(3) for dlc in range(len(DLC_TO_LEN)):
if p.is_white(): p.can_send(id_, msg, WHITE_GMLAN_BUS) else: p.can_send(id_, msg, OTHER_GMLAN_BUS) if __name__ == "__main__": pl = Panda.list() assert (len(pl) == 2) p0 = Panda(pl[1]) p1 = Panda(pl[0]) p0.set_safety_mode(Panda.SAFETY_ALLOUTPUT) p1.set_safety_mode(Panda.SAFETY_ALLOUTPUT) print("0: ", p0.get_type()) print("1: ", p1.get_type()) set_gmlan(p0) set_gmlan(p1) p0.can_clear(0xFFFF) p1.can_clear(0xFFFF) loops = 0 while True: for speed in [33.3, 83.3]: set_speed_kbps(p0, speed) set_speed_kbps(p1, speed) p0.can_clear(0xFFFF) p1.can_clear(0xFFFF)