Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GM Camera: use ECM brake pressed bit #1138

Merged
merged 10 commits into from
Nov 9, 2022
11 changes: 8 additions & 3 deletions board/safety/safety_gm.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ AddrCheckStruct gm_addr_checks[] = {
{190, 0, 7, .expected_timestep = 100000U}, // Bolt EUV
{190, 0, 8, .expected_timestep = 100000U}}}, // Escalade
{.msg = {{452, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}},
{.msg = {{201, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}},
};
#define GM_RX_CHECK_LEN (sizeof(gm_addr_checks) / sizeof(gm_addr_checks[0]))
addr_checks gm_rx_checks = {gm_addr_checks, GM_RX_CHECK_LEN};
Expand Down Expand Up @@ -119,12 +120,16 @@ static int gm_rx_hook(CANPacket_t *to_push) {
cruise_button_prev = button;
}

if (addr == 190) {
// Reference for signal and threshold:
// https://github.com/commaai/openpilot/blob/master/selfdrive/car/gm/carstate.py
// Reference for brake pressed signals:
// https://github.com/commaai/openpilot/blob/master/selfdrive/car/gm/carstate.py
if ((addr == 190) && (gm_hw == GM_ASCM)) {
brake_pressed = GET_BYTE(to_push, 1) >= 8U;
}

if ((addr == 201) && (gm_hw == GM_CAM)) {
brake_pressed = GET_BIT(to_push, 40U) != 0U;
}

if (addr == 452) {
gas_pressed = GET_BYTE(to_push, 5) != 0U;

Expand Down
25 changes: 20 additions & 5 deletions tests/safety/test_gm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ class Buttons:


class GmLongitudinalBase(common.PandaSafetyTest):
# pylint: disable=no-member,abstract-method

PCM_CRUISE = False # openpilot can control the PCM state if longitudinal

# pylint: disable=no-member,abstract-method
def test_set_resume_buttons(self):
"""
SET and RESUME enter controls allowed on their falling edge.
Expand Down Expand Up @@ -176,11 +177,26 @@ def setUp(self):
self.safety.init_tests()


class TestGmCameraSafety(TestGmSafetyBase):
class TestGmCameraSafetyBase(TestGmSafetyBase):

FWD_BUS_LOOKUP = {0: 2, 2: 0}

@classmethod
def setUpClass(cls):
if cls.__name__ == "TestGmCameraSafetyBase":
cls.packer = None
cls.safety = None
raise unittest.SkipTest

def _user_brake_msg(self, brake):
values = {"BrakePressed": brake}
return self.packer.make_can_msg_panda("ECMEngineStatus", 0, values)


class TestGmCameraSafety(TestGmCameraSafetyBase):
TX_MSGS = [[384, 0], # pt bus
[388, 2]] # camera bus
FWD_BLACKLISTED_ADDRS = {2: [384], 0: [388]} # block LKAS message and PSCMStatus
FWD_BUS_LOOKUP = {0: 2, 2: 0}
BUTTONS_BUS = 2 # tx only

def setUp(self):
Expand Down Expand Up @@ -212,11 +228,10 @@ def test_gas_safety_check(self):
pass


class TestGmCameraLongitudinalSafety(GmLongitudinalBase, TestGmSafetyBase):
class TestGmCameraLongitudinalSafety(GmLongitudinalBase, TestGmCameraSafetyBase):
TX_MSGS = [[384, 0], [789, 0], [715, 0], [880, 0], # pt bus
[388, 2]] # camera bus
FWD_BLACKLISTED_ADDRS = {2: [384, 715, 880, 789], 0: [388]} # block LKAS, ACC messages and PSCMStatus
FWD_BUS_LOOKUP = {0: 2, 2: 0}
BUTTONS_BUS = 0 # rx only

MAX_GAS = 3400
Expand Down