From 4410a59d9268eb597b7ee84fd79d6c3f3640ff11 Mon Sep 17 00:00:00 2001 From: George Hotz Date: Thu, 25 Jan 2018 23:57:04 -0800 Subject: [PATCH] add safety param support --- board/main.c | 4 ++-- board/safety.h | 6 +++--- board/safety/safety_defaults.h | 4 ++-- board/safety/safety_elm327.h | 2 +- board/safety/safety_honda.h | 2 +- board/safety/safety_toyota.h | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/board/main.c b/board/main.c index e50bcf8d27e8c6..0a7f15655932d1 100644 --- a/board/main.c +++ b/board/main.c @@ -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; @@ -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(); diff --git a/board/safety.h b/board/safety.h index dc4631f4606de8..8842141544a686 100644 --- a/board/safety.h +++ b/board/safety.h @@ -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); @@ -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; } } diff --git a/board/safety/safety_defaults.h b/board/safety/safety_defaults.h index 86155f32b9a68e..b7b4d37295c9c9 100644 --- a/board/safety/safety_defaults.h +++ b/board/safety/safety_defaults.h @@ -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; } @@ -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; } diff --git a/board/safety/safety_elm327.h b/board/safety/safety_elm327.h index ddacc27be0131f..b9af35ebdc5016 100644 --- a/board/safety/safety_elm327.h +++ b/board/safety/safety_elm327.h @@ -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; } diff --git a/board/safety/safety_honda.h b/board/safety/safety_honda.h index 55ef003e5fee1e..bf30d847079e09 100644 --- a/board/safety/safety_honda.h +++ b/board/safety/safety_honda.h @@ -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; } diff --git a/board/safety/safety_toyota.h b/board/safety/safety_toyota.h index 0dab4b91cb9564..0ae238b7da66b7 100644 --- a/board/safety/safety_toyota.h +++ b/board/safety/safety_toyota.h @@ -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; } @@ -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; }