improve sensor chart flush behavior (#2545)

* disable sensor chart

* type signature, guards

* we can't log the message as that confuses the parser

* dead

* this syntax was technically illegal

* more

* turn it back on

* remove config

* api

* implement

* ui

* java ui
This commit is contained in:
Matthew Kennedy 2021-04-12 11:05:52 -07:00 committed by GitHub
parent 7407b99657
commit 5e2e18d2b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 58 additions and 47 deletions

View File

@ -201,8 +201,6 @@ void setDodgeNeon1995EngineConfiguration(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
engineConfiguration->ignitionPinMode = OM_DEFAULT;
engineConfiguration->clt.config = {0, 30, 100, 32500, 7550, 700, 2700};
engineConfiguration->sensorChartFrequency = 7;
}
void setDodgeNeonNGCEngineConfiguration(DECLARE_CONFIG_PARAMETER_SIGNATURE) {

View File

@ -39,8 +39,6 @@ void setMazda626EngineConfiguration(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
// chartsize 600
engineConfiguration->engineChartSize = 600;
engineConfiguration->sensorChartFrequency = 2;
engineConfiguration->injector.flow = 330;
engineConfiguration->specs.displacement = 2.0;

View File

@ -21,8 +21,6 @@ void setSubaru2003Wrx(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
engineConfiguration->trigger.customTotalToothCount = 5;
engineConfiguration->trigger.customSkippedToothCount = 1;
engineConfiguration->sensorChartFrequency = 2;
engineConfiguration->useStepperIdle = true;
// See http://rusefi.com/forum/viewtopic.php?f=4&t=1161

View File

@ -102,6 +102,8 @@ extern int icuFallingCallbackCounter;
extern WaveChart waveChart;
#endif /* EFI_ENGINE_SNIFFER */
#include "sensor_chart.h"
extern pin_output_mode_e DEFAULT_OUTPUT;
extern pin_output_mode_e INVERTED_OUTPUT;
@ -198,6 +200,10 @@ void printOverallStatus(efitimesec_t nowSeconds) {
waveChart.publishIfFull();
#endif /* EFI_ENGINE_SNIFFER */
#if EFI_SENSOR_CHART
publishSensorChartIfFull();
#endif // EFI_SENSOR_CHART
/**
* we report the version every 4 seconds - this way the console does not need to
* request it and we will display it pretty soon

View File

@ -971,7 +971,6 @@ static void setDefaultEngineConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
engineConfiguration->ignitionMode = IM_ONE_COIL;
engineConfiguration->globalTriggerAngleOffset = 0;
engineConfiguration->extraInjectionOffset = 0;
engineConfiguration->sensorChartFrequency = 20;
engineConfiguration->fuelAlgorithm = LM_SPEED_DENSITY;

View File

@ -19,67 +19,81 @@ static char LOGGING_BUFFER[SC_BUFFER_SIZE] CCM_OPTIONAL;
static Logging scLogging("analog chart", LOGGING_BUFFER, sizeof(LOGGING_BUFFER));
#endif /* EFI_TEXT_LOGGING */
static int pendingData = false;
static int initialized = false;
EXTERN_ENGINE;
enum class ScState {
PreArm,
Armed,
Logging,
Full
};
static ScState state = ScState::PreArm;
static uint32_t lastRevCount = 0;
void scAddData(float angle, float value) {
#if EFI_TEXT_LOGGING
if (!initialized) {
return; // this is possible because of initialization sequence
}
if (engineConfiguration->sensorChartFrequency < 2) {
/**
* analog chart frequency cannot be 1 because of the way
* data flush is implemented, see below
*/
//todofirmwareError()
// Don't log if we need a flush
if (state == ScState::Full) {
return;
}
if (getRevolutionCounter() % engineConfiguration->sensorChartFrequency != 0) {
/**
* We are here if we do NOT need to add an event to the analog chart
*/
if (pendingData) {
/**
* We are here if that's the first time we do not need to add
* data after we have added some data - meaning it's time to flush
*/
// message terminator
scLogging.appendPrintf(DELIMETER);
// output pending data
scheduleLogging(&scLogging);
pendingData = false;
}
return;
}
if (!pendingData) {
pendingData = true;
auto currentRev = getRevolutionCounter();
if (state == ScState::PreArm) {
// nothing to do - we just need to grab the rev counter once so we can detect a change
state = ScState::Armed;
} else if (state == ScState::Armed) {
// If armed, wait for a NEW revolution to start
if (lastRevCount != currentRev) {
state = ScState::Logging;
// Reset logging and append header
scLogging.reset();
// message header
scLogging.appendPrintf( "%s%s", PROTOCOL_ANALOG_CHART, DELIMETER);
}
} else if (state == ScState::Logging) {
// If running and the revolution idx changes, terminate logging and wait for flush
if (lastRevCount != currentRev) {
state = ScState::Full;
}
}
lastRevCount = currentRev;
if (state == ScState::Logging) {
if (scLogging.remainingSize() > 100) {
scLogging.appendPrintf( "%.2f|%.2f|", angle, value);
} else {
state = ScState::Full;
}
}
#endif /* EFI_TEXT_LOGGING */
}
static void setSensorChartFrequency(int value) {
engineConfiguration->sensorChartFrequency = value;
}
void initSensorChart(void) {
#if EFI_SIMULATOR
printf("initSensorChart\n");
#endif
addConsoleActionI("set_sensor_chart_freq", setSensorChartFrequency);
initialized = true;
}
void publishSensorChartIfFull() {
if (state != ScState::Full) {
return;
}
scLogging.appendPrintf(DELIMETER);
scheduleLogging(&scLogging);
state = ScState::Armed;
}
#endif /* EFI_SENSOR_CHART */

View File

@ -11,3 +11,4 @@
void scAddData(float angle, float value);
void initSensorChart(void);
void publishSensorChartIfFull();

View File

@ -649,7 +649,7 @@ adc_channel_e fuelLevelSensor;+This is the processor pin that your fuel level se
float idle_derivativeFilterLoss;+0.1 is a good default value; "x", 1, 0.0, -1000000, 1000000, 4
int sensorChartFrequency;;"index", 1, 0, 0, 300, 0
int unused520;;"index", 1, 0, 0, 300, 0
struct trigger_config_s @brief Trigger wheel(s) configuration

View File

@ -2979,7 +2979,6 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00"
dialog = monitoringSettings, "rusEFI Console Settings"
field = "Sensor Sniffer", sensorChartMode
field = " Threshold", sensorSnifferRpmThreshold
field = " Each X cycle", sensorChartFrequency
field = "Engine Sniffer", isEngineChartEnabled
field = " Threshold", engineSnifferRpmThreshold

View File

@ -77,7 +77,7 @@ bool Logging::validateBuffer(const char *text, uint32_t extraLen) {
if (remainingSize() < extraLen + 1) {
#if EFI_PROD_CODE
const char * msg = extraLen > 50 ? "(long)" : text;
warning(CUSTOM_LOGGING_BUFFER_OVERFLOW, "output overflow %s %d [%s]", name, extraLen, msg);
warning(CUSTOM_LOGGING_BUFFER_OVERFLOW, "output overflow %s %d", name, extraLen);
#endif /* EFI_PROD_CODE */
return true;
}

View File

@ -111,7 +111,6 @@ public class SensorSnifferPane {
content.add(lowerPanel, BorderLayout.SOUTH);
lowerPanel.add(new EnumConfigField(uiContext, Fields.SENSORCHARTMODE, "Mode").getContent());
lowerPanel.add(new ConfigField(uiContext, Fields.SENSORCHARTFREQUENCY, "Every XXX engine cycles").getContent());
lowerPanel.add(new ConfigField(uiContext, Fields.SENSORSNIFFERRPMTHRESHOLD, "RPM threshold").getContent());
}

View File

@ -132,7 +132,6 @@ public class EngineSnifferPanel {
lowerButtons.add(new ConfigField(uiContext, Fields.GLOBALTRIGGERANGLEOFFSET, "Trigger Offset").getContent());
lowerButtons.add(new BitConfigField(uiContext, Fields.VERBOSETRIGGERSYNCHDETAILS, "Verbose trigger Sync").getContent());
lowerButtons.add(new BitConfigField(uiContext, Fields.ISENGINECHARTENABLED, "Collect Engine Data").getContent());
lowerButtons.add(new ConfigField(uiContext, Fields.SENSORCHARTFREQUENCY, "Frequency").getContent());
lowerButtons.add(new ConfigField(uiContext, Fields.ENGINECHARTSIZE, "Engine Sniffer size").getContent());
lowerButtons.add(new ConfigField(uiContext, Fields.ENGINESNIFFERRPMTHRESHOLD, "RPM threshold").getContent());
bottomPanel.add(lowerButtons, BorderLayout.NORTH);