2017-03-24 10:41:36 -07:00
/**
* @ 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
2017-03-24 10:41:36 -07:00
* http : //rusefi.com/forum/viewtopic.php?t=210 Commands overview
*
*
* @ date Mar 15 , 2013
2018-01-20 17:55:31 -08:00
* @ author Andrey Belomutskiy , ( c ) 2012 - 2018
2017-03-24 10:41:36 -07:00
*
* 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"
2017-03-24 10:41:36 -07:00
# include "status_loop.h"
2019-04-01 14:04:49 -07:00
# include "hip9011_logic.h"
2019-01-11 16:08:15 -08:00
# include "engine_controller.h"
2017-03-24 10:41:36 -07:00
# include "adc_inputs.h"
2019-04-12 19:10:57 -07:00
# if EFI_WAVE_ANALYZER
2017-03-24 10:41:36 -07:00
# include "wave_analyzer.h"
# endif /* EFI_WAVE_ANALYZER */
# include "trigger_central.h"
2019-05-27 15:58:43 -07:00
# include "allsensors.h"
2017-03-24 10:41:36 -07:00
# include "io_pins.h"
2019-03-29 06:11:13 -07:00
# include "efi_gpio.h"
2017-03-24 10:41:36 -07:00
# 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"
2017-03-24 10:41:36 -07:00
# 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"
2019-07-08 00:35:41 -07:00
# include "periodic_thread_controller.h"
2019-01-03 21:16:08 -08:00
# include "cdm_ion_sense.h"
2017-03-24 10:41:36 -07:00
extern afr_Map3D_t afrMap ;
extern bool main_loop_started ;
2019-04-12 19:10:57 -07:00
# if EFI_PROD_CODE
2017-03-24 10:41:36 -07:00
// 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"
2019-07-13 07:24:23 -07:00
# include "periodic_task.h"
2019-08-07 16:49:13 -07:00
extern int vvtEventRiseCounter ;
extern int vvtEventFallCounter ;
2019-08-07 17:13:30 -07:00
extern int icuWidthCallbackCounter ;
extern int icuWidthPeriodCounter ;
2017-12-16 21:17:55 -08:00
# endif /* EFI_PROD_CODE */
2019-04-12 19:10:57 -07:00
# if EFI_CJ125
2019-04-01 14:04:49 -07:00
# 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 */
2017-03-24 10:41:36 -07:00
2019-07-13 07:36:31 -07:00
# if EFI_ENGINE_SNIFFER
# include "engine_sniffer.h"
extern WaveChart waveChart ;
# endif /* EFI_ENGINE_SNIFFER */
2017-03-24 10:41:36 -07:00
// this 'true' value is needed for simulator
static volatile bool fullLog = true ;
int warningEnabled = true ;
//int warningEnabled = FALSE;
2019-04-12 19:10:57 -07:00
# if EFI_TUNER_STUDIO
2017-03-24 10:41:36 -07:00
extern TunerStudioOutputChannels tsOutputChannels ;
2018-11-16 04:40:06 -08:00
extern tunerstudio_counters_s tsState ;
2017-03-24 10:41:36 -07:00
# endif
extern bool hasFirmwareErrorFlag ;
2018-09-17 18:42:04 -07:00
extern int maxTriggerReentraint ;
extern uint32_t maxLockedDuration ;
2017-03-24 10:41:36 -07:00
# define FULL_LOGGING_KEY "fl"
2019-04-12 19:10:57 -07:00
# if !defined(STATUS_LOGGING_BUFFER_SIZE)
2019-03-29 07:29:01 -07:00
# define STATUS_LOGGING_BUFFER_SIZE 1800
# endif /* STATUS_LOGGING_BUFFER_SIZE */
2019-01-03 21:16:08 -08:00
2019-03-29 07:29:01 -07:00
static char LOGGING_BUFFER [ STATUS_LOGGING_BUFFER_SIZE ] CCM_OPTIONAL ;
2017-03-24 10:41:36 -07:00
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 FILE_LOGGER [ 1000 ] MAIN_RAM ;
2017-03-24 10:41:36 -07:00
static Logging fileLogger ( " file logger " , FILE_LOGGER , sizeof ( FILE_LOGGER ) ) ;
# endif /* EFI_FILE_LOGGING */
static int logFileLineIndex = 0 ;
# define TAB "\t"
2019-07-13 06:54:06 -07:00
static void reportSensorF ( Logging * log , const char * caption , const char * units , float value ,
2017-03-24 10:41:36 -07:00
int precision ) {
2019-06-16 14:13:11 -07:00
bool isLogFileFormatting = true ;
2018-08-31 19:38:59 -07:00
if ( ! isLogFileFormatting ) {
2019-04-12 19:10:57 -07:00
# if EFI_PROD_CODE || EFI_SIMULATOR
2017-03-24 10:41:36 -07:00
debugFloat ( log , caption , value , precision ) ;
# endif /* EFI_PROD_CODE || EFI_SIMULATOR */
} else {
2019-04-12 19:10:57 -07:00
# if EFI_FILE_LOGGING
2017-03-24 10:41:36 -07:00
if ( logFileLineIndex = = 0 ) {
append ( log , caption ) ;
append ( log , TAB ) ;
} else if ( logFileLineIndex = = 1 ) {
append ( log , units ) ;
append ( log , TAB ) ;
} else {
appendFloat ( log , value , precision ) ;
append ( log , TAB ) ;
}
# endif /* EFI_FILE_LOGGING */
}
}
2019-07-13 06:54:06 -07:00
static void reportSensorI ( Logging * log , const char * caption , const char * units , int value ) {
2019-04-12 19:10:57 -07:00
# if EFI_FILE_LOGGING
2017-03-24 10:41:36 -07:00
if ( logFileLineIndex = = 0 ) {
append ( log , caption ) ;
append ( log , TAB ) ;
} else if ( logFileLineIndex = = 1 ) {
append ( log , units ) ;
append ( log , TAB ) ;
} else {
appendPrintf ( log , " %d%s " , value , TAB ) ;
}
# 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 ) {
2017-03-24 10:41:36 -07:00
return ( engineConfiguration - > fuelAlgorithm < < 4 ) +
( engineConfiguration - > injectionMode < < 2 ) +
engineConfiguration - > ignitionMode ;
}
2019-06-16 14:13:11 -07:00
static void printSensors ( Logging * log ) {
bool fileFormat = true ; // todo:remove this unused variable
2017-03-24 10:41:36 -07:00
// current time, in milliseconds
int nowMs = currentTimeMillis ( ) ;
float sec = ( ( float ) nowMs ) / 1000 ;
2019-07-13 06:54:06 -07:00
reportSensorF ( log , " time " , " " , sec , 3 ) ; // log column 1
2017-03-24 10:41:36 -07:00
int rpm = 0 ;
2019-04-12 19:10:57 -07:00
# if EFI_SHAFT_POSITION_INPUT
2019-01-21 18:48:58 -08:00
rpm = GET_RPM ( ) ;
2019-07-13 06:54:06 -07:00
reportSensorI ( log , " rpm " , " RPM " , rpm ) ; // log column 2
2017-03-24 10:41:36 -07:00
# endif
2018-01-24 18:31:42 -08:00
// why do we still send data into console in text mode?
2017-03-24 10:41:36 -07:00
if ( hasCltSensor ( ) ) {
2019-07-13 06:54:06 -07:00
reportSensorF ( log , " CLT " , " C " , getCoolantTemperature ( PASS_ENGINE_PARAMETER_SIGNATURE ) , 2 ) ; // log column #4
2017-03-24 10:41:36 -07:00
}
if ( hasTpsSensor ( ) ) {
2019-07-13 06:54:06 -07:00
reportSensorF ( log , " TPS " , " % " , getTPS ( PASS_ENGINE_PARAMETER_SIGNATURE ) , 2 ) ; // log column #5
2017-03-24 10:41:36 -07:00
}
2018-01-24 18:31:42 -08:00
if ( hasIatSensor ( ) ) {
2019-07-13 06:54:06 -07:00
reportSensorF ( log , " IAT " , " C " , getIntakeAirTemperature ( PASS_ENGINE_PARAMETER_SIGNATURE ) , 2 ) ; // log column #7
2018-01-24 18:31:42 -08:00
}
2018-01-24 19:17:10 -08:00
if ( hasVBatt ( PASS_ENGINE_PARAMETER_SIGNATURE ) ) {
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_NAME_VBAT , " V " , getVBatt ( PASS_ENGINE_PARAMETER_SIGNATURE ) , 2 ) ; // log column #6
2018-01-24 19:17:10 -08:00
}
2019-04-12 19:10:57 -07:00
# if EFI_ANALOG_SENSORS
2018-01-24 19:51:02 -08:00
if ( hasMapSensor ( PASS_ENGINE_PARAMETER_SIGNATURE ) ) {
2019-07-13 06:54:06 -07:00
reportSensorF ( log , " MAP " , " kPa " , getMap ( PASS_ENGINE_PARAMETER_SIGNATURE ) , 2 ) ;
// reportSensorF(log, "map_r", "V", getRawMap(), 2);
2018-01-24 19:51:02 -08:00
}
# endif /* EFI_ANALOG_SENSORS */
2019-04-12 19:10:57 -07:00
# if EFI_ANALOG_SENSORS
2018-01-24 19:51:02 -08:00
if ( hasBaroSensor ( ) ) {
2019-07-13 06:54:06 -07:00
reportSensorF ( log , " baro " , " kPa " , getBaroPressure ( ) , 2 ) ;
2018-01-24 19:51:02 -08:00
}
# endif /* EFI_ANALOG_SENSORS */
2018-01-24 18:31:42 -08:00
if ( ! fileFormat ) {
return ;
}
2018-01-25 06:42:08 -08:00
if ( hasAfrSensor ( PASS_ENGINE_PARAMETER_SIGNATURE ) ) {
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_NAME_AFR , " AFR " , getAfr ( PASS_ENGINE_PARAMETER_SIGNATURE ) , 2 ) ;
2018-01-25 06:42:08 -08:00
}
2018-01-24 18:31:42 -08:00
// below are the more advanced data points which only go into log file
2019-04-12 19:10:57 -07:00
# if HAL_USE_ADC
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_NAME_CPU_TEMP , " C " , getMCUInternalTemperature ( ) , 2 ) ; // log column #3
2018-01-24 18:31:42 -08:00
# endif
2019-07-13 06:54:06 -07:00
reportSensorI ( log , " mode " , " v " , packEngineMode ( PASS_ENGINE_PARAMETER_SIGNATURE ) ) ; // log column #3
2018-01-24 18:31:42 -08:00
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_NAME_ACCEL_X , " G " , engine - > sensors . accelerometer . x , 3 ) ;
reportSensorF ( log , GAUGE_NAME_ACCEL_Y , " G " , engine - > sensors . accelerometer . y , 3 ) ;
2017-08-28 19:55:29 -07:00
2017-03-24 10:41:36 -07:00
if ( hasMafSensor ( ) ) {
2019-07-13 06:54:06 -07:00
reportSensorF ( log , " maf " , " V " , getMafVoltage ( PASS_ENGINE_PARAMETER_SIGNATURE ) , 2 ) ;
reportSensorF ( log , " mafr " , " kg/hr " , getRealMaf ( PASS_ENGINE_PARAMETER_SIGNATURE ) , 2 ) ;
2017-03-24 10:41:36 -07:00
}
2019-04-12 19:10:57 -07:00
# if EFI_IDLE_CONTROL
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_NAME_IAC , " % " , getIdlePosition ( ) , 2 ) ;
2017-03-24 10:41:36 -07:00
# endif /* EFI_IDLE_CONTROL */
2019-04-12 19:10:57 -07:00
# if EFI_ANALOG_SENSORS
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_NAME_TARGET_AFR , " AFR " , engine - > engineState . targetAFR , 2 ) ;
2017-03-24 10:41:36 -07:00
# endif /* EFI_ANALOG_SENSORS */
2017-07-23 17:43:28 -07:00
# define DEBUG_F_PRECISION 6
2019-04-12 19:10:57 -07:00
# if EFI_TUNER_STUDIO
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_NAME_DEBUG_F1 , " v " , tsOutputChannels . debugFloatField1 , DEBUG_F_PRECISION ) ;
reportSensorF ( log , GAUGE_NAME_DEBUG_F2 , " v " , tsOutputChannels . debugFloatField2 , DEBUG_F_PRECISION ) ;
reportSensorF ( log , GAUGE_NAME_DEBUG_F3 , " v " , tsOutputChannels . debugFloatField3 , DEBUG_F_PRECISION ) ;
reportSensorF ( log , GAUGE_NAME_DEBUG_F4 , " v " , tsOutputChannels . debugFloatField4 , DEBUG_F_PRECISION ) ;
reportSensorF ( log , GAUGE_NAME_DEBUG_F5 , " v " , tsOutputChannels . debugFloatField5 , DEBUG_F_PRECISION ) ;
reportSensorF ( log , GAUGE_NAME_DEBUG_F6 , " v " , tsOutputChannels . debugFloatField6 , DEBUG_F_PRECISION ) ;
reportSensorF ( log , GAUGE_NAME_DEBUG_F7 , " v " , tsOutputChannels . debugFloatField7 , DEBUG_F_PRECISION ) ;
reportSensorI ( log , GAUGE_NAME_DEBUG_I1 , " v " , tsOutputChannels . debugIntField1 ) ;
reportSensorI ( log , GAUGE_NAME_DEBUG_I2 , " v " , tsOutputChannels . debugIntField2 ) ;
reportSensorI ( log , GAUGE_NAME_DEBUG_I3 , " v " , tsOutputChannels . debugIntField3 ) ;
reportSensorI ( log , GAUGE_NAME_DEBUG_I4 , " v " , tsOutputChannels . debugIntField4 ) ;
reportSensorI ( log , GAUGE_NAME_DEBUG_I5 , " v " , tsOutputChannels . debugIntField5 ) ;
2017-03-24 10:41:36 -07:00
# endif /* EFI_TUNER_STUDIO */
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_NAME_TCHARGE , " K " , engine - > engineState . sd . tChargeK , 2 ) ; // log column #8
2017-05-15 20:28:49 -07:00
if ( hasMapSensor ( PASS_ENGINE_PARAMETER_SIGNATURE ) ) {
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_NAME_FUEL_VE , " % " , engine - > engineState . currentBaroCorrectedVE * PERCENT_MULT , 2 ) ;
2017-03-24 10:41:36 -07:00
}
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_NAME_VVT , " deg " , engine - > triggerCentral . vvtPosition , 1 ) ;
2017-03-24 10:41:36 -07:00
2017-05-15 20:28:49 -07:00
float engineLoad = getEngineLoadT ( PASS_ENGINE_PARAMETER_SIGNATURE ) ;
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_NAME_ENGINE_LOAD , " x " , engineLoad , 2 ) ;
2017-03-24 10:41:36 -07:00
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_COIL_DWELL_TIME , " ms " , ENGINE ( engineState . sparkDwell ) , 2 ) ;
reportSensorF ( log , GAUGE_NAME_TIMING_ADVANCE , " deg " , engine - > engineState . timingAdvance , 2 ) ;
2017-03-24 10:41:36 -07:00
2017-05-15 20:28:49 -07:00
floatms_t fuelBase = getBaseFuel ( rpm PASS_ENGINE_PARAMETER_SUFFIX ) ;
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_NAME_FUEL_BASE , " ms " , fuelBase , 2 ) ;
reportSensorF ( log , GAUGE_NAME_FUEL_LAST_INJECTION , " ms " , ENGINE ( actualLastInjection ) , 2 ) ;
reportSensorF ( log , GAUGE_NAME_INJECTOR_LAG , " ms " , engine - > engineState . injectorLag , 2 ) ;
reportSensorF ( log , GAUGE_NAME_FUEL_RUNNING , " ms " , ENGINE ( engineState . runningFuel ) , 2 ) ;
reportSensorF ( log , GAUGE_NAME_FUEL_PID_CORR , " ms " , ENGINE ( engineState . fuelPidCorrection ) , 2 ) ;
2017-03-24 10:41:36 -07:00
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_NAME_FUEL_WALL_AMOUNT , " v " , ENGINE ( wallFuel ) . getWallFuel ( 0 ) , 2 ) ;
reportSensorF ( log , GAUGE_NAME_FUEL_WALL_CORRECTION , " v " , ENGINE ( wallFuel ) . wallFuelCorrection , 2 ) ;
2017-03-24 10:41:36 -07:00
2019-07-13 06:54:06 -07:00
reportSensorI ( log , GAUGE_NAME_VERSION , " # " , getRusEfiVersion ( ) ) ;
2017-03-24 10:41:36 -07:00
2019-04-12 19:10:57 -07:00
# if EFI_VEHICLE_SPEED
2017-03-24 10:41:36 -07:00
if ( hasVehicleSpeedSensor ( ) ) {
float vehicleSpeed = getVehicleSpeed ( ) ;
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_NAME_VVS , " kph " , vehicleSpeed , 2 ) ;
2017-03-24 10:41:36 -07:00
float sp2rpm = rpm = = 0 ? 0 : vehicleSpeed / rpm ;
2019-07-13 06:54:06 -07:00
reportSensorF ( log , " sp2rpm " , " x " , sp2rpm , 2 ) ;
2017-03-24 10:41:36 -07:00
}
# endif /* EFI_PROD_CODE */
2018-01-24 18:31:42 -08:00
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_NAME_KNOCK_COUNTER , " count " , engine - > knockCount , 0 ) ;
reportSensorF ( log , GAUGE_NAME_KNOCK_LEVEL , " v " , engine - > knockVolts , 2 ) ;
2017-03-24 10:41:36 -07:00
2019-07-13 06:54:06 -07:00
// reportSensorF(log, "vref", "V", getVRef(engineConfiguration), 2);
2018-01-24 18:31:42 -08:00
2017-03-24 10:41:36 -07:00
2019-07-13 06:54:06 -07:00
reportSensorF ( log , " f: tps delta " , " v " , engine - > tpsAccelEnrichment . getMaxDelta ( ) , 2 ) ;
reportSensorF ( log , GAUGE_NAME_FUEL_TPS_EXTRA , " ms " , engine - > engineState . tpsAccelEnrich , 2 ) ;
2017-03-24 10:41:36 -07:00
2019-07-13 06:54:06 -07:00
reportSensorF ( log , " f: el delta " , " v " , engine - > engineLoadAccelEnrichment . getMaxDelta ( ) , 2 ) ;
2017-05-15 20:28:49 -07:00
if ( hasMapSensor ( PASS_ENGINE_PARAMETER_SIGNATURE ) ) {
2019-07-13 06:54:06 -07:00
reportSensorF ( log , " f: el fuel " , " v " , engine - > engineLoadAccelEnrichment . getEngineLoadEnrichment ( PASS_ENGINE_PARAMETER_SIGNATURE ) * 100 / getMap ( PASS_ENGINE_PARAMETER_SIGNATURE ) , 2 ) ;
2017-03-24 10:41:36 -07:00
}
2019-07-13 06:54:06 -07:00
reportSensorF ( log , GAUGE_NAME_FUEL_INJ_DUTY , " % " , getInjectorDutyCycle ( rpm PASS_ENGINE_PARAMETER_SUFFIX ) , 2 ) ;
reportSensorF ( log , GAUGE_NAME_DWELL_DUTY , " % " , getCoilDutyCycle ( rpm PASS_ENGINE_PARAMETER_SUFFIX ) , 2 ) ;
2018-01-24 18:31:42 -08:00
2017-03-24 10:41:36 -07:00
// debugFloat(&logger, "tch", getTCharge1(tps), 2);
2017-08-06 16:43:01 -07:00
for ( int i = 0 ; i < FSIO_ANALOG_INPUT_COUNT ; i + + ) {
2017-03-24 10:41:36 -07:00
if ( engineConfiguration - > fsioAdc [ i ] ! = EFI_ADC_NONE ) {
strcpy ( buf , " adcX " ) ;
buf [ 3 ] = ' 0 ' + i ;
2019-07-13 06:54:06 -07:00
reportSensorF ( log , buf , " " , getVoltage ( " fsio " , engineConfiguration - > fsioAdc [ i ] ) , 2 ) ;
2017-03-24 10:41:36 -07:00
}
}
2019-07-13 06:54:06 -07:00
reportSensorI ( log , GAUGE_NAME_WARNING_COUNTER , " count " , engine - > engineState . warnings . warningCounter ) ;
reportSensorI ( log , GAUGE_NAME_WARNING_LAST , " code " , engine - > engineState . warnings . lastErrorCode ) ;
2017-03-24 10:41:36 -07:00
2019-07-13 06:54:06 -07:00
reportSensorI ( log , INDICATOR_NAME_CLUTCH_UP , " bool " , engine - > clutchUpState ) ;
reportSensorI ( log , INDICATOR_NAME_CLUTCH_DOWN , " bool " , engine - > clutchDownState ) ;
reportSensorI ( log , INDICATOR_NAME_BRAKE_DOWN , " bool " , engine - > brakePedalState ) ;
2017-05-15 17:23:45 -07:00
2017-03-24 10:41:36 -07:00
}
void writeLogLine ( void ) {
2019-04-12 19:10:57 -07:00
# if EFI_FILE_LOGGING
2017-03-24 10:41:36 -07:00
if ( ! main_loop_started )
return ;
resetLogging ( & fileLogger ) ;
2019-06-16 14:13:11 -07:00
printSensors ( & fileLogger ) ;
2017-03-24 10:41:36 -07:00
if ( isSdCardAlive ( ) ) {
appendPrintf ( & fileLogger , " \r \n " ) ;
appendToLog ( fileLogger . buffer ) ;
logFileLineIndex + + ;
}
# endif /* EFI_FILE_LOGGING */
}
# define INITIAL_FULL_LOG TRUE
//#define INITIAL_FULL_LOG FALSE
volatile int needToReportStatus = FALSE ;
static int prevCkpEventCounter = - 1 ;
static LoggingWithStorage logger2 ( " main event handler " ) ;
static void printStatus ( void ) {
needToReportStatus = TRUE ;
}
/**
* 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
2017-03-24 10:41:36 -07:00
static void printOutPin ( const char * pinName , brain_pin_e hwPin ) {
if ( hwPin ! = GPIO_UNASSIGNED ) {
2019-08-18 09:14:33 -07:00
appendPrintf ( & logger , " %s%s%s@%s%s " , PROTOCOL_OUTPIN , DELIMETER , pinName , hwPortname ( hwPin ) , DELIMETER ) ;
2017-03-24 10:41:36 -07:00
}
}
# endif /* EFI_PROD_CODE */
2019-07-13 11:08:08 -07:00
# ifndef FIRMWARE_ID
# define FIRMWARE_ID "source"
# endif
2018-04-01 20:49:57 -07:00
void printOverallStatus ( systime_t nowSeconds ) {
2019-07-13 07:36:31 -07:00
# if EFI_ENGINE_SNIFFER
waveChart . publishIfFull ( ) ;
# endif /* EFI_ENGINE_SNIFFER */
2017-03-24 10:41:36 -07:00
/**
* 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
2019-08-18 12:04:02 -07:00
printOutPin ( PROTOCOL_CRANK1 , CONFIGB ( triggerInputPins ) [ 0 ] ) ;
printOutPin ( PROTOCOL_CRANK2 , CONFIGB ( triggerInputPins ) [ 1 ] ) ;
printOutPin ( PROTOCOL_VVT_NAME , engineConfiguration - > camInputs [ 0 ] ) ;
printOutPin ( PROTOCOL_HIP_NAME , CONFIGB ( hip9011IntHoldPin ) ) ;
printOutPin ( PROTOCOL_TACH_NAME , CONFIGB ( tachOutputPin ) ) ;
printOutPin ( PROTOCOL_DIZZY_NAME , engineConfiguration - > dizzySparkOutputPin ) ;
2019-04-12 19:10:57 -07:00
# if EFI_WAVE_ANALYZER
2019-08-18 12:04:02 -07:00
printOutPin ( PROTOCOL_WA_CHANNEL_1 , CONFIGB ( logicAnalyzerPins ) [ 0 ] ) ;
printOutPin ( PROTOCOL_WA_CHANNEL_2 , CONFIGB ( logicAnalyzerPins ) [ 1 ] ) ;
2017-03-24 10:41:36 -07:00
# endif /* EFI_WAVE_ANALYZER */
for ( int i = 0 ; i < engineConfiguration - > specs . cylindersCount ; i + + ) {
2019-01-09 19:57:33 -08:00
printOutPin ( enginePins . coils [ i ] . name , CONFIGB ( ignitionPins ) [ i ] ) ;
2017-03-24 10:41:36 -07:00
2019-01-09 19:57:33 -08:00
printOutPin ( enginePins . injectors [ i ] . name , CONFIGB ( injectionPins ) [ i ] ) ;
2017-03-24 10:41:36 -07:00
}
2017-11-27 18:49:58 -08:00
for ( int i = 0 ; i < AUX_DIGITAL_VALVE_COUNT ; i + + ) {
printOutPin ( enginePins . auxValve [ i ] . name , engineConfiguration - > auxValves [ i ] ) ;
}
2017-03-24 10:41:36 -07:00
# endif /* EFI_PROD_CODE */
2018-04-01 20:49:57 -07:00
scheduleLogging ( & logger ) ;
2017-03-24 10:41:36 -07:00
}
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
2017-03-24 10:41:36 -07:00
*/
2017-04-09 19:26:11 -07:00
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]);
// }
2017-03-24 10:41:36 -07:00
if ( ! isCommandLineConsoleReady ( ) ) {
return ;
}
2019-04-12 19:10:57 -07:00
# if EFI_PROD_CODE
2017-03-24 10:41:36 -07:00
// todo: unify with simulator!
if ( hasFirmwareError ( ) ) {
2017-11-19 19:04:28 -08:00
scheduleMsg ( & logger , " FATAL error: %s " , getFirmwareError ( ) ) ;
2017-03-24 10:41:36 -07:00
warningEnabled = false ;
scheduleLogging ( & logger ) ;
return ;
}
2019-06-16 14:13:11 -07:00
# endif /* EFI_PROD_CODE */
2017-03-24 10:41:36 -07:00
2019-06-16 14:13:11 -07:00
# if HAL_USE_ADC
2017-03-24 10:41:36 -07:00
printFullAdcReportIfNeeded ( & logger ) ;
2019-06-16 14:13:11 -07:00
# endif /* HAL_USE_ADC */
2017-03-24 10:41:36 -07:00
systime_t nowSeconds = getTimeNowSeconds ( ) ;
2019-04-12 19:10:57 -07:00
# if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
2019-02-02 23:47:20 -08:00
int currentCkpEventCounter = engine - > triggerCentral . triggerState . getTotalEventCounter ( ) ;
2017-03-24 10:41:36 -07:00
if ( prevCkpEventCounter = = currentCkpEventCounter & & timeOfPreviousReport = = nowSeconds ) {
return ;
}
timeOfPreviousReport = nowSeconds ;
prevCkpEventCounter = currentCkpEventCounter ;
# else
chThdSleepMilliseconds ( 200 ) ;
# endif
# if EFI_WAVE_ANALYZER
printWave ( & logger ) ;
2019-06-16 14:13:11 -07:00
# endif /* EFI_WAVE_ANALYZER */
2017-03-24 10:41:36 -07:00
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 ) {
2017-04-12 20:25:58 -07:00
float baseFuelMs = getBaseTableFuel ( ( int ) rpm , engineLoad ) ;
2017-03-24 10:41:36 -07:00
2019-01-27 20:41:46 -08:00
float magicAir = getCylinderAirMass ( 1 , 100 , convertCelsiusToKelvin ( 20 ) PASS_ENGINE_PARAMETER_SUFFIX ) ;
2017-03-24 10:41:36 -07:00
2019-01-27 20:41:46 -08:00
scheduleMsg ( & logger , " SD magic fuel %.2f " , sdMath ( 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 ,
2017-03-24 10:41:36 -07:00
engineConfiguration - > specs . displacement ) ;
scheduleMsg ( & logger2 , " algo=%s/pump=%s " , getEngine_load_mode_e ( engineConfiguration - > fuelAlgorithm ) ,
boolToString ( enginePins . fuelPumpRelay . getLogicValue ( ) ) ) ;
2018-06-12 02:15:10 -07:00
scheduleMsg ( & logger2 , " injection phase=%.2f/global fuel correction=%.2f " , getInjectionOffset ( rpm ) , engineConfiguration - > globalFuelCorrection ) ;
2017-03-24 10:41:36 -07:00
2018-01-23 09:05:14 -08:00
scheduleMsg ( & logger2 , " baro correction=%.2f " , engine - > engineState . baroCorrection ) ;
2017-03-24 10:41:36 -07:00
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-03-24 10:41:36 -07:00
2017-07-06 16:30:18 -07:00
if ( ! engine - > rpmCalculator . isStopped ( PASS_ENGINE_PARAMETER_SIGNATURE ) ) {
2017-03-24 10:41:36 -07:00
float iatCorrection = engine - > engineState . iatFuelCorrection ;
float cltCorrection = engine - > engineState . cltFuelCorrection ;
floatms_t injectorLag = engine - > engineState . injectorLag ;
2018-01-23 09:05:14 -08:00
scheduleMsg ( & logger2 , " rpm=%.2f engineLoad=%.2f " , rpm , engineLoad ) ;
scheduleMsg ( & logger2 , " baseFuel=%.2f " , baseFuelMs ) ;
2017-03-24 10:41:36 -07:00
2018-01-23 09:05:14 -08:00
scheduleMsg ( & logger2 , " iatCorrection=%.2f cltCorrection=%.2f injectorLag=%.2f " , iatCorrection , cltCorrection ,
2017-03-24 10:41:36 -07:00
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 ) ;
2017-03-24 10:41:36 -07:00
}
# endif
}
2019-04-12 19:10:57 -07:00
# if EFI_ENGINE_CONTROL
2017-03-24 10:41:36 -07:00
static void showFuelInfo ( void ) {
2019-01-21 18:48:58 -08:00
showFuelInfo2 ( ( float ) GET_RPM ( ) , getEngineLoadT ( PASS_ENGINE_PARAMETER_SIGNATURE ) ) ;
2017-03-24 10:41:36 -07:00
}
# endif
2018-07-26 12:51:06 -07:00
static OutputPin * leds [ ] = { & enginePins . warningLedPin , & enginePins . runningLedPin , & enginePins . checkEnginePin ,
& enginePins . errorLedPin , & enginePins . communicationLedPin , & enginePins . checkEnginePin } ;
2017-03-24 10:41:36 -07:00
static void initStatusLeds ( void ) {
2018-07-26 12:51:06 -07:00
enginePins . communicationLedPin . initPin ( " led: comm status " , engineConfiguration - > communicationLedPin ) ;
2017-03-24 10:41:36 -07:00
// we initialize this here so that we can blink it on start-up
2019-01-09 19:57:33 -08:00
enginePins . checkEnginePin . initPin ( " MalfunctionIndicator " , CONFIGB ( malfunctionIndicatorPin ) , & CONFIGB ( malfunctionIndicatorPinMode ) ) ;
2017-04-21 14:50:28 -07:00
2019-04-28 20:04:52 -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 ) ;
2017-03-24 10:41:36 -07:00
}
2019-07-13 06:52:30 -07:00
# define BLINKING_PERIOD_MS 33
2017-03-24 10:41:36 -07:00
2019-04-12 19:10:57 -07:00
# if EFI_PROD_CODE
2017-03-24 10:41:36 -07:00
static bool isTriggerErrorNow ( ) {
2019-04-12 19:10:57 -07:00
# if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
2019-07-13 06:52:30 -07:00
bool justHadError = ( getTimeNowNt ( ) - engine - > triggerCentral . triggerState . lastDecodingErrorTime ) < US2NT ( MS2US ( 200 ) ) ;
2017-03-24 10:41:36 -07:00
return justHadError | | isTriggerDecoderError ( ) ;
2019-01-31 14:55:23 -08:00
# else
return false ;
# endif /* EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT */
2017-03-24 10:41:36 -07:00
}
extern bool consoleByteArrived ;
2019-07-13 08:06:03 -07:00
class CommunicationBlinkingTask : public PeriodicTimerController {
2017-03-24 10:41:36 -07:00
2019-07-13 07:24:23 -07:00
int getPeriodMs ( ) override {
return counter % 2 = = 0 ? onTimeMs : offTimeMs ;
}
2017-03-24 10:41:36 -07:00
2019-07-13 07:24:23 -07:00
void setAllLeds ( int value ) {
// make sure we do not turn the fatal LED off if already have
// fatal error by now
2019-07-13 11:08:08 -07:00
for ( uint32_t i = 0 ; ! hasFirmwareError ( ) & & i < sizeof ( leds ) / sizeof ( leds [ 0 ] ) ; i + + ) {
2019-07-13 07:24:23 -07:00
leds [ i ] - > setValue ( value ) ;
}
}
2017-03-24 10:41:36 -07:00
2019-07-13 07:24:23 -07:00
void PeriodicTask ( ) override {
counter + + ;
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 ) ;
enginePins . warningLedPin . setValue ( 0 ) ;
} else {
if ( hasFirmwareError ( ) ) {
// special behavior in case of fatal error - not equal on/off time
// this special behaviour helps to notice that something is not right, also
// differentiates software firmware error from fatal interrupt error with CPU halt.
offTimeMs = 50 ;
onTimeMs = 450 ;
} else {
onTimeMs = is_usb_serial_ready ( ) ? 3 * BLINKING_PERIOD_MS : BLINKING_PERIOD_MS ;
2019-04-12 19:10:57 -07:00
# if EFI_INTERNAL_FLASH
2019-07-13 07:24:23 -07:00
if ( getNeedToWriteConfiguration ( ) ) {
onTimeMs = 2 * onTimeMs ;
}
2017-03-24 10:41:36 -07:00
# endif
2019-07-13 07:24:23 -07:00
offTimeMs = onTimeMs ;
}
enginePins . communicationLedPin . setValue ( 1 ) ;
# if EFI_ENGINE_CONTROL
if ( isTriggerErrorNow ( ) | | isIgnitionTimingError ( ) | | consoleByteArrived ) {
consoleByteArrived = false ;
enginePins . warningLedPin . setValue ( 1 ) ;
}
# endif /* EFI_ENGINE_CONTROL */
2017-03-24 10:41:36 -07:00
}
2019-07-13 07:24:23 -07:00
}
2019-02-05 18:29:55 -08:00
2019-07-13 07:24:23 -07:00
private :
int counter = 0 ;
int onTimeMs = 100 ;
int offTimeMs = 100 ;
} ;
2017-03-24 10:41:36 -07:00
2019-07-13 08:06:03 -07:00
static CommunicationBlinkingTask communicationsBlinkingTask ;
2017-03-24 10:41:36 -07:00
# 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 :
LcdController ( ) : PeriodicController ( " BenchThread " ) { }
private :
void PeriodicTask ( efitime_t nowNt ) override {
2019-02-21 02:44:45 -08:00
UNUSED ( nowNt ) ;
2019-02-11 12:09:24 -08:00
setPeriod ( NOT_TOO_OFTEN ( 10 /* ms */ , engineConfiguration - > bc . lcdThreadPeriodMs ) ) ;
2017-03-24 10:41:36 -07:00
if ( engineConfiguration - > bc . useLcdScreen ) {
# if EFI_HD44780_LCD
2017-05-08 05:15:46 -07:00
updateHD44780lcd ( ) ;
2017-03-24 10:41:36 -07:00
# endif
}
}
2019-02-11 12:09:24 -08:00
} ;
static LcdController lcdInstance ;
2019-03-29 07:29:01 -07:00
# endif /* EFI_LCD */
2017-03-24 10:41:36 -07:00
2019-04-12 19:10:57 -07:00
# if EFI_HIP_9011
2019-01-07 20:55:56 -08:00
extern HIP9011 instance ;
2017-04-09 19:07:41 -07:00
# endif /* EFI_HIP_9011 */
2019-04-12 19:10:57 -07:00
# if EFI_TUNER_STUDIO
2017-03-24 10:41:36 -07:00
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 */
2017-03-24 10:41:36 -07:00
int rpm = 0 ;
2019-01-03 21:16:08 -08:00
# endif /* EFI_SHAFT_POSITION_INPUT */
2017-03-24 10:41:36 -07:00
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 tps = getTPS ( PASS_ENGINE_PARAMETER_SIGNATURE ) ;
float coolant = getCoolantTemperature ( PASS_ENGINE_PARAMETER_SIGNATURE ) ;
float intake = getIntakeAirTemperature ( PASS_ENGINE_PARAMETER_SIGNATURE ) ;
2017-03-24 10:41:36 -07:00
2017-05-15 20:28:49 -07:00
float engineLoad = getEngineLoadT ( PASS_ENGINE_PARAMETER_SIGNATURE ) ;
2017-03-24 10:41:36 -07:00
// header
tsOutputChannels - > tsConfigVersion = TS_FILE_VERSION ;
// engine state
tsOutputChannels - > rpm = rpm ;
tsOutputChannels - > coolantTemperature = coolant ;
tsOutputChannels - > intakeAirTemperature = intake ;
tsOutputChannels - > throttlePositon = tps ;
2019-07-09 23:14:47 -07:00
tsOutputChannels - > massAirFlowVoltage = hasMafSensor ( ) ? getMafVoltage ( PASS_ENGINE_PARAMETER_SIGNATURE ) : 0 ;
2018-09-29 09:16:36 -07:00
// For air-interpolated tCharge mode, we calculate a decent massAirFlow approximation, so we can show it to users even without MAF sensor!
tsOutputChannels - > massAirFlow = hasMafSensor ( ) ? getRealMaf ( PASS_ENGINE_PARAMETER_SIGNATURE ) : engine - > engineState . airFlow ;
2017-11-15 11:30:13 -08:00
tsOutputChannels - > oilPressure = engine - > sensors . oilPressure ;
2017-08-28 19:32:29 -07:00
2018-06-12 02:15:10 -07:00
tsOutputChannels - > injectionOffset = engine - > engineState . injectionOffset ;
2017-08-28 19:32:29 -07:00
tsOutputChannels - > accelerationX = engine - > sensors . accelerometer . x ;
tsOutputChannels - > accelerationY = engine - > sensors . accelerometer . y ;
2017-05-15 20:28:49 -07:00
if ( hasMapSensor ( PASS_ENGINE_PARAMETER_SIGNATURE ) ) {
2019-05-27 12:56:12 -07:00
float mapValue = getMap ( PASS_ENGINE_PARAMETER_SIGNATURE ) ;
2019-05-27 08:17:28 -07:00
tsOutputChannels - > veValue = engine - > engineState . currentBaroCorrectedVE * PERCENT_MULT ;
2017-03-24 10:41:36 -07:00
// todo: bug here? target afr could work based on real MAF?
tsOutputChannels - > currentTargetAfr = afrMap . getValue ( rpm , mapValue ) ;
tsOutputChannels - > manifoldAirPressure = mapValue ;
}
2018-01-16 09:58:35 -08:00
if ( hasAfrSensor ( PASS_ENGINE_PARAMETER_SIGNATURE ) ) {
tsOutputChannels - > airFuelRatio = getAfr ( PASS_ENGINE_PARAMETER_SIGNATURE ) ;
}
2017-05-15 20:28:49 -07:00
if ( hasVBatt ( PASS_ENGINE_PARAMETER_SIGNATURE ) ) {
tsOutputChannels - > vBatt = getVBatt ( PASS_ENGINE_PARAMETER_SIGNATURE ) ;
2017-03-24 10:41:36 -07:00
}
2017-05-15 20:28:49 -07:00
tsOutputChannels - > tpsADC = getTPS12bitAdc ( PASS_ENGINE_PARAMETER_SIGNATURE ) / TPS_TS_CONVERSION ;
2019-04-12 19:10:57 -07:00
# if EFI_ANALOG_SENSORS
2017-03-24 10:41:36 -07:00
tsOutputChannels - > baroPressure = hasBaroSensor ( ) ? getBaroPressure ( ) : 0 ;
# endif /* EFI_ANALOG_SENSORS */
tsOutputChannels - > engineLoad = engineLoad ;
2017-05-18 12:57:55 -07:00
2017-03-24 10:41:36 -07:00
tsOutputChannels - > triggerErrorsCounter = engine - > triggerCentral . triggerState . totalTriggerErrorCounter ;
tsOutputChannels - > baroCorrection = engine - > engineState . baroCorrection ;
2017-05-15 20:28:49 -07:00
tsOutputChannels - > pedalPosition = hasPedalPositionSensor ( PASS_ENGINE_PARAMETER_SIGNATURE ) ? getPedalPosition ( PASS_ENGINE_PARAMETER_SIGNATURE ) : 0 ;
2017-03-24 10:41:36 -07:00
tsOutputChannels - > knockCount = engine - > knockCount ;
tsOutputChannels - > knockLevel = engine - > knockVolts ;
2019-03-14 10:28:51 -07:00
tsOutputChannels - > fuelTankLevel = engine - > sensors . fuelTankLevel ;
2017-03-24 10:41:36 -07:00
tsOutputChannels - > hasFatalError = hasFirmwareError ( ) ;
tsOutputChannels - > totalTriggerErrorCounter = engine - > triggerCentral . triggerState . totalTriggerErrorCounter ;
2017-05-15 20:28:49 -07:00
tsOutputChannels - > injectorDutyCycle = getInjectorDutyCycle ( rpm PASS_ENGINE_PARAMETER_SUFFIX ) ;
2017-03-24 10:41:36 -07:00
tsOutputChannels - > fuelRunning = ENGINE ( engineState . runningFuel ) ;
tsOutputChannels - > fuelPidCorrection = ENGINE ( engineState . fuelPidCorrection ) ;
tsOutputChannels - > injectorLagMs = ENGINE ( engineState . injectorLag ) ;
tsOutputChannels - > fuelBase = engine - > engineState . baseFuel ;
tsOutputChannels - > actualLastInjection = ENGINE ( actualLastInjection ) ;
2017-05-15 20:28:49 -07:00
tsOutputChannels - > coilDutyCycle = getCoilDutyCycle ( rpm PASS_ENGINE_PARAMETER_SUFFIX ) ;
2017-03-24 10:41:36 -07:00
2018-12-23 20:58:40 -08:00
efitimesec_t timeSeconds = getTimeNowSeconds ( ) ;
tsOutputChannels - > timeSeconds = timeSeconds ;
2017-03-24 10:41:36 -07:00
tsOutputChannels - > firmwareVersion = getRusEfiVersion ( ) ;
2019-01-11 06:58:48 -08:00
tsOutputChannels - > isWarnNow = engine - > engineState . warnings . isWarningNow ( timeSeconds , true ) ;
2017-06-04 12:00:19 -07:00
tsOutputChannels - > isCltBroken = engine - > isCltBroken ;
2019-04-12 19:10:57 -07:00
# if EFI_HIP_9011
2019-01-07 20:55:56 -08:00
tsOutputChannels - > isKnockChipOk = ( instance . invalidHip9011ResponsesCount = = 0 ) ;
2018-05-30 21:32:44 -07:00
# endif /* EFI_HIP_9011 */
2017-03-24 10:41:36 -07:00
2017-12-03 04:42:44 -08:00
switch ( engineConfiguration - > debugMode ) {
2019-05-09 16:39:21 -07:00
case DBG_AUX_TEMPERATURE :
tsOutputChannels - > debugFloatField1 = engine - > sensors . auxTemp1 ;
tsOutputChannels - > debugFloatField2 = engine - > sensors . auxTemp2 ;
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 :
2017-03-24 10:41:36 -07:00
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 :
2017-03-24 10:41:36 -07:00
tsOutputChannels - > debugIntField1 = engine - > triggerCentral . getHwEventCounter ( ( int ) SHAFT_PRIMARY_FALLING ) ;
tsOutputChannels - > debugIntField2 = engine - > triggerCentral . getHwEventCounter ( ( int ) SHAFT_SECONDARY_FALLING ) ;
tsOutputChannels - > debugIntField3 = engine - > triggerCentral . getHwEventCounter ( ( int ) SHAFT_3RD_FALLING ) ;
2019-08-07 16:49:13 -07:00
# if EFI_PROD_CODE
tsOutputChannels - > debugIntField4 = vvtEventRiseCounter ;
tsOutputChannels - > debugIntField5 = vvtEventFallCounter ;
2019-08-07 17:13:30 -07:00
tsOutputChannels - > debugFloatField5 = icuWidthCallbackCounter + icuWidthPeriodCounter ;
2019-08-07 16:49:13 -07:00
# endif /* EFI_PROD_CODE */
2017-03-24 10:41:36 -07:00
tsOutputChannels - > debugFloatField1 = engine - > triggerCentral . getHwEventCounter ( ( int ) SHAFT_PRIMARY_RISING ) ;
tsOutputChannels - > debugFloatField2 = engine - > triggerCentral . getHwEventCounter ( ( int ) SHAFT_SECONDARY_RISING ) ;
tsOutputChannels - > debugFloatField3 = engine - > triggerCentral . getHwEventCounter ( ( int ) SHAFT_3RD_RISING ) ;
2017-12-03 04:42:44 -08:00
tsOutputChannels - > debugFloatField4 = engine - > rpmCalculator . getRpmAcceleration ( ) ;
break ;
case DBG_FSIO_ADC :
2017-03-24 10:41:36 -07:00
// todo: implement a proper loop
if ( engineConfiguration - > fsioAdc [ 0 ] ! = EFI_ADC_NONE ) {
strcpy ( buf , " adcX " ) ;
tsOutputChannels - > debugFloatField1 = getVoltage ( " fsio " , engineConfiguration - > fsioAdc [ 0 ] ) ;
}
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_SD_CARD :
2017-03-24 10:41:36 -07:00
tsOutputChannels - > debugIntField1 = engine - > engineState . totalLoggedBytes ;
2017-12-03 04:42:44 -08:00
break ;
case DBG_CRANKING_DETAILS :
2017-03-24 10:41:36 -07:00
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 :
2019-01-07 20:55:56 -08:00
// 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
2018-01-28 10:04:19 -08:00
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 */
2019-04-25 05:32:20 -07:00
case DBG_ANALOG_INPUTS :
2017-12-03 04:42:44 -08:00
tsOutputChannels - > debugFloatField1 = ( engineConfiguration - > vbattAdcChannel ! = EFI_ADC_NONE ) ? getVoltageDivided ( " vbatt " , engineConfiguration - > vbattAdcChannel ) : 0.0f ;
2019-06-30 11:28:47 -07:00
tsOutputChannels - > debugFloatField2 = ( engineConfiguration - > tps1_1AdcChannel ! = EFI_ADC_NONE ) ? getVoltageDivided ( " tps " , engineConfiguration - > tps1_1AdcChannel ) : 0.0f ;
2017-12-03 04:42:44 -08:00
tsOutputChannels - > debugFloatField3 = ( engineConfiguration - > mafAdcChannel ! = EFI_ADC_NONE ) ? getVoltageDivided ( " maf " , engineConfiguration - > mafAdcChannel ) : 0.0f ;
tsOutputChannels - > debugFloatField4 = ( engineConfiguration - > map . sensor . hwChannel ! = EFI_ADC_NONE ) ? getVoltageDivided ( " map " , engineConfiguration - > map . sensor . hwChannel ) : 0.0f ;
tsOutputChannels - > debugFloatField5 = ( engineConfiguration - > clt . adcChannel ! = EFI_ADC_NONE ) ? getVoltageDivided ( " clt " , engineConfiguration - > clt . adcChannel ) : 0.0f ;
tsOutputChannels - > debugFloatField6 = ( engineConfiguration - > iat . adcChannel ! = EFI_ADC_NONE ) ? getVoltageDivided ( " iat " , engineConfiguration - > iat . adcChannel ) : 0.0f ;
tsOutputChannels - > debugFloatField7 = ( engineConfiguration - > afr . hwChannel ! = EFI_ADC_NONE ) ? getVoltageDivided ( " ego " , engineConfiguration - > afr . hwChannel ) : 0.0f ;
break ;
2019-04-25 05:32:20 -07:00
case DBG_ANALOG_INPUTS2 :
tsOutputChannels - > debugFloatField4 = getVoltage ( " debug " , engineConfiguration - > throttlePedalPositionAdcChannel ) ;
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 ;
2017-12-03 04:42:44 -08:00
default :
;
}
2017-03-24 10:41:36 -07:00
tsOutputChannels - > wallFuelAmount = ENGINE ( wallFuel ) . getWallFuel ( 0 ) ;
2019-07-12 19:34:38 -07:00
tsOutputChannels - > wallFuelCorrection = ENGINE ( wallFuel ) . wallFuelCorrection ;
2017-03-24 10:41:36 -07:00
// TPS acceleration
tsOutputChannels - > deltaTps = engine - > tpsAccelEnrichment . getMaxDelta ( ) ;
tsOutputChannels - > tpsAccelFuel = engine - > engineState . tpsAccelEnrich ;
// engine load acceleration
2017-05-15 20:28:49 -07:00
if ( hasMapSensor ( PASS_ENGINE_PARAMETER_SIGNATURE ) ) {
2019-05-27 12:56:12 -07:00
tsOutputChannels - > engineLoadAccelExtra = engine - > engineLoadAccelEnrichment . getEngineLoadEnrichment ( PASS_ENGINE_PARAMETER_SIGNATURE ) * 100 / getMap ( PASS_ENGINE_PARAMETER_SIGNATURE ) ;
2017-03-24 10:41:36 -07:00
}
tsOutputChannels - > engineLoadDelta = engine - > engineLoadAccelEnrichment . getMaxDelta ( ) ;
tsOutputChannels - > iatCorrection = ENGINE ( engineState . iatFuelCorrection ) ;
tsOutputChannels - > cltCorrection = ENGINE ( engineState . cltFuelCorrection ) ;
tsOutputChannels - > checkEngine = hasErrorCodes ( ) ;
tsOutputChannels - > vvtPosition = engine - > triggerCentral . vvtPosition ;
2017-05-15 20:28:49 -07:00
tsOutputChannels - > engineMode = packEngineMode ( PASS_ENGINE_PARAMETER_SIGNATURE ) ;
2017-03-24 10:41:36 -07:00
2019-01-31 08:57:15 -08:00
# if HAL_USE_ADC
2017-03-24 10:41:36 -07:00
tsOutputChannels - > internalMcuTemperature = getMCUInternalTemperature ( ) ;
2019-01-31 08:57:15 -08:00
# endif /* HAL_USE_ADC */
2017-03-24 10:41:36 -07:00
2019-04-12 19:10:57 -07:00
# if EFI_MAX_31855
2017-03-24 10:41:36 -07:00
for ( int i = 0 ; i < EGT_CHANNEL_COUNT ; i + + )
tsOutputChannels - > egtValues . values [ i ] = getEgtValue ( i ) ;
# endif /* EFI_MAX_31855 */
2019-01-31 08:57:15 -08:00
# if EFI_IDLE_CONTROL
tsOutputChannels - > idlePosition = getIdlePosition ( ) ;
# endif
2019-04-12 19:10:57 -07:00
# if EFI_PROD_CODE
2019-01-31 08:57:15 -08:00
tsOutputChannels - > isTriggerError = isTriggerErrorNow ( ) ;
2019-04-12 19:10:57 -07:00
# if EFI_INTERNAL_FLASH
2017-03-24 10:41:36 -07:00
tsOutputChannels - > needBurn = getNeedToWriteConfiguration ( ) ;
2017-07-24 16:37:09 -07:00
# endif /* EFI_INTERNAL_FLASH */
2019-04-12 19:10:57 -07:00
# if EFI_FILE_LOGGING
2017-03-24 10:41:36 -07:00
tsOutputChannels - > hasSdCard = isSdCardAlive ( ) ;
2017-07-24 16:37:09 -07:00
# endif /* EFI_FILE_LOGGING */
2017-03-24 10:41:36 -07:00
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 ;
2019-04-12 19:10:57 -07:00
# if EFI_VEHICLE_SPEED
2017-03-24 10:41:36 -07:00
float vehicleSpeed = getVehicleSpeed ( ) ;
tsOutputChannels - > vehicleSpeedKph = vehicleSpeed ;
tsOutputChannels - > speedToRpmRatio = vehicleSpeed / rpm ;
# endif /* EFI_VEHICLE_SPEED */
2017-05-15 20:28:49 -07:00
tsOutputChannels - > isCltError = ! isValidCoolantTemperature ( getCoolantTemperature ( PASS_ENGINE_PARAMETER_SIGNATURE ) ) ;
tsOutputChannels - > isIatError = ! isValidIntakeAirTemperature ( getIntakeAirTemperature ( PASS_ENGINE_PARAMETER_SIGNATURE ) ) ;
2017-03-24 10:41:36 -07:00
# endif /* EFI_PROD_CODE */
2017-12-31 16:25:59 -08:00
tsOutputChannels - > fuelConsumptionPerHour = engine - > engineState . fuelConsumption . perSecondConsumption ;
2019-01-11 06:58:48 -08:00
tsOutputChannels - > warningCounter = engine - > engineState . warnings . warningCounter ;
tsOutputChannels - > lastErrorCode = engine - > engineState . warnings . lastErrorCode ;
2019-01-13 17:45:58 -08:00
for ( int i = 0 ; i < 8 ; i + + ) {
tsOutputChannels - > recentErrorCodes [ i ] = engine - > engineState . warnings . recentWarnings . get ( i ) ;
}
2017-03-24 10:41:36 -07:00
tsOutputChannels - > knockNowIndicator = engine - > knockCount > 0 ;
tsOutputChannels - > knockEverIndicator = engine - > knockEver ;
tsOutputChannels - > clutchUpState = engine - > clutchUpState ;
tsOutputChannels - > clutchDownState = engine - > clutchDownState ;
2017-05-15 02:08:17 -07:00
tsOutputChannels - > brakePedalState = engine - > brakePedalState ;
2019-01-26 21:02:58 -08:00
tsOutputChannels - > acSwitchState = engine - > acSwitchState ;
2017-05-15 02:08:17 -07:00
2018-09-29 09:16:36 -07:00
// tCharge depends on the previous state, so we should use the stored value.
2019-06-19 19:34:11 -07:00
tsOutputChannels - > tCharge = ENGINE ( engineState . sd . tCharge ) ;
2017-03-24 10:41:36 -07:00
float timing = engine - > engineState . timingAdvance ;
tsOutputChannels - > ignitionAdvance = timing > 360 ? timing - 720 : timing ;
tsOutputChannels - > sparkDwell = ENGINE ( engineState . sparkDwell ) ;
2017-05-15 20:28:49 -07:00
tsOutputChannels - > crankingFuelMs = engine - > isCylinderCleanupMode ? 0 : getCrankingFuel ( PASS_ENGINE_PARAMETER_SIGNATURE ) ;
2019-06-19 19:34:11 -07:00
tsOutputChannels - > chargeAirMass = engine - > engineState . sd . airMassInOneCylinder ;
2017-03-24 10:41:36 -07:00
}
extern TunerStudioOutputChannels tsOutputChannels ;
void prepareTunerStudioOutputs ( void ) {
// sensor state for EFI Analytics Tuner Studio
2017-05-15 20:28:49 -07:00
updateTunerStudioState ( & tsOutputChannels PASS_ENGINE_PARAMETER_SUFFIX ) ;
2017-03-24 10:41:36 -07:00
}
# endif /* EFI_TUNER_STUDIO */
2017-04-09 19:26:11 -07:00
void initStatusLoop ( void ) {
2017-03-24 10:41:36 -07:00
setFullLog ( INITIAL_FULL_LOG ) ;
addConsoleActionI ( FULL_LOGGING_KEY , setFullLog ) ;
addConsoleActionI ( " warn " , setWarningEnabled ) ;
2019-04-12 19:10:57 -07:00
# if EFI_ENGINE_CONTROL
2017-03-24 10:41:36 -07:00
addConsoleActionFF ( " fuelinfo2 " , ( VoidFloatFloat ) showFuelInfo2 ) ;
addConsoleAction ( " fuelinfo " , showFuelInfo ) ;
# endif
2019-04-12 19:10:57 -07:00
# if EFI_PROD_CODE
2017-12-16 21:37:52 -08:00
2017-03-24 10:41:36 -07:00
addConsoleAction ( " status " , printStatus ) ;
# endif /* EFI_PROD_CODE */
}
2017-04-09 19:26:11 -07:00
void startStatusThreads ( void ) {
2017-03-24 10:41:36 -07:00
// todo: refactoring needed, this file should probably be split into pieces
2019-04-12 19:10:57 -07:00
# if EFI_PROD_CODE
2017-03-24 10:41:36 -07:00
initStatusLeds ( ) ;
2019-07-13 08:06:03 -07:00
communicationsBlinkingTask . Start ( ) ;
2017-03-24 10:41:36 -07:00
# endif /* EFI_PROD_CODE */
2019-07-13 07:24:23 -07:00
2019-04-12 19:10:57 -07:00
# if EFI_LCD
2019-02-11 12:09:24 -08:00
lcdInstance . Start ( ) ;
2019-03-29 07:29:01 -07:00
# endif /* EFI_LCD */
2017-03-24 10:41:36 -07:00
}
void setFullLog ( int value ) {
print ( " Setting full logging: %s \r \n " , boolToString ( value ) ) ;
printMsg ( & logger , " %s%d " , FULL_LOGGING_KEY , value ) ;
fullLog = value ;
}
bool getFullLog ( void ) {
return fullLog ;
}