microRusEFI used as Body Control Module BCM BCU

This commit is contained in:
rusefi 2020-09-06 23:39:25 -04:00
parent 0e3d16b5d5
commit 995bc111ca
5 changed files with 35 additions and 16 deletions

View File

@ -14,6 +14,8 @@
#define CAN_PEDAL_TPS_OFFSET 2 #define CAN_PEDAL_TPS_OFFSET 2
#define CAN_SENSOR_1_OFFSET 3 #define CAN_SENSOR_1_OFFSET 3
#define CAN_TIMEOUT MS2NT(100)
class Logging; class Logging;
class CanSensorBase; class CanSensorBase;

View File

@ -124,7 +124,7 @@ static void handleGetDataRequest(const CANRxFrame& rx) {
obdSendValue(_1_MODE, pid, 2, (2<<8)|(0)); // 2 = "Closed loop, using oxygen sensor feedback to determine fuel mix" obdSendValue(_1_MODE, pid, 2, (2<<8)|(0)); // 2 = "Closed loop, using oxygen sensor feedback to determine fuel mix"
break; break;
case PID_ENGINE_LOAD: case PID_ENGINE_LOAD:
obdSendValue(_1_MODE, pid, 1, getFuelingLoad(PASS_ENGINE_PARAMETER_SIGNATURE) * 2.55f); obdSendValue(_1_MODE, pid, 1, getFuelingLoad(PASS_ENGINE_PARAMETER_SIGNATURE) * ODB_TPS_BYTE_PERCENT);
break; break;
case PID_COOLANT_TEMP: case PID_COOLANT_TEMP:
obdSendValue(_1_MODE, pid, 1, Sensor::get(SensorType::Clt).value_or(0) + ODB_TEMP_EXTRA); obdSendValue(_1_MODE, pid, 1, Sensor::get(SensorType::Clt).value_or(0) + ODB_TEMP_EXTRA);
@ -154,7 +154,7 @@ static void handleGetDataRequest(const CANRxFrame& rx) {
obdSendValue(_1_MODE, pid, 2, getRealMaf(PASS_ENGINE_PARAMETER_SIGNATURE) * 100.0f); // grams/sec (A*256+B)/100 obdSendValue(_1_MODE, pid, 2, getRealMaf(PASS_ENGINE_PARAMETER_SIGNATURE) * 100.0f); // grams/sec (A*256+B)/100
break; break;
case PID_THROTTLE: case PID_THROTTLE:
obdSendValue(_1_MODE, pid, 1, Sensor::get(SensorType::Tps1).value_or(0) * 2.55f); // (A*100/255) obdSendValue(_1_MODE, pid, 1, Sensor::get(SensorType::Tps1).value_or(0) * ODB_TPS_BYTE_PERCENT); // (A*100/255)
break; break;
case PID_FUEL_AIR_RATIO_1: { case PID_FUEL_AIR_RATIO_1: {
float lambda = Sensor::get(SensorType::Lambda).value_or(0); float lambda = Sensor::get(SensorType::Lambda).value_or(0);

View File

@ -45,3 +45,4 @@ void obdOnCanPacketRx(const CANRxFrame& rx);
#define ODB_RPM_MULT 4 #define ODB_RPM_MULT 4
#define ODB_TEMP_EXTRA 40 #define ODB_TEMP_EXTRA 40
#define ODB_TPS_BYTE_PERCENT 2.55f

View File

@ -12,6 +12,7 @@
#include "hal.h" #include "hal.h"
#include "can_msg_tx.h" #include "can_msg_tx.h"
#include "obd2.h" #include "obd2.h"
#include "can.h"
/** /**
* Sensor which reads it's value from CAN * Sensor which reads it's value from CAN
@ -79,12 +80,13 @@ private:
const uint8_t m_offset; const uint8_t m_offset;
}; };
template <int Size, int TScale> template <int Size, int Offset>
class ObdCanSensor: public CanSensorBase { class ObdCanSensor: public CanSensorBase {
public: public:
ObdCanSensor(int PID, SensorType type, efitick_t timeout) : ObdCanSensor(int PID, float Scale, SensorType type) :
CanSensorBase(OBD_TEST_RESPONSE, type, timeout) { CanSensorBase(OBD_TEST_RESPONSE, type, CAN_TIMEOUT) {
this->PID = PID; this->PID = PID;
this->Scale = Scale;
} }
void decodeFrame(const CANRxFrame& frame, efitick_t nowNt) override { void decodeFrame(const CANRxFrame& frame, efitick_t nowNt) override {
@ -99,7 +101,7 @@ public:
iValue = frame.data8[3]; iValue = frame.data8[3];
} }
float fValue = 1.0 * iValue / TScale; float fValue = (1.0 * iValue / Scale) - Offset;
setValidValue(fValue, nowNt); setValidValue(fValue, nowNt);
} }
@ -114,5 +116,6 @@ public:
} }
int PID; int PID;
float Scale;
}; };

View File

@ -14,30 +14,43 @@
EXTERN_CONFIG EXTERN_CONFIG
; ;
#define TIMEOUT MS2NT(100)
CanSensor<int16_t, PACK_MULT_PERCENT> canPedalSensor( CanSensor<int16_t, PACK_MULT_PERCENT> canPedalSensor(
CAN_DEFAULT_BASE + CAN_PEDAL_TPS_OFFSET, /*offset =*/ 0, CAN_DEFAULT_BASE + CAN_PEDAL_TPS_OFFSET, /*offset =*/ 0,
SensorType::AcceleratorPedal, TIMEOUT SensorType::AcceleratorPedal, CAN_TIMEOUT
); );
ObdCanSensor<2, ODB_RPM_MULT> obdRpmSensor( ObdCanSensor<2, 0> obdRpmSensor(
PID_RPM, PID_RPM, ODB_RPM_MULT,
SensorType::Rpm, TIMEOUT SensorType::Rpm
); );
ObdCanSensor<1, 1> obdCltSensor( ObdCanSensor<1, ODB_TEMP_EXTRA> obdCltSensor(
PID_COOLANT_TEMP, PID_COOLANT_TEMP, 1,
SensorType::Clt, TIMEOUT SensorType::Clt
); );
ObdCanSensor<1, ODB_TEMP_EXTRA> obdIatSensor(
PID_INTAKE_TEMP, 1,
SensorType::Iat
);
ObdCanSensor<1, 0> obdTpsSensor(
PID_INTAKE_TEMP, ODB_TPS_BYTE_PERCENT,
SensorType::Tps1
);
//ObdCanSensor<1, ODB_TPS_BYTE_PERCENT> obdTpsSensor(
// PID_ENGINE_LOAD,
// SensorType::Tps, TIMEOUT
//);
void initCanSensors() { void initCanSensors() {
if (CONFIG(consumeObdSensors)) { if (CONFIG(consumeObdSensors)) {
// registerCanSensor(canPedalSensor); // registerCanSensor(canPedalSensor);
registerCanSensor(obdRpmSensor); registerCanSensor(obdRpmSensor);
// registerCanSensor(obdCltSensor); // registerCanSensor(obdCltSensor);
// registerCanSensor(obdIatSensor);
// registerCanSensor(obdTpsSensor);
} }
} }
#endif // EFI_CAN_SUPPORT #endif // EFI_CAN_SUPPORT