2022-01-21 20:00:14 -08:00
|
|
|
extern int _app_start[0xc000]; // Only first 3 sectors of size 0x4000 are used
|
|
|
|
|
|
|
|
|
|
// Prototypes
|
2022-05-02 13:36:19 -07:00
|
|
|
void set_safety_mode(uint16_t mode, uint16_t param);
|
2022-01-21 20:00:14 -08:00
|
|
|
bool is_car_safety_mode(uint16_t mode);
|
|
|
|
|
|
2024-09-20 15:51:27 -07:00
|
|
|
static int get_health_pkt(void *dat) {
|
2022-01-21 20:00:14 -08:00
|
|
|
COMPILE_TIME_ASSERT(sizeof(struct health_t) <= USBPACKET_MAX_SIZE);
|
|
|
|
|
struct health_t * health = (struct health_t*)dat;
|
|
|
|
|
|
|
|
|
|
health->uptime_pkt = uptime_cnt;
|
2024-02-15 13:49:06 -08:00
|
|
|
health->voltage_pkt = current_board->read_voltage_mV();
|
|
|
|
|
health->current_pkt = current_board->read_current_mA();
|
2022-01-21 20:00:14 -08:00
|
|
|
|
2025-07-19 21:05:12 -07:00
|
|
|
health->ignition_line_pkt = (uint8_t)(harness_check_ignition());
|
2024-01-20 17:05:12 -08:00
|
|
|
health->ignition_can_pkt = ignition_can;
|
2022-01-21 20:00:14 -08:00
|
|
|
|
|
|
|
|
health->controls_allowed_pkt = controls_allowed;
|
2022-09-15 13:08:46 -07:00
|
|
|
health->safety_tx_blocked_pkt = safety_tx_blocked;
|
|
|
|
|
health->safety_rx_invalid_pkt = safety_rx_invalid;
|
|
|
|
|
health->tx_buffer_overflow_pkt = tx_buffer_overflow;
|
|
|
|
|
health->rx_buffer_overflow_pkt = rx_buffer_overflow;
|
2023-05-08 13:30:23 +02:00
|
|
|
health->car_harness_status_pkt = harness.status;
|
2022-01-21 20:00:14 -08:00
|
|
|
health->safety_mode_pkt = (uint8_t)(current_safety_mode);
|
|
|
|
|
health->safety_param_pkt = current_safety_param;
|
2022-03-24 14:31:31 -07:00
|
|
|
health->alternative_experience_pkt = alternative_experience;
|
2024-01-20 17:05:12 -08:00
|
|
|
health->power_save_enabled_pkt = power_save_status == POWER_SAVE_STATUS_ENABLED;
|
|
|
|
|
health->heartbeat_lost_pkt = heartbeat_lost;
|
2024-02-11 04:20:36 +05:30
|
|
|
health->safety_rx_checks_invalid_pkt = safety_rx_checks_invalid;
|
2022-01-21 20:00:14 -08:00
|
|
|
|
2025-07-30 18:20:18 -07:00
|
|
|
health->spi_error_count_pkt = spi_error_count;
|
2023-04-05 22:05:14 -07:00
|
|
|
|
2022-01-21 20:00:14 -08:00
|
|
|
health->fault_status_pkt = fault_status;
|
|
|
|
|
health->faults_pkt = faults;
|
|
|
|
|
|
2024-02-11 04:20:36 +05:30
|
|
|
health->interrupt_load_pkt = interrupt_load;
|
2022-04-11 11:59:47 +02:00
|
|
|
|
2022-08-17 20:43:49 -07:00
|
|
|
health->fan_power = fan_state.power;
|
|
|
|
|
|
2023-05-08 13:30:23 +02:00
|
|
|
health->sbu1_voltage_mV = harness.sbu1_voltage_mV;
|
|
|
|
|
health->sbu2_voltage_mV = harness.sbu2_voltage_mV;
|
|
|
|
|
|
2023-11-09 18:01:46 -08:00
|
|
|
health->som_reset_triggered = bootkick_reset_triggered;
|
|
|
|
|
|
2022-01-21 20:00:14 -08:00
|
|
|
return sizeof(*health);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// send on serial, first byte to select the ring
|
2024-01-20 21:50:42 -08:00
|
|
|
void comms_endpoint2_write(const uint8_t *data, uint32_t len) {
|
2022-08-03 13:11:52 +02:00
|
|
|
uart_ring *ur = get_ring_by_number(data[0]);
|
|
|
|
|
if ((len != 0U) && (ur != NULL)) {
|
2023-11-23 16:30:20 -08:00
|
|
|
if ((data[0] < 2U) || (data[0] >= 4U)) {
|
2022-08-03 13:11:52 +02:00
|
|
|
for (uint32_t i = 1; i < len; i++) {
|
2024-01-19 03:59:01 +05:30
|
|
|
while (!put_char(ur, data[i])) {
|
2022-01-21 20:00:14 -08:00
|
|
|
// wait
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-03 13:11:52 +02:00
|
|
|
int comms_control_handler(ControlPacket_t *req, uint8_t *resp) {
|
2022-01-21 20:00:14 -08:00
|
|
|
unsigned int resp_len = 0;
|
|
|
|
|
uart_ring *ur = NULL;
|
2023-02-14 12:16:15 +01:00
|
|
|
uint32_t time;
|
2022-11-10 21:34:43 -08:00
|
|
|
|
|
|
|
|
#ifdef DEBUG_COMMS
|
2022-11-29 22:55:10 -08:00
|
|
|
print("raw control request: "); hexdump(req, sizeof(ControlPacket_t)); print("\n");
|
|
|
|
|
print("- request "); puth(req->request); print("\n");
|
|
|
|
|
print("- param1 "); puth(req->param1); print("\n");
|
|
|
|
|
print("- param2 "); puth(req->param2); print("\n");
|
2022-11-10 21:34:43 -08:00
|
|
|
#endif
|
|
|
|
|
|
2022-08-03 13:11:52 +02:00
|
|
|
switch (req->request) {
|
2023-02-14 12:16:15 +01:00
|
|
|
// **** 0xa8: get microsecond timer
|
|
|
|
|
case 0xa8:
|
|
|
|
|
time = microsecond_timer_get();
|
|
|
|
|
resp[0] = (time & 0x000000FFU);
|
|
|
|
|
resp[1] = ((time & 0x0000FF00U) >> 8U);
|
|
|
|
|
resp[2] = ((time & 0x00FF0000U) >> 16U);
|
|
|
|
|
resp[3] = ((time & 0xFF000000U) >> 24U);
|
|
|
|
|
resp_len = 4U;
|
|
|
|
|
break;
|
2022-01-21 20:00:14 -08:00
|
|
|
// **** 0xb0: set IR power
|
|
|
|
|
case 0xb0:
|
2022-08-03 13:11:52 +02:00
|
|
|
current_board->set_ir_power(req->param1);
|
2022-01-21 20:00:14 -08:00
|
|
|
break;
|
|
|
|
|
// **** 0xb1: set fan power
|
|
|
|
|
case 0xb1:
|
2022-08-17 20:43:49 -07:00
|
|
|
fan_set_power(req->param1);
|
2022-01-21 20:00:14 -08:00
|
|
|
break;
|
|
|
|
|
// **** 0xb2: get fan rpm
|
|
|
|
|
case 0xb2:
|
2022-08-17 20:43:49 -07:00
|
|
|
resp[0] = (fan_state.rpm & 0x00FFU);
|
|
|
|
|
resp[1] = ((fan_state.rpm & 0xFF00U) >> 8U);
|
2022-01-21 20:00:14 -08:00
|
|
|
resp_len = 2;
|
|
|
|
|
break;
|
2025-07-19 21:05:12 -07:00
|
|
|
// **** 0xc0: reset communications state
|
2023-01-13 10:59:58 -08:00
|
|
|
case 0xc0:
|
|
|
|
|
comms_can_reset();
|
|
|
|
|
break;
|
2022-01-21 20:00:14 -08:00
|
|
|
// **** 0xc1: get hardware type
|
|
|
|
|
case 0xc1:
|
|
|
|
|
resp[0] = hw_type;
|
|
|
|
|
resp_len = 1;
|
|
|
|
|
break;
|
2023-01-15 20:13:26 -08:00
|
|
|
// **** 0xc2: CAN health stats
|
2022-09-15 13:04:10 -07:00
|
|
|
case 0xc2:
|
|
|
|
|
COMPILE_TIME_ASSERT(sizeof(can_health_t) <= USBPACKET_MAX_SIZE);
|
|
|
|
|
if (req->param1 < 3U) {
|
2023-06-21 18:56:10 -07:00
|
|
|
update_can_health_pkt(req->param1, 0U);
|
2022-09-16 20:39:18 -07:00
|
|
|
can_health[req->param1].can_speed = (bus_config[req->param1].can_speed / 10U);
|
|
|
|
|
can_health[req->param1].can_data_speed = (bus_config[req->param1].can_data_speed / 10U);
|
|
|
|
|
can_health[req->param1].canfd_enabled = bus_config[req->param1].canfd_enabled;
|
|
|
|
|
can_health[req->param1].brs_enabled = bus_config[req->param1].brs_enabled;
|
2022-10-12 15:28:20 -07:00
|
|
|
can_health[req->param1].canfd_non_iso = bus_config[req->param1].canfd_non_iso;
|
2022-09-15 13:04:10 -07:00
|
|
|
resp_len = sizeof(can_health[req->param1]);
|
2024-09-19 10:35:11 -07:00
|
|
|
(void)memcpy(resp, (uint8_t*)(&can_health[req->param1]), resp_len);
|
2022-09-15 13:04:10 -07:00
|
|
|
}
|
|
|
|
|
break;
|
2023-01-15 20:13:26 -08:00
|
|
|
// **** 0xc3: fetch MCU UID
|
|
|
|
|
case 0xc3:
|
|
|
|
|
(void)memcpy(resp, ((uint8_t *)UID_BASE), 12);
|
|
|
|
|
resp_len = 12;
|
|
|
|
|
break;
|
2023-08-01 16:33:34 -07:00
|
|
|
// **** 0xc4: get interrupt call rate
|
2023-06-20 11:47:43 -07:00
|
|
|
case 0xc4:
|
|
|
|
|
if (req->param1 < NUM_INTERRUPTS) {
|
|
|
|
|
uint32_t load = interrupts[req->param1].call_rate;
|
|
|
|
|
resp[0] = (load & 0x000000FFU);
|
|
|
|
|
resp[1] = ((load & 0x0000FF00U) >> 8U);
|
|
|
|
|
resp[2] = ((load & 0x00FF0000U) >> 16U);
|
|
|
|
|
resp[3] = ((load & 0xFF000000U) >> 24U);
|
|
|
|
|
resp_len = 4U;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2023-08-01 16:33:34 -07:00
|
|
|
// **** 0xc5: DEBUG: drive relay
|
|
|
|
|
case 0xc5:
|
|
|
|
|
set_intercept_relay((req->param1 & 0x1U), (req->param1 & 0x2U));
|
|
|
|
|
break;
|
2023-10-06 13:38:35 -07:00
|
|
|
// **** 0xc6: DEBUG: read SOM GPIO
|
|
|
|
|
case 0xc6:
|
|
|
|
|
resp[0] = current_board->read_som_gpio();
|
|
|
|
|
resp_len = 1;
|
|
|
|
|
break;
|
2023-01-15 20:13:26 -08:00
|
|
|
// **** 0xd0: fetch serial (aka the provisioned dongle ID)
|
2022-01-21 20:00:14 -08:00
|
|
|
case 0xd0:
|
|
|
|
|
// addresses are OTP
|
2022-08-03 13:11:52 +02:00
|
|
|
if (req->param1 == 1U) {
|
2022-01-21 20:00:14 -08:00
|
|
|
(void)memcpy(resp, (uint8_t *)DEVICE_SERIAL_NUMBER_ADDRESS, 0x10);
|
|
|
|
|
resp_len = 0x10;
|
|
|
|
|
} else {
|
|
|
|
|
get_provision_chunk(resp);
|
|
|
|
|
resp_len = PROVISION_CHUNK_LEN;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
// **** 0xd1: enter bootloader mode
|
|
|
|
|
case 0xd1:
|
|
|
|
|
// this allows reflashing of the bootstub
|
2022-08-03 13:11:52 +02:00
|
|
|
switch (req->param1) {
|
2022-01-21 20:00:14 -08:00
|
|
|
case 0:
|
|
|
|
|
// only allow bootloader entry on debug builds
|
|
|
|
|
#ifdef ALLOW_DEBUG
|
2022-11-29 22:55:10 -08:00
|
|
|
print("-> entering bootloader\n");
|
2022-01-21 20:00:14 -08:00
|
|
|
enter_bootloader_mode = ENTER_BOOTLOADER_MAGIC;
|
|
|
|
|
NVIC_SystemReset();
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2022-11-29 22:55:10 -08:00
|
|
|
print("-> entering softloader\n");
|
2022-01-21 20:00:14 -08:00
|
|
|
enter_bootloader_mode = ENTER_SOFTLOADER_MAGIC;
|
|
|
|
|
NVIC_SystemReset();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2022-11-29 22:55:10 -08:00
|
|
|
print("Bootloader mode invalid\n");
|
2022-01-21 20:00:14 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
// **** 0xd2: get health packet
|
|
|
|
|
case 0xd2:
|
|
|
|
|
resp_len = get_health_pkt(resp);
|
|
|
|
|
break;
|
|
|
|
|
// **** 0xd3: get first 64 bytes of signature
|
|
|
|
|
case 0xd3:
|
|
|
|
|
{
|
|
|
|
|
resp_len = 64;
|
|
|
|
|
char * code = (char*)_app_start;
|
|
|
|
|
int code_len = _app_start[0];
|
|
|
|
|
(void)memcpy(resp, &code[code_len], resp_len);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
// **** 0xd4: get second 64 bytes of signature
|
|
|
|
|
case 0xd4:
|
|
|
|
|
{
|
|
|
|
|
resp_len = 64;
|
|
|
|
|
char * code = (char*)_app_start;
|
|
|
|
|
int code_len = _app_start[0];
|
|
|
|
|
(void)memcpy(resp, &code[code_len + 64], resp_len);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
// **** 0xd6: get version
|
|
|
|
|
case 0xd6:
|
|
|
|
|
COMPILE_TIME_ASSERT(sizeof(gitversion) <= USBPACKET_MAX_SIZE);
|
|
|
|
|
(void)memcpy(resp, gitversion, sizeof(gitversion));
|
|
|
|
|
resp_len = sizeof(gitversion) - 1U;
|
|
|
|
|
break;
|
|
|
|
|
// **** 0xd8: reset ST
|
|
|
|
|
case 0xd8:
|
|
|
|
|
NVIC_SystemReset();
|
|
|
|
|
break;
|
2024-03-21 13:56:36 -07:00
|
|
|
// **** 0xdb: set OBD CAN multiplexing mode
|
2022-01-21 20:00:14 -08:00
|
|
|
case 0xdb:
|
2025-09-10 20:00:41 -07:00
|
|
|
current_board->set_can_mode((req->param1 == 1U) ? CAN_MODE_OBD_CAN2 : CAN_MODE_NORMAL);
|
2022-01-21 20:00:14 -08:00
|
|
|
break;
|
|
|
|
|
// **** 0xdc: set safety mode
|
|
|
|
|
case 0xdc:
|
2022-08-03 13:11:52 +02:00
|
|
|
set_safety_mode(req->param1, (uint16_t)req->param2);
|
2022-01-21 20:00:14 -08:00
|
|
|
break;
|
|
|
|
|
// **** 0xdd: get healthpacket and CANPacket versions
|
|
|
|
|
case 0xdd:
|
|
|
|
|
resp[0] = HEALTH_PACKET_VERSION;
|
|
|
|
|
resp[1] = CAN_PACKET_VERSION;
|
2022-09-15 13:04:10 -07:00
|
|
|
resp[2] = CAN_HEALTH_PACKET_VERSION;
|
|
|
|
|
resp_len = 3;
|
2022-01-21 20:00:14 -08:00
|
|
|
break;
|
|
|
|
|
// **** 0xde: set can bitrate
|
|
|
|
|
case 0xde:
|
2025-09-10 20:00:41 -07:00
|
|
|
if ((req->param1 < PANDA_CAN_CNT) && is_speed_valid(req->param2, speeds, sizeof(speeds)/sizeof(speeds[0]))) {
|
2022-08-03 13:11:52 +02:00
|
|
|
bus_config[req->param1].can_speed = req->param2;
|
|
|
|
|
bool ret = can_init(CAN_NUM_FROM_BUS_NUM(req->param1));
|
2022-01-21 20:00:14 -08:00
|
|
|
UNUSED(ret);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2022-03-24 14:31:31 -07:00
|
|
|
// **** 0xdf: set alternative experience
|
2022-01-21 20:00:14 -08:00
|
|
|
case 0xdf:
|
|
|
|
|
// you can only set this if you are in a non car safety mode
|
|
|
|
|
if (!is_car_safety_mode(current_safety_mode)) {
|
2022-08-03 13:11:52 +02:00
|
|
|
alternative_experience = req->param1;
|
2025-03-15 17:19:30 -04:00
|
|
|
current_safety_param_sp = req->param2;
|
Modular Assistive Driving System (MADS) (#57)
* improvements on the state machine for exiting controls and improvements on replay drive, and optimizations
* New tests on hyundai for now to see how they behave with lkas and main button pressed interchangeably
* cleaning up hyundai tests and ensuring we always cleanup mads states at the end of the tests
* Adjusting tests
* Adjusting the tests a bit more to ensure clean states
* Cleaning up and simplifying logic
* ensuring all tests always cleanup
* improving the state
* make static happy
* Refactor safety replay script for better debugging and update Honda safety code
The commit performs a comprehensive revision of the safety replay script, specifically focusing on introducing debug variables and enhancing the logging capabilities for improved debugging. Furthermore, changes were made to the Honda safety code. The test helpers within libpanda were also expanded for inclusion of additional test conditions.
* Introduce 'ACC_MAIN_OFF' as a new disengagement reason in Sunnypilot's 'safety_mads.h'
The Sunnypilot's 'safety_mads.h' file has been updated to include 'ACC_MAIN_OFF' as a new cause for disconnection in the 'DisengageReason' enumeration. If an 'acc_main_off' signal is received, the 'mads_exit_controls' function halts all requests for lateral control engagement. Additionally, the status of 'controls_requested_lat' now mirrors 'controls_allowed_lat' after a button press.
* simpler logic cleaner
* reorder code for readability
* tmp
* Refactor state transitions and add event handlers
Renamed StateTransition to EdgeTransition for clarity and updated related logic. Introduced event handlers for button presses and ACC state changes, reducing duplicated control flow code. Improved encapsulation and maintainability by restructuring state update functions.
* reorder
* Refactor MADS state handling logic
Removed redundant event handler functions and unnecessary timestamp fields to streamline the code. Simplified button and binary state updates by integrating logic directly into transition checks. Commented out unused fields
* adding some more tests
* split init
* format
* update naming
* Refine lateral control request logic in safety_mads.h
The logic for setting the `controls_requested_lat` variable in safety_mads.h has been refined. Previously, it switched state based on the current value of `controls_allowed_lat`. Now, it also takes into account the current state of `acc_main`, ensuring a more nuanced control request mechanism that accounts for different operational scenarios.
* Fix button state handling in mads_exit_controls logic.
Refactor button state transitions to better handle lateral control requests when ACC is active. Ensure controls are correctly disengaged under specific conditions, by setting `controls_requested_lat` more reliably during state transitions. This change improves safety by preventing inadvertent disengagement when ACC is not active.
* Add test for LKAS button press with ACC main on
This commit introduces a new test to ensure that controls remain enabled when the LKAS/LFA button is pressed while ACC main is on. It checks that LKAS button operations don't interfere with control permissions in this specific configuration, improving test coverage and preventing potential safety issues.
* Add mismatch detection and change mads_acc_main to bool
Enhanced mismatch detection logic by tracking cases where 'controls_allowed' is true while 'controls_allowed_lat' is false, updating the script to print relevant debug information. Additionally, changed the data type of 'mads_acc_main' and 'mads_acc_main_prev' from int to bool for improved type accuracy and consistency.
* update controls_allowed_lat_pkt on health pkt to actually follow is_lat_active() which has the final word on whether we can allow lat or not.
* Can't perform this test on toyota as we never really process a button disengagement for toyota
* wow, we forgot about pcm hyundai can-fd
* nuke nuke nuke
* Revert "nuke nuke nuke"
This reverts commit 9bf0de640a3439ac43c27bcbc6568853966d370b.
* update name
* event driven update states
* add get_pcm_main_cruise_available
* split PCM and non-PCM main cruise tets
* fix some
* pcm main cruise availability mutation
* toyota pass fake lkas btn pressed
* more
* make pcm acc main rising edge on init
* only falling edge when actually 0 (need test for mutation)
* misra
* remove state flags, main button related
* skip lkas related tests with toyota and subaru fake button
* need for honda
* static
* mutation
* misra
* skip nidec pcm alt
* engage mads if controls allowed rising
* static
* remove non pcm properties
* fixup! engage mads if controls allowed rising
* move back
* fix static
* move around
* Hyundai openpilot longitudinal main cruise button state handling
* main button unit test
* acc_main_on mismatch unit tests
* clean up old main cruise button unit tests
* add more reasons
* cleanup
* rename
* rearrange
* Revert "rearrange"
This reverts commit f07caaa5b98b74c23667b387430ac48ba95bf21c.
* more rearrange
* rename
* more
* too slow
* Revert "too slow"
This reverts commit 31a249aebfa9c985e37be050e525b6924ca9e83d.
* too slow v2
* cleanup
* rename
* more cleanup
* Parse more flags from alt exp, more tests, hyundai main cruise allowed
* missed
* mutation for controls allowed rising edge
* ford mutation
* Update tests/safety/test.sh
Co-authored-by: DevTekVE <devtekve@gmail.com>
* license
* unused
* remove
* comment
* Apply suggestions from code review
Co-authored-by: DevTekVE <devtekve@gmail.com>
* comment
* refactor alternative experience handling with helper function
* use always allowed mads button alt exp
* rename
* parenthesis
* use alternative experience for unit tests inits
* cleanup
* rename
* mutation tests for alternative experience flags
* bump timer
* test for disengage and no disengage lateral on brake
* test allow MADS engage with brake pressed
* rename
* move around
* button combo test
* use acc_main_on directly from global
* fix caught failures from last commit's fix
* Revert "use acc_main_on directly from global"
This reverts commit 346964f55d020a287a1a679e22691ad8873e2a64.
* Properly fix lmao
* Add support for LKAS button handling across Chrysler platforms
Introduced LKAS button message parsing for multiple Chrysler platforms, including specific handling for center stack button messages. Updated tests and safety configurations to reflect these changes, ensuring compatibility with different vehicle variants. This enhances modularity and improves safety feature integration.
* Dockerfile: point to sunnypilot/opendbc
* Happy days :)
* clean
* testx
* Revert "Happy days :)"
This reverts commit 7ea27b53c8f3b1e37677c1ce9498229fceac9de6.
* symlink prior building
* comment
* only parse mads lateral, not stock op's lateral
* do not allow controls allowed if acc_main_on is off
* expose system_enabled, do not allow controls allowed to steer if system_mads is off
* fix hyundai tests with acc_main_on requirement
* fix test with new controls allowed with system_mads off
* fix replay drive
* Change 'DISABLE_DISENGAGE_LATERAL_ON_BRAKE' to 'DISENGAGE_LATERAL_ON_BRAKE'
The commit modifies the usage of the 'DISABLE_DISENGAGE_LATERAL_ON_BRAKE' variable globally and replaces it with 'DISENGAGE_LATERAL_ON_BRAKE'. This change promotes correct and clear semantics, since the variable now indicates a state rather than the negation of a state.
* Adding some more debug printouts on replay drive
* remove unified engagement mode in panda
* treat MADS button as user entry
* controls allow should be allowed at all times
* squash! treat MADS button as user entry
* heartbeat for mads
* heartbeat mismatch exit control
* remove always allow mads button from alt
* move to safety_mads
* check heartbeat directly in main
* remove main cruise allowed from alt
* uint
* squash! check heartbeat directly in main
* update tests
* not needed
* fix mads_exit_controls sometimes not assigning disengage reason
* more disengage lateral on brake tests
* extern
* missesd
* honda mutation test
* again
* rename
* more dlob test
* update name
* fix tests
* fix panda tests
* Refactor MADS state management to simplify pointer usage.
This change replaces many pointer-based state variables with direct ones, improving code readability and reducing complexity. It also standardizes the use of `const` for parameters and updates function implementations accordingly. These improvements enhance maintainability and reduce potential for pointer-related errors.
* Simplify braking logic in m_mads_check_braking function
Removed redundant conditions to streamline braking logic. This change maintains functionality while improving code readability and maintainability. Only necessary checks are now performed to determine disengagement.
* Prevent lateral control engagement during braking
Added a condition to disable lateral control engagement when braking with disengage-on-brake enabled. This change is marked as a demonstration and is not final for merging. Moved the disengage_reason to be set only when an actual disengagement occurred.
* Refactor MADS state handling and fix type consistency
Remove redundant `get_mads_state` inline definition and migrate it to a static function. Fix return type syntax in `get_mads_pending_disengage_reason`. Minor formatting adjustments improve readability and code clarity.
Refactor disengagement logic with enhanced reason tracking
Added distinction between active and pending disengagement reasons to improve system state tracking. Updated related enums, structs, and logic to ensure proper handling during control transitions. Added new safety tests to verify behavior under braking and ACC conditions.
Refactoring lateral control permissions and brake checks in MADS
This revision refactors the MADS safety code. The aim is to simplify and improve readability. Operations and checks for brake states and lateral control permissions have been consolidated into fewer methods. In addition, unused 'previous_disengage' state tracking has been removed from MADSState structure to avoid unnecessary state tracking. Moreover, the 'can_allow_controls_lat' function has been removed entirely and its functionality has been incorporated into other functions, reducing the function count and complexity of the code. The braking status is now tracked with BinaryStateTracking for consistency. These changes maintain the system's functionality while optimizing the code and improving maintainability.
* Why MISRA, why!? WHY!???? I DIDNT EVEN TOUCH THIS FILE OR NOWHERE NEAR!
* Some format
* no more messing with misra
* const
* more generic names
* revert to validate
* are you srs
* make gpio.h stock again and add to supression lists the check on gpio.h since we are not even touching it and we don't plan on ever doing so
* hard code to skip heartbeat check
* update comment
* cleanup
* Update tests/safety/test_honda.py
---------
Co-authored-by: DevTekVE <devtekve@gmail.com>
2024-12-15 18:05:31 -05:00
|
|
|
mads_set_alternative_experience(&alternative_experience);
|
2022-01-21 20:00:14 -08:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
// **** 0xe0: uart read
|
|
|
|
|
case 0xe0:
|
2022-08-03 13:11:52 +02:00
|
|
|
ur = get_ring_by_number(req->param1);
|
2022-01-21 20:00:14 -08:00
|
|
|
if (!ur) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// read
|
2024-02-03 23:20:30 -08:00
|
|
|
uint16_t req_length = MIN(req->length, USBPACKET_MAX_SIZE);
|
|
|
|
|
while ((resp_len < req_length) &&
|
2024-01-19 03:59:01 +05:30
|
|
|
get_char(ur, (char*)&resp[resp_len])) {
|
2022-01-21 20:00:14 -08:00
|
|
|
++resp_len;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
// **** 0xe5: set CAN loopback (for testing)
|
|
|
|
|
case 0xe5:
|
2024-02-19 01:26:44 +05:30
|
|
|
can_loopback = req->param1 > 0U;
|
2022-01-21 20:00:14 -08:00
|
|
|
can_init_all();
|
|
|
|
|
break;
|
2025-06-03 18:37:28 -07:00
|
|
|
// **** 0xe6: set custom clock source period and pulse length
|
2023-08-01 16:17:42 -07:00
|
|
|
case 0xe6:
|
2025-06-03 18:37:28 -07:00
|
|
|
clock_source_set_timer_params(req->param1, req->param2);
|
2023-08-01 16:17:42 -07:00
|
|
|
break;
|
2022-01-21 20:00:14 -08:00
|
|
|
// **** 0xe7: set power save state
|
|
|
|
|
case 0xe7:
|
2022-08-03 13:11:52 +02:00
|
|
|
set_power_save_state(req->param1);
|
2022-01-21 20:00:14 -08:00
|
|
|
break;
|
2024-11-21 11:04:09 -08:00
|
|
|
// **** 0xe8: set can-fd auto swithing mode
|
|
|
|
|
case 0xe8:
|
2024-11-21 11:07:57 -08:00
|
|
|
bus_config[req->param1].canfd_auto = req->param2 > 0U;
|
|
|
|
|
break;
|
2022-01-21 20:00:14 -08:00
|
|
|
// **** 0xf1: Clear CAN ring buffer.
|
|
|
|
|
case 0xf1:
|
2022-08-03 13:11:52 +02:00
|
|
|
if (req->param1 == 0xFFFFU) {
|
2022-11-29 22:55:10 -08:00
|
|
|
print("Clearing CAN Rx queue\n");
|
2022-01-21 20:00:14 -08:00
|
|
|
can_clear(&can_rx_q);
|
2025-09-10 20:00:41 -07:00
|
|
|
} else if (req->param1 < PANDA_CAN_CNT) {
|
2022-11-29 22:55:10 -08:00
|
|
|
print("Clearing CAN Tx queue\n");
|
2022-08-03 13:11:52 +02:00
|
|
|
can_clear(can_queues[req->param1]);
|
2022-01-21 20:00:14 -08:00
|
|
|
} else {
|
2022-11-29 22:55:10 -08:00
|
|
|
print("Clearing CAN CAN ring buffer failed: wrong bus number\n");
|
2022-01-21 20:00:14 -08:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
// **** 0xf3: Heartbeat. Resets heartbeat counter.
|
|
|
|
|
case 0xf3:
|
|
|
|
|
{
|
|
|
|
|
heartbeat_counter = 0U;
|
|
|
|
|
heartbeat_lost = false;
|
|
|
|
|
heartbeat_disabled = false;
|
2022-08-03 13:11:52 +02:00
|
|
|
heartbeat_engaged = (req->param1 == 1U);
|
Modular Assistive Driving System (MADS) (#57)
* improvements on the state machine for exiting controls and improvements on replay drive, and optimizations
* New tests on hyundai for now to see how they behave with lkas and main button pressed interchangeably
* cleaning up hyundai tests and ensuring we always cleanup mads states at the end of the tests
* Adjusting tests
* Adjusting the tests a bit more to ensure clean states
* Cleaning up and simplifying logic
* ensuring all tests always cleanup
* improving the state
* make static happy
* Refactor safety replay script for better debugging and update Honda safety code
The commit performs a comprehensive revision of the safety replay script, specifically focusing on introducing debug variables and enhancing the logging capabilities for improved debugging. Furthermore, changes were made to the Honda safety code. The test helpers within libpanda were also expanded for inclusion of additional test conditions.
* Introduce 'ACC_MAIN_OFF' as a new disengagement reason in Sunnypilot's 'safety_mads.h'
The Sunnypilot's 'safety_mads.h' file has been updated to include 'ACC_MAIN_OFF' as a new cause for disconnection in the 'DisengageReason' enumeration. If an 'acc_main_off' signal is received, the 'mads_exit_controls' function halts all requests for lateral control engagement. Additionally, the status of 'controls_requested_lat' now mirrors 'controls_allowed_lat' after a button press.
* simpler logic cleaner
* reorder code for readability
* tmp
* Refactor state transitions and add event handlers
Renamed StateTransition to EdgeTransition for clarity and updated related logic. Introduced event handlers for button presses and ACC state changes, reducing duplicated control flow code. Improved encapsulation and maintainability by restructuring state update functions.
* reorder
* Refactor MADS state handling logic
Removed redundant event handler functions and unnecessary timestamp fields to streamline the code. Simplified button and binary state updates by integrating logic directly into transition checks. Commented out unused fields
* adding some more tests
* split init
* format
* update naming
* Refine lateral control request logic in safety_mads.h
The logic for setting the `controls_requested_lat` variable in safety_mads.h has been refined. Previously, it switched state based on the current value of `controls_allowed_lat`. Now, it also takes into account the current state of `acc_main`, ensuring a more nuanced control request mechanism that accounts for different operational scenarios.
* Fix button state handling in mads_exit_controls logic.
Refactor button state transitions to better handle lateral control requests when ACC is active. Ensure controls are correctly disengaged under specific conditions, by setting `controls_requested_lat` more reliably during state transitions. This change improves safety by preventing inadvertent disengagement when ACC is not active.
* Add test for LKAS button press with ACC main on
This commit introduces a new test to ensure that controls remain enabled when the LKAS/LFA button is pressed while ACC main is on. It checks that LKAS button operations don't interfere with control permissions in this specific configuration, improving test coverage and preventing potential safety issues.
* Add mismatch detection and change mads_acc_main to bool
Enhanced mismatch detection logic by tracking cases where 'controls_allowed' is true while 'controls_allowed_lat' is false, updating the script to print relevant debug information. Additionally, changed the data type of 'mads_acc_main' and 'mads_acc_main_prev' from int to bool for improved type accuracy and consistency.
* update controls_allowed_lat_pkt on health pkt to actually follow is_lat_active() which has the final word on whether we can allow lat or not.
* Can't perform this test on toyota as we never really process a button disengagement for toyota
* wow, we forgot about pcm hyundai can-fd
* nuke nuke nuke
* Revert "nuke nuke nuke"
This reverts commit 9bf0de640a3439ac43c27bcbc6568853966d370b.
* update name
* event driven update states
* add get_pcm_main_cruise_available
* split PCM and non-PCM main cruise tets
* fix some
* pcm main cruise availability mutation
* toyota pass fake lkas btn pressed
* more
* make pcm acc main rising edge on init
* only falling edge when actually 0 (need test for mutation)
* misra
* remove state flags, main button related
* skip lkas related tests with toyota and subaru fake button
* need for honda
* static
* mutation
* misra
* skip nidec pcm alt
* engage mads if controls allowed rising
* static
* remove non pcm properties
* fixup! engage mads if controls allowed rising
* move back
* fix static
* move around
* Hyundai openpilot longitudinal main cruise button state handling
* main button unit test
* acc_main_on mismatch unit tests
* clean up old main cruise button unit tests
* add more reasons
* cleanup
* rename
* rearrange
* Revert "rearrange"
This reverts commit f07caaa5b98b74c23667b387430ac48ba95bf21c.
* more rearrange
* rename
* more
* too slow
* Revert "too slow"
This reverts commit 31a249aebfa9c985e37be050e525b6924ca9e83d.
* too slow v2
* cleanup
* rename
* more cleanup
* Parse more flags from alt exp, more tests, hyundai main cruise allowed
* missed
* mutation for controls allowed rising edge
* ford mutation
* Update tests/safety/test.sh
Co-authored-by: DevTekVE <devtekve@gmail.com>
* license
* unused
* remove
* comment
* Apply suggestions from code review
Co-authored-by: DevTekVE <devtekve@gmail.com>
* comment
* refactor alternative experience handling with helper function
* use always allowed mads button alt exp
* rename
* parenthesis
* use alternative experience for unit tests inits
* cleanup
* rename
* mutation tests for alternative experience flags
* bump timer
* test for disengage and no disengage lateral on brake
* test allow MADS engage with brake pressed
* rename
* move around
* button combo test
* use acc_main_on directly from global
* fix caught failures from last commit's fix
* Revert "use acc_main_on directly from global"
This reverts commit 346964f55d020a287a1a679e22691ad8873e2a64.
* Properly fix lmao
* Add support for LKAS button handling across Chrysler platforms
Introduced LKAS button message parsing for multiple Chrysler platforms, including specific handling for center stack button messages. Updated tests and safety configurations to reflect these changes, ensuring compatibility with different vehicle variants. This enhances modularity and improves safety feature integration.
* Dockerfile: point to sunnypilot/opendbc
* Happy days :)
* clean
* testx
* Revert "Happy days :)"
This reverts commit 7ea27b53c8f3b1e37677c1ce9498229fceac9de6.
* symlink prior building
* comment
* only parse mads lateral, not stock op's lateral
* do not allow controls allowed if acc_main_on is off
* expose system_enabled, do not allow controls allowed to steer if system_mads is off
* fix hyundai tests with acc_main_on requirement
* fix test with new controls allowed with system_mads off
* fix replay drive
* Change 'DISABLE_DISENGAGE_LATERAL_ON_BRAKE' to 'DISENGAGE_LATERAL_ON_BRAKE'
The commit modifies the usage of the 'DISABLE_DISENGAGE_LATERAL_ON_BRAKE' variable globally and replaces it with 'DISENGAGE_LATERAL_ON_BRAKE'. This change promotes correct and clear semantics, since the variable now indicates a state rather than the negation of a state.
* Adding some more debug printouts on replay drive
* remove unified engagement mode in panda
* treat MADS button as user entry
* controls allow should be allowed at all times
* squash! treat MADS button as user entry
* heartbeat for mads
* heartbeat mismatch exit control
* remove always allow mads button from alt
* move to safety_mads
* check heartbeat directly in main
* remove main cruise allowed from alt
* uint
* squash! check heartbeat directly in main
* update tests
* not needed
* fix mads_exit_controls sometimes not assigning disengage reason
* more disengage lateral on brake tests
* extern
* missesd
* honda mutation test
* again
* rename
* more dlob test
* update name
* fix tests
* fix panda tests
* Refactor MADS state management to simplify pointer usage.
This change replaces many pointer-based state variables with direct ones, improving code readability and reducing complexity. It also standardizes the use of `const` for parameters and updates function implementations accordingly. These improvements enhance maintainability and reduce potential for pointer-related errors.
* Simplify braking logic in m_mads_check_braking function
Removed redundant conditions to streamline braking logic. This change maintains functionality while improving code readability and maintainability. Only necessary checks are now performed to determine disengagement.
* Prevent lateral control engagement during braking
Added a condition to disable lateral control engagement when braking with disengage-on-brake enabled. This change is marked as a demonstration and is not final for merging. Moved the disengage_reason to be set only when an actual disengagement occurred.
* Refactor MADS state handling and fix type consistency
Remove redundant `get_mads_state` inline definition and migrate it to a static function. Fix return type syntax in `get_mads_pending_disengage_reason`. Minor formatting adjustments improve readability and code clarity.
Refactor disengagement logic with enhanced reason tracking
Added distinction between active and pending disengagement reasons to improve system state tracking. Updated related enums, structs, and logic to ensure proper handling during control transitions. Added new safety tests to verify behavior under braking and ACC conditions.
Refactoring lateral control permissions and brake checks in MADS
This revision refactors the MADS safety code. The aim is to simplify and improve readability. Operations and checks for brake states and lateral control permissions have been consolidated into fewer methods. In addition, unused 'previous_disengage' state tracking has been removed from MADSState structure to avoid unnecessary state tracking. Moreover, the 'can_allow_controls_lat' function has been removed entirely and its functionality has been incorporated into other functions, reducing the function count and complexity of the code. The braking status is now tracked with BinaryStateTracking for consistency. These changes maintain the system's functionality while optimizing the code and improving maintainability.
* Why MISRA, why!? WHY!???? I DIDNT EVEN TOUCH THIS FILE OR NOWHERE NEAR!
* Some format
* no more messing with misra
* const
* more generic names
* revert to validate
* are you srs
* make gpio.h stock again and add to supression lists the check on gpio.h since we are not even touching it and we don't plan on ever doing so
* hard code to skip heartbeat check
* update comment
* cleanup
* Update tests/safety/test_honda.py
---------
Co-authored-by: DevTekVE <devtekve@gmail.com>
2024-12-15 18:05:31 -05:00
|
|
|
heartbeat_engaged_mads = true; // FIXME-SP: Implement proper heartbeat check from sunnypilot
|
2022-01-21 20:00:14 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// **** 0xf6: set siren enabled
|
|
|
|
|
case 0xf6:
|
2022-08-03 13:11:52 +02:00
|
|
|
siren_enabled = (req->param1 != 0U);
|
2022-01-21 20:00:14 -08:00
|
|
|
break;
|
|
|
|
|
// **** 0xf8: disable heartbeat checks
|
|
|
|
|
case 0xf8:
|
2022-08-17 22:42:18 -07:00
|
|
|
if (!is_car_safety_mode(current_safety_mode)) {
|
|
|
|
|
heartbeat_disabled = true;
|
|
|
|
|
}
|
2022-01-21 20:00:14 -08:00
|
|
|
break;
|
2022-10-12 15:28:20 -07:00
|
|
|
// **** 0xf9: set CAN FD data bitrate
|
2022-01-21 20:00:14 -08:00
|
|
|
case 0xf9:
|
2022-11-29 15:56:43 -08:00
|
|
|
if ((req->param1 < PANDA_CAN_CNT) &&
|
2022-09-16 23:51:55 -07:00
|
|
|
is_speed_valid(req->param2, data_speeds, sizeof(data_speeds)/sizeof(data_speeds[0]))) {
|
2022-08-03 13:11:52 +02:00
|
|
|
bus_config[req->param1].can_data_speed = req->param2;
|
|
|
|
|
bus_config[req->param1].canfd_enabled = (req->param2 >= bus_config[req->param1].can_speed);
|
|
|
|
|
bus_config[req->param1].brs_enabled = (req->param2 > bus_config[req->param1].can_speed);
|
|
|
|
|
bool ret = can_init(CAN_NUM_FROM_BUS_NUM(req->param1));
|
2022-01-21 20:00:14 -08:00
|
|
|
UNUSED(ret);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2022-10-12 15:28:20 -07:00
|
|
|
// **** 0xfc: set CAN FD non-ISO mode
|
|
|
|
|
case 0xfc:
|
2025-07-19 21:05:12 -07:00
|
|
|
if (req->param1 < PANDA_CAN_CNT) {
|
2022-10-12 15:28:20 -07:00
|
|
|
bus_config[req->param1].canfd_non_iso = (req->param2 != 0U);
|
|
|
|
|
bool ret = can_init(CAN_NUM_FROM_BUS_NUM(req->param1));
|
|
|
|
|
UNUSED(ret);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2022-01-21 20:00:14 -08:00
|
|
|
default:
|
2022-11-29 22:55:10 -08:00
|
|
|
print("NO HANDLER ");
|
2022-08-03 13:11:52 +02:00
|
|
|
puth(req->request);
|
2022-11-29 22:55:10 -08:00
|
|
|
print("\n");
|
2022-01-21 20:00:14 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return resp_len;
|
|
|
|
|
}
|