rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
sensor_chart.cpp
Go to the documentation of this file.
1/**
2 * @file sensor_chart.cpp
3 *
4 * @date Dec 20, 2013
5 * @author Andrey Belomutskiy, (c) 2012-2020
6 */
7
8#include "pch.h"
9
10#include "sensor_chart.h"
11
12#if EFI_SENSOR_CHART
13#include "status_loop.h"
14
15#if EFI_TEXT_LOGGING
16static char LOGGING_BUFFER[SC_BUFFER_SIZE] CCM_OPTIONAL;
17static Logging scLogging("analog chart", LOGGING_BUFFER, sizeof(LOGGING_BUFFER));
18#endif /* EFI_TEXT_LOGGING */
19
20static int initialized = false;
21
22enum class ScState {
23 PreArm,
24 Armed,
25 Logging,
26 Full
27};
28
30static uint32_t lastRevCount = 0;
31
32void scAddData(float angle, float value) {
33#if EFI_TEXT_LOGGING
34 if (!initialized) {
35 return; // this is possible because of initialization sequence
36 }
37
38 // Don't log if we need a flush
39 if (state == ScState::Full) {
40 return;
41 }
42
43 auto currentRev = getRevolutionCounter();
44
45 if (state == ScState::PreArm) {
46 // nothing to do - we just need to grab the rev counter once so we can detect a change
48 } else if (state == ScState::Armed) {
49 // If armed, wait for a NEW revolution to start
50 if (lastRevCount != currentRev) {
52
53 // Reset logging and append header
55 scLogging.appendPrintf(PROTOCOL_ANALOG_CHART LOG_DELIMITER);
56 }
57 } else if (state == ScState::Logging) {
58 // If running and the revolution idx changes, terminate logging and wait for flush
59 if (lastRevCount != currentRev) {
61 }
62 }
63
64 lastRevCount = currentRev;
65
66 if (state == ScState::Logging) {
67 if (scLogging.remainingSize() > 100) {
68 scLogging.appendPrintf( "%.2f|%.2f|", angle, value);
69 } else {
71 }
72 }
73#endif /* EFI_TEXT_LOGGING */
74}
75
76void initSensorChart(void) {
77#if EFI_SIMULATOR
78 printf("initSensorChart\n");
79#endif
80
81 initialized = true;
82}
83
85 if (state != ScState::Full) {
86 return;
87 }
88
89 scLogging.appendPrintf(LOG_DELIMITER);
91
93}
94
95#endif /* EFI_SENSOR_CHART */
size_t remainingSize() const
Definition datalogging.h:49
void reset()
void appendPrintf(const char *fmt,...) __attribute__((format(printf
void scheduleLogging(Logging *logging)
ScState
static Logging scLogging("analog chart", LOGGING_BUFFER, sizeof(LOGGING_BUFFER))
void scAddData(float angle, float value)
static uint32_t lastRevCount
void publishSensorChartIfFull()
static int initialized
static ScState state
static char LOGGING_BUFFER[SC_BUFFER_SIZE] CCM_OPTIONAL
void initSensorChart(void)
printf("\n")