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"
|
2019-07-03 18:48:04 -07:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2019-10-14 03:18:08 -07:00
|
|
|
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
|
2020-09-13 01:49:25 -07:00
|
|
|
scLogging.appendPrintf(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;
|
2020-09-13 01:49:25 -07:00
|
|
|
scLogging.reset();
|
2015-07-10 06:01:56 -07:00
|
|
|
// message header
|
2020-09-13 01:49:25 -07:00
|
|
|
scLogging.appendPrintf( "%s%s", PROTOCOL_ANALOG_CHART, DELIMETER);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2020-09-13 01:49:25 -07:00
|
|
|
if (scLogging.remainingSize() > 100) {
|
|
|
|
scLogging.appendPrintf( "%.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 */
|