Skip to content

Commit

Permalink
Hyundai wheel speed counter is actually 4 bits spread over two signals
Browse files Browse the repository at this point in the history
  • Loading branch information
adeebshihadeh committed May 18, 2020
1 parent 0d581aa commit 0610ed1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions board/safety/safety_hyundai.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const CanMsg HYUNDAI_TX_MSGS[] = {{832, 0, 8}, {1265, 0, 4}, {1157, 0, 4}};
AddrCheckStruct hyundai_rx_checks[] = {
{.msg = {{608, 0, 8}}, .max_counter = 3U, .expected_timestep = 10000U},
{.msg = {{897, 0, 8}}, .max_counter = 255U, .expected_timestep = 10000U},
{.msg = {{902, 0, 8}}, .max_counter = 3U, .expected_timestep = 10000U},
{.msg = {{902, 0, 8}}, .max_counter = 15U, .expected_timestep = 10000U},
{.msg = {{916, 0, 8}}, .max_counter = 7U, .expected_timestep = 10000U},
{.msg = {{1057, 0, 8}}, .max_counter = 15U, .expected_timestep = 20000U},
};
Expand All @@ -27,7 +27,7 @@ static uint8_t hyundai_get_counter(CAN_FIFOMailBox_TypeDef *to_push) {
} else if (addr == 897) {
cnt = GET_BYTE(to_push, 5);
} else if (addr == 902) {
cnt = (GET_BYTE(to_push, 1) >> 6) & 0x3;
cnt = ((GET_BYTE(to_push, 3) >> 6) << 2) | (GET_BYTE(to_push, 1) >> 6);
} else if (addr == 916) {
cnt = (GET_BYTE(to_push, 1) >> 5) & 0x7;
} else if (addr == 1057) {
Expand Down
3 changes: 2 additions & 1 deletion tests/safety/test_hyundai.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def _brake_msg(self, brake):
def _speed_msg(self, speed):
# panda safety doesn't scale, so undo the scaling
values = {"WHL_SPD_%s"%s: speed*0.03125 for s in ["FL", "FR", "RL", "RR"]}
values["WHL_SPD_AliveCounter_LSB"] = self.cnt_speed % 4
values["WHL_SPD_AliveCounter_LSB"] = (self.cnt_speed % 16) & 0x3
values["WHL_SPD_AliveCounter_MSB"] = (self.cnt_speed % 16) >> 2
self.__class__.cnt_speed += 1
return self.packer.make_can_msg_panda("WHL_SPD11", 0, values)

Expand Down

0 comments on commit 0610ed1

Please sign in to comment.