86 lines
2.0 KiB
C++
86 lines
2.0 KiB
C++
/**
|
|
* @file sensor_chart.cpp
|
|
*
|
|
* @date Dec 20, 2013
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
|
*/
|
|
|
|
#include "global.h"
|
|
#include "os_access.h"
|
|
#include "sensor_chart.h"
|
|
#include "engine.h"
|
|
#include "rpm_calculator.h"
|
|
|
|
#if EFI_SENSOR_CHART
|
|
#include "status_loop.h"
|
|
|
|
#if EFI_TEXT_LOGGING
|
|
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;
|
|
|
|
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()
|
|
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;
|
|
scLogging.reset();
|
|
// message header
|
|
scLogging.appendPrintf( "%s%s", PROTOCOL_ANALOG_CHART, DELIMETER);
|
|
}
|
|
|
|
if (scLogging.remainingSize() > 100) {
|
|
scLogging.appendPrintf( "%.2f|%.2f|", angle, value);
|
|
}
|
|
#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;
|
|
}
|
|
|
|
#endif /* EFI_SENSOR_CHART */
|