Skip to content

Commit f99f5ce

Browse files
committed
from pr
1 parent 29a6703 commit f99f5ce

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

opendbc/safety/safety/safety_gm.h

+23-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
#include "safety_declarations.h"
44

5+
// TODO: do checksum and counter checks. Add correct timestep, 0.1s for now.
6+
#define GM_COMMON_RX_CHECKS \
7+
{.msg = {{0x184, 0, 8, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}, { 0 }, { 0 }}}, \
8+
{.msg = {{0x34A, 0, 5, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}, { 0 }, { 0 }}}, \
9+
{.msg = {{0x1E1, 0, 7, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}, { 0 }, { 0 }}}, \
10+
{.msg = {{0xBE, 0, 6, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}, /* Volt, Silverado, Acadia Denali */ \
11+
{0xBE, 0, 7, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}, /* Bolt EUV */ \
12+
{0xBE, 0, 8, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}}}, /* Escalade */ \
13+
{.msg = {{0x1C4, 0, 8, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}, { 0 }, { 0 }}}, \
14+
{.msg = {{0xC9, 0, 8, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}, { 0 }, { 0 }}}, \
15+
516
static const LongitudinalLimits *gm_long_limits;
617

718
enum {
@@ -18,13 +29,12 @@ typedef enum {
1829
static GmHardware gm_hw = GM_ASCM;
1930
static bool gm_cam_long = false;
2031
static bool gm_pcm_cruise = false;
32+
static bool gm_ev = false;
2133

2234
static void gm_rx_hook(const CANPacket_t *to_push) {
2335

2436
const int GM_STANDSTILL_THRSLD = 10; // 0.311kph
2537

26-
27-
2838
if (GET_BUS(to_push) == 0U) {
2939
int addr = GET_ADDR(to_push);
3040

@@ -178,6 +188,7 @@ static bool gm_fwd_hook(int bus_num, int addr) {
178188

179189
static safety_config gm_init(uint16_t param) {
180190
const uint16_t GM_PARAM_HW_CAM = 1;
191+
const uint16_t GM_PARAM_EV = 4;
181192

182193
static const LongitudinalLimits GM_ASCM_LONG_LIMITS = {
183194
.max_gas = 3072,
@@ -202,22 +213,20 @@ static safety_config gm_init(uint16_t param) {
202213
{0x184, 2, 8, false}}; // camera bus
203214

204215

205-
// TODO: do checksum and counter checks. Add correct timestep, 0.1s for now.
206216
static RxCheck gm_rx_checks[] = {
207-
{.msg = {{0x184, 0, 8, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}, { 0 }, { 0 }}},
208-
{.msg = {{0x34A, 0, 5, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}, { 0 }, { 0 }}},
209-
{.msg = {{0x1E1, 0, 7, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}, { 0 }, { 0 }}},
210-
{.msg = {{0xBE, 0, 6, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}, // Volt, Silverado, Acadia Denali
211-
{0xBE, 0, 7, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}, // Bolt EUV
212-
{0xBE, 0, 8, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}}}, // Escalade
213-
{.msg = {{0x1C4, 0, 8, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}, { 0 }, { 0 }}},
214-
{.msg = {{0xC9, 0, 8, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}, { 0 }, { 0 }}},
217+
GM_COMMON_RX_CHECKS
218+
};
219+
220+
static RxCheck gm_ev_rx_checks[] = {
221+
GM_COMMON_RX_CHECKS
222+
{.msg = {{0xBD, 0, 7, .ignore_checksum = true, .ignore_counter = true, .frequency = 40U}, { 0 }, { 0 }}},
215223
};
216224

217225
static const CanMsg GM_CAM_TX_MSGS[] = {{0x180, 0, 4, true}, // pt bus
218226
{0x1E1, 2, 7, false}, {0x184, 2, 8, false}}; // camera bus
219227

220228
gm_hw = GET_FLAG(param, GM_PARAM_HW_CAM) ? GM_CAM : GM_ASCM;
229+
gm_ev = GET_FLAG(param, GM_PARAM_EV);
221230

222231
if (gm_hw == GM_ASCM) {
223232
gm_long_limits = &GM_ASCM_LONG_LIMITS;
@@ -239,6 +248,9 @@ static safety_config gm_init(uint16_t param) {
239248
// cppcheck-suppress knownConditionTrueFalse
240249
ret = gm_cam_long ? BUILD_SAFETY_CFG(gm_rx_checks, GM_CAM_LONG_TX_MSGS) : BUILD_SAFETY_CFG(gm_rx_checks, GM_CAM_TX_MSGS);
241250
}
251+
if (gm_ev) {
252+
SET_RX_CHECKS(gm_ev_rx_checks, ret);
253+
}
242254
return ret;
243255
}
244256

opendbc/safety/tests/test_gm.py

+26-7
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ class TestGmSafetyBase(common.PandaCarSafetyTest, common.DriverTorqueSteeringSaf
8888

8989
PCM_CRUISE = True # openpilot is tied to the PCM state if not longitudinal
9090

91+
EXTRA_SAFETY_PARAM = 0
92+
9193
def setUp(self):
9294
self.packer = CANPackerPanda("gm_global_a_powertrain_generated")
9395
self.packer_chassis = CANPackerPanda("gm_global_a_chassis")
@@ -111,10 +113,6 @@ def _user_brake_msg(self, brake):
111113
values = {"BrakePedalPos": 8 if brake else 0}
112114
return self.packer.make_can_msg_panda("ECMAcceleratorPos", 0, values)
113115

114-
def _user_regen_msg(self, regen):
115-
values = {"RegenPaddle": 2 if regen else 0}
116-
return self.packer.make_can_msg_panda("EBCMRegenPaddle", 0, values)
117-
118116
def _user_gas_msg(self, gas):
119117
values = {"AcceleratorPedal2": 1 if gas else 0}
120118
if self.PCM_CRUISE:
@@ -136,6 +134,15 @@ def _button_msg(self, buttons):
136134
return self.packer.make_can_msg_panda("ASCMSteeringButton", self.BUTTONS_BUS, values)
137135

138136

137+
class TestGmEVSafetyBase(TestGmSafetyBase):
138+
EXTRA_SAFETY_PARAM = GMSafetyFlags.EV
139+
140+
# existence of _user_regen_msg adds regen tests
141+
def _user_regen_msg(self, regen):
142+
values = {"RegenPaddle": 2 if regen else 0}
143+
return self.packer.make_can_msg_panda("EBCMRegenPaddle", 0, values)
144+
145+
139146
class TestGmAscmSafety(GmLongitudinalBase, TestGmSafetyBase):
140147
TX_MSGS = [[0x180, 0], [0x409, 0], [0x40A, 0], [0x2CB, 0], [0x370, 0], # pt bus
141148
[0xA1, 1], [0x306, 1], [0x308, 1], [0x310, 1], # obs bus
@@ -152,10 +159,14 @@ def setUp(self):
152159
self.packer = CANPackerPanda("gm_global_a_powertrain_generated")
153160
self.packer_chassis = CANPackerPanda("gm_global_a_chassis")
154161
self.safety = libsafety_py.libsafety
155-
self.safety.set_safety_hooks(CarParams.SafetyModel.gm, 0)
162+
self.safety.set_safety_hooks(CarParams.SafetyModel.gm, self.EXTRA_SAFETY_PARAM)
156163
self.safety.init_tests()
157164

158165

166+
class TestGmAscmEVSafety(TestGmAscmSafety, TestGmEVSafetyBase):
167+
pass
168+
169+
159170
class TestGmCameraSafetyBase(TestGmSafetyBase):
160171
def _user_brake_msg(self, brake):
161172
values = {"BrakePressed": brake}
@@ -172,7 +183,7 @@ def setUp(self):
172183
self.packer = CANPackerPanda("gm_global_a_powertrain_generated")
173184
self.packer_chassis = CANPackerPanda("gm_global_a_chassis")
174185
self.safety = libsafety_py.libsafety
175-
self.safety.set_safety_hooks(CarParams.SafetyModel.gm, GMSafetyFlags.HW_CAM)
186+
self.safety.set_safety_hooks(CarParams.SafetyModel.gm, GMSafetyFlags.HW_CAM | self.EXTRA_SAFETY_PARAM)
176187
self.safety.init_tests()
177188

178189
def test_buttons(self):
@@ -190,6 +201,10 @@ def test_buttons(self):
190201
self.assertEqual(enabled, self._tx(self._button_msg(Buttons.CANCEL)))
191202

192203

204+
class TestGmCameraEVSafety(TestGmCameraSafety, TestGmEVSafetyBase):
205+
pass
206+
207+
193208
class TestGmCameraLongitudinalSafety(GmLongitudinalBase, TestGmCameraSafetyBase):
194209
TX_MSGS = [[0x180, 0], [0x315, 0], [0x2CB, 0], [0x370, 0], # pt bus
195210
[0x184, 2]] # camera bus
@@ -204,9 +219,13 @@ def setUp(self):
204219
self.packer = CANPackerPanda("gm_global_a_powertrain_generated")
205220
self.packer_chassis = CANPackerPanda("gm_global_a_chassis")
206221
self.safety = libsafety_py.libsafety
207-
self.safety.set_safety_hooks(CarParams.SafetyModel.gm, GMSafetyFlags.HW_CAM | GMSafetyFlags.HW_CAM_LONG)
222+
self.safety.set_safety_hooks(CarParams.SafetyModel.gm, GMSafetyFlags.HW_CAM | GMSafetyFlags.HW_CAM_LONG | self.EXTRA_SAFETY_PARAM)
208223
self.safety.init_tests()
209224

210225

226+
class TestGmCameraLongitudinalEVSafety(TestGmCameraLongitudinalSafety, TestGmEVSafetyBase):
227+
pass
228+
229+
211230
if __name__ == "__main__":
212231
unittest.main()

0 commit comments

Comments
 (0)