Skip to content

Commit

Permalink
Safety tests: Convert message addresses from decimal to hexadecimal (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyhaibin committed Sep 1, 2023
1 parent afb241a commit 579fff0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
16 changes: 8 additions & 8 deletions tests/safety/test_chrysler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@


class TestChryslerSafety(common.PandaSafetyTest, common.MotorTorqueSteeringSafetyTest):
TX_MSGS = [[571, 0], [658, 0], [678, 0]]
TX_MSGS = [[0x23B, 0], [0x292, 0], [0x2A6, 0]]
STANDSTILL_THRESHOLD = 0
RELAY_MALFUNCTION_ADDR = 0x292
RELAY_MALFUNCTION_BUS = 0
FWD_BLACKLISTED_ADDRS = {2: [658, 678]}
FWD_BLACKLISTED_ADDRS = {2: [0x292, 0x2A6]}
FWD_BUS_LOOKUP = {0: 2, 2: 0}

MAX_RATE_UP = 3
Expand Down Expand Up @@ -75,9 +75,9 @@ def test_buttons(self):


class TestChryslerRamDTSafety(TestChryslerSafety):
TX_MSGS = [[177, 2], [166, 0], [250, 0]]
RELAY_MALFUNCTION_ADDR = 166
FWD_BLACKLISTED_ADDRS = {2: [166, 250]}
TX_MSGS = [[0xB1, 2], [0xA6, 0], [0xFA, 0]]
RELAY_MALFUNCTION_ADDR = 0xA6
FWD_BLACKLISTED_ADDRS = {2: [0xA6, 0xFA]}

MAX_RATE_UP = 6
MAX_RATE_DOWN = 6
Expand All @@ -98,9 +98,9 @@ def _speed_msg(self, speed):
return self.packer.make_can_msg_panda("ESP_8", 0, values)

class TestChryslerRamHDSafety(TestChryslerSafety):
TX_MSGS = [[629, 0], [630, 0], [570, 2]]
RELAY_MALFUNCTION_ADDR = 630
FWD_BLACKLISTED_ADDRS = {2: [629, 630]}
TX_MSGS = [[0x275, 0], [0x276, 0], [0x23A, 2]]
RELAY_MALFUNCTION_ADDR = 0x276
FWD_BLACKLISTED_ADDRS = {2: [0x275, 0x276]}

MAX_TORQUE = 361
MAX_RATE_UP = 14
Expand Down
20 changes: 10 additions & 10 deletions tests/safety/test_gm.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_cancel_button(self):

class TestGmSafetyBase(common.PandaSafetyTest, common.DriverTorqueSteeringSafetyTest):
STANDSTILL_THRESHOLD = 10 * 0.0311
RELAY_MALFUNCTION_ADDR = 384
RELAY_MALFUNCTION_ADDR = 0x180
RELAY_MALFUNCTION_BUS = 0
BUTTONS_BUS = 0 # rx or tx
BRAKE_BUS = 0 # tx only
Expand Down Expand Up @@ -140,9 +140,9 @@ def _button_msg(self, buttons):


class TestGmAscmSafety(GmLongitudinalBase, TestGmSafetyBase):
TX_MSGS = [[384, 0], [1033, 0], [1034, 0], [715, 0], [880, 0], # pt bus
[161, 1], [774, 1], [776, 1], [784, 1], # obs bus
[789, 2], # ch bus
TX_MSGS = [[0x180, 0], [0x409, 0], [0x40A, 0], [0x2CB, 0], [0x370, 0], # pt bus
[0xA1, 1], [0x306, 1], [0x308, 1], [0x310, 1], # obs bus
[0x315, 2], # ch bus
[0x104c006c, 3], [0x10400060, 3]] # gmlan
FWD_BLACKLISTED_ADDRS: Dict[int, List[int]] = {}
FWD_BUS_LOOKUP: Dict[int, int] = {}
Expand Down Expand Up @@ -177,9 +177,9 @@ def _user_brake_msg(self, brake):


class TestGmCameraSafety(TestGmCameraSafetyBase):
TX_MSGS = [[384, 0], # pt bus
[388, 2]] # camera bus
FWD_BLACKLISTED_ADDRS = {2: [384], 0: [388]} # block LKAS message and PSCMStatus
TX_MSGS = [[0x180, 0], # pt bus
[0x184, 2]] # camera bus
FWD_BLACKLISTED_ADDRS = {2: [0x180], 0: [0x184]} # block LKAS message and PSCMStatus
BUTTONS_BUS = 2 # tx only

def setUp(self):
Expand All @@ -205,9 +205,9 @@ def test_buttons(self):


class TestGmCameraLongitudinalSafety(GmLongitudinalBase, TestGmCameraSafetyBase):
TX_MSGS = [[384, 0], [789, 0], [715, 0], [880, 0], # pt bus
[388, 2]] # camera bus
FWD_BLACKLISTED_ADDRS = {2: [384, 715, 880, 789], 0: [388]} # block LKAS, ACC messages and PSCMStatus
TX_MSGS = [[0x180, 0], [0x315, 0], [0x2CB, 0], [0x370, 0], # pt bus
[0x184, 2]] # camera bus
FWD_BLACKLISTED_ADDRS = {2: [0x180, 0x2CB, 0x370, 0x315], 0: [0x184]} # block LKAS, ACC messages and PSCMStatus
BUTTONS_BUS = 0 # rx only

MAX_GAS = 3400
Expand Down
25 changes: 12 additions & 13 deletions tests/safety/test_hyundai.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def checksum(msg):
addr, t, dat, bus = msg

chksum = 0
if addr == 902:
if addr == 0x386:
for i, b in enumerate(dat):
for j in range(8):
# exclude checksum and counter bits
Expand All @@ -28,26 +28,26 @@ def checksum(msg):
ret[7] |= (chksum & 0xc) << 4
else:
for i, b in enumerate(dat):
if addr in [608, 1057] and i == 7:
b &= 0x0F if addr == 1057 else 0xF0
elif addr == 916 and i == 6:
if addr in [0x260, 0x421] and i == 7:
b &= 0x0F if addr == 0x421 else 0xF0
elif addr == 0x394 and i == 6:
b &= 0xF0
elif addr == 916 and i == 7:
elif addr == 0x394 and i == 7:
continue
chksum += sum(divmod(b, 16))
chksum = (16 - chksum) % 16
ret = bytearray(dat)
ret[6 if addr == 916 else 7] |= chksum << (4 if addr == 1057 else 0)
ret[6 if addr == 0x394 else 7] |= chksum << (4 if addr == 0x421 else 0)

return addr, t, ret, bus


class TestHyundaiSafety(HyundaiButtonBase, common.PandaSafetyTest, common.DriverTorqueSteeringSafetyTest):
TX_MSGS = [[832, 0], [1265, 0], [1157, 0]]
TX_MSGS = [[0x340, 0], [0x4F1, 0], [0x485, 0]]
STANDSTILL_THRESHOLD = 12 # 0.375 kph
RELAY_MALFUNCTION_ADDR = 832
RELAY_MALFUNCTION_ADDR = 0x340
RELAY_MALFUNCTION_BUS = 0
FWD_BLACKLISTED_ADDRS = {2: [832, 1157]}
FWD_BLACKLISTED_ADDRS = {2: [0x340, 0x485]}
FWD_BUS_LOOKUP = {0: 2, 2: 0}

MAX_RATE_UP = 3
Expand Down Expand Up @@ -168,11 +168,10 @@ def _user_gas_msg(self, gas):
return self.packer.make_can_msg_panda("E_EMS11", 0, values, fix_checksum=checksum)

class TestHyundaiLongitudinalSafety(HyundaiLongitudinalBase, TestHyundaiSafety):
TX_MSGS = [[832, 0], [1265, 0], [1157, 0], [1056, 0], [1057, 0], [1290, 0], [905, 0], [1186, 0], [909, 0], [1155, 0], [2000, 0]]
TX_MSGS = [[0x340, 0], [0x4F1, 0], [0x485, 0], [0x420, 0], [0x421, 0], [0x50A, 0], [0x389, 0], [0x4A2, 0], [0x38D, 0], [0x483, 0], [0x7D0, 0]]


DISABLED_ECU_UDS_MSG = (2000, 0)
DISABLED_ECU_ACTUATION_MSG = (1057, 0)
DISABLED_ECU_UDS_MSG = (0x7D0, 0)
DISABLED_ECU_ACTUATION_MSG = (0x421, 0)

def setUp(self):
self.packer = CANPackerPanda("hyundai_kia_generic")
Expand Down

0 comments on commit 579fff0

Please sign in to comment.