mirror of
https://github.com/infiniteCable2/opendbc.git
synced 2026-02-18 13:03:52 +08:00
safety: misc cleanups (#2552)
* little cleanups * passes * update * oops * these names were always confusing * Revert "these names were always confusing" This reverts commit d17a250d6791f6423604e78e8e52691020b9aeae.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
.cache/
|
||||
/build/
|
||||
.mypy_cache/
|
||||
*.pyc
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
#include "opendbc/safety/safety_declarations.h"
|
||||
|
||||
static void body_rx_hook(const CANPacket_t *to_push) {
|
||||
// body is never at standstill
|
||||
vehicle_moving = true;
|
||||
|
||||
if (GET_ADDR(to_push) == 0x201U) {
|
||||
controls_allowed = true;
|
||||
}
|
||||
@@ -20,8 +17,8 @@ static bool body_tx_hook(const CANPacket_t *to_send) {
|
||||
tx = false;
|
||||
}
|
||||
|
||||
// Allow going into CAN flashing mode for base & knee even if controls are not allowed
|
||||
bool flash_msg = ((addr == 0x250) || (addr == 0x350)) && (len == 8);
|
||||
// Allow going into CAN flashing mode even if controls are not allowed
|
||||
bool flash_msg = (addr == 0x250) && (len == 8);
|
||||
if (!controls_allowed && (GET_BYTES(to_send, 0, 4) == 0xdeadfaceU) && (GET_BYTES(to_send, 4, 4) == 0x0ab00b1eU) && flash_msg) {
|
||||
tx = true;
|
||||
}
|
||||
@@ -35,7 +32,6 @@ static safety_config body_init(uint16_t param) {
|
||||
};
|
||||
|
||||
static const CanMsg BODY_TX_MSGS[] = {{0x250, 0, 8, .check_relay = false}, {0x250, 0, 6, .check_relay = false}, {0x251, 0, 5, .check_relay = false}, // body
|
||||
{0x350, 0, 8, .check_relay = false}, {0x350, 0, 6, .check_relay = false}, {0x351, 0, 5, .check_relay = false}, // knee
|
||||
{0x1, 0, 8, .check_relay = false}}; // CAN flasher
|
||||
|
||||
UNUSED(param);
|
||||
|
||||
@@ -33,7 +33,7 @@ static bool elm327_tx_hook(const CANPacket_t *to_send) {
|
||||
return tx;
|
||||
}
|
||||
|
||||
// If current_board->has_obd and safety_param == 0, bus 1 is multiplexed to the OBD-II port
|
||||
// If safety_param == 0, bus 1 is multiplexed to the OBD-II port
|
||||
const safety_hooks elm327_hooks = {
|
||||
.init = nooutput_init,
|
||||
.rx = default_rx_hook,
|
||||
|
||||
@@ -75,7 +75,6 @@ static void honda_rx_hook(const CANPacket_t *to_push) {
|
||||
|
||||
// sample speed
|
||||
if (addr == 0x158) {
|
||||
// first 2 bytes
|
||||
vehicle_moving = GET_BYTE(to_push, 0) | GET_BYTE(to_push, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ extern uint16_t hyundai_canfd_crc_lut[256];
|
||||
uint16_t hyundai_canfd_crc_lut[256];
|
||||
|
||||
static const uint8_t HYUNDAI_PREV_BUTTON_SAMPLES = 8; // roughly 160 ms
|
||||
//
|
||||
|
||||
extern const uint32_t HYUNDAI_STANDSTILL_THRSLD;
|
||||
const uint32_t HYUNDAI_STANDSTILL_THRSLD = 12; // 0.375 kph
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ static uint8_t rivian_get_counter(const CANPacket_t *to_push) {
|
||||
if ((addr == 0x208) || (addr == 0x150)) {
|
||||
// Signal: ESP_Status_Counter, VDM_PropStatus_Counter
|
||||
cnt = GET_BYTE(to_push, 1) & 0xFU;
|
||||
} else {
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,6 @@ static bool subaru_preglobal_tx_hook(const CANPacket_t *to_send) {
|
||||
if (steer_torque_cmd_checks(desired_torque, steer_req, SUBARU_PG_STEERING_LIMITS)) {
|
||||
tx = false;
|
||||
}
|
||||
|
||||
}
|
||||
return tx;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ static uint32_t volkswagen_mqb_meb_compute_crc(const CANPacket_t *to_push) {
|
||||
int addr = GET_ADDR(to_push);
|
||||
int len = GET_LEN(to_push);
|
||||
|
||||
// This is CRC-8H2F/AUTOSAR with a twist. See the OpenDBC implementation
|
||||
// This is CRC-8H2F/AUTOSAR with a twist. See the opendbc/car/volkswagen/ implementation
|
||||
// of this algorithm for a version with explanatory comments.
|
||||
|
||||
uint8_t crc = 0xFFU;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "opendbc/safety/safety_declarations.h"
|
||||
#include "opendbc/safety/board/can.h"
|
||||
|
||||
// include the safety policies.
|
||||
// all the safety modes
|
||||
#include "opendbc/safety/modes/defaults.h"
|
||||
#include "opendbc/safety/modes/honda.h"
|
||||
#include "opendbc/safety/modes/toyota.h"
|
||||
|
||||
@@ -56,7 +56,7 @@ cppcheck() {
|
||||
PANDA_OPTS=" --enable=all --enable=unusedFunction --addon=misra"
|
||||
|
||||
printf "\n${GREEN}** Safety with CANFD **${NC}\n"
|
||||
cppcheck $PANDA_OPTS -DCANFD $BASEDIR/opendbc/safety/main.c
|
||||
cppcheck $PANDA_OPTS -DCANFD $BASEDIR/opendbc/safety/tests/misra/main.c
|
||||
|
||||
printf "\n${GREEN}Success!${NC} took $SECONDS seconds\n"
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from opendbc.safety.tests.common import CANPackerPanda
|
||||
|
||||
|
||||
class TestBody(common.PandaSafetyTest):
|
||||
TX_MSGS = [[0x250, 0], [0x251, 0], [0x350, 0], [0x351, 0],
|
||||
TX_MSGS = [[0x250, 0], [0x251, 0],
|
||||
[0x1, 0], [0x1, 1], [0x1, 2], [0x1, 3]]
|
||||
FWD_BUS_LOOKUP = {}
|
||||
|
||||
@@ -26,44 +26,34 @@ class TestBody(common.PandaSafetyTest):
|
||||
values = {"TORQUE_L": torque_l, "TORQUE_R": torque_r}
|
||||
return self.packer.make_can_msg_panda("TORQUE_CMD", 0, values)
|
||||
|
||||
def _knee_torque_cmd_msg(self, torque_l, torque_r):
|
||||
values = {"TORQUE_L": torque_l, "TORQUE_R": torque_r}
|
||||
return self.packer.make_can_msg_panda("KNEE_TORQUE_CMD", 0, values)
|
||||
|
||||
def _max_motor_rpm_cmd_msg(self, max_rpm_l, max_rpm_r):
|
||||
values = {"MAX_RPM_L": max_rpm_l, "MAX_RPM_R": max_rpm_r}
|
||||
return self.packer.make_can_msg_panda("MAX_MOTOR_RPM_CMD", 0, values)
|
||||
|
||||
def test_rx_hook(self):
|
||||
self.assertFalse(self.safety.get_controls_allowed())
|
||||
self.assertFalse(self.safety.get_vehicle_moving())
|
||||
|
||||
# controls allowed and vehicle moving when we get MOTORS_DATA message
|
||||
# controls allowed when we get MOTORS_DATA message
|
||||
self.assertTrue(self._rx(self._torque_cmd_msg(0, 0)))
|
||||
self.assertFalse(self.safety.get_vehicle_moving())
|
||||
self.assertFalse(self.safety.get_controls_allowed())
|
||||
|
||||
self.assertTrue(self._rx(self._motors_data_msg(0, 0)))
|
||||
self.assertTrue(self.safety.get_vehicle_moving()) # always moving
|
||||
self.assertTrue(self.safety.get_controls_allowed())
|
||||
|
||||
def test_tx_hook(self):
|
||||
self.assertFalse(self._tx(self._torque_cmd_msg(0, 0)))
|
||||
self.assertFalse(self._tx(self._knee_torque_cmd_msg(0, 0)))
|
||||
self.safety.set_controls_allowed(True)
|
||||
self.assertTrue(self._tx(self._torque_cmd_msg(0, 0)))
|
||||
self.assertTrue(self._tx(self._knee_torque_cmd_msg(0, 0)))
|
||||
|
||||
def test_can_flasher(self):
|
||||
# CAN flasher always allowed
|
||||
self.safety.set_controls_allowed(False)
|
||||
self.assertTrue(self._tx(common.make_msg(0, 0x1, 8)))
|
||||
|
||||
# 0xdeadfaceU enters CAN flashing mode for base & knee
|
||||
for addr in (0x250, 0x350):
|
||||
self.assertTrue(self._tx(common.make_msg(0, addr, dat=b'\xce\xfa\xad\xde\x1e\x0b\xb0\x0a')))
|
||||
self.assertFalse(self._tx(common.make_msg(0, addr, dat=b'\xce\xfa\xad\xde\x1e\x0b\xb0'))) # not correct data/len
|
||||
self.assertFalse(self._tx(common.make_msg(0, addr + 1, dat=b'\xce\xfa\xad\xde\x1e\x0b\xb0\x0a'))) # wrong address
|
||||
# 0xdeadfaceU allowed for CAN flashing mode
|
||||
self.assertTrue(self._tx(common.make_msg(0, 0x250, dat=b'\xce\xfa\xad\xde\x1e\x0b\xb0\x0a')))
|
||||
self.assertFalse(self._tx(common.make_msg(0, 0x250, dat=b'\xce\xfa\xad\xde\x1e\x0b\xb0'))) # not correct data/len
|
||||
self.assertFalse(self._tx(common.make_msg(0, 0x251, dat=b'\xce\xfa\xad\xde\x1e\x0b\xb0\x0a'))) # wrong address
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user