Move CAN Ignition Hooks from panda to opendbc #2970
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #1834
Summary
Ports the CAN-based ignition detection logic from panda's
board/drivers/can_common.hto opendbc as a standalone header. This allows opendbc's safety code to detect ignition state from CAN messages for vehicles that broadcast it (GM, Mazda, Rivian, Tesla).Implementation Details
ignition.hwithignition_can_hook()called fromsafety_rx_hook()ignition_can_init()called on safety mode changes to reset stateDetection Logic (verified against panda source)
data[0] & 0x2- SystemPowerMode Run/Crankdata[0] >> 5 == 6data[7] >> 4 & 0x3 == 1with counter validationdata[0] >> 5 & 0x3 == 3with counter validationTesting
Files Changed
opendbc/safety/ignition.h- New file with ignition detection logicopendbc/safety/safety.h- Include ignition.h, call hook in rx path, init on mode changeopendbc/safety/declarations.h- Add extern declarations for ignition_can stateopendbc/safety/tests/test_can_ignition.py- Test coverage for all supported vehiclesopendbc/safety/tests/libsafety/safety.c- Add get/set helpers for testingopendbc/safety/tests/libsafety/libsafety_py.py- FFI bindings for test helpers