fome-fw/firmware/development/sensor_chart.cpp

86 lines
2.0 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
2020-01-13 18:57:43 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
2015-07-10 06:01:56 -07:00
*/
2018-09-16 19:26:57 -07:00
#include "global.h"
#include "os_access.h"
2019-07-05 17:03:32 -07:00
#include "sensor_chart.h"
2015-07-10 06:01:56 -07:00
#include "engine.h"
#include "rpm_calculator.h"
2019-04-12 19:10:57 -07:00
#if EFI_SENSOR_CHART
2016-05-28 16:02:28 -07:00
#include "status_loop.h"
2015-07-10 06:01:56 -07:00
2019-04-12 19:10:57 -07:00
#if EFI_TEXT_LOGGING
2020-08-26 20:08:48 -07:00
static char LOGGING_BUFFER[SC_BUFFER_SIZE] CCM_OPTIONAL;
2018-09-16 21:00:19 -07:00
static Logging scLogging("analog chart", LOGGING_BUFFER, sizeof(LOGGING_BUFFER));
#endif /* EFI_TEXT_LOGGING */
2015-07-10 06:01:56 -07:00
2016-05-28 16:02:28 -07:00
static int pendingData = false;
static int initialized = false;
2015-07-10 06:01:56 -07:00
2019-01-13 21:09:40 -08:00
EXTERN_ENGINE;
2015-07-10 06:01:56 -07:00
void scAddData(float angle, float value) {
2019-04-12 19:10:57 -07:00
#if EFI_TEXT_LOGGING
2015-07-10 06:01:56 -07:00
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) {
2015-07-10 06:01:56 -07:00
/**
* 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
2018-09-16 21:00:19 -07:00
appendPrintf(&scLogging, DELIMETER);
2015-07-10 06:01:56 -07:00
// output pending data
2019-07-09 04:52:20 -07:00
scheduleLogging(&scLogging);
2015-07-10 06:01:56 -07:00
pendingData = false;
}
return;
}
if (!pendingData) {
pendingData = true;
2018-09-16 21:00:19 -07:00
resetLogging(&scLogging);
2015-07-10 06:01:56 -07:00
// message header
2019-07-05 16:40:12 -07:00
appendPrintf(&scLogging, "%s%s", PROTOCOL_ANALOG_CHART, DELIMETER);
2015-07-10 06:01:56 -07:00
}
2018-09-16 21:00:19 -07:00
if (remainingSize(&scLogging) > 100) {
appendPrintf(&scLogging, "%.2f|%.2f|", angle, value);
2015-07-10 06:01:56 -07:00
}
2018-09-16 21:00:19 -07:00
#endif /* EFI_TEXT_LOGGING */
2015-07-10 06:01:56 -07:00
}
static void setSensorChartFrequency(int value) {
engineConfiguration->sensorChartFrequency = value;
}
void initSensorChart(void) {
2018-01-30 11:53:13 -08:00
#if EFI_SIMULATOR
printf("initSensorChart\n");
#endif
2015-07-10 06:01:56 -07:00
addConsoleActionI("set_sensor_chart_freq", setSensorChartFrequency);
initialized = true;
}
2015-09-13 09:01:42 -07:00
#endif /* EFI_SENSOR_CHART */