diff --git a/opendbc_repo/opendbc/car/hyundai/carcontroller.py b/opendbc_repo/opendbc/car/hyundai/carcontroller.py index ad2e600157..18fe0df227 100644 --- a/opendbc_repo/opendbc/car/hyundai/carcontroller.py +++ b/opendbc_repo/opendbc/car/hyundai/carcontroller.py @@ -1034,7 +1034,8 @@ class CarController(CarControllerBase): ) else: adrv_messages = hyundaicanfd.create_adrv_messages(self.packer, self.CAN, self.frame, - car_fingerprint=self.CP.carFingerprint) + car_fingerprint=self.CP.carFingerprint, + drive_gear=drive_gear) can_sends.extend(adrv_messages) # The front radar treats ADAS_DRV's 0x100 broadcast as its host heartbeat # and stops publishing object tracks when it disappears. diff --git a/opendbc_repo/opendbc/car/hyundai/hyundaicanfd.py b/opendbc_repo/opendbc/car/hyundai/hyundaicanfd.py index 8cc18edc76..c29a6f0a47 100644 --- a/opendbc_repo/opendbc/car/hyundai/hyundaicanfd.py +++ b/opendbc_repo/opendbc/car/hyundai/hyundaicanfd.py @@ -21,7 +21,7 @@ def cache_adrv_0x51_template(car_fingerprint: CAR, dat: bytes | None) -> None: _adrv_0x51_templates[car_fingerprint] = bytes(dat) -def create_adrv_0x51(packer, CAN, frame: int, car_fingerprint: CAR | None = None): +def create_adrv_0x51(packer, CAN, frame: int, car_fingerprint: CAR | None = None, drive_gear: bool = False): template = _adrv_0x51_templates.get(car_fingerprint) if template is None: return packer.make_can_msg("ADRV_0x51", CAN.ACAN, {}) @@ -29,6 +29,7 @@ def create_adrv_0x51(packer, CAN, frame: int, car_fingerprint: CAR | None = None # EV6 MRR30 tracks stop when the ADAS takeover replaces this platform payload with zeros. dat = bytearray(template) dat[2] = (template[2] + frame + 1) & 0xFF + dat[3] = (dat[3] & ~0x1) | int(drive_gear) crc = hkg_can_fd_checksum(0x51, None, dat) dat[0] = crc & 0xFF dat[1] = (crc >> 8) & 0xFF @@ -815,13 +816,13 @@ def create_fca_warning_light(packer, CAN, frame): return ret -def create_adrv_messages(packer, CAN, frame, blended_hda2=False, car_fingerprint=None): +def create_adrv_messages(packer, CAN, frame, blended_hda2=False, car_fingerprint=None, drive_gear=False): # messages needed to car happy after disabling # the ADAS Driving ECU to do longitudinal control ret = [] - ret.append(create_adrv_0x51(packer, CAN, frame, car_fingerprint)) + ret.append(create_adrv_0x51(packer, CAN, frame, car_fingerprint, drive_gear)) if blended_hda2: return ret diff --git a/opendbc_repo/opendbc/car/hyundai/tests/test_hyundai.py b/opendbc_repo/opendbc/car/hyundai/tests/test_hyundai.py index efe7339658..84da4d8ad3 100644 --- a/opendbc_repo/opendbc/car/hyundai/tests/test_hyundai.py +++ b/opendbc_repo/opendbc/car/hyundai/tests/test_hyundai.py @@ -159,7 +159,8 @@ class TestHyundaiFingerprint: hyundaicanfd.cache_adrv_0x51_template(CAR.KIA_EV6, factory) try: - address, dat, bus = hyundaicanfd.create_adrv_0x51(packer, can_bus, 7, CAR.KIA_EV6) + address, dat, bus = hyundaicanfd.create_adrv_0x51(packer, can_bus, 7, CAR.KIA_EV6, drive_gear=True) + _, parked_dat, _ = hyundaicanfd.create_adrv_0x51(packer, can_bus, 8, CAR.KIA_EV6, drive_gear=False) _, other_dat, _ = hyundaicanfd.create_adrv_0x51(packer, can_bus, 7, CAR.HYUNDAI_IONIQ_6) finally: hyundaicanfd.cache_adrv_0x51_template(CAR.KIA_EV6, None) @@ -169,6 +170,9 @@ class TestHyundaiFingerprint: assert dat[2] == (factory[2] + 8) & 0xFF assert dat[3:] == factory[3:] assert int.from_bytes(dat[:2], "little") == hkg_can_fd_checksum(address, None, bytearray(dat)) + assert parked_dat[3] == factory[3] & ~0x1 + assert parked_dat[4:] == factory[4:] + assert int.from_bytes(parked_dat[:2], "little") == hkg_can_fd_checksum(address, None, bytearray(parked_dat)) assert other_dat[3:] == bytes(29) def test_ev6_init_captures_factory_adrv_0x51(self, monkeypatch): @@ -193,7 +197,7 @@ class TestHyundaiFingerprint: packer = CANPacker(DBC[CP.carFingerprint][Bus.pt]) try: - _, dat, _ = hyundaicanfd.create_adrv_0x51(packer, CanBus(CP), 0, CAR.KIA_EV6) + _, dat, _ = hyundaicanfd.create_adrv_0x51(packer, CanBus(CP), 0, CAR.KIA_EV6, drive_gear=True) finally: hyundaicanfd.cache_adrv_0x51_template(CAR.KIA_EV6, None)