46 lines
1.6 KiB
C
46 lines
1.6 KiB
C
#pragma once
|
||
|
||
#include <Arduino.h>
|
||
|
||
// Nissan X-Trail T31 (2007–2014, including 2014 facelift).
|
||
// Same CAN COMM family as Qashqai J10: 500 kbit/s, 11-bit IDs.
|
||
// Tap: OBD pin 6/14, or BCM behind the glovebox (green 40-pin:
|
||
// pin 20 CAN-H blue, pin 40 CAN-L pink).
|
||
//
|
||
// Byte 0 = first data byte. Bit 0 = LSB of that byte.
|
||
|
||
static const unsigned long CAN_ID_BCM_60D = 0x60D;
|
||
|
||
static const uint8_t BCM60D_B0_DRIVER_OPEN = 0x10;
|
||
static const uint8_t BCM60D_B0_PASSENGER_OPEN = 0x20;
|
||
static const uint8_t BCM60D_B0_REAR_LH_OPEN = 0x40;
|
||
static const uint8_t BCM60D_B0_REAR_RH_OPEN = 0x80;
|
||
|
||
// data[1] bits 2–3: 00 OFF, 01 ACC, 11 ON, 10 START
|
||
static const uint8_t BCM60D_B1_IGN_MASK = 0x0C;
|
||
static const uint8_t BCM60D_B1_IGN_OFF = 0x00;
|
||
static const uint8_t BCM60D_B1_IGN_ACC = 0x04;
|
||
static const uint8_t BCM60D_B1_IGN_START = 0x08;
|
||
static const uint8_t BCM60D_B1_IGN_ON = 0x0C;
|
||
|
||
// data[2] C.4 / C.5 — any door locked
|
||
static const uint8_t BCM60D_B2_LOCKED = 0x18;
|
||
|
||
static const unsigned long CAN_ID_LOCK_358 = 0x358;
|
||
static const uint8_t LOCK358_B5_DRIVER_LOCKED = 0x01;
|
||
static const uint8_t LOCK358_B5_OTHER_LOCKED = 0x02;
|
||
|
||
inline bool bcm60dIgnOn(uint8_t b1) {
|
||
uint8_t ign = b1 & BCM60D_B1_IGN_MASK;
|
||
return ign == BCM60D_B1_IGN_ON || ign == BCM60D_B1_IGN_START;
|
||
}
|
||
|
||
inline bool bcm60dLocked(uint8_t b2) {
|
||
return (b2 & BCM60D_B2_LOCKED) != 0;
|
||
}
|
||
|
||
inline bool lock358FullyLocked(uint8_t b5) {
|
||
return (b5 & (LOCK358_B5_DRIVER_LOCKED | LOCK358_B5_OTHER_LOCKED)) ==
|
||
(LOCK358_B5_DRIVER_LOCKED | LOCK358_B5_OTHER_LOCKED);
|
||
}
|