mirror of https://github.com/commaai/panda.git
safety_param: change to unsigned (#910)
* make safety_param unsigned
* final one
* uint32_t
* change flags as well
* Revert "change flags as well"
This reverts commit ed8897dd86
.
* unsigned
* update health packet version
update health packet version
* update struct H->I
* bump health version
* actually used
This commit is contained in:
parent
a1d97f9a0b
commit
7dd9493eb1
|
@ -1,5 +1,5 @@
|
|||
// When changing this struct, python/__init__.py needs to be kept up to date!
|
||||
#define HEALTH_PACKET_VERSION 5
|
||||
#define HEALTH_PACKET_VERSION 6
|
||||
struct __attribute__((packed)) health_t {
|
||||
uint32_t uptime_pkt;
|
||||
uint32_t voltage_pkt;
|
||||
|
@ -16,7 +16,7 @@ struct __attribute__((packed)) health_t {
|
|||
uint8_t car_harness_status_pkt;
|
||||
uint8_t usb_power_mode_pkt;
|
||||
uint8_t safety_mode_pkt;
|
||||
int16_t safety_param_pkt;
|
||||
uint32_t safety_param_pkt;
|
||||
uint8_t fault_status_pkt;
|
||||
uint8_t power_save_enabled_pkt;
|
||||
uint8_t heartbeat_lost_pkt;
|
||||
|
|
|
@ -69,13 +69,13 @@ void debug_ring_callback(uart_ring *ring) {
|
|||
// ****************************** safety mode ******************************
|
||||
|
||||
// this is the only way to leave silent mode
|
||||
void set_safety_mode(uint16_t mode, int16_t param) {
|
||||
void set_safety_mode(uint16_t mode, uint32_t param) {
|
||||
uint16_t mode_copy = mode;
|
||||
int err = set_safety_hooks(mode_copy, param);
|
||||
if (err == -1) {
|
||||
puts("Error: safety set mode failed. Falling back to SILENT\n");
|
||||
mode_copy = SAFETY_SILENT;
|
||||
err = set_safety_hooks(mode_copy, 0);
|
||||
err = set_safety_hooks(mode_copy, 0U);
|
||||
if (err == -1) {
|
||||
puts("Error: Failed setting SILENT mode. Hanging\n");
|
||||
while (true) {
|
||||
|
@ -105,7 +105,7 @@ void set_safety_mode(uint16_t mode, int16_t param) {
|
|||
heartbeat_counter = 0U;
|
||||
heartbeat_lost = false;
|
||||
if (current_board->has_obd) {
|
||||
if (param == 0) {
|
||||
if (param == 0U) {
|
||||
current_board->set_can_mode(CAN_MODE_OBD_CAN2);
|
||||
} else {
|
||||
current_board->set_can_mode(CAN_MODE_NORMAL);
|
||||
|
@ -367,7 +367,7 @@ int main(void) {
|
|||
microsecond_timer_init();
|
||||
|
||||
// init to SILENT and can silent
|
||||
set_safety_mode(SAFETY_SILENT, 0);
|
||||
set_safety_mode(SAFETY_SILENT, 0U);
|
||||
|
||||
// enable CAN TXs
|
||||
current_board->enable_can_transceivers(true);
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
#define SAFETY_BODY 27U
|
||||
|
||||
uint16_t current_safety_mode = SAFETY_SILENT;
|
||||
int16_t current_safety_param = 0;
|
||||
uint32_t current_safety_param = 0;
|
||||
const safety_hooks *current_hooks = &nooutput_hooks;
|
||||
const addr_checks *current_rx_checks = &default_rx_checks;
|
||||
|
||||
|
@ -262,7 +262,7 @@ const safety_hook_config safety_hook_registry[] = {
|
|||
#endif
|
||||
};
|
||||
|
||||
int set_safety_hooks(uint16_t mode, int16_t param) {
|
||||
int set_safety_hooks(uint16_t mode, uint32_t param) {
|
||||
// reset state set by safety mode
|
||||
safety_mode_cnt = 0U;
|
||||
relay_malfunction = false;
|
||||
|
|
|
@ -31,7 +31,7 @@ static int body_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {
|
|||
return tx;
|
||||
}
|
||||
|
||||
static const addr_checks* body_init(int16_t param) {
|
||||
static const addr_checks* body_init(uint32_t param) {
|
||||
UNUSED(param);
|
||||
controls_allowed = false;
|
||||
relay_malfunction_reset();
|
||||
|
|
|
@ -196,7 +196,7 @@ static int chrysler_fwd_hook(int bus_num, CANPacket_t *to_fwd) {
|
|||
return bus_fwd;
|
||||
}
|
||||
|
||||
static const addr_checks* chrysler_init(int16_t param) {
|
||||
static const addr_checks* chrysler_init(uint32_t param) {
|
||||
UNUSED(param);
|
||||
controls_allowed = false;
|
||||
relay_malfunction_reset();
|
||||
|
|
|
@ -10,7 +10,7 @@ int default_rx_hook(CANPacket_t *to_push) {
|
|||
|
||||
// *** no output safety mode ***
|
||||
|
||||
static const addr_checks* nooutput_init(int16_t param) {
|
||||
static const addr_checks* nooutput_init(uint32_t param) {
|
||||
UNUSED(param);
|
||||
controls_allowed = false;
|
||||
relay_malfunction_reset();
|
||||
|
@ -50,8 +50,7 @@ const safety_hooks nooutput_hooks = {
|
|||
const uint16_t ALLOUTPUT_PARAM_PASSTHROUGH = 1;
|
||||
bool alloutput_passthrough = false;
|
||||
|
||||
static const addr_checks* alloutput_init(int16_t param) {
|
||||
UNUSED(param);
|
||||
static const addr_checks* alloutput_init(uint32_t param) {
|
||||
alloutput_passthrough = GET_FLAG(param, ALLOUTPUT_PARAM_PASSTHROUGH);
|
||||
controls_allowed = true;
|
||||
relay_malfunction_reset();
|
||||
|
|
|
@ -219,7 +219,7 @@ static int gm_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {
|
|||
return tx;
|
||||
}
|
||||
|
||||
static const addr_checks* gm_init(int16_t param) {
|
||||
static const addr_checks* gm_init(uint32_t param) {
|
||||
UNUSED(param);
|
||||
controls_allowed = false;
|
||||
relay_malfunction_reset();
|
||||
|
|
|
@ -362,8 +362,7 @@ static int honda_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {
|
|||
return tx;
|
||||
}
|
||||
|
||||
static const addr_checks* honda_nidec_init(int16_t param) {
|
||||
UNUSED(param);
|
||||
static const addr_checks* honda_nidec_init(uint32_t param) {
|
||||
controls_allowed = false;
|
||||
relay_malfunction_reset();
|
||||
gas_interceptor_detected = 0;
|
||||
|
@ -379,7 +378,7 @@ static const addr_checks* honda_nidec_init(int16_t param) {
|
|||
return &honda_rx_checks;
|
||||
}
|
||||
|
||||
static const addr_checks* honda_bosch_init(int16_t param) {
|
||||
static const addr_checks* honda_bosch_init(uint32_t param) {
|
||||
controls_allowed = false;
|
||||
relay_malfunction_reset();
|
||||
honda_hw = HONDA_BOSCH;
|
||||
|
|
|
@ -364,7 +364,7 @@ static int hyundai_fwd_hook(int bus_num, CANPacket_t *to_fwd) {
|
|||
return bus_fwd;
|
||||
}
|
||||
|
||||
static const addr_checks* hyundai_init(int16_t param) {
|
||||
static const addr_checks* hyundai_init(uint32_t param) {
|
||||
controls_allowed = false;
|
||||
relay_malfunction_reset();
|
||||
|
||||
|
@ -384,7 +384,7 @@ static const addr_checks* hyundai_init(int16_t param) {
|
|||
return &hyundai_rx_checks;
|
||||
}
|
||||
|
||||
static const addr_checks* hyundai_legacy_init(int16_t param) {
|
||||
static const addr_checks* hyundai_legacy_init(uint32_t param) {
|
||||
controls_allowed = false;
|
||||
relay_malfunction_reset();
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ static int mazda_fwd_hook(int bus, CANPacket_t *to_fwd) {
|
|||
return bus_fwd;
|
||||
}
|
||||
|
||||
static const addr_checks* mazda_init(int16_t param) {
|
||||
static const addr_checks* mazda_init(uint32_t param) {
|
||||
UNUSED(param);
|
||||
controls_allowed = false;
|
||||
relay_malfunction_reset();
|
||||
|
|
|
@ -189,7 +189,7 @@ static int nissan_fwd_hook(int bus_num, CANPacket_t *to_fwd) {
|
|||
return bus_fwd;
|
||||
}
|
||||
|
||||
static const addr_checks* nissan_init(int16_t param) {
|
||||
static const addr_checks* nissan_init(uint32_t param) {
|
||||
controls_allowed = 0;
|
||||
nissan_alt_eps = param ? 1 : 0;
|
||||
relay_malfunction_reset();
|
||||
|
|
|
@ -313,7 +313,7 @@ static int subaru_legacy_fwd_hook(int bus_num, CANPacket_t *to_fwd) {
|
|||
return bus_fwd;
|
||||
}
|
||||
|
||||
static const addr_checks* subaru_init(int16_t param) {
|
||||
static const addr_checks* subaru_init(uint32_t param) {
|
||||
UNUSED(param);
|
||||
controls_allowed = false;
|
||||
relay_malfunction_reset();
|
||||
|
@ -328,7 +328,7 @@ const safety_hooks subaru_hooks = {
|
|||
.fwd = subaru_fwd_hook,
|
||||
};
|
||||
|
||||
static const addr_checks* subaru_legacy_init(int16_t param) {
|
||||
static const addr_checks* subaru_legacy_init(uint32_t param) {
|
||||
UNUSED(param);
|
||||
controls_allowed = false;
|
||||
relay_malfunction_reset();
|
||||
|
|
|
@ -244,7 +244,7 @@ static int tesla_fwd_hook(int bus_num, CANPacket_t *to_fwd) {
|
|||
return bus_fwd;
|
||||
}
|
||||
|
||||
static const addr_checks* tesla_init(int16_t param) {
|
||||
static const addr_checks* tesla_init(uint32_t param) {
|
||||
tesla_powertrain = GET_FLAG(param, TESLA_FLAG_POWERTRAIN);
|
||||
tesla_longitudinal = GET_FLAG(param, TESLA_FLAG_LONGITUDINAL_CONTROL);
|
||||
controls_allowed = 0;
|
||||
|
|
|
@ -246,7 +246,7 @@ static int toyota_tx_hook(CANPacket_t *to_send, bool longitudinal_allowed) {
|
|||
return tx;
|
||||
}
|
||||
|
||||
static const addr_checks* toyota_init(int16_t param) {
|
||||
static const addr_checks* toyota_init(uint32_t param) {
|
||||
controls_allowed = 0;
|
||||
relay_malfunction_reset();
|
||||
gas_interceptor_detected = 0;
|
||||
|
|
|
@ -76,7 +76,7 @@ static uint8_t volkswagen_mqb_compute_crc(CANPacket_t *to_push) {
|
|||
return crc ^ 0xFFU;
|
||||
}
|
||||
|
||||
static const addr_checks* volkswagen_mqb_init(int16_t param) {
|
||||
static const addr_checks* volkswagen_mqb_init(uint32_t param) {
|
||||
UNUSED(param);
|
||||
|
||||
controls_allowed = false;
|
||||
|
|
|
@ -49,7 +49,7 @@ static uint8_t volkswagen_pq_compute_checksum(CANPacket_t *to_push) {
|
|||
return checksum;
|
||||
}
|
||||
|
||||
static const addr_checks* volkswagen_pq_init(int16_t param) {
|
||||
static const addr_checks* volkswagen_pq_init(uint32_t param) {
|
||||
UNUSED(param);
|
||||
|
||||
controls_allowed = false;
|
||||
|
|
|
@ -84,7 +84,7 @@ void generic_rx_checks(bool stock_ecu_detected);
|
|||
void relay_malfunction_set(void);
|
||||
void relay_malfunction_reset(void);
|
||||
|
||||
typedef const addr_checks* (*safety_hook_init)(int16_t param);
|
||||
typedef const addr_checks* (*safety_hook_init)(uint32_t param);
|
||||
typedef int (*rx_hook)(CANPacket_t *to_push);
|
||||
typedef int (*tx_hook)(CANPacket_t *to_send, bool longitudinal_allowed);
|
||||
typedef int (*tx_lin_hook)(int lin_num, uint8_t *data, int len);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
extern int _app_start[0xc000]; // Only first 3 sectors of size 0x4000 are used
|
||||
|
||||
// Prototypes
|
||||
void set_safety_mode(uint16_t mode, int16_t param);
|
||||
void set_safety_mode(uint16_t mode, uint32_t param);
|
||||
bool is_car_safety_mode(uint16_t mode);
|
||||
|
||||
int get_health_pkt(void *dat) {
|
||||
|
@ -273,7 +273,7 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp) {
|
|||
|
||||
// **** 0xdc: set safety mode
|
||||
case 0xdc:
|
||||
set_safety_mode(setup->b.wValue.w, (uint16_t) setup->b.wIndex.w);
|
||||
set_safety_mode(setup->b.wValue.w, (uint32_t) setup->b.wIndex.w);
|
||||
break;
|
||||
// **** 0xdd: get healthpacket and CANPacket versions
|
||||
case 0xdd:
|
||||
|
|
|
@ -170,8 +170,8 @@ class Panda(object):
|
|||
HW_TYPE_RED_PANDA = b'\x07'
|
||||
|
||||
CAN_PACKET_VERSION = 2
|
||||
HEALTH_PACKET_VERSION = 5
|
||||
HEALTH_STRUCT = struct.Struct("<IIIIIIIIBBBBBBBHBBBHIf")
|
||||
HEALTH_PACKET_VERSION = 6
|
||||
HEALTH_STRUCT = struct.Struct("<IIIIIIIIBBBBBBBIBBBHIf")
|
||||
|
||||
F2_DEVICES = (HW_TYPE_PEDAL, )
|
||||
F4_DEVICES = (HW_TYPE_WHITE_PANDA, HW_TYPE_GREY_PANDA, HW_TYPE_BLACK_PANDA, HW_TYPE_UNO, HW_TYPE_DOS)
|
||||
|
|
|
@ -57,7 +57,7 @@ void set_timer(uint32_t t);
|
|||
int safety_rx_hook(CANPacket_t *to_send);
|
||||
int safety_tx_hook(CANPacket_t *to_push);
|
||||
int safety_fwd_hook(int bus_num, CANPacket_t *to_fwd);
|
||||
int set_safety_hooks(uint16_t mode, int16_t param);
|
||||
int set_safety_hooks(uint16_t mode, uint32_t param);
|
||||
|
||||
void safety_tick_current_rx_checks();
|
||||
bool addr_checks_valid();
|
||||
|
|
Loading…
Reference in New Issue