From 1dfee5973bc2884b61e55b7614f2fe90d0e2a1f3 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 19 Jul 2022 17:18:42 -0700 Subject: [PATCH] Subaru: cleanup counter handling (#992) --- Dockerfile.panda | 2 +- tests/safety/test_subaru.py | 30 +++++++++--------------------- tests/safety/test_subaru_legacy.py | 7 ++----- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/Dockerfile.panda b/Dockerfile.panda index 8ded718f2..c604d2695 100644 --- a/Dockerfile.panda +++ b/Dockerfile.panda @@ -46,7 +46,7 @@ ENV LC_ALL en_US.UTF-8 RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash ENV PATH="/root/.pyenv/bin:/root/.pyenv/shims:${PATH}" ENV OPENPILOT_REF="1b0167ce24afb037b36464c40f9c5e0d657e77d9" -ENV OPENDBC_REF="2afccacd528758ffe4cbdb78b9cb9fe712744bcc" +ENV OPENDBC_REF="e2465cc701e878fdae5b4e363496c2fa5d2f7c08" COPY requirements.txt /tmp/ RUN pyenv install 3.8.10 && \ diff --git a/tests/safety/test_subaru.py b/tests/safety/test_subaru.py index 040d58c26..a90031dc6 100755 --- a/tests/safety/test_subaru.py +++ b/tests/safety/test_subaru.py @@ -7,12 +7,6 @@ from panda.tests.safety.common import CANPackerPanda class TestSubaruSafety(common.PandaSafetyTest, common.DriverTorqueSteeringSafetyTest): - cnt_gas = 0 - cnt_torque_driver = 0 - cnt_cruise = 0 - cnt_speed = 0 - cnt_brake = 0 - TX_MSGS = [[0x122, 0], [0x221, 0], [0x322, 0]] STANDSTILL_THRESHOLD = 20 # 1kph (see dbc file) RELAY_MALFUNCTION_ADDR = 0x122 @@ -42,35 +36,29 @@ class TestSubaruSafety(common.PandaSafetyTest, common.DriverTorqueSteeringSafety # TODO: this is unused def _torque_driver_msg(self, torque): - values = {"Steer_Torque_Sensor": torque, "Counter": self.cnt_torque_driver % 4} - self.__class__.cnt_torque_driver += 1 - return self.packer.make_can_msg_panda("Steering_Torque", 0, values) + values = {"Steer_Torque_Sensor": torque} + return self.packer.make_can_msg_panda("Steering_Torque", 0, values, counter=True) def _speed_msg(self, speed): # subaru safety doesn't use the scaled value, so undo the scaling values = {s: speed * 0.057 for s in ["FR", "FL", "RR", "RL"]} - values["Counter"] = self.cnt_speed % 4 - self.__class__.cnt_speed += 1 - return self.packer.make_can_msg_panda("Wheel_Speeds", 0, values) + return self.packer.make_can_msg_panda("Wheel_Speeds", 0, values, counter=True) def _user_brake_msg(self, brake): - values = {"Brake": brake, "Counter": self.cnt_brake % 4} - self.__class__.cnt_brake += 1 - return self.packer.make_can_msg_panda("Brake_Status", 0, values) + values = {"Brake": brake} + return self.packer.make_can_msg_panda("Brake_Status", 0, values, counter=True) def _torque_cmd_msg(self, torque, steer_req=1): values = {"LKAS_Output": torque} return self.packer.make_can_msg_panda("ES_LKAS", 0, values) def _user_gas_msg(self, gas): - values = {"Throttle_Pedal": gas, "Counter": self.cnt_gas % 4} - self.__class__.cnt_gas += 1 - return self.packer.make_can_msg_panda("Throttle", 0, values) + values = {"Throttle_Pedal": gas} + return self.packer.make_can_msg_panda("Throttle", 0, values, counter=True) def _pcm_status_msg(self, enable): - values = {"Cruise_Activated": enable, "Counter": self.cnt_cruise % 4} - self.__class__.cnt_cruise += 1 - return self.packer.make_can_msg_panda("CruiseControl", 0, values) + values = {"Cruise_Activated": enable} + return self.packer.make_can_msg_panda("CruiseControl", 0, values, counter=True) if __name__ == "__main__": diff --git a/tests/safety/test_subaru_legacy.py b/tests/safety/test_subaru_legacy.py index 93230a047..fbbbf776b 100755 --- a/tests/safety/test_subaru_legacy.py +++ b/tests/safety/test_subaru_legacy.py @@ -7,8 +7,6 @@ from panda.tests.safety.common import CANPackerPanda class TestSubaruLegacySafety(common.PandaSafetyTest, common.DriverTorqueSteeringSafetyTest): - cnt_gas = 0 - TX_MSGS = [[0x161, 0], [0x164, 0]] STANDSTILL_THRESHOLD = 20 # 1kph (see dbc file) RELAY_MALFUNCTION_ADDR = 0x164 @@ -55,9 +53,8 @@ class TestSubaruLegacySafety(common.PandaSafetyTest, common.DriverTorqueSteering return self.packer.make_can_msg_panda("ES_LKAS", 0, values) def _user_gas_msg(self, gas): - values = {"Throttle_Pedal": gas, "Counter": self.cnt_gas % 4} - self.__class__.cnt_gas += 1 - return self.packer.make_can_msg_panda("Throttle", 0, values) + values = {"Throttle_Pedal": gas} + return self.packer.make_can_msg_panda("Throttle", 0, values, counter=True) def _pcm_status_msg(self, enable): values = {"Cruise_Activated": enable}