Skip to content

Commit

Permalink
Hyundai-Kia-Genesis (HKG) (commaai#503)
Browse files Browse the repository at this point in the history
* update hkg steer torque message

* misra

* Get bus

* Allow sending LFA HDA message

* Add blacklisted addr

* Update safety replay

* Cleanup bus checks

* Update to new torque message
  • Loading branch information
pd0wm authored Apr 16, 2020
1 parent 6f105e8 commit 715b1a1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
13 changes: 7 additions & 6 deletions board/safety/safety_hyundai.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const int HYUNDAI_MAX_RATE_DOWN = 7;
const int HYUNDAI_DRIVER_TORQUE_ALLOWANCE = 50;
const int HYUNDAI_DRIVER_TORQUE_FACTOR = 2;
const int HYUNDAI_STANDSTILL_THRSLD = 30; // ~1kph
const AddrBus HYUNDAI_TX_MSGS[] = {{832, 0}, {1265, 0}};
const AddrBus HYUNDAI_TX_MSGS[] = {{832, 0}, {1265, 0}, {1157, 0}};

// TODO: do checksum and counter checks
AddrCheckStruct hyundai_rx_checks[] = {
Expand All @@ -32,11 +32,12 @@ static int hyundai_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {

bool unsafe_allow_gas = unsafe_mode & UNSAFE_DISABLE_DISENGAGE_ON_GAS;

if (valid && GET_BUS(to_push) == 0) {
int addr = GET_ADDR(to_push);
int addr = GET_ADDR(to_push);
int bus = GET_BUS(to_push);

if (addr == 897) {
int torque_driver_new = ((GET_BYTES_04(to_push) >> 11) & 0xfff) - 2048;
if (valid && (bus == 0)) {
if (addr == 593) {
int torque_driver_new = ((GET_BYTES_04(to_push) & 0x7ff) * 0.79) - 808; // scale down new driver torque signal to match previous one
// update array of samples
update_sample(&hyundai_torque_driver, torque_driver_new);
}
Expand Down Expand Up @@ -170,7 +171,7 @@ static int hyundai_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
if (bus_num == 0) {
bus_fwd = 2;
}
if ((bus_num == 2) && (addr != 832)) {
if ((bus_num == 2) && (addr != 832) && (addr != 1157)) {
bus_fwd = 0;
}
}
Expand Down
10 changes: 5 additions & 5 deletions tests/safety/test_hyundai.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@


class TestHyundaiSafety(common.PandaSafetyTest):

TX_MSGS = [[832, 0], [1265, 0]]
TX_MSGS = [[832, 0], [1265, 0], [1157, 0]]
STANDSTILL_THRESHOLD = 30 # ~1kph
RELAY_MALFUNCTION_ADDR = 832
RELAY_MALFUNCTION_BUS = 0
FWD_BLACKLISTED_ADDRS = {2: [832]}
FWD_BLACKLISTED_ADDRS = {2: [832, 1157]}
FWD_BUS_LOOKUP = {0: 2, 2: 0}

def setUp(self):
Expand Down Expand Up @@ -57,9 +56,10 @@ def _set_prev_torque(self, t):
self.safety.set_hyundai_desired_torque_last(t)
self.safety.set_hyundai_rt_torque_last(t)

# TODO: this is unused
def _torque_driver_msg(self, torque):
values = {"CR_Mdps_DrvTq": torque}
return self.packer.make_can_msg_panda("MDPS11", 0, values)
values = {"CR_Mdps_StrColTq": torque}
return self.packer.make_can_msg_panda("MDPS12", 0, values)

def _torque_msg(self, torque):
values = {"CR_Lkas_StrToqReq": torque}
Expand Down
3 changes: 1 addition & 2 deletions tests/safety_replay/test_safety_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
("38bfd238edecbcd7|2019-06-07--10-15-25.bz2", Panda.SAFETY_TOYOTA, 66), # TOYOTA.PRIUS
("f89c604cf653e2bf|2018-09-29--13-46-50.bz2", Panda.SAFETY_GM, 0), # GM.VOLT
("0375fdf7b1ce594d|2019-05-21--20-10-33.bz2", Panda.SAFETY_HONDA_BOSCH_GIRAFFE, 1), # HONDA.ACCORD
("02ec6bea180a4d36|2019-04-17--11-21-35.bz2", Panda.SAFETY_HYUNDAI, 0), # HYUNDAI.SANTA_FE
("6fb4948a7ebe670e|2019-11-12--00-35-53.bz2", Panda.SAFETY_CHRYSLER, 0), # CHRYSLER.PACIFICA_2018_HYBRID
("791340bc01ed993d|2019-04-08--10-26-00.bz2", Panda.SAFETY_SUBARU, 0), # SUBARU.IMPREZA
("76b83eb0245de90e|2020-03-05--19-16-05.bz2", Panda.SAFETY_VOLKSWAGEN_MQB, 0), # VOLKSWAGEN.GOLF (MK7)
("d12cd943127f267b|2020-03-27--15-57-18.bz2", Panda.SAFETY_VOLKSWAGEN_PQ, 0), # 2009 VW Passat R36 (B6), supporting OP port not yet upstreamed
("fbbfa6af821552b9|2020-03-03--08-09-43.bz2", Panda.SAFETY_NISSAN, 0), # NISSAN.XTRAIL
("5b7c365c50084530_2020-04-15--16-13-24--3--rlog.bz2", Panda.SAFETY_HYUNDAI, 0), # HYUNDAI.SONATA
]

if __name__ == "__main__":
Expand All @@ -40,4 +40,3 @@
for f in failed:
print("\n**** failed on %s ****" % f)
assert len(failed) == 0, "\nfailed on %d logs" % len(failed)

0 comments on commit 715b1a1

Please sign in to comment.