Skip to content

Commit

Permalink
GM Camera: use ECM brake pressed bit (#1138)
Browse files Browse the repository at this point in the history
* GM camera: use ECM brake pressed bit

* back to ECMEngineStatus

* length 8

* common gmcamera class

* move to longitudinal base

* Revert "move to longitudinal base"

This reverts commit 67abe4c.

* fix
  • Loading branch information
sshane committed Nov 9, 2022
1 parent 8f7befa commit 281eb77
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
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

0 comments on commit 281eb77

Please sign in to comment.