mirror of
https://github.com/MoreTore/openpilot.git
synced 2026-09-30 19:33:49 +08:00
Merge panda subtree
This commit is contained in:
@@ -55,7 +55,7 @@ void set_toyota_camera_forwarded(int t);
|
||||
void set_toyota_rt_torque_last(int t);
|
||||
|
||||
void init_tests_honda(void);
|
||||
int get_honda_ego_speed(void);
|
||||
bool get_honda_moving(void);
|
||||
int get_honda_brake_prev(void);
|
||||
int get_honda_gas_prev(void);
|
||||
void set_honda_alt_brake_msg(bool);
|
||||
|
||||
@@ -32,6 +32,7 @@ struct sample_t subaru_torque_driver;
|
||||
TIM_TypeDef timer;
|
||||
TIM_TypeDef *TIM2 = &timer;
|
||||
|
||||
// from config.h
|
||||
#define MIN(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
@@ -42,6 +43,14 @@ TIM_TypeDef *TIM2 = &timer;
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a > _b ? _a : _b; })
|
||||
|
||||
// from llcan.h
|
||||
#define GET_BUS(msg) (((msg)->RDTR >> 4) & 0xFF)
|
||||
#define GET_LEN(msg) ((msg)->RDTR & 0xf)
|
||||
#define GET_ADDR(msg) ((((msg)->RIR & 4) != 0) ? ((msg)->RIR >> 3) : ((msg)->RIR >> 21))
|
||||
#define GET_BYTE(msg, b) (((int)(b) > 3) ? (((msg)->RDHR >> (8U * ((unsigned int)(b) % 4U))) & 0XFFU) : (((msg)->RDLR >> (8U * (unsigned int)(b))) & 0xFFU))
|
||||
#define GET_BYTES_04(msg) ((msg)->RDLR)
|
||||
#define GET_BYTES_48(msg) ((msg)->RDHR)
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
#define PANDA
|
||||
@@ -199,8 +208,8 @@ void set_subaru_desired_torque_last(int t){
|
||||
subaru_desired_torque_last = t;
|
||||
}
|
||||
|
||||
int get_honda_ego_speed(void){
|
||||
return honda_ego_speed;
|
||||
bool get_honda_moving(void){
|
||||
return honda_moving;
|
||||
}
|
||||
|
||||
int get_honda_brake_prev(void){
|
||||
@@ -274,7 +283,7 @@ void init_tests_subaru(void){
|
||||
}
|
||||
|
||||
void init_tests_honda(void){
|
||||
honda_ego_speed = 0;
|
||||
honda_moving = false;
|
||||
honda_brake_prev = 0;
|
||||
honda_gas_prev = 0;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import libpandasafety_py
|
||||
|
||||
MAX_BRAKE = 255
|
||||
|
||||
INTERCEPTOR_THRESHOLD = 328
|
||||
|
||||
class TestHondaSafety(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUp(cls):
|
||||
@@ -66,7 +68,9 @@ class TestHondaSafety(unittest.TestCase):
|
||||
to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *')
|
||||
to_send[0].RIR = addr << 21
|
||||
to_send[0].RDTR = 6
|
||||
to_send[0].RDLR = ((gas & 0xff) << 8) | ((gas & 0xff00) >> 8)
|
||||
gas2 = gas * 2
|
||||
to_send[0].RDLR = ((gas & 0xff) << 8) | ((gas & 0xff00) >> 8) | \
|
||||
((gas2 & 0xff) << 24) | ((gas2 & 0xff00) << 8)
|
||||
|
||||
return to_send
|
||||
|
||||
@@ -99,9 +103,9 @@ class TestHondaSafety(unittest.TestCase):
|
||||
self.assertFalse(self.safety.get_controls_allowed())
|
||||
|
||||
def test_sample_speed(self):
|
||||
self.assertEqual(0, self.safety.get_honda_ego_speed())
|
||||
self.assertEqual(0, self.safety.get_honda_moving())
|
||||
self.safety.safety_rx_hook(self._speed_msg(100))
|
||||
self.assertEqual(100, self.safety.get_honda_ego_speed())
|
||||
self.assertEqual(1, self.safety.get_honda_moving())
|
||||
|
||||
def test_prev_brake(self):
|
||||
self.assertFalse(self.safety.get_honda_brake_prev())
|
||||
@@ -176,16 +180,15 @@ class TestHondaSafety(unittest.TestCase):
|
||||
|
||||
def test_disengage_on_gas_interceptor(self):
|
||||
for long_controls_allowed in [0, 1]:
|
||||
self.safety.set_long_controls_allowed(long_controls_allowed)
|
||||
self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201))
|
||||
self.safety.set_controls_allowed(1)
|
||||
self.safety.safety_rx_hook(self._send_interceptor_msg(0x1000, 0x201))
|
||||
if long_controls_allowed:
|
||||
self.assertFalse(self.safety.get_controls_allowed())
|
||||
else:
|
||||
self.assertTrue(self.safety.get_controls_allowed())
|
||||
self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201))
|
||||
self.safety.set_gas_interceptor_detected(False)
|
||||
for g in range(0, 0x1000):
|
||||
self.safety.set_long_controls_allowed(long_controls_allowed)
|
||||
self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201))
|
||||
self.safety.set_controls_allowed(True)
|
||||
self.safety.safety_rx_hook(self._send_interceptor_msg(g, 0x201))
|
||||
remain_enabled = (not long_controls_allowed or g <= INTERCEPTOR_THRESHOLD)
|
||||
self.assertEqual(remain_enabled, self.safety.get_controls_allowed())
|
||||
self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201))
|
||||
self.safety.set_gas_interceptor_detected(False)
|
||||
self.safety.set_long_controls_allowed(True)
|
||||
|
||||
def test_allow_engage_with_gas_interceptor_pressed(self):
|
||||
|
||||
@@ -15,6 +15,8 @@ RT_INTERVAL = 250000
|
||||
|
||||
MAX_TORQUE_ERROR = 350
|
||||
|
||||
INTERCEPTOR_THRESHOLD = 475
|
||||
|
||||
def twos_comp(val, bits):
|
||||
if val >= 0:
|
||||
return val
|
||||
@@ -81,7 +83,9 @@ class TestToyotaSafety(unittest.TestCase):
|
||||
to_send = libpandasafety_py.ffi.new('CAN_FIFOMailBox_TypeDef *')
|
||||
to_send[0].RIR = addr << 21
|
||||
to_send[0].RDTR = 6
|
||||
to_send[0].RDLR = ((gas & 0xff) << 8) | ((gas & 0xff00) >> 8)
|
||||
gas2 = gas * 2
|
||||
to_send[0].RDLR = ((gas & 0xff) << 8) | ((gas & 0xff00) >> 8) | \
|
||||
((gas2 & 0xff) << 24) | ((gas2 & 0xff00) << 8)
|
||||
|
||||
return to_send
|
||||
|
||||
@@ -145,16 +149,15 @@ class TestToyotaSafety(unittest.TestCase):
|
||||
|
||||
def test_disengage_on_gas_interceptor(self):
|
||||
for long_controls_allowed in [0, 1]:
|
||||
self.safety.set_long_controls_allowed(long_controls_allowed)
|
||||
self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201))
|
||||
self.safety.set_controls_allowed(True)
|
||||
self.safety.safety_rx_hook(self._send_interceptor_msg(0x1000, 0x201))
|
||||
if long_controls_allowed:
|
||||
self.assertFalse(self.safety.get_controls_allowed())
|
||||
else:
|
||||
self.assertTrue(self.safety.get_controls_allowed())
|
||||
self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201))
|
||||
self.safety.set_gas_interceptor_detected(False)
|
||||
for g in range(0, 0x1000):
|
||||
self.safety.set_long_controls_allowed(long_controls_allowed)
|
||||
self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201))
|
||||
self.safety.set_controls_allowed(True)
|
||||
self.safety.safety_rx_hook(self._send_interceptor_msg(g, 0x201))
|
||||
remain_enabled = (not long_controls_allowed or g <= INTERCEPTOR_THRESHOLD)
|
||||
self.assertEqual(remain_enabled, self.safety.get_controls_allowed())
|
||||
self.safety.safety_rx_hook(self._send_interceptor_msg(0, 0x201))
|
||||
self.safety.set_gas_interceptor_detected(False)
|
||||
self.safety.set_long_controls_allowed(True)
|
||||
|
||||
def test_allow_engage_with_gas_interceptor_pressed(self):
|
||||
|
||||
Reference in New Issue
Block a user