2020-03-31 13:49:19 -07:00
|
|
|
/**
|
|
|
|
* @file can_verbose.cpp
|
|
|
|
*
|
|
|
|
* TODO: change 'verbose' into 'broadcast'?
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
|
|
|
|
#include "scaled_channel.h"
|
|
|
|
#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;
|
2020-03-19 14:58:46 -07:00
|
|
|
|
2021-09-07 14:39:30 -07:00
|
|
|
uint8_t pad6 : 1;
|
|
|
|
uint8_t pad7 : 1;
|
|
|
|
uint8_t pad8 : 1;
|
2020-03-19 14:58:46 -07:00
|
|
|
|
2021-09-07 14:39:30 -07:00
|
|
|
uint8_t pad[3];
|
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;
|
|
|
|
msg.lastErrorCode = engine->engineState.warnings.lastErrorCode;
|
|
|
|
|
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();
|
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;
|
|
|
|
uint8_t pad[1];
|
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);
|
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;
|
|
|
|
uint8_t pad[2];
|
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);
|
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
|
2021-09-07 14:39:30 -07:00
|
|
|
msg.mcuTemp = getMCUInternalTemperature();
|
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 {
|
2021-09-07 14:39:30 -07:00
|
|
|
scaled_afr afr;
|
|
|
|
scaled_pressure oilPressure;
|
|
|
|
scaled_angle vvtPos;
|
|
|
|
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) {
|
2021-09-07 14:39:30 -07:00
|
|
|
msg.cylAirmass = engine->engineState.sd.airMassInOneCylinder;
|
2022-01-12 12:41:35 -08:00
|
|
|
msg.estAirflow = engine->engineState.airflowEstimate;
|
2021-09-07 14:39:30 -07:00
|
|
|
msg.fuel_pulse = engine->actualLastInjection[0];
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2020-03-19 14:58:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // EFI_CAN_SUPPORT
|