Skip to content

Commit 597436d

Browse files
authored
NOOUTPUT safety mode is now SILENT. NOOUTPUT still exists but keeps C… (commaai#388)
* NOOUTPUT safety mode is now SILENT. NOOUTPUT still exists but keeps CAN live * README mention of 'no output' * mispelled
1 parent d229f8d commit 597436d

13 files changed

+41
-29
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ To print out the serial console from the ESP8266, run PORT=1 tests/debug_console
8787
Safety Model
8888
------
8989

90-
When a panda powers up, by default it's in `SAFETY_NOOUTPUT` mode. While in no output mode, the buses are also forced to be silent. In order to send messages, you have to select a safety mode. Currently, setting safety modes is only supported over USB.
90+
When a panda powers up, by default it's in `SAFETY_SILENT` mode. While in `SAFETY_SILENT` mode, the buses are also forced to be silent. In order to send messages, you have to select a safety mode. Currently, setting safety modes is only supported over USB.
9191

9292
Safety modes optionally supports `controls_allowed`, which allows or blocks a subset of messages based on a customizable state in the board.
9393

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.6.3
1+
v1.6.4

board/main.c

+19-10
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,20 @@ void set_safety_mode(uint16_t mode, int16_t param) {
121121
while (true) {} // ERROR: we can't continue if safety mode isn't succesfully set
122122
} else {
123123
switch (mode) {
124-
case SAFETY_NOOUTPUT:
124+
case SAFETY_SILENT:
125125
set_intercept_relay(false);
126126
if(board_has_obd()){
127127
current_board->set_can_mode(CAN_MODE_NORMAL);
128128
}
129129
can_silent = ALL_CAN_SILENT;
130130
break;
131+
case SAFETY_NOOUTPUT:
132+
set_intercept_relay(false);
133+
if(board_has_obd()){
134+
current_board->set_can_mode(CAN_MODE_NORMAL);
135+
}
136+
can_silent = ALL_CAN_LIVE;
137+
break;
131138
case SAFETY_ELM327:
132139
set_intercept_relay(false);
133140
heartbeat_counter = 0U;
@@ -434,8 +441,10 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
434441
// **** 0xdc: set safety mode
435442
case 0xdc:
436443
// Blocked over WiFi.
437-
// Allow NOOUTPUT and ELM security mode to be set over wifi.
438-
if (hardwired || (setup->b.wValue.w == SAFETY_NOOUTPUT) || (setup->b.wValue.w == SAFETY_ELM327)) {
444+
// Allow SILENT, NOOUTPUT and ELM security mode to be set over wifi.
445+
if (hardwired || (setup->b.wValue.w == SAFETY_SILENT) ||
446+
(setup->b.wValue.w == SAFETY_NOOUTPUT) ||
447+
(setup->b.wValue.w == SAFETY_ELM327)) {
439448
set_safety_mode(setup->b.wValue.w, (uint16_t) setup->b.wIndex.w);
440449
}
441450
break;
@@ -649,7 +658,7 @@ void __attribute__ ((noinline)) enable_fpu(void) {
649658

650659
uint64_t tcnt = 0;
651660

652-
// go into NOOUTPUT when the EON does not send a heartbeat for this amount of seconds.
661+
// go into SILENT when the EON does not send a heartbeat for this amount of seconds.
653662
#define EON_HEARTBEAT_IGNITION_CNT_ON 5U
654663
#define EON_HEARTBEAT_IGNITION_CNT_OFF 2U
655664

@@ -690,12 +699,12 @@ void TIM1_BRK_TIM9_IRQHandler(void) {
690699
heartbeat_counter += 1U;
691700
}
692701

693-
// check heartbeat counter if we are running EON code. If the heartbeat has been gone for a while, go to NOOUTPUT safety mode.
702+
// check heartbeat counter if we are running EON code. If the heartbeat has been gone for a while, go to SILENT safety mode.
694703
#ifdef EON
695704
if (heartbeat_counter >= (check_started() ? EON_HEARTBEAT_IGNITION_CNT_ON : EON_HEARTBEAT_IGNITION_CNT_OFF)) {
696-
puts("EON hasn't sent a heartbeat for 0x"); puth(heartbeat_counter); puts(" seconds. Safety is set to NOOUTPUT mode.\n");
697-
if(current_safety_mode != SAFETY_NOOUTPUT){
698-
set_safety_mode(SAFETY_NOOUTPUT, 0U);
705+
puts("EON hasn't sent a heartbeat for 0x"); puth(heartbeat_counter); puts(" seconds. Safety is set to SILENT mode.\n");
706+
if(current_safety_mode != SAFETY_SILENT){
707+
set_safety_mode(SAFETY_SILENT, 0U);
699708
}
700709
}
701710
#endif
@@ -767,8 +776,8 @@ int main(void) {
767776
TIM2->EGR = TIM_EGR_UG;
768777
// use TIM2->CNT to read
769778

770-
// init to NOOUTPUT and can silent
771-
set_safety_mode(SAFETY_NOOUTPUT, 0);
779+
// init to SILENT and can silent
780+
set_safety_mode(SAFETY_SILENT, 0);
772781

773782
#ifndef EON
774783
spi_init();

board/safety.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "safety/safety_elm327.h"
1919

2020
// from cereal.car.CarParams.SafetyModel
21-
#define SAFETY_NOOUTPUT 0U
21+
#define SAFETY_SILENT 0U
2222
#define SAFETY_HONDA 1U
2323
#define SAFETY_TOYOTA 2U
2424
#define SAFETY_ELM327 3U
@@ -35,8 +35,9 @@
3535
#define SAFETY_TOYOTA_IPAS 16U
3636
#define SAFETY_ALLOUTPUT 17U
3737
#define SAFETY_GM_ASCM 18U
38+
#define SAFETY_NOOUTPUT 19U
3839

39-
uint16_t current_safety_mode = SAFETY_NOOUTPUT;
40+
uint16_t current_safety_mode = SAFETY_SILENT;
4041
const safety_hooks *current_hooks = &nooutput_hooks;
4142

4243
void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push){
@@ -72,7 +73,7 @@ typedef struct {
7273
} safety_hook_config;
7374

7475
const safety_hook_config safety_hook_registry[] = {
75-
{SAFETY_NOOUTPUT, &nooutput_hooks},
76+
{SAFETY_SILENT, &nooutput_hooks},
7677
{SAFETY_HONDA, &honda_hooks},
7778
{SAFETY_TOYOTA, &toyota_hooks},
7879
{SAFETY_ELM327, &elm327_hooks},
@@ -83,6 +84,7 @@ const safety_hook_config safety_hook_registry[] = {
8384
{SAFETY_SUBARU, &subaru_hooks},
8485
{SAFETY_MAZDA, &mazda_hooks},
8586
{SAFETY_VOLKSWAGEN, &volkswagen_hooks},
87+
{SAFETY_NOOUTPUT, &nooutput_hooks},
8688
#ifdef ALLOW_DEBUG
8789
{SAFETY_CADILLAC, &cadillac_hooks},
8890
{SAFETY_TOYOTA_IPAS, &toyota_ipas_hooks},

drivers/linux/panda.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#define PANDA_DLC_MASK 0x0F
4040

4141
#define SAFETY_ALLOUTPUT 17
42-
#define SAFETY_NOOUTPUT 0
42+
#define SAFETY_SILENT 0
4343

4444
struct panda_usb_ctx {
4545
struct panda_inf_priv *priv;
@@ -159,7 +159,7 @@ static int panda_set_output_enable(struct panda_inf_priv* priv, bool enable){
159159
return usb_control_msg(priv->priv_dev->udev,
160160
usb_sndctrlpipe(priv->priv_dev->udev, 0),
161161
0xDC, USB_TYPE_VENDOR | USB_RECIP_DEVICE,
162-
enable ? SAFETY_ALLOUTPUT : SAFETY_NOOUTPUT, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
162+
enable ? SAFETY_ALLOUTPUT : SAFETY_SILENT, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
163163
}
164164

165165
static void panda_usb_write_bulk_callback(struct urb *urb)

drivers/windows/panda_shared/panda.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ bool Panda::esp_reset(uint16_t bootmode = 0) {
277277
return this->control_transfer(REQUEST_OUT, 0xda, bootmode, 0, NULL, 0, 0) != -1;
278278
}
279279

280-
bool Panda::set_safety_mode(PANDA_SAFETY_MODE mode = SAFETY_NOOUTPUT) {
280+
bool Panda::set_safety_mode(PANDA_SAFETY_MODE mode = SAFETY_SILENT) {
281281
return this->control_transfer(REQUEST_OUT, 0xdc, mode, 0, NULL, 0, 0) != -1;
282282
}
283283

drivers/windows/panda_shared/panda.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
namespace panda {
4040
typedef enum _PANDA_SAFETY_MODE : uint16_t {
41-
SAFETY_NOOUTPUT = 0,
41+
SAFETY_SILENT = 0,
4242
SAFETY_HONDA = 1,
4343
SAFETY_ALLOUTPUT = 17,
4444
} PANDA_SAFETY_MODE;

examples/tesla_tester.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def tesla_tester():
2222
body_bus_num = 1 # My TDC to OBD adapter has PT on bus0 BDY on bus1 and CH on bus2
2323
p.set_can_speed_kbps(body_bus_num, body_bus_speed)
2424

25-
# Now set the panda from its default of SAFETY_NOOUTPUT (read only) to SAFETY_ALLOUTPUT
25+
# Now set the panda from its default of SAFETY_SILENT (read only) to SAFETY_ALLOUTPUT
2626
# Careful, as this will let us send any CAN messages we want (which could be very bad!)
2727
print("Setting Panda to output mode...")
2828
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
@@ -37,7 +37,7 @@ def tesla_tester():
3737

3838
#Back to safety...
3939
print("Disabling output on Panda...")
40-
p.set_safety_mode(Panda.SAFETY_NOOUTPUT)
40+
p.set_safety_mode(Panda.SAFETY_SILENT)
4141

4242
print("Reading VIN from 0x568. This is painfully slow and can take up to 3 minutes (1 minute per message; 3 messages needed for full VIN)...")
4343

python/__init__.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def close(self):
110110
class Panda(object):
111111

112112
# matches cereal.car.CarParams.SafetyModel
113-
SAFETY_NOOUTPUT = 0
113+
SAFETY_SILENT = 0
114114
SAFETY_HONDA = 1
115115
SAFETY_TOYOTA = 2
116116
SAFETY_ELM327 = 3
@@ -127,6 +127,7 @@ class Panda(object):
127127
SAFETY_TOYOTA_IPAS = 16
128128
SAFETY_ALLOUTPUT = 17
129129
SAFETY_GM_ASCM = 18
130+
SAFETY_NOOUTPUT = 19
130131

131132
SERIAL_DEBUG = 0
132133
SERIAL_ESP = 1
@@ -354,7 +355,7 @@ def health(self):
354355
"can_fwd_errs": a[3],
355356
"gmlan_send_errs": a[4],
356357
"ignition_line": a[5],
357-
"ignition_can": a[6],
358+
"ignition_can": a[6],
358359
"controls_allowed": a[7],
359360
"gas_interceptor_detected": a[8],
360361
"car_harness_status": a[9],
@@ -414,7 +415,7 @@ def esp_reset(self, bootmode=0):
414415
self._handle.controlWrite(Panda.REQUEST_OUT, 0xda, int(bootmode), 0, b'')
415416
time.sleep(0.2)
416417

417-
def set_safety_mode(self, mode=SAFETY_NOOUTPUT):
418+
def set_safety_mode(self, mode=SAFETY_SILENT):
418419
self._handle.controlWrite(Panda.REQUEST_OUT, 0xdc, mode, 0, b'')
419420

420421
def set_can_forwarding(self, from_bus, to_bus):
@@ -634,4 +635,4 @@ def get_fan_rpm(self):
634635

635636
# ****************** Phone *****************
636637
def set_phone_power(self, enabled):
637-
self._handle.controlWrite(Panda.REQUEST_OUT, 0xb3, int(enabled), 0, b'')
638+
self._handle.controlWrite(Panda.REQUEST_OUT, 0xb3, int(enabled), 0, b'')

tests/automated/2_usb_to_can.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_can_loopback(p):
4141
@panda_connect_and_init
4242
def test_safety_nooutput(p):
4343
# enable output mode
44-
p.set_safety_mode(Panda.SAFETY_NOOUTPUT)
44+
p.set_safety_mode(Panda.SAFETY_SILENT)
4545

4646
# enable CAN loopback mode
4747
p.set_can_loopback(True)

tests/black_white_loopback_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def run_test(sleep_duration):
6767
print("Number of cycles:", counter, "Non-zero bus errors:", nonzero_bus_errors, "Zero bus errors:", zero_bus_errors, "Content errors:", content_errors)
6868

6969
# Toggle relay
70-
black_panda.set_safety_mode(Panda.SAFETY_NOOUTPUT)
70+
black_panda.set_safety_mode(Panda.SAFETY_SILENT)
7171
time.sleep(1)
7272
black_panda.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
7373
time.sleep(1)

tests/black_white_relay_endurance.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def run_test(sleep_duration):
7272

7373
if (time.time() - temp_start_time) > 3600*6:
7474
# Toggle relay
75-
black_panda.set_safety_mode(Panda.SAFETY_NOOUTPUT)
75+
black_panda.set_safety_mode(Panda.SAFETY_SILENT)
7676
time.sleep(1)
7777
black_panda.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
7878
time.sleep(1)

tests/black_white_relay_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def run_test(sleep_duration):
7474
assert False
7575

7676
# Switch off relay
77-
black_panda.set_safety_mode(Panda.SAFETY_NOOUTPUT)
77+
black_panda.set_safety_mode(Panda.SAFETY_SILENT)
7878
time.sleep(0.05)
7979

8080
if not test_buses(black_panda, other_panda, (0, False, [0, 2])):

0 commit comments

Comments
 (0)