rusefi/firmware/development/sensor_chart.cpp

80 lines
1.8 KiB
C++
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
2015-09-13 12:02:21 -07:00
* @file sensor_chart.cpp
2015-07-10 06:01:56 -07:00
*
* @date Dec 20, 2013
2018-01-20 17:55:31 -08:00
* @author Andrey Belomutskiy, (c) 2012-2018
2015-07-10 06:01:56 -07:00
*/
2015-09-12 16:01:20 -07:00
#include "sensor_chart.h"
2015-07-10 06:01:56 -07:00
#include "main.h"
#include "engine.h"
#include "rpm_calculator.h"
2015-09-13 09:01:42 -07:00
#if EFI_SENSOR_CHART || defined(__DOXYGEN__)
2016-05-28 16:02:28 -07:00
#include "status_loop.h"
2015-07-10 06:01:56 -07:00
2017-05-03 18:24:18 -07:00
static char LOGGING_BUFFER[5000] CCM_OPTIONAL;
2015-07-10 06:01:56 -07:00
static Logging logging("analog chart", LOGGING_BUFFER, sizeof(LOGGING_BUFFER));
2016-05-28 16:02:28 -07:00
static int pendingData = false;
static int initialized = false;
2015-07-10 06:01:56 -07:00
extern engine_configuration_s *engineConfiguration;
void scAddData(float angle, float value) {
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
appendPrintf(&logging, DELIMETER);
// output pending data
if (getFullLog()) {
scheduleLogging(&logging);
}
pendingData = false;
}
return;
}
if (!pendingData) {
pendingData = true;
resetLogging(&logging);
// message header
appendPrintf(&logging, "analog_chart%s", DELIMETER);
}
if (remainingSize(&logging) > 100) {
2018-01-23 09:05:14 -08:00
appendPrintf(&logging, "%.2f|%.2f|", angle, value);
2015-07-10 06:01:56 -07:00
}
}
static void setSensorChartFrequency(int value) {
engineConfiguration->sensorChartFrequency = value;
}
void initSensorChart(void) {
addConsoleActionI("set_sensor_chart_freq", setSensorChartFrequency);
initialized = true;
}
2015-09-13 09:01:42 -07:00
#endif /* EFI_SENSOR_CHART */