Skip to content

Conversation

@rosacry
Copy link

@rosacry rosacry commented Dec 19, 2025

Closes #1834

Summary

Ports the CAN-based ignition detection logic from panda's board/drivers/can_common.h to 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

  • Created ignition.h with ignition_can_hook() called from safety_rx_hook()
  • Added ignition_can_init() called on safety mode changes to reset state
  • Counter validation for Rivian (mod 15) and Tesla (mod 16) prevents false positives from overlapping addresses

Detection Logic (verified against panda source)

Vehicle Address Logic
GM 0x1F1 data[0] & 0x2 - SystemPowerMode Run/Crank
Mazda 0x9E data[0] >> 5 == 6
Rivian 0x152 data[7] >> 4 & 0x3 == 1 with counter validation
Tesla 0x221 data[0] >> 5 & 0x3 == 3 with counter validation

Testing

  • 20 comprehensive unit tests covering:
    • Each vehicle's ignition on/off states
    • GM crank detection (SystemPowerMode)
    • Counter sequence requirements for Rivian and Tesla
    • Counter wraparound behavior
    • False positive prevention (Honda, Toyota, Subaru)
    • State reset on safety mode change
    • Test helper functions

Files Changed

  • opendbc/safety/ignition.h - New file with ignition detection logic
  • opendbc/safety/safety.h - Include ignition.h, call hook in rx path, init on mode change
  • opendbc/safety/declarations.h - Add extern declarations for ignition_can state
  • opendbc/safety/tests/test_can_ignition.py - Test coverage for all supported vehicles
  • opendbc/safety/tests/libsafety/safety.c - Add get/set helpers for testing
  • opendbc/safety/tests/libsafety/libsafety_py.py - FFI bindings for test helpers

Copilot AI review requested due to automatic review settings December 19, 2025 20:47
@github-actions github-actions bot added the car safety vehicle-specific safety code label Dec 19, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR moves CAN-based ignition detection logic from the panda firmware to opendbc's safety code. The implementation allows opendbc to detect ignition state from CAN messages for vehicles that broadcast it (GM, Mazda, Rivian, and Tesla), enabling more accurate ignition detection without relying solely on hardware signals.

Key changes:

  • New standalone ignition.h header with vehicle-specific ignition detection logic
  • Counter validation for Rivian (mod 15) and Tesla (mod 16) to prevent false positives from overlapping CAN addresses
  • Integration into safety_rx_hook for all incoming CAN messages and proper state reset on safety mode changes

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
opendbc/safety/ignition.h New header implementing CAN ignition detection for GM, Mazda, Rivian, and Tesla with counter-based validation for Rivian/Tesla
opendbc/safety/safety.h Integrates ignition hook into rx path and initializes state on safety mode changes
opendbc/safety/declarations.h Adds extern declarations for ignition_can state variables
opendbc/safety/tests/test_can_ignition.py Comprehensive test suite covering all supported vehicles, counter validation, wraparound, and false positive prevention
opendbc/safety/tests/libsafety/safety.c Adds get/set helper functions for testing ignition_can state
opendbc/safety/tests/libsafety/libsafety_py.py Adds FFI bindings for test helper functions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

car safety vehicle-specific safety code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[$250 bounty] Move CAN ignition hooks and add test

1 participant