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"
|
2018-09-16 19:26:57 -07:00
|
|
|
#include "global.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#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
|
|
|
|
2018-09-16 21:00:19 -07:00
|
|
|
#if EFI_TEXT_LOGGING || defined(__DOXYGEN__)
|
2017-05-03 18:24:18 -07:00
|
|
|
static char LOGGING_BUFFER[5000] 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
|
|
|
|
|
|
|
extern engine_configuration_s *engineConfiguration;
|
|
|
|
|
|
|
|
void scAddData(float angle, float value) {
|
2018-09-16 21:00:19 -07:00
|
|
|
#if EFI_TEXT_LOGGING || defined(__DOXYGEN__)
|
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) {
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
if (getFullLog()) {
|
2018-09-16 21:00:19 -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
|
2018-09-16 21:00:19 -07:00
|
|
|
appendPrintf(&scLogging, "analog_chart%s", 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 */
|