2020-03-31 13:49:19 -07:00
|
|
|
/**
|
|
|
|
* @file can_verbose.cpp
|
|
|
|
*
|
|
|
|
* TODO: change 'verbose' into 'broadcast'?
|
|
|
|
*
|
2022-10-13 17:24:29 -07:00
|
|
|
* If you edit this file, please update rusEFI_CAN_verbose.dbc!
|
|
|
|
* Kvaser Database Editor works well for this task, and is free.
|
|
|
|
*
|
2020-03-31 13:49:19 -07:00
|
|
|
* @author Matthew Kennedy, (c) 2020
|
|
|
|
*/
|
2020-03-19 14:58:46 -07:00
|
|
|
|
2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
2020-03-19 14:58:46 -07:00
|
|
|
#if EFI_CAN_SUPPORT
|
|
|
|
|
2022-09-04 20:11:19 -07:00
|
|
|
#include "efi_scaled_channel.h"
|
2020-03-19 14:58:46 -07:00
|
|
|
#include "can_msg_tx.h"
|
2020-03-29 18:15:06 -07:00
|
|
|
#include "can.h"
|
2020-03-19 14:58:46 -07:00
|
|
|
#include "fuel_math.h"
|
|
|
|
#include "spark_logic.h"
|
|
|
|
|
|
|
|
struct Status {
|
2021-09-07 14:39:30 -07:00
|
|
|
uint16_t warningCounter;
|
|
|
|
uint16_t lastErrorCode;
|
2020-03-19 14:58:46 -07:00
|
|
|
|
2021-09-07 14:39:30 -07:00
|
|
|
uint8_t revLimit : 1;
|
|
|
|
uint8_t mainRelay : 1;
|
|
|
|
uint8_t fuelPump : 1;
|
|
|
|
uint8_t checkEngine : 1;
|
|
|
|
uint8_t o2Heater : 1;
|
2023-06-23 02:14:13 -07:00
|
|
|
uint8_t lambdaProtectActive : 1;
|
2020-03-19 14:58:46 -07:00
|
|
|
|
2021-09-07 14:39:30 -07:00
|
|
|
uint8_t pad7 : 1;
|
|
|
|
uint8_t pad8 : 1;
|
2020-03-19 14:58:46 -07:00
|
|
|
|
2023-04-28 13:02:52 -07:00
|
|
|
uint8_t gear;
|
|
|
|
|
|
|
|
uint8_t pad[2];
|
2020-03-19 14:58:46 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void populateFrame(Status& msg) {
|
2021-09-07 14:39:30 -07:00
|
|
|
msg.warningCounter = engine->engineState.warnings.warningCounter;
|
2023-04-11 17:01:34 -07:00
|
|
|
msg.lastErrorCode = static_cast<uint16_t>(engine->engineState.warnings.lastErrorCode);
|
2021-09-07 14:39:30 -07:00
|
|
|
|
2022-01-20 19:22:52 -08:00
|
|
|
msg.revLimit = Sensor::getOrZero(SensorType::Rpm) > engineConfiguration->rpmHardLimit;
|
2021-09-07 14:39:30 -07:00
|
|
|
msg.mainRelay = enginePins.mainRelay.getLogicValue();
|
|
|
|
msg.fuelPump = enginePins.fuelPumpRelay.getLogicValue();
|
|
|
|
msg.checkEngine = enginePins.checkEnginePin.getLogicValue();
|
|
|
|
msg.o2Heater = enginePins.o2heater.getLogicValue();
|
2023-06-29 00:10:18 -07:00
|
|
|
msg.lambdaProtectActive = engine->lambdaMonitor.isCut();
|
2023-06-23 02:14:13 -07:00
|
|
|
|
2023-04-30 08:50:00 -07:00
|
|
|
msg.gear = Sensor::getOrZero(SensorType::DetectedGear);
|
2020-03-19 14:58:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Speeds {
|
2021-09-07 14:39:30 -07:00
|
|
|
uint16_t rpm;
|
|
|
|
scaled_angle timing;
|
|
|
|
scaled_channel<uint8_t, 2> injDuty;
|
|
|
|
scaled_channel<uint8_t, 2> coilDuty;
|
|
|
|
scaled_channel<uint8_t> vssKph;
|
2022-08-01 12:27:06 -07:00
|
|
|
uint8_t EthanolPercent;
|
2020-03-19 14:58:46 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void populateFrame(Speeds& msg) {
|
2022-01-20 19:22:52 -08:00
|
|
|
auto rpm = Sensor::getOrZero(SensorType::Rpm);
|
2021-09-07 14:39:30 -07:00
|
|
|
msg.rpm = rpm;
|
2020-03-19 14:58:46 -07:00
|
|
|
|
2021-12-06 18:19:37 -08:00
|
|
|
auto timing = engine->engineState.timingAdvance[0];
|
2021-09-07 14:39:30 -07:00
|
|
|
msg.timing = timing > 360 ? timing - 720 : timing;
|
2020-03-19 14:58:46 -07:00
|
|
|
|
2021-09-07 14:39:30 -07:00
|
|
|
msg.injDuty = getInjectorDutyCycle(rpm);
|
|
|
|
msg.coilDuty = getCoilDutyCycle(rpm);
|
2020-03-19 14:58:46 -07:00
|
|
|
|
2021-10-05 16:59:07 -07:00
|
|
|
msg.vssKph = Sensor::getOrZero(SensorType::VehicleSpeed);
|
2022-08-01 12:27:06 -07:00
|
|
|
|
|
|
|
msg.EthanolPercent = Sensor::getOrZero(SensorType::FuelEthanolPercent);
|
2020-03-19 14:58:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
struct PedalAndTps {
|
2021-09-07 14:39:30 -07:00
|
|
|
scaled_percent pedal;
|
|
|
|
scaled_percent tps1;
|
|
|
|
scaled_percent tps2;
|
2023-04-28 13:02:52 -07:00
|
|
|
scaled_percent wastegate;
|
2020-03-19 14:58:46 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void populateFrame(PedalAndTps& msg)
|
|
|
|
{
|
2021-09-07 14:39:30 -07:00
|
|
|
msg.pedal = Sensor::get(SensorType::AcceleratorPedal).value_or(-1);
|
|
|
|
msg.tps1 = Sensor::get(SensorType::Tps1).value_or(-1);
|
|
|
|
msg.tps2 = Sensor::get(SensorType::Tps2).value_or(-1);
|
2023-04-28 13:02:52 -07:00
|
|
|
msg.wastegate = Sensor::get(SensorType::WastegatePosition).value_or(-1);
|
2020-03-19 14:58:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Sensors1 {
|
2021-09-07 14:39:30 -07:00
|
|
|
scaled_pressure map;
|
|
|
|
scaled_channel<uint8_t> clt;
|
|
|
|
scaled_channel<uint8_t> iat;
|
|
|
|
scaled_channel<uint8_t> aux1;
|
|
|
|
scaled_channel<uint8_t> aux2;
|
|
|
|
scaled_channel<uint8_t> mcuTemp;
|
|
|
|
scaled_channel<uint8_t, 2> fuelLevel;
|
2020-03-19 14:58:46 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void populateFrame(Sensors1& msg) {
|
2021-10-05 16:59:07 -07:00
|
|
|
msg.map = Sensor::getOrZero(SensorType::Map);
|
2020-03-19 14:58:46 -07:00
|
|
|
|
2021-10-05 16:59:07 -07:00
|
|
|
msg.clt = Sensor::getOrZero(SensorType::Clt) + PACK_ADD_TEMPERATURE;
|
|
|
|
msg.iat = Sensor::getOrZero(SensorType::Iat) + PACK_ADD_TEMPERATURE;
|
2020-03-19 14:58:46 -07:00
|
|
|
|
2021-10-05 16:59:07 -07:00
|
|
|
msg.aux1 = Sensor::getOrZero(SensorType::AuxTemp1) + PACK_ADD_TEMPERATURE;
|
|
|
|
msg.aux2 = Sensor::getOrZero(SensorType::AuxTemp2) + PACK_ADD_TEMPERATURE;
|
2020-03-19 14:58:46 -07:00
|
|
|
|
2022-07-03 05:25:24 -07:00
|
|
|
#if HAL_USE_ADC
|
2022-10-13 17:24:29 -07:00
|
|
|
msg.mcuTemp = getMCUInternalTemperature() + PACK_ADD_TEMPERATURE;
|
2022-07-03 05:25:24 -07:00
|
|
|
#endif
|
|
|
|
|
2021-10-05 16:59:07 -07:00
|
|
|
msg.fuelLevel = Sensor::getOrZero(SensorType::FuelLevel);
|
2020-03-19 14:58:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Sensors2 {
|
2022-08-01 12:27:06 -07:00
|
|
|
scaled_afr afr; // deprecated
|
2021-09-07 14:39:30 -07:00
|
|
|
scaled_pressure oilPressure;
|
2022-08-01 12:27:06 -07:00
|
|
|
scaled_angle vvtPos; // deprecated
|
2021-09-07 14:39:30 -07:00
|
|
|
scaled_voltage vbatt;
|
2020-03-19 14:58:46 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void populateFrame(Sensors2& msg) {
|
2021-10-05 16:59:07 -07:00
|
|
|
msg.afr = Sensor::getOrZero(SensorType::Lambda1) * STOICH_RATIO;
|
2021-09-07 14:39:30 -07:00
|
|
|
msg.oilPressure = Sensor::get(SensorType::OilPressure).value_or(-1);
|
2022-04-16 13:49:59 -07:00
|
|
|
#if EFI_SHAFT_POSITION_INPUT
|
2021-09-07 14:39:30 -07:00
|
|
|
msg.vvtPos = engine->triggerCentral.getVVTPosition(0, 0);
|
2022-04-16 13:49:59 -07:00
|
|
|
#endif // EFI_SHAFT_POSITION_INPUT
|
2021-10-05 16:59:07 -07:00
|
|
|
msg.vbatt = Sensor::getOrZero(SensorType::BatteryVoltage);
|
2020-03-19 14:58:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Fueling {
|
2021-09-07 14:39:30 -07:00
|
|
|
scaled_channel<uint16_t, 1000> cylAirmass;
|
|
|
|
scaled_channel<uint16_t, 100> estAirflow;
|
|
|
|
scaled_ms fuel_pulse;
|
2022-04-03 03:58:11 -07:00
|
|
|
uint16_t knockCount;
|
2020-03-19 14:58:46 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void populateFrame(Fueling& msg) {
|
2022-11-26 09:25:04 -08:00
|
|
|
msg.cylAirmass = engine->fuelComputer.sdAirMassInOneCylinder;
|
2022-01-12 12:41:35 -08:00
|
|
|
msg.estAirflow = engine->engineState.airflowEstimate;
|
2022-08-31 20:14:20 -07:00
|
|
|
msg.fuel_pulse = (float)engine->outputChannels.actualLastInjection;
|
2022-04-18 05:03:16 -07:00
|
|
|
msg.knockCount = engine->module<KnockController>()->getKnockCount();
|
2021-09-07 14:39:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Fueling2 {
|
|
|
|
scaled_channel<uint16_t> fuelConsumedGram;
|
|
|
|
scaled_channel<uint16_t, PACK_MULT_FUEL_FLOW> fuelFlowRate;
|
|
|
|
scaled_percent fuelTrim[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
static void populateFrame(Fueling2& msg) {
|
|
|
|
msg.fuelConsumedGram = engine->engineState.fuelConsumption.getConsumedGrams();
|
|
|
|
msg.fuelFlowRate = engine->engineState.fuelConsumption.getConsumptionGramPerSecond();
|
2020-03-19 14:58:46 -07:00
|
|
|
|
2021-09-07 14:39:30 -07:00
|
|
|
for (size_t i = 0; i < 2; i++) {
|
2021-11-17 00:54:21 -08:00
|
|
|
msg.fuelTrim[i] = 100.0f * (engine->stftCorrection[i] - 1.0f);
|
2021-09-07 14:39:30 -07:00
|
|
|
}
|
2020-03-19 14:58:46 -07:00
|
|
|
}
|
|
|
|
|
2022-08-01 12:27:06 -07:00
|
|
|
struct Fueling3 {
|
|
|
|
scaled_channel<uint16_t, 10000> Lambda;
|
|
|
|
scaled_channel<uint16_t, 10000> Lambda2;
|
|
|
|
scaled_channel<int16_t, 30> FuelPressureLow;
|
|
|
|
scaled_channel<int16_t, 10> FuelPressureHigh;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void populateFrame(Fueling3& msg) {
|
|
|
|
msg.Lambda = Sensor::getOrZero(SensorType::Lambda1);
|
|
|
|
msg.Lambda2 = Sensor::getOrZero(SensorType::Lambda2);
|
|
|
|
msg.FuelPressureLow = Sensor::getOrZero(SensorType::FuelPressureLow);
|
|
|
|
msg.FuelPressureHigh = KPA2BAR(Sensor::getOrZero(SensorType::FuelPressureHigh));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Cams {
|
|
|
|
int8_t Bank1IntakeActual;
|
|
|
|
int8_t Bank1IntakeTarget;
|
|
|
|
int8_t Bank1ExhaustActual;
|
|
|
|
int8_t Bank1ExhaustTarget;
|
|
|
|
int8_t Bank2IntakeActual;
|
|
|
|
int8_t Bank2IntakeTarget;
|
|
|
|
int8_t Bank2ExhaustActual;
|
|
|
|
int8_t Bank2ExhaustTarget;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void populateFrame(Cams& msg) {
|
2022-12-17 11:43:51 -08:00
|
|
|
#if EFI_SHAFT_POSITION_INPUT
|
2022-08-01 12:27:06 -07:00
|
|
|
msg.Bank1IntakeActual = engine->triggerCentral.getVVTPosition(0, 0);
|
|
|
|
msg.Bank1ExhaustActual = engine->triggerCentral.getVVTPosition(0, 1);
|
|
|
|
msg.Bank2IntakeActual = engine->triggerCentral.getVVTPosition(1, 0);
|
|
|
|
msg.Bank2ExhaustActual = engine->triggerCentral.getVVTPosition(1, 1);
|
2022-12-17 11:43:51 -08:00
|
|
|
#endif // EFI_SHAFT_POSITION_INPUT
|
|
|
|
|
2022-08-01 12:27:06 -07:00
|
|
|
// TODO: maybe don't rely on outputChannels here
|
|
|
|
msg.Bank1IntakeTarget = engine->outputChannels.vvtTargets[0];
|
|
|
|
msg.Bank1ExhaustTarget = engine->outputChannels.vvtTargets[1];
|
|
|
|
msg.Bank2IntakeTarget = engine->outputChannels.vvtTargets[2];
|
|
|
|
msg.Bank2ExhaustTarget = engine->outputChannels.vvtTargets[3];
|
|
|
|
}
|
|
|
|
|
2020-03-19 14:58:46 -07:00
|
|
|
void sendCanVerbose() {
|
2021-11-17 00:54:21 -08:00
|
|
|
auto base = engineConfiguration->verboseCanBaseAddress;
|
2021-11-28 11:59:26 -08:00
|
|
|
auto isExt = engineConfiguration->rusefiVerbose29b;
|
|
|
|
|
2022-05-09 13:49:23 -07:00
|
|
|
transmitStruct<Status> (CanCategory::VERBOSE, base + 0, isExt);
|
|
|
|
transmitStruct<Speeds> (CanCategory::VERBOSE, base + 1, isExt);
|
|
|
|
transmitStruct<PedalAndTps> (CanCategory::VERBOSE, base + CAN_PEDAL_TPS_OFFSET, isExt);
|
|
|
|
transmitStruct<Sensors1> (CanCategory::VERBOSE, base + CAN_SENSOR_1_OFFSET, isExt);
|
|
|
|
transmitStruct<Sensors2> (CanCategory::VERBOSE, base + 4, isExt);
|
|
|
|
transmitStruct<Fueling> (CanCategory::VERBOSE, base + 5, isExt);
|
|
|
|
transmitStruct<Fueling2> (CanCategory::VERBOSE, base + 6, isExt);
|
2022-08-01 12:27:06 -07:00
|
|
|
transmitStruct<Fueling3> (CanCategory::VERBOSE, base + 7, isExt);
|
|
|
|
transmitStruct<Cams> (CanCategory::VERBOSE, base + 8, isExt);
|
2020-03-19 14:58:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // EFI_CAN_SUPPORT
|