Skip to content

Commit 8110ba3

Browse files
committed
Body Harness - c3x
1 parent abdc418 commit 8110ba3

File tree

4 files changed

+91
-14
lines changed

4 files changed

+91
-14
lines changed

board/power_saving.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void set_power_save_state(int state) {
3333
enable = true;
3434
}
3535

36-
current_board->enable_can_transceivers(enable);
36+
current_board->enable_can_transceivers(true);
3737

3838
// Switch off IR when in power saving
3939
if(!enable){

board/safety/safety_elm327.h

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,44 @@
33
#include "safety_declarations.h"
44
#include "safety_defaults.h"
55

6+
#define CAN_GATEWAY_INPUT 0x800
7+
#define CAN_GATEWAY_OUTPUT 0x801
8+
#define CAN_GATEWAY_SIZE 8
9+
#define OTA_IN 0x1
10+
611
static bool elm327_tx_hook(const CANPacket_t *to_send) {
712
const int GM_CAMERA_DIAG_ADDR = 0x24B;
813

914
bool tx = true;
1015
int addr = GET_ADDR(to_send);
1116
int len = GET_LEN(to_send);
1217

13-
// All ISO 15765-4 messages must be 8 bytes long
14-
if (len != 8) {
15-
tx = false;
18+
// All ISO 15765-4 messages must be 8 bytes long
19+
// TODO: Replace this with the check functionality from safety_honda
20+
bool is_body = (addr == 0x16f118f0) || (addr == 0x0ef81218) || (addr == CAN_GATEWAY_INPUT);
21+
if (is_body) {
22+
if ((len != 8) && (addr == 0x16f118f0)){ // honda bcm diag request
23+
tx = false;
24+
}
25+
else if ((len != 2) && (addr == 0x0ef81218)){ // 2017 honda civic hatch keyfob replay
26+
tx = false;
27+
}
28+
else if ((len != CAN_GATEWAY_SIZE) && (addr == CAN_GATEWAY_INPUT)){ // body harness heartbeat frame
29+
tx = false;
30+
}
31+
else {
32+
tx = false; // we shouldn't end up here if we did things correctly
33+
}
34+
}
35+
// // allow OTA flashing
36+
// else if (addr == OTA_IN){
37+
// tx = true;
38+
// }
39+
else {
40+
//All ISO 15765-4 messages must be 8 bytes long
41+
if (len != 8) {
42+
tx = false;
43+
}
1644
}
1745

1846
// Check valid 29 bit send addresses for ISO 15765-4

board/safety/safety_honda.h

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void honda_rx_hook(const CANPacket_t *to_push) {
8787

8888
// check ACC main state
8989
// 0x326 for all Bosch and some Nidec, 0x1A6 for some Nidec
90-
if ((addr == 0x326) || (addr == 0x1A6)) {
90+
if (((addr == 0x326) && (bus == pt_bus)) || (addr == 0x1A6)) {
9191
acc_main_on = GET_BIT(to_push, ((addr == 0x326) ? 28U : 47U));
9292
if (!acc_main_on) {
9393
controls_allowed = false;
@@ -173,6 +173,11 @@ static void honda_rx_hook(const CANPacket_t *to_push) {
173173
int bus_rdr_car = (honda_hw == HONDA_BOSCH) ? 0 : 2; // radar bus, car side
174174
bool stock_ecu_detected = false;
175175

176+
// // TODO: tick the body harness gatewayheartbeat. If we lose contact with the OP, should we go not controls_allowed???
177+
// if ((addr == 0x801) && (len == 8)) {
178+
//
179+
// }
180+
176181
// If steering controls messages are received on the destination bus, it's an indication
177182
// that the relay might be malfunctioning
178183
if ((addr == 0xE4) || (addr == 0x194)) {
@@ -197,6 +202,7 @@ static bool honda_tx_hook(const CANPacket_t *to_send) {
197202
.min_accel = -350,
198203

199204
.max_gas = 2000,
205+
.min_gas = -40,
200206
.inactive_gas = -30000,
201207
};
202208

@@ -299,11 +305,29 @@ static bool honda_tx_hook(const CANPacket_t *to_send) {
299305
}
300306
}
301307

308+
// KWP over CAN. Allow only short turn signal request and cancel
309+
// TODO: move to gateway firmware
310+
if (addr == 0x16F118F0){
311+
bool signalCmd = ((GET_LEN(to_send) == 8U) && ((GET_BYTES(to_send, 0, 4) == 0x000F0A30U) || (GET_BYTES(to_send, 0, 4) == 0x000F0B30U)) && (GET_BYTES(to_send, 4, 4) == 0x0U));
312+
bool cancelCmd = ((GET_LEN(to_send) == 1U) && (GET_BYTE(to_send, 0) == 0x20U));
313+
// always allow cancel
314+
if (!cancelCmd) {
315+
if (!controls_allowed) {
316+
tx = false;
317+
}
318+
else {
319+
if (!signalCmd) {
320+
tx = false;
321+
}
322+
}
323+
}
324+
}
325+
302326
return tx;
303327
}
304328

305329
static safety_config honda_nidec_init(uint16_t param) {
306-
static CanMsg HONDA_N_TX_MSGS[] = {{0xE4, 0, 5}, {0x194, 0, 4}, {0x1FA, 0, 8}, {0x30C, 0, 8}, {0x33D, 0, 5}};
330+
static CanMsg HONDA_N_TX_MSGS[] = {{0xE4, 0, 5}, {0x194, 0, 4}, {0x1FA, 0, 8}, {0x30C, 0, 8}, {0x33D, 0, 5}, {0x16F118F0, 0, 8}, {0x16F118F0, 0, 1}};
307331

308332
const uint16_t HONDA_PARAM_NIDEC_ALT = 4;
309333

@@ -321,7 +345,7 @@ static safety_config honda_nidec_init(uint16_t param) {
321345

322346
if (enable_nidec_alt) {
323347
// For Nidecs with main on signal on an alternate msg (missing 0x326)
324-
static RxCheck honda_nidec_alt_rx_checks[] = {
348+
static RxCheck honda_nidec_alt_rx_checks[] = {
325349
HONDA_COMMON_NO_SCM_FEEDBACK_RX_CHECKS(0)
326350
};
327351

@@ -336,10 +360,10 @@ static safety_config honda_nidec_init(uint16_t param) {
336360
}
337361

338362
static safety_config honda_bosch_init(uint16_t param) {
339-
static CanMsg HONDA_BOSCH_TX_MSGS[] = {{0xE4, 0, 5}, {0xE5, 0, 8}, {0x296, 1, 4}, {0x33D, 0, 5}, {0x33DA, 0, 5}, {0x33DB, 0, 8}}; // Bosch
340-
static CanMsg HONDA_BOSCH_LONG_TX_MSGS[] = {{0xE4, 1, 5}, {0x1DF, 1, 8}, {0x1EF, 1, 8}, {0x1FA, 1, 8}, {0x30C, 1, 8}, {0x33D, 1, 5}, {0x33DA, 1, 5}, {0x33DB, 1, 8}, {0x39F, 1, 8}, {0x18DAB0F1, 1, 8}}; // Bosch w/ gas and brakes
341-
static CanMsg HONDA_RADARLESS_TX_MSGS[] = {{0xE4, 0, 5}, {0x296, 2, 4}, {0x33D, 0, 8}}; // Bosch radarless
342-
static CanMsg HONDA_RADARLESS_LONG_TX_MSGS[] = {{0xE4, 0, 5}, {0x33D, 0, 8}, {0x1C8, 0, 8}, {0x30C, 0, 8}}; // Bosch radarless w/ gas and brakes
363+
static CanMsg HONDA_BOSCH_TX_MSGS[] = {{0xE4, 0, 5}, {0xE5, 0, 8}, {0x296, 1, 4}, {0x33D, 0, 5}, {0x33DA, 0, 5}, {0x33DB, 0, 8}, {0x16F118F0, 0, 8}, {0x16F118F0, 0, 1}}; // Bosch w/ body
364+
static CanMsg HONDA_BOSCH_LONG_TX_MSGS[] = {{0xE4, 1, 5}, {0x1DF, 1, 8}, {0x1EF, 1, 8}, {0x1FA, 1, 8}, {0x30C, 1, 8}, {0x33D, 1, 5}, {0x33DA, 1, 5}, {0x33DB, 1, 8}, {0x39F, 1, 8}, {0x16F118F0, 0, 8}, {0x16F118F0, 0, 1}, {0x18DAB0F1, 1, 8}}; // Bosch w/ gas and brakes and body
365+
static CanMsg HONDA_RADARLESS_TX_MSGS[] = {{0xE4, 0, 5}, {0x296, 2, 4}, {0x33D, 0, 8}, {0x16F118F0, 0, 8}, {0x16F118F0, 0, 1}}; // Bosch radarless
366+
static CanMsg HONDA_RADARLESS_LONG_TX_MSGS[] = {{0xE4, 0, 5}, {0x33D, 0, 8}, {0x1C8, 0, 8}, {0x30C, 0, 8}, {0x16F118F0, 0, 8}, {0x16F118F0, 0, 1}}; // Bosch radarless w/ gas and brakes
343367

344368
const uint16_t HONDA_PARAM_ALT_BRAKE = 1;
345369
const uint16_t HONDA_PARAM_RADARLESS = 8;

tests/safety/test_honda.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ class Btn:
1919
HONDA_NIDEC = 0
2020
HONDA_BOSCH = 1
2121

22+
turnSignalCmdLeftMsg = b"\x30\x0a\x0f\x00\x00\x00\x00\x00"
23+
turnSignalCmdRightMsg = b"\x30\x0b\x0f\x00\x00\x00\x00\x00"
24+
turnSignalCmdCancelMsg = b"\x20"
25+
trunkCmdReleaseMsg = b"\x30\x09\x01\x00\x00\x00\x00\x00"
26+
27+
def interceptor_msg(gas, addr):
28+
to_send = common.make_msg(0, addr, 6)
29+
to_send[0].data[0] = (gas & 0xFF00) >> 8
30+
to_send[0].data[1] = gas & 0xFF
31+
to_send[0].data[2] = (gas & 0xFF00) >> 8
32+
to_send[0].data[3] = gas & 0xFF
33+
return to_send
2234

2335
# Honda safety has several different configurations tested here:
2436
# * Nidec
@@ -136,6 +148,18 @@ def test_rx_hook(self):
136148
self._rx(self._button_msg(Btn.SET, main_on=True))
137149
self.assertTrue(self.safety.get_controls_allowed())
138150

151+
# Never allow dangerous commands; e.g. trunk release
152+
def test_kwp_over_can(self):
153+
self.safety.set_controls_allowed(0)
154+
self.assertTrue(self._tx(libpanda_py.make_CANPacket(0x16F118F0, 0, turnSignalCmdCancelMsg)))
155+
self.assertFalse(self._tx(libpanda_py.make_CANPacket(0x16F118F0, 0, turnSignalCmdLeftMsg)))
156+
self.assertFalse(self._tx(libpanda_py.make_CANPacket(0x16F118F0, 0, turnSignalCmdRightMsg)))
157+
self.assertFalse(self._tx(libpanda_py.make_CANPacket(0x16F118F0, 0, trunkCmdReleaseMsg)))
158+
self.safety.set_controls_allowed(1)
159+
self.assertTrue(self._tx(libpanda_py.make_CANPacket(0x16F118F0, 0, turnSignalCmdCancelMsg)))
160+
self.assertTrue(self._tx(libpanda_py.make_CANPacket(0x16F118F0, 0, turnSignalCmdLeftMsg)))
161+
self.assertTrue(self._tx(libpanda_py.make_CANPacket(0x16F118F0, 0, turnSignalCmdRightMsg)))
162+
self.assertFalse(self._tx(libpanda_py.make_CANPacket(0x16F118F0, 0, trunkCmdReleaseMsg)))
139163

140164
class HondaPcmEnableBase(common.PandaCarSafetyTest):
141165
# pylint: disable=no-member,abstract-method
@@ -459,6 +483,7 @@ class TestHondaBoschLongSafety(HondaButtonEnableBase, TestHondaBoschSafetyBase):
459483
Covers the Honda Bosch safety mode with longitudinal control
460484
"""
461485
NO_GAS = -30000
486+
MIN_GAS = -40
462487
MAX_GAS = 2000
463488
MAX_ACCEL = 2.0 # accel is used for brakes, but openpilot can set positive values
464489
MIN_ACCEL = -3.5
@@ -495,10 +520,10 @@ def test_diagnostics(self):
495520

496521
def test_gas_safety_check(self):
497522
for controls_allowed in [True, False]:
498-
for gas in np.arange(self.NO_GAS, self.MAX_GAS + 2000, 100):
499-
accel = 0 if gas < 0 else gas / 1000
523+
for gas in np.arange(self.NO_GAS, self.MAX_GAS + 200, 1):
524+
accel = 0 if gas < self.MIN_GAS else gas / 1000
500525
self.safety.set_controls_allowed(controls_allowed)
501-
send = (controls_allowed and 0 <= gas <= self.MAX_GAS) or gas == self.NO_GAS
526+
send = (controls_allowed and self.MIN_GAS <= gas <= self.MAX_GAS) or gas == self.NO_GAS
502527
self.assertEqual(send, self._tx(self._send_gas_brake_msg(gas, accel)), (controls_allowed, gas, accel))
503528

504529
def test_brake_safety_check(self):

0 commit comments

Comments
 (0)