mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-02-23 18:23:53 +08:00
FPv2: brand filter helper (#28439)
* pass in brand * needs to be flipped for exact matching since it's subtractive * new helper * makes more sense flipped * clean up * not that stuff here * not here
This commit is contained in:
@@ -28,11 +28,16 @@ def chunks(l, n=128):
|
||||
yield l[i:i + n]
|
||||
|
||||
|
||||
def is_brand(brand: str, filter_brand: Optional[str]) -> bool:
|
||||
"""Returns if brand matches filter_brand or no brand filter is specified"""
|
||||
return filter_brand is None or brand == filter_brand
|
||||
|
||||
|
||||
def build_fw_dict(fw_versions: List[capnp.lib.capnp._DynamicStructBuilder],
|
||||
filter_brand: Optional[str] = None) -> Dict[Tuple[int, Optional[int]], Set[bytes]]:
|
||||
fw_versions_dict = defaultdict(set)
|
||||
for fw in fw_versions:
|
||||
if (filter_brand is None or fw.brand == filter_brand) and not fw.logging:
|
||||
if is_brand(fw.brand, filter_brand) and not fw.logging:
|
||||
sub_addr = fw.subAddress if fw.subAddress != 0 else None
|
||||
fw_versions_dict[(fw.address, sub_addr)].add(fw.fwVersion)
|
||||
return dict(fw_versions_dict)
|
||||
@@ -277,7 +282,7 @@ def get_fw_versions(logcan, sendcan, query_brand=None, extra=None, timeout=0.1,
|
||||
|
||||
# Get versions and build capnp list to put into CarParams
|
||||
car_fw = []
|
||||
requests = [(brand, config, r) for brand, config, r in REQUESTS if query_brand is None or brand == query_brand]
|
||||
requests = [(brand, config, r) for brand, config, r in REQUESTS if is_brand(brand, query_brand)]
|
||||
for addr in tqdm(addrs, disable=not progress):
|
||||
for addr_chunk in chunks(addr):
|
||||
for brand, config, r in requests:
|
||||
|
||||
Reference in New Issue
Block a user