35 PID_FUEL_SYSTEM_STATUS,
59 static void obdSendPacket(
int mode,
int PID,
int numBytes, uint32_t iValue,
size_t busIndex) {
66 resp[0] = (uint8_t)(2 + numBytes);
68 resp[1] = (uint8_t)(0x40 + mode);
69 resp[2] = (uint8_t)PID;
71 for (
int i = 8 * (numBytes - 1), j = 3; i >= 0; i -= 8, j++) {
72 resp[j] = (uint8_t)((iValue >> i) & 0xff);
78 static void obdSendValue(
int mode,
int PID,
int numBytes,
float value,
size_t busIndex) {
80 int iValue = (int)
efiRound(value, 1.0f);
82 iValue = maxI(minI(iValue, (numBytes == 1) ? 255 : 65535), 0);
92 for (
int i = 0; i < 32 && supportedPids[i] > 0; i++)
93 value |= 1 << (31 + bitOffset - supportedPids[i]);
95 #ifdef MOCK_SUPPORTED_PIDS
97 value = MOCK_SUPPORTED_PIDS;
104 int pid = rx.
data8[2];
106 case PID_SUPPORTED_PIDS_REQUEST_01_20:
109 case PID_SUPPORTED_PIDS_REQUEST_21_40:
112 case PID_SUPPORTED_PIDS_REQUEST_41_60:
115 case PID_MONITOR_STATUS:
118 case PID_FUEL_SYSTEM_STATUS:
122 case PID_ENGINE_LOAD:
125 case PID_COOLANT_TEMP:
143 case PID_TIMING_ADVANCE: {
145 timing = (timing > 360.0f) ? (timing - 720.0f) : timing;
146 obdSendValue(_1_MODE, pid, 1, (timing + 64.0f) * 2.0f, busIndex);
149 case PID_INTAKE_TEMP:
158 case PID_FUEL_AIR_RATIO_1: {
161 uint16_t scaled = lambda * 32768;
165 }
case PID_FUEL_RATE: {
167 float gPerHour = gPerSecond * 3600;
168 float literPerHour = gPerHour * 0.00139f;
169 obdSendValue(_1_MODE, pid, 2, literPerHour * 20.0f, busIndex);
193 if (CAN_SID(rx) != OBD_TEST_REQUEST) {
197 if (rx.
data8[0] == _OBD_2 && rx.
data8[1] == OBD_CURRENT_DATA) {
199 }
else if (rx.
data8[0] == 1 && rx.
data8[1] == OBD_STORED_DIAGNOSTIC_TROUBLE_CODES) {
202 }
else if (rx.
data8[0] == 1 && rx.
data8[1] == OBD_PENDING_DIAGNOSTIC_TROUBLE_CODES) {
float stftCorrection[STFT_BANK_COUNT]
constexpr auto & module()
WarningCodeState warnings
angle_t timingAdvance[MAX_CYLINDER_COUNT]
static float getOrZero(SensorType type)
float efiRound(float value, float precision)
UNUSED(samplingTimeSeconds)
static void handleDtcRequest(int numCodes, ObdCode *dtcCode)
static void obdSendPacket(int mode, int PID, int numBytes, uint32_t iValue, size_t busIndex)
static const int16_t supportedPids4160[]
static void obdWriteSupportedPids(int PID, int bitOffset, const int16_t *supportedPids, size_t busIndex)
static void obdSendValue(int mode, int PID, int numBytes, float value, size_t busIndex)
static const int16_t supportedPids2140[]
static void handleGetDataRequest(const CANRxFrame &rx, size_t busIndex)
static const int16_t supportedPids0120[]
void obdOnCanPacketRx(const CANRxFrame &rx, size_t busIndex)
uint8_t data8[8]
Frame data.