Skip to content

Commit

Permalink
add safety param support
Browse files Browse the repository at this point in the history
  • Loading branch information
geohot committed Jan 26, 2018
1 parent 65fb2b2 commit 4410a59
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions board/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, int hardwired) {
// and it's blocked over WiFi
// Allow ELM security mode to be set over wifi.
if (hardwired || setup->b.wValue.w == SAFETY_NOOUTPUT || setup->b.wValue.w == SAFETY_ELM327) {
safety_set_mode(setup->b.wValue.w);
safety_set_mode(setup->b.wValue.w, (int16_t)setup->b.wIndex.w);
switch (setup->b.wValue.w) {
case SAFETY_NOOUTPUT:
can_silent = ALL_CAN_SILENT;
Expand Down Expand Up @@ -530,7 +530,7 @@ int main() {
usb_init();

// default to silent mode to prevent issues with Ford
safety_set_mode(SAFETY_NOOUTPUT);
safety_set_mode(SAFETY_NOOUTPUT, 0);
can_silent = ALL_CAN_SILENT;
can_init_all();

Expand Down
6 changes: 3 additions & 3 deletions board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push);
int safety_tx_hook(CAN_FIFOMailBox_TypeDef *to_send);
int safety_tx_lin_hook(int lin_num, uint8_t *data, int len);

typedef void (*safety_hook_init)();
typedef void (*safety_hook_init)(int16_t param);
typedef void (*rx_hook)(CAN_FIFOMailBox_TypeDef *to_push);
typedef int (*tx_hook)(CAN_FIFOMailBox_TypeDef *to_send);
typedef int (*tx_lin_hook)(int lin_num, uint8_t *data, int len);
Expand Down Expand Up @@ -60,11 +60,11 @@ const safety_hook_config safety_hook_registry[] = {

#define HOOK_CONFIG_COUNT (sizeof(safety_hook_registry)/sizeof(safety_hook_config))

int safety_set_mode(uint16_t mode) {
int safety_set_mode(uint16_t mode, int16_t param) {
for (int i = 0; i < HOOK_CONFIG_COUNT; i++) {
if (safety_hook_registry[i].id == mode) {
current_hooks = safety_hook_registry[i].hooks;
if (current_hooks->init) current_hooks->init();
if (current_hooks->init) current_hooks->init(param);
return 0;
}
}
Expand Down
4 changes: 2 additions & 2 deletions board/safety/safety_defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ void default_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {}

// *** no output safety mode ***

static void nooutput_init() {
static void nooutput_init(int16_t param) {
controls_allowed = 0;
}

Expand All @@ -23,7 +23,7 @@ const safety_hooks nooutput_hooks = {

// *** all output safety mode ***

static void alloutput_init() {
static void alloutput_init(int16_t param) {
controls_allowed = 1;
}

Expand Down
2 changes: 1 addition & 1 deletion board/safety/safety_elm327.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static int elm327_tx_lin_hook(int lin_num, uint8_t *data, int len) {
return true;
}

static void elm327_init() {
static void elm327_init(int16_t param) {
controls_allowed = 1;
}

Expand Down
2 changes: 1 addition & 1 deletion board/safety/safety_honda.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static int honda_tx_lin_hook(int lin_num, uint8_t *data, int len) {
return true;
}

static void honda_init() {
static void honda_init(int16_t param) {
controls_allowed = 0;
}

Expand Down
4 changes: 2 additions & 2 deletions board/safety/safety_toyota.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static int toyota_tx_lin_hook(int lin_num, uint8_t *data, int len) {
return true;
}

static void toyota_init() {
static void toyota_init(int16_t param) {
controls_allowed = 0;
actuation_limits = 1;
}
Expand All @@ -166,7 +166,7 @@ const safety_hooks toyota_hooks = {
.tx_lin = toyota_tx_lin_hook,
};

static void toyota_nolimits_init() {
static void toyota_nolimits_init(int16_t param) {
controls_allowed = 0;
actuation_limits = 0;
}
Expand Down

0 comments on commit 4410a59

Please sign in to comment.