rusefi-1/firmware/console/status_loop.cpp

860 lines
30 KiB
C++
Raw Normal View History

/**
* @file status_loop.cpp
* @brief Human-readable protocol status messages
*
2019-05-02 14:52:48 -07:00
* http://rusefi.com/forum/viewtopic.php?t=263 rusEfi console overview
* http://rusefi.com/forum/viewtopic.php?t=210 Commands overview
*
*
* @date Mar 15, 2013
2020-01-13 18:57:43 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
*
* This file is part of rusEfi - see http://rusefi.com
*
* rusEfi is free software; you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*
*/
2018-09-16 19:26:57 -07:00
#include "global.h"
#include "status_loop.h"
#include "hip9011_logic.h"
2019-01-11 16:08:15 -08:00
#include "engine_controller.h"
#include "adc_inputs.h"
#if EFI_LOGIC_ANALYZER
#include "logic_analyzer.h"
#endif /* EFI_LOGIC_ANALYZER */
#include "trigger_central.h"
2019-05-27 15:58:43 -07:00
#include "allsensors.h"
#include "sensor_reader.h"
#include "io_pins.h"
2019-03-29 06:11:13 -07:00
#include "efi_gpio.h"
#include "mmc_card.h"
#include "console_io.h"
#include "malfunction_central.h"
#include "speed_density.h"
#include "advance_map.h"
#include "tunerstudio.h"
#include "fuel_math.h"
#include "main_trigger_callback.h"
#include "engine_math.h"
#include "spark_logic.h"
#include "idle_thread.h"
#include "engine_configuration.h"
2019-07-06 17:15:49 -07:00
#include "os_util.h"
#include "svnversion.h"
#include "engine.h"
#include "lcd_controller.h"
#include "settings.h"
2018-01-29 16:41:39 -08:00
#include "can_hw.h"
#include "periodic_thread_controller.h"
2019-01-03 21:16:08 -08:00
#include "cdm_ion_sense.h"
#include "binary_logging.h"
extern afr_Map3D_t afrMap;
extern bool main_loop_started;
2019-04-12 19:10:57 -07:00
#if EFI_PROD_CODE
// todo: move this logic to algo folder!
#include "rtc_helper.h"
#include "lcd_HD44780.h"
#include "rusefi.h"
#include "pin_repository.h"
#include "flash_main.h"
#include "max31855.h"
#include "vehicle_speed.h"
2019-03-29 06:11:13 -07:00
#include "single_timer_executor.h"
#include "periodic_task.h"
extern int icuRisingCallbackCounter;
extern int icuFallingCallbackCounter;
2017-12-16 21:17:55 -08:00
#endif /* EFI_PROD_CODE */
2019-04-12 19:10:57 -07:00
#if EFI_CJ125
#include "cj125.h"
2018-11-03 08:44:57 -07:00
#endif /* EFI_CJ125 */
2018-02-06 13:21:41 -08:00
#if EFI_MAP_AVERAGING
#include "map_averaging.h"
#endif
2019-04-12 19:10:57 -07:00
#if EFI_FSIO
2017-12-16 21:17:55 -08:00
#include "fsio_impl.h"
#endif /* EFI_FSIO */
#if (BOARD_TLE8888_COUNT > 0)
#include "tle8888.h"
#endif /* BOARD_TLE8888_COUNT */
2019-07-13 07:36:31 -07:00
#if EFI_ENGINE_SNIFFER
#include "engine_sniffer.h"
extern WaveChart waveChart;
#endif /* EFI_ENGINE_SNIFFER */
int warningEnabled = true;
2018-09-17 18:42:04 -07:00
extern int maxTriggerReentraint;
extern uint32_t maxLockedDuration;
2019-12-21 17:35:13 -08:00
2019-04-12 19:10:57 -07:00
#if !defined(STATUS_LOGGING_BUFFER_SIZE)
#define STATUS_LOGGING_BUFFER_SIZE 1800
#endif /* STATUS_LOGGING_BUFFER_SIZE */
2019-01-03 21:16:08 -08:00
static char LOGGING_BUFFER[STATUS_LOGGING_BUFFER_SIZE] CCM_OPTIONAL;
static Logging logger("status loop", LOGGING_BUFFER, sizeof(LOGGING_BUFFER));
static void setWarningEnabled(int value) {
warningEnabled = value;
}
2019-04-12 19:10:57 -07:00
#if EFI_FILE_LOGGING
2017-05-03 18:24:18 -07:00
// this one needs to be in main ram so that SD card SPI DMA works fine
static char sdLogBuffer[2048] MAIN_RAM;
static uint64_t binaryLogCount = 0;
#endif /* EFI_FILE_LOGGING */
EXTERN_ENGINE;
static char buf[6];
/**
* This is useful if we are changing engine mode dynamically
* For example http://rusefi.com/forum/viewtopic.php?f=5&t=1085
*/
2017-05-15 20:28:49 -07:00
static int packEngineMode(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return (engineConfiguration->fuelAlgorithm << 4) +
(engineConfiguration->injectionMode << 2) +
engineConfiguration->ignitionMode;
}
2019-09-20 16:38:19 -07:00
static float getAirFlowGauge(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return hasMafSensor() ? getRealMaf(PASS_ENGINE_PARAMETER_SIGNATURE) : engine->engineState.airFlow;
}
void writeLogLine() {
#if EFI_FILE_LOGGING
if (!main_loop_started)
2018-01-24 18:31:42 -08:00
return;
size_t length = efi::size(sdLogBuffer);
if (binaryLogCount == 0) {
memset(sdLogBuffer, 0xAA, length);
writeHeader(sdLogBuffer);
} else {
updateTunerStudioState(&tsOutputChannels);
length = writeBlock(sdLogBuffer);
}
appendToLog(sdLogBuffer, length);
2017-05-15 17:23:45 -07:00
binaryLogCount++;
#endif /* EFI_FILE_LOGGING */
}
static int prevCkpEventCounter = -1;
static LoggingWithStorage logger2("main event handler");
/**
* Time when the firmware version was reported last time, in seconds
* TODO: implement a request/response instead of just constantly sending this out
*/
static systime_t timeOfPreviousPrintVersion = (systime_t) -1;
2019-04-12 19:10:57 -07:00
#if EFI_PROD_CODE
static void printOutPin(const char *pinName, brain_pin_e hwPin) {
if (hwPin != GPIO_UNASSIGNED) {
appendPrintf(&logger, "%s%s%s@%s%s", PROTOCOL_OUTPIN, DELIMETER, pinName, hwPortname(hwPin), DELIMETER);
}
}
#endif /* EFI_PROD_CODE */
void printOverallStatus(systime_t nowSeconds) {
2019-07-13 07:36:31 -07:00
#if EFI_ENGINE_SNIFFER
waveChart.publishIfFull();
#endif /* EFI_ENGINE_SNIFFER */
/**
* we report the version every 4 seconds - this way the console does not need to
* request it and we will display it pretty soon
*/
if (overflowDiff(nowSeconds, timeOfPreviousPrintVersion) < 4) {
return;
}
timeOfPreviousPrintVersion = nowSeconds;
2019-01-11 16:08:15 -08:00
int seconds = getTimeNowSeconds();
2019-07-13 11:08:08 -07:00
printCurrentState(&logger, seconds, getConfigurationName(engineConfiguration->engineType), FIRMWARE_ID);
2019-04-12 19:10:57 -07:00
#if EFI_PROD_CODE
printOutPin(PROTOCOL_CRANK1, CONFIG(triggerInputPins)[0]);
printOutPin(PROTOCOL_CRANK2, CONFIG(triggerInputPins)[1]);
printOutPin(PROTOCOL_VVT_NAME, engineConfiguration->camInputs[0]);
printOutPin(PROTOCOL_HIP_NAME, CONFIG(hip9011IntHoldPin));
printOutPin(PROTOCOL_TACH_NAME, CONFIG(tachOutputPin));
printOutPin(PROTOCOL_DIZZY_NAME, engineConfiguration->dizzySparkOutputPin);
#if EFI_LOGIC_ANALYZER
printOutPin(PROTOCOL_WA_CHANNEL_1, CONFIG(logicAnalyzerPins)[0]);
printOutPin(PROTOCOL_WA_CHANNEL_2, CONFIG(logicAnalyzerPins)[1]);
#endif /* EFI_LOGIC_ANALYZER */
for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
printOutPin(enginePins.coils[i].getShortName(), CONFIG(ignitionPins)[i]);
printOutPin(enginePins.injectors[i].getShortName(), CONFIG(injectionPins)[i]);
}
2017-11-27 18:49:58 -08:00
for (int i = 0; i < AUX_DIGITAL_VALVE_COUNT;i++) {
printOutPin(enginePins.auxValve[i].getShortName(), engineConfiguration->auxValves[i]);
2017-11-27 18:49:58 -08:00
}
#endif /* EFI_PROD_CODE */
scheduleLogging(&logger);
}
static systime_t timeOfPreviousReport = (systime_t) -1;
/**
2019-05-02 14:52:48 -07:00
* @brief Sends all pending data to rusEfi console
2018-04-01 20:29:00 -07:00
*
* This method is periodically invoked by the main loop
2020-06-13 19:46:10 -07:00
* todo: is this mostly dead code?
*/
void updateDevConsoleState(void) {
2018-04-01 20:29:00 -07:00
// todo: make SWO work
// char *msg = "hello\r\n";
// for(int i=0;i<strlen(msg);i++) {
// ITM_SendChar(msg[i]);
// }
if (!isCommandLineConsoleReady()) {
return;
}
2019-04-12 19:10:57 -07:00
#if EFI_PROD_CODE
// todo: unify with simulator!
if (hasFirmwareError()) {
2020-03-28 18:28:32 -07:00
scheduleMsg(&logger, "%s error: %s", CRITICAL_PREFIX, getFirmwareError());
warningEnabled = false;
scheduleLogging(&logger);
return;
}
2019-06-16 14:13:11 -07:00
#endif /* EFI_PROD_CODE */
2019-06-16 14:13:11 -07:00
#if HAL_USE_ADC
printFullAdcReportIfNeeded(&logger);
2019-06-16 14:13:11 -07:00
#endif /* HAL_USE_ADC */
systime_t nowSeconds = getTimeNowSeconds();
2019-04-12 19:10:57 -07:00
#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
int currentCkpEventCounter = engine->triggerCentral.triggerState.getTotalEventCounter();
if (prevCkpEventCounter == currentCkpEventCounter && timeOfPreviousReport == nowSeconds) {
return;
}
timeOfPreviousReport = nowSeconds;
prevCkpEventCounter = currentCkpEventCounter;
#else
chThdSleepMilliseconds(200);
#endif
#if EFI_LOGIC_ANALYZER
printWave(&logger);
#endif /* EFI_LOGIC_ANALYZER */
scheduleLogging(&logger);
}
/*
* command example:
* sfm 3500 400
* that would be 'show fuel for rpm 3500 maf 4.0'
*/
static void showFuelInfo2(float rpm, float engineLoad) {
float baseFuelMs = getBaseTableFuel((int) rpm, engineLoad);
2019-01-27 20:41:46 -08:00
float magicAir = getCylinderAirMass(1, 100, convertCelsiusToKelvin(20) PASS_ENGINE_PARAMETER_SUFFIX);
2020-06-03 18:12:12 -07:00
scheduleMsg(&logger, "SD magic fuel %.2f", getInjectionDurationForAirmass(magicAir, 14.7 PASS_ENGINE_PARAMETER_SUFFIX));
2018-01-23 09:05:14 -08:00
scheduleMsg(&logger, "inj flow %.2fcc/min displacement %.2fL", engineConfiguration->injector.flow,
engineConfiguration->specs.displacement);
scheduleMsg(&logger2, "algo=%s/pump=%s", getEngine_load_mode_e(engineConfiguration->fuelAlgorithm),
boolToString(enginePins.fuelPumpRelay.getLogicValue()));
scheduleMsg(&logger2, "injection phase=%.2f/global fuel correction=%.2f", getInjectionOffset(rpm), engineConfiguration->globalFuelCorrection);
2018-01-23 09:05:14 -08:00
scheduleMsg(&logger2, "baro correction=%.2f", engine->engineState.baroCorrection);
2019-04-12 19:10:57 -07:00
#if EFI_ENGINE_CONTROL
2018-01-23 09:05:14 -08:00
scheduleMsg(&logger, "base cranking fuel %.2f", engineConfiguration->cranking.baseFuel);
scheduleMsg(&logger2, "cranking fuel: %.2f", getCrankingFuel(PASS_ENGINE_PARAMETER_SIGNATURE));
2017-07-06 16:30:18 -07:00
if (!engine->rpmCalculator.isStopped(PASS_ENGINE_PARAMETER_SIGNATURE)) {
2019-08-26 20:41:04 -07:00
float iatCorrection = engine->engineState.running.intakeTemperatureCoefficient;
float cltCorrection = engine->engineState.running.coolantTemperatureCoefficient;
floatms_t injectorLag = engine->engineState.running.injectorLag;
2018-01-23 09:05:14 -08:00
scheduleMsg(&logger2, "rpm=%.2f engineLoad=%.2f", rpm, engineLoad);
scheduleMsg(&logger2, "baseFuel=%.2f", baseFuelMs);
2018-01-23 09:05:14 -08:00
scheduleMsg(&logger2, "iatCorrection=%.2f cltCorrection=%.2f injectorLag=%.2f", iatCorrection, cltCorrection,
injectorLag);
2017-05-15 20:28:49 -07:00
float value = getRunningFuel(baseFuelMs PASS_ENGINE_PARAMETER_SUFFIX);
2018-01-23 09:05:14 -08:00
scheduleMsg(&logger2, "injection pulse width: %.2f", value);
}
#endif
}
2019-04-12 19:10:57 -07:00
#if EFI_ENGINE_CONTROL
static void showFuelInfo(void) {
2019-01-21 18:48:58 -08:00
showFuelInfo2((float) GET_RPM(), getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE));
}
#endif
static OutputPin *leds[] = { &enginePins.warningLedPin, &enginePins.runningLedPin,
2018-07-26 12:51:06 -07:00
&enginePins.errorLedPin, &enginePins.communicationLedPin, &enginePins.checkEnginePin };
static void initStatusLeds(void) {
2018-07-26 12:51:06 -07:00
enginePins.communicationLedPin.initPin("led: comm status", engineConfiguration->communicationLedPin);
// we initialize this here so that we can blink it on start-up
enginePins.checkEnginePin.initPin("Check engine light", CONFIG(malfunctionIndicatorPin), &CONFIG(malfunctionIndicatorPinMode));
2017-04-21 14:50:28 -07:00
enginePins.warningLedPin.initPin("led: warning status", engineConfiguration->warningLedPin);
2018-07-26 12:51:06 -07:00
enginePins.runningLedPin.initPin("led: running status", engineConfiguration->runningLedPin);
enginePins.debugTriggerSync.initPin("debug: sync", CONFIG(debugTriggerSync));
}
2019-04-12 19:10:57 -07:00
#if EFI_PROD_CODE
static bool isTriggerErrorNow() {
2019-04-12 19:10:57 -07:00
#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
2019-12-21 18:18:38 -08:00
bool justHadError = (getTimeNowNt() - engine->triggerCentral.triggerState.lastDecodingErrorTime) < MS2NT(200);
return justHadError || isTriggerDecoderError();
2019-01-31 14:55:23 -08:00
#else
return false;
#endif /* EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT */
}
extern bool consoleByteArrived;
class CommunicationBlinkingTask : public PeriodicTimerController {
int getPeriodMs() override {
return counter % 2 == 0 ? onTimeMs : offTimeMs;
}
void setAllLeds(int value) {
2020-03-28 18:28:32 -07:00
// make sure we do not turn the critical LED off if already have
// critical error by now
2019-07-13 11:08:08 -07:00
for (uint32_t i = 0; !hasFirmwareError() && i < sizeof(leds) / sizeof(leds[0]); i++) {
leds[i]->setValue(value);
}
}
void PeriodicTask() override {
counter++;
bool lowVBatt = getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE) < LOW_VBATT;
if (counter == 1) {
// first invocation of BlinkingTask
setAllLeds(1);
} else if (counter == 2) {
// second invocation of BlinkingTask
setAllLeds(0);
} else if (counter % 2 == 0) {
enginePins.communicationLedPin.setValue(0);
2020-05-20 19:15:47 -07:00
#if HW_CHECK_MODE
// we have to do anything possible to help users notice FACTORY MODE
enginePins.errorLedPin.setValue(1);
enginePins.runningLedPin.setValue(1);
#endif // HW_CHECK_MODE
if (!lowVBatt) {
enginePins.warningLedPin.setValue(0);
}
} else {
#define BLINKING_PERIOD_MS 33
if (hasFirmwareError()) {
2020-03-28 18:28:32 -07:00
// special behavior in case of critical error - not equal on/off time
// this special behaviour helps to notice that something is not right, also
2020-03-28 18:28:32 -07:00
// differentiates software firmware error from critical interrupt error with CPU halt.
offTimeMs = 50;
onTimeMs = 450;
} else if (consoleByteArrived) {
consoleByteArrived = false;
offTimeMs = 100;
onTimeMs = 33;
#if EFI_INTERNAL_FLASH
} else if (getNeedToWriteConfiguration()) {
offTimeMs = onTimeMs = 500;
#endif // EFI_INTERNAL_FLASH
} else {
onTimeMs = is_usb_serial_ready() ? 3 * BLINKING_PERIOD_MS : BLINKING_PERIOD_MS;
offTimeMs = 0.6 * onTimeMs;
}
enginePins.communicationLedPin.setValue(1);
2020-05-20 19:15:47 -07:00
#if HW_CHECK_MODE
// we have to do anything possible to help users notice FACTORY MODE
enginePins.errorLedPin.setValue(0);
enginePins.runningLedPin.setValue(0);
#endif // HW_CHECK_MODE
#if EFI_ENGINE_CONTROL
if (lowVBatt || isTriggerErrorNow() || isIgnitionTimingError()) {
// todo: at the moment warning codes do not affect warning LED?!
enginePins.warningLedPin.setValue(1);
}
#endif /* EFI_ENGINE_CONTROL */
}
}
private:
int counter = 0;
int onTimeMs = 100;
int offTimeMs = 100;
};
static CommunicationBlinkingTask communicationsBlinkingTask;
#endif /* EFI_PROD_CODE */
2019-04-12 19:10:57 -07:00
#if EFI_LCD
2019-02-11 12:09:24 -08:00
class LcdController : public PeriodicController<UTILITY_THREAD_STACK_SIZE> {
public:
2019-12-14 06:12:37 -08:00
LcdController() : PeriodicController("LCD") { }
2019-02-11 12:09:24 -08:00
private:
void PeriodicTask(efitick_t nowNt) override {
UNUSED(nowNt);
2020-06-13 19:46:10 -07:00
setPeriod(NOT_TOO_OFTEN(10 /* ms */, 300));
if (engineConfiguration->useLcdScreen) {
#if EFI_HD44780_LCD
2017-05-08 05:15:46 -07:00
updateHD44780lcd();
#endif
}
}
2019-02-11 12:09:24 -08:00
};
static LcdController lcdInstance;
#endif /* EFI_LCD */
2019-04-12 19:10:57 -07:00
#if EFI_HIP_9011
extern HIP9011 instance;
2017-04-09 19:07:41 -07:00
#endif /* EFI_HIP_9011 */
2019-09-20 16:38:19 -07:00
2019-04-12 19:10:57 -07:00
#if EFI_TUNER_STUDIO
2017-05-15 20:28:49 -07:00
void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ENGINE_PARAMETER_SUFFIX) {
2019-04-12 19:10:57 -07:00
#if EFI_SHAFT_POSITION_INPUT
2019-01-21 18:48:58 -08:00
int rpm = GET_RPM();
2019-01-03 21:16:08 -08:00
#else /* EFI_SHAFT_POSITION_INPUT */
int rpm = 0;
2019-01-03 21:16:08 -08:00
#endif /* EFI_SHAFT_POSITION_INPUT */
2019-04-12 19:10:57 -07:00
#if EFI_PROD_CODE
2017-06-07 19:55:05 -07:00
executorStatistics();
2019-01-03 21:16:08 -08:00
#endif /* EFI_PROD_CODE */
2017-06-07 19:55:05 -07:00
2017-05-15 20:28:49 -07:00
float engineLoad = getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE);
// header
tsOutputChannels->tsConfigVersion = TS_FILE_VERSION;
2019-09-20 16:38:19 -07:00
// offset 0
tsOutputChannels->rpm = rpm;
SensorResult clt = Sensor::get(SensorType::Clt);
tsOutputChannels->coolantTemperature = clt.Value;
tsOutputChannels->isCltError = !clt.Valid;
SensorResult iat = Sensor::get(SensorType::Iat);
tsOutputChannels->intakeAirTemperature = iat.Value;
tsOutputChannels->isIatError = !iat.Valid;
SensorResult auxTemp1 = Sensor::get(SensorType::AuxTemp1);
tsOutputChannels->auxTemp1 = auxTemp1.Value;
SensorResult auxTemp2 = Sensor::get(SensorType::AuxTemp2);
tsOutputChannels->auxTemp2 = auxTemp2.Value;
2020-02-27 00:28:49 -08:00
SensorResult tps1 = Sensor::get(SensorType::Tps1);
tsOutputChannels->throttlePosition = tps1.Value;
tsOutputChannels->isTpsError = !tps1.Valid;
tsOutputChannels->tpsADC = convertVoltageTo10bitADC(Sensor::getRaw(SensorType::Tps1Primary));
2020-02-27 00:28:49 -08:00
SensorResult tps2 = Sensor::get(SensorType::Tps2);
tsOutputChannels->throttle2Position = tps2.Value;
SensorResult pedal = Sensor::get(SensorType::AcceleratorPedal);
tsOutputChannels->pedalPosition = pedal.Value;
// Only report fail if you have one (many people don't)
2020-05-30 18:50:57 -07:00
tsOutputChannels->isPedalError = !pedal.Valid && Sensor::hasSensor(SensorType::AcceleratorPedalPrimary);
2020-02-27 00:28:49 -08:00
// Set raw sensors
2020-05-30 18:50:57 -07:00
tsOutputChannels->rawTps1Primary = Sensor::getRaw(SensorType::Tps1Primary);
tsOutputChannels->rawPpsPrimary = Sensor::getRaw(SensorType::AcceleratorPedalPrimary);
tsOutputChannels->rawClt = Sensor::getRaw(SensorType::Clt);
tsOutputChannels->rawIat = Sensor::getRaw(SensorType::Iat);
tsOutputChannels->rawOilPressure = Sensor::getRaw(SensorType::OilPressure);
2019-09-20 16:38:19 -07:00
// offset 16
tsOutputChannels->massAirFlowVoltage = hasMafSensor() ? getMafVoltage(PASS_ENGINE_PARAMETER_SIGNATURE) : 0;
2017-08-28 19:32:29 -07:00
2018-01-16 09:58:35 -08:00
if (hasAfrSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) {
2019-09-20 16:38:19 -07:00
// offset 20
2018-01-16 09:58:35 -08:00
tsOutputChannels->airFuelRatio = getAfr(PASS_ENGINE_PARAMETER_SIGNATURE);
}
2019-09-20 16:38:19 -07:00
// offset 24
tsOutputChannels->engineLoad = engineLoad;
2020-04-04 04:42:14 -07:00
// KLUDGE? we always show VBatt because Proteus board has VBatt input sensor hardcoded
2020-04-04 04:42:14 -07:00
// offset 28
tsOutputChannels->vBatt = getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE);
2019-09-20 16:38:19 -07:00
// offset 36
2019-04-12 19:10:57 -07:00
#if EFI_ANALOG_SENSORS
tsOutputChannels->baroPressure = hasBaroSensor() ? getBaroPressure() : 0;
#endif /* EFI_ANALOG_SENSORS */
2019-09-20 16:38:19 -07:00
// 48
tsOutputChannels->fuelBase = engine->engineState.baseFuel;
// 64
tsOutputChannels->actualLastInjection = ENGINE(actualLastInjection);
2017-05-18 12:57:55 -07:00
2019-09-20 16:38:19 -07:00
2019-09-22 04:37:36 -07:00
// 104
2019-09-22 04:49:26 -07:00
tsOutputChannels->rpmAcceleration = engine->rpmCalculator.getRpmAcceleration();
2019-09-20 16:38:19 -07:00
// offset 108
// For air-interpolated tCharge mode, we calculate a decent massAirFlow approximation, so we can show it to users even without MAF sensor!
tsOutputChannels->massAirFlow = getAirFlowGauge(PASS_ENGINE_PARAMETER_SIGNATURE);
2019-09-20 16:38:19 -07:00
// offset 116
// TPS acceleration
tsOutputChannels->deltaTps = engine->tpsAccelEnrichment.getMaxDelta();
// 128
tsOutputChannels->totalTriggerErrorCounter = engine->triggerCentral.triggerState.totalTriggerErrorCounter;
2019-09-20 16:38:19 -07:00
// 132
tsOutputChannels->orderingErrorCounter = engine->triggerCentral.triggerState.orderingErrorCounter;
// 68
tsOutputChannels->baroCorrection = engine->engineState.baroCorrection;
2019-09-20 16:38:19 -07:00
// 140
#if EFI_ENGINE_CONTROL
2019-09-20 16:38:19 -07:00
tsOutputChannels->injectorDutyCycle = getInjectorDutyCycle(rpm PASS_ENGINE_PARAMETER_SUFFIX);
#endif
2019-09-20 16:38:19 -07:00
// 148
tsOutputChannels->fuelTankLevel = engine->sensors.fuelTankLevel;
// 160
2019-10-16 21:06:54 -07:00
tsOutputChannels->wallFuelAmount = ENGINE(wallFuel[0]).getWallFuel();
2019-09-20 16:38:19 -07:00
// 164
tsOutputChannels->iatCorrection = ENGINE(engineState.running.intakeTemperatureCoefficient);
// 168
2019-10-16 21:06:54 -07:00
tsOutputChannels->wallFuelCorrection = ENGINE(wallFuel[0]).wallFuelCorrection;
2019-09-20 16:38:19 -07:00
// 184
tsOutputChannels->cltCorrection = ENGINE(engineState.running.coolantTemperatureCoefficient);
// 188
tsOutputChannels->fuelRunning = ENGINE(engineState.running.fuel);
// 196
tsOutputChannels->injectorLagMs = ENGINE(engineState.running.injectorLag);
// 224
efitimesec_t timeSeconds = getTimeNowSeconds();
tsOutputChannels->timeSeconds = timeSeconds;
#if EFI_SHAFT_POSITION_INPUT
2019-09-20 16:38:19 -07:00
// 248
tsOutputChannels->vvtPosition = engine->triggerCentral.getVVTPosition();
#endif
2019-09-20 16:38:19 -07:00
// 252
tsOutputChannels->engineMode = packEngineMode(PASS_ENGINE_PARAMETER_SIGNATURE);
2019-12-25 11:15:44 -08:00
// 120
2019-09-20 16:38:19 -07:00
tsOutputChannels->firmwareVersion = getRusEfiVersion();
// 268
tsOutputChannels->shortTermFuelTrim = 100.0f * (ENGINE(engineState.running.pidCorrection) - 1.0f);
// 276
tsOutputChannels->accelerationX = engine->sensors.accelerometer.x;
// 278
tsOutputChannels->accelerationY = engine->sensors.accelerometer.y;
// 280
tsOutputChannels->oilPressure = Sensor::get(SensorType::OilPressure).Value;
// 288
tsOutputChannels->injectionOffset = engine->engineState.injectionOffset;
2019-09-20 16:38:19 -07:00
if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) {
float mapValue = getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
// // offset 112
tsOutputChannels->veValue = engine->engineState.currentBaroCorrectedVE * PERCENT_MULT;
// todo: bug here? target afr could work based on real MAF?
tsOutputChannels->currentTargetAfr = afrMap.getValue(rpm, mapValue);
// offset 40
tsOutputChannels->manifoldAirPressure = mapValue;
}
tsOutputChannels->knockCount = engine->knockCount;
tsOutputChannels->knockLevel = engine->knockVolts;
2020-05-20 19:15:47 -07:00
#if HW_CHECK_MODE
tsOutputChannels->hasCriticalError = 1;
#else
2020-03-28 18:28:32 -07:00
tsOutputChannels->hasCriticalError = hasFirmwareError();
2020-05-20 19:15:47 -07:00
#endif // HW_CHECK_MODE
tsOutputChannels->isWarnNow = engine->engineState.warnings.isWarningNow(timeSeconds, true);
2019-04-12 19:10:57 -07:00
#if EFI_HIP_9011
tsOutputChannels->isKnockChipOk = (instance.invalidHip9011ResponsesCount == 0);
2018-05-30 21:32:44 -07:00
#endif /* EFI_HIP_9011 */
2020-03-24 16:55:12 -07:00
#if EFI_LAUNCH_CONTROL
tsOutputChannels->launchTriggered = engine->isLaunchCondition;
#endif
2019-09-20 16:38:19 -07:00
tsOutputChannels->tpsAccelFuel = engine->engineState.tpsAccelEnrich;
// engine load acceleration
if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) {
tsOutputChannels->engineLoadAccelExtra = engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE) * 100 / getMap(PASS_ENGINE_PARAMETER_SIGNATURE);
}
tsOutputChannels->engineLoadDelta = engine->engineLoadAccelEnrichment.getMaxDelta();
tsOutputChannels->checkEngine = hasErrorCodes();
#if HAL_USE_ADC
tsOutputChannels->internalMcuTemperature = getMCUInternalTemperature();
#endif /* HAL_USE_ADC */
#if EFI_MAX_31855
for (int i = 0; i < EGT_CHANNEL_COUNT; i++)
tsOutputChannels->egtValues.values[i] = getEgtValue(i);
#endif /* EFI_MAX_31855 */
#if EFI_IDLE_CONTROL
tsOutputChannels->idlePosition = getIdlePosition();
#endif
#if EFI_PROD_CODE
tsOutputChannels->isTriggerError = isTriggerErrorNow();
#if EFI_INTERNAL_FLASH
tsOutputChannels->needBurn = getNeedToWriteConfiguration();
#endif /* EFI_INTERNAL_FLASH */
#if EFI_FILE_LOGGING
tsOutputChannels->hasSdCard = isSdCardAlive();
#endif /* EFI_FILE_LOGGING */
tsOutputChannels->isFuelPumpOn = enginePins.fuelPumpRelay.getLogicValue();
tsOutputChannels->isFanOn = enginePins.fanRelay.getLogicValue();
tsOutputChannels->isO2HeaterOn = enginePins.o2heater.getLogicValue();
tsOutputChannels->isIgnitionEnabled = engineConfiguration->isIgnitionEnabled;
tsOutputChannels->isInjectionEnabled = engineConfiguration->isInjectionEnabled;
tsOutputChannels->isCylinderCleanupEnabled = engineConfiguration->isCylinderCleanupEnabled;
tsOutputChannels->isCylinderCleanupActivated = engine->isCylinderCleanupMode;
tsOutputChannels->secondTriggerChannelEnabled = engineConfiguration->secondTriggerChannelEnabled;
#if EFI_VEHICLE_SPEED
float vehicleSpeed = getVehicleSpeed();
tsOutputChannels->vehicleSpeedKph = vehicleSpeed;
tsOutputChannels->speedToRpmRatio = vehicleSpeed / rpm;
#endif /* EFI_VEHICLE_SPEED */
#endif /* EFI_PROD_CODE */
tsOutputChannels->fuelConsumptionPerHour = engine->engineState.fuelConsumption.perSecondConsumption;
tsOutputChannels->warningCounter = engine->engineState.warnings.warningCounter;
tsOutputChannels->lastErrorCode = engine->engineState.warnings.lastErrorCode;
for (int i = 0; i < 8;i++) {
tsOutputChannels->recentErrorCodes[i] = engine->engineState.warnings.recentWarnings.get(i);
}
tsOutputChannels->knockNowIndicator = engine->knockCount > 0;
tsOutputChannels->knockEverIndicator = engine->knockEver;
tsOutputChannels->clutchUpState = engine->clutchUpState;
tsOutputChannels->clutchDownState = engine->clutchDownState;
tsOutputChannels->brakePedalState = engine->brakePedalState;
tsOutputChannels->acSwitchState = engine->acSwitchState;
#if EFI_ENGINE_CONTROL
2019-09-20 16:38:19 -07:00
// tCharge depends on the previous state, so we should use the stored value.
tsOutputChannels->tCharge = ENGINE(engineState.sd.tCharge);
float timing = engine->engineState.timingAdvance;
tsOutputChannels->ignitionAdvance = timing > 360 ? timing - 720 : timing;
// 60
tsOutputChannels->sparkDwell = ENGINE(engineState.sparkDwell);
tsOutputChannels->crankingFuelMs = engine->isCylinderCleanupMode ? 0 : getCrankingFuel(PASS_ENGINE_PARAMETER_SIGNATURE);
tsOutputChannels->chargeAirMass = engine->engineState.sd.airMassInOneCylinder;
tsOutputChannels->coilDutyCycle = getCoilDutyCycle(rpm PASS_ENGINE_PARAMETER_SUFFIX);
#endif // EFI_ENGINE_CONTROL
2019-09-20 16:38:19 -07:00
2017-12-03 04:42:44 -08:00
switch (engineConfiguration->debugMode) {
2020-03-23 07:32:41 -07:00
case DBG_START_STOP:
tsOutputChannels->debugIntField1 = engine->startStopStateToggleCounter;
break;
2017-12-17 10:14:39 -08:00
case DBG_STATUS:
2018-12-23 20:58:40 -08:00
tsOutputChannels->debugFloatField1 = timeSeconds;
2017-12-17 10:14:39 -08:00
tsOutputChannels->debugIntField1 = atoi(VCS_VERSION);
break;
2018-09-17 18:42:04 -07:00
case DBG_METRICS:
2019-04-12 19:10:57 -07:00
#if EFI_CLOCK_LOCKS
2018-09-17 18:42:04 -07:00
tsOutputChannels->debugIntField1 = maxLockedDuration;
tsOutputChannels->debugIntField2 = maxTriggerReentraint;
#endif /* EFI_CLOCK_LOCKS */
break;
2017-12-03 04:42:44 -08:00
case DBG_TPS_ACCEL:
tsOutputChannels->debugIntField1 = engine->tpsAccelEnrichment.cb.getSize();
2017-12-03 04:42:44 -08:00
break;
case DBG_SR5_PROTOCOL: {
const int _10_6 = 100000;
2017-03-26 19:45:19 -07:00
tsOutputChannels->debugIntField1 = tsState.textCommandCounter * _10_6 + tsState.totalCounter;
tsOutputChannels->debugIntField2 = tsState.outputChannelsCommandCounter * _10_6 + tsState.writeValueCommandCounter;
tsOutputChannels->debugIntField3 = tsState.readPageCommandsCounter * _10_6 + tsState.burnCommandCounter;
2017-12-03 04:42:44 -08:00
break;
}
case DBG_AUX_VALVES:
2017-11-27 18:10:49 -08:00
tsOutputChannels->debugFloatField1 = engine->engineState.auxValveStart;
tsOutputChannels->debugFloatField2 = engine->engineState.auxValveEnd;
2017-12-03 04:42:44 -08:00
break;
2019-08-07 19:20:16 -07:00
case DBG_TRIGGER_COUNTERS:
tsOutputChannels->debugIntField1 = engine->triggerCentral.getHwEventCounter((int)SHAFT_PRIMARY_FALLING);
tsOutputChannels->debugIntField2 = engine->triggerCentral.getHwEventCounter((int)SHAFT_SECONDARY_FALLING);
// no one uses shaft so far tsOutputChannels->debugIntField3 = engine->triggerCentral.getHwEventCounter((int)SHAFT_3RD_FALLING);
2019-11-11 19:19:35 -08:00
#if EFI_PROD_CODE && HAL_USE_ICU == TRUE
tsOutputChannels->debugIntField3 = icuRisingCallbackCounter + icuFallingCallbackCounter;
2019-09-02 18:02:08 -07:00
tsOutputChannels->debugIntField4 = engine->triggerCentral.vvtEventRiseCounter;
tsOutputChannels->debugIntField5 = engine->triggerCentral.vvtEventFallCounter;
2019-08-07 16:49:13 -07:00
#endif /* EFI_PROD_CODE */
tsOutputChannels->debugFloatField1 = engine->triggerCentral.getHwEventCounter((int)SHAFT_PRIMARY_RISING);
tsOutputChannels->debugFloatField2 = engine->triggerCentral.getHwEventCounter((int)SHAFT_SECONDARY_RISING);
tsOutputChannels->debugIntField4 = engine->triggerCentral.triggerState.currentCycle.eventCount[0];
tsOutputChannels->debugIntField5 = engine->triggerCentral.triggerState.currentCycle.eventCount[1];
// debugFloatField6 used
// no one uses shaft so far tsOutputChannels->debugFloatField3 = engine->triggerCentral.getHwEventCounter((int)SHAFT_3RD_RISING);
2017-12-03 04:42:44 -08:00
break;
case DBG_FSIO_ADC:
// todo: implement a proper loop
if (engineConfiguration->fsioAdc[0] != EFI_ADC_NONE) {
strcpy(buf, "adcX");
tsOutputChannels->debugFloatField1 = getVoltage("fsio", engineConfiguration->fsioAdc[0] PASS_ENGINE_PARAMETER_SUFFIX);
}
2017-12-03 04:42:44 -08:00
break;
2017-12-16 21:17:55 -08:00
case DBG_FSIO_EXPRESSION:
2019-04-12 19:10:57 -07:00
#if EFI_PROD_CODE && EFI_FSIO
2017-12-16 21:17:55 -08:00
tsOutputChannels->debugFloatField1 = getFsioOutputValue(0 PASS_ENGINE_PARAMETER_SUFFIX);
tsOutputChannels->debugFloatField2 = getFsioOutputValue(1 PASS_ENGINE_PARAMETER_SUFFIX);
tsOutputChannels->debugFloatField3 = getFsioOutputValue(2 PASS_ENGINE_PARAMETER_SUFFIX);
tsOutputChannels->debugFloatField4 = getFsioOutputValue(3 PASS_ENGINE_PARAMETER_SUFFIX);
tsOutputChannels->debugFloatField5 = getFsioOutputValue(4 PASS_ENGINE_PARAMETER_SUFFIX);
tsOutputChannels->debugFloatField6 = getFsioOutputValue(5 PASS_ENGINE_PARAMETER_SUFFIX);
tsOutputChannels->debugFloatField7 = getFsioOutputValue(6 PASS_ENGINE_PARAMETER_SUFFIX);
#endif /* EFI_FSIO */
break;
2017-12-03 04:42:44 -08:00
case DBG_VEHICLE_SPEED_SENSOR:
2017-05-21 20:17:08 -07:00
tsOutputChannels->debugIntField1 = engine->engineState.vssEventCounter;
2017-12-03 04:42:44 -08:00
break;
case DBG_CRANKING_DETAILS:
tsOutputChannels->debugIntField1 = engine->rpmCalculator.getRevolutionCounterSinceStart();
2017-12-03 04:42:44 -08:00
break;
2019-04-12 19:10:57 -07:00
#if EFI_HIP_9011
2017-12-03 04:42:44 -08:00
case DBG_KNOCK:
// todo: maybe extract hipPostState(tsOutputChannels);
tsOutputChannels->debugIntField1 = instance.correctResponsesCount;
tsOutputChannels->debugIntField2 = instance.invalidHip9011ResponsesCount;
2017-12-03 04:42:44 -08:00
break;
2017-04-09 19:07:41 -07:00
#endif /* EFI_HIP_9011 */
2019-04-12 19:10:57 -07:00
#if EFI_CJ125 && HAL_USE_SPI
case DBG_CJ125:
cjPostState(tsOutputChannels);
break;
2019-02-01 20:16:34 -08:00
#endif /* EFI_CJ125 && HAL_USE_SPI */
2018-02-06 13:21:41 -08:00
#if EFI_MAP_AVERAGING
case DBG_MAP:
postMapState(tsOutputChannels);
break;
#endif /* EFI_MAP_AVERAGING */
2019-04-12 19:10:57 -07:00
#if EFI_CAN_SUPPORT
2018-01-29 16:41:39 -08:00
case DBG_CAN:
postCanState(tsOutputChannels);
break;
#endif /* EFI_CAN_SUPPORT */
case DBG_ANALOG_INPUTS:
tsOutputChannels->debugFloatField1 = (engineConfiguration->vbattAdcChannel != EFI_ADC_NONE) ? getVoltageDivided("vbatt", engineConfiguration->vbattAdcChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f;
tsOutputChannels->debugFloatField2 = Sensor::getRaw(SensorType::Tps1);
tsOutputChannels->debugFloatField3 = (engineConfiguration->mafAdcChannel != EFI_ADC_NONE) ? getVoltageDivided("maf", engineConfiguration->mafAdcChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f;
tsOutputChannels->debugFloatField4 = (engineConfiguration->map.sensor.hwChannel != EFI_ADC_NONE) ? getVoltageDivided("map", engineConfiguration->map.sensor.hwChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f;
tsOutputChannels->debugFloatField5 = (engineConfiguration->clt.adcChannel != EFI_ADC_NONE) ? getVoltageDivided("clt", engineConfiguration->clt.adcChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f;
tsOutputChannels->debugFloatField6 = (engineConfiguration->iat.adcChannel != EFI_ADC_NONE) ? getVoltageDivided("iat", engineConfiguration->iat.adcChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f;
tsOutputChannels->debugFloatField7 = (engineConfiguration->afr.hwChannel != EFI_ADC_NONE) ? getVoltageDivided("ego", engineConfiguration->afr.hwChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f;
2017-12-03 04:42:44 -08:00
break;
case DBG_ANALOG_INPUTS2:
tsOutputChannels->debugFloatField1 = Sensor::get(SensorType::Tps1Primary).value_or(0) - Sensor::get(SensorType::Tps1Secondary).value_or(0);
tsOutputChannels->debugFloatField2 = Sensor::get(SensorType::Tps2Primary).value_or(0) - Sensor::get(SensorType::Tps2Secondary).value_or(0);
break;
2017-12-16 21:17:55 -08:00
case DBG_INSTANT_RPM:
2017-12-05 20:49:39 -08:00
{
2017-12-13 18:08:34 -08:00
float instantRpm = engine->triggerCentral.triggerState.instantRpm;
2017-12-05 20:49:39 -08:00
tsOutputChannels->debugFloatField1 = instantRpm;
2019-01-21 17:33:21 -08:00
tsOutputChannels->debugFloatField2 = instantRpm / GET_RPM_VALUE;
2017-12-05 20:49:39 -08:00
}
break;
2019-01-03 21:16:08 -08:00
case DBG_ION:
2019-05-05 14:21:36 -07:00
#if EFI_CDM_INTEGRATION
ionPostState(tsOutputChannels);
#endif /* EFI_CDM_INTEGRATION */
2019-01-03 21:16:08 -08:00
break;
case DBG_TLE8888:
#if (BOARD_TLE8888_COUNT > 0)
tle8888PostState(tsOutputChannels->getDebugChannels());
#endif /* BOARD_TLE8888_COUNT */
break;
2017-12-03 04:42:44 -08:00
default:
;
}
}
void prepareTunerStudioOutputs(void) {
// sensor state for EFI Analytics Tuner Studio
2017-05-15 20:28:49 -07:00
updateTunerStudioState(&tsOutputChannels PASS_ENGINE_PARAMETER_SUFFIX);
}
#endif /* EFI_TUNER_STUDIO */
void initStatusLoop(void) {
addConsoleActionI("warn", setWarningEnabled);
2019-04-12 19:10:57 -07:00
#if EFI_ENGINE_CONTROL
addConsoleActionFF("fuelinfo2", (VoidFloatFloat) showFuelInfo2);
addConsoleAction("fuelinfo", showFuelInfo);
#endif
}
void startStatusThreads(void) {
// todo: refactoring needed, this file should probably be split into pieces
2019-04-12 19:10:57 -07:00
#if EFI_PROD_CODE
initStatusLeds();
communicationsBlinkingTask.Start();
#endif /* EFI_PROD_CODE */
2019-04-12 19:10:57 -07:00
#if EFI_LCD
2019-02-11 12:09:24 -08:00
lcdInstance.Start();
#endif /* EFI_LCD */
}