2017-07-15 12:17:32 +08:00
|
|
|
void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push);
|
2017-07-21 14:36:06 +08:00
|
|
|
int safety_tx_hook(CAN_FIFOMailBox_TypeDef *to_send);
|
|
|
|
int safety_tx_lin_hook(int lin_num, uint8_t *data, int len);
|
2017-07-15 12:17:32 +08:00
|
|
|
|
|
|
|
typedef void (*safety_hook_init)();
|
|
|
|
typedef void (*rx_hook)(CAN_FIFOMailBox_TypeDef *to_push);
|
2017-07-21 14:36:06 +08:00
|
|
|
typedef int (*tx_hook)(CAN_FIFOMailBox_TypeDef *to_send);
|
|
|
|
typedef int (*tx_lin_hook)(int lin_num, uint8_t *data, int len);
|
2017-07-15 12:17:32 +08:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
safety_hook_init init;
|
|
|
|
rx_hook rx;
|
|
|
|
tx_hook tx;
|
|
|
|
tx_lin_hook tx_lin;
|
|
|
|
} safety_hooks;
|
|
|
|
|
2017-07-22 02:48:03 +08:00
|
|
|
// This can be set by the safety hooks.
|
|
|
|
int controls_allowed = 0;
|
|
|
|
|
2017-07-15 12:17:32 +08:00
|
|
|
// Include the actual safety policies.
|
2017-07-18 01:20:08 +08:00
|
|
|
#include "safety/safety_defaults.h"
|
|
|
|
#include "safety/safety_honda.h"
|
2017-07-15 12:17:32 +08:00
|
|
|
|
|
|
|
const safety_hooks *current_hooks = &nooutput_hooks;
|
|
|
|
|
|
|
|
void safety_rx_hook(CAN_FIFOMailBox_TypeDef *to_push){
|
|
|
|
current_hooks->rx(to_push);
|
|
|
|
}
|
|
|
|
|
2017-07-21 14:36:06 +08:00
|
|
|
int safety_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|
|
|
return current_hooks->tx(to_send);
|
2017-07-15 12:17:32 +08:00
|
|
|
}
|
|
|
|
|
2017-07-21 14:36:06 +08:00
|
|
|
int safety_tx_lin_hook(int lin_num, uint8_t *data, int len){
|
|
|
|
return current_hooks->tx_lin(lin_num, data, len);
|
2017-07-15 12:17:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint16_t id;
|
|
|
|
const safety_hooks *hooks;
|
|
|
|
} safety_hook_config;
|
|
|
|
|
2017-07-18 01:48:16 +08:00
|
|
|
#define SAFETY_NOOUTPUT 0
|
|
|
|
#define SAFETY_HONDA 1
|
|
|
|
#define SAFETY_ALLOUTPUT 0x1337
|
|
|
|
|
2017-07-15 12:17:32 +08:00
|
|
|
const safety_hook_config safety_hook_registry[] = {
|
2017-07-18 01:48:16 +08:00
|
|
|
{SAFETY_NOOUTPUT, &nooutput_hooks},
|
|
|
|
{SAFETY_HONDA, &honda_hooks},
|
|
|
|
{SAFETY_ALLOUTPUT, &alloutput_hooks},
|
2017-07-15 12:17:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define HOOK_CONFIG_COUNT (sizeof(safety_hook_registry)/sizeof(safety_hook_config))
|
|
|
|
|
2017-07-21 14:42:19 +08:00
|
|
|
int safety_set_mode(uint16_t mode){
|
2017-07-18 01:27:34 +08:00
|
|
|
for (int i = 0; i < HOOK_CONFIG_COUNT; i++) {
|
|
|
|
if (safety_hook_registry[i].id == mode) {
|
2017-07-15 12:17:32 +08:00
|
|
|
current_hooks = safety_hook_registry[i].hooks;
|
|
|
|
current_hooks->init();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2017-07-18 01:20:08 +08:00
|
|
|
|