clean up (utils are cleaner and less buggy)

pull/26939/head
Shane Smiskol 2 years ago
parent 8704b98ec8
commit c083ef8f87
  1. 2
      selfdrive/car/hyundai/tests/test_hyundai.py
  2. 23
      selfdrive/car/hyundai/values.py

@ -36,7 +36,7 @@ class TestHyundaiFingerprint(unittest.TestCase):
self.assertIn(fuzzy_ecu, [e[0] for e in ecus]) self.assertIn(fuzzy_ecu, [e[0] for e in ecus])
def test_fuzzy_fw_dates(self): def test_fuzzy_fw_dates(self):
# Some newer CAN FD platforms have date codes in a different format we don't yet parse, # Some newer platforms have date codes in a different format we don't yet parse,
# for now assert date format is consistent across each platform # for now assert date format is consistent across each platform
for car_model, ecus in FW_VERSIONS.items(): for car_model, ecus in FW_VERSIONS.items():
with self.subTest(car_model=car_model): with self.subTest(car_model=car_model):

@ -1,6 +1,5 @@
import re import re
from datetime import datetime from datetime import datetime
from dateutil.relativedelta import relativedelta
from dateutil import rrule from dateutil import rrule
from collections import defaultdict from collections import defaultdict
from dataclasses import dataclass from dataclasses import dataclass
@ -347,7 +346,6 @@ FINGERPRINTS = {
}], }],
} }
import time
def get_platform_codes(fw_versions: List[bytes]) -> Set[bytes]: def get_platform_codes(fw_versions: List[bytes]) -> Set[bytes]:
# platform_code_pattern = re.compile(b'(?<=' + HYUNDAI_VERSION_REQUEST_LONG[1:] + b')[A-Z]{2}[A-Za-z0-9]{0,2}') # platform_code_pattern = re.compile(b'(?<=' + HYUNDAI_VERSION_REQUEST_LONG[1:] + b')[A-Z]{2}[A-Za-z0-9]{0,2}')
@ -367,30 +365,11 @@ def get_platform_codes(fw_versions: List[bytes]) -> Set[bytes]:
final_codes.add(code) final_codes.add(code)
continue continue
delta = relativedelta(months=1)
dates = {datetime.strptime(date.decode()[:4], '%y%m') for date in dates} dates = {datetime.strptime(date.decode()[:4], '%y%m') for date in dates}
for date in rrule.rrule(rrule.MONTHLY, dtstart=min(dates), until=max(dates)): for date in rrule.rrule(rrule.MONTHLY, dtstart=min(dates), until=max(dates)):
final_codes.add(code + b'_' + date.strftime('%y%m').encode()) final_codes.add(code + b'_' + date.strftime('%y%m').encode())
return final_codes
# # current_date = datetime.strptime(max(dates).decode(), '%y%m%d') return final_codes
# # max_date = datetime.strptime(max(dates).decode(), '%y%m%d')
# print('code, dates:', code, datesp)
#
# min_date, max_date = min(dates), max(dates)
# current_year, current_month = int(min_date[:2]), int(min_date[2:4])
# max_year, max_month = int(max_date[:2]), int(max_date[2:4])
# # print(current_year, current_month, max_year, max_month)
# # return set()
# while current_year < max_year or current_month < max_month:
# time.sleep(0.1)
# print(current_month, current_year, max_month, max_year)
# date_code = str(current_year).zfill(2) + str(current_month).zfill(2)
# final_codes.add(code + b'_' + date_code.encode())
# current_year += (current_month + 1) // 13
# current_month = (current_month % 12) + 1
#
# return final_codes
HYUNDAI_VERSION_REQUEST_LONG = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER]) + \ HYUNDAI_VERSION_REQUEST_LONG = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER]) + \

Loading…
Cancel
Save