LCOV - code coverage report
Current view: top level - firmware/development - sensor_chart.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 3 30 10.0 %
Date: 2024-07-27 05:50:15 Functions: 1 3 33.3 %

          Line data    Source code
       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
      16             : static char LOGGING_BUFFER[SC_BUFFER_SIZE] CCM_OPTIONAL;
      17             : static Logging scLogging("analog chart", LOGGING_BUFFER, sizeof(LOGGING_BUFFER));
      18             : #endif /* EFI_TEXT_LOGGING */
      19             : 
      20             : static int initialized = false;
      21             : 
      22             : enum class ScState {
      23             :         PreArm,
      24             :         Armed,
      25             :         Logging,
      26             :         Full
      27             : };
      28             : 
      29             : static ScState state = ScState::PreArm;
      30             : static uint32_t lastRevCount = 0;
      31             : 
      32           0 : void scAddData(float angle, float value) {
      33             : #if EFI_TEXT_LOGGING
      34           0 :         if (!initialized) {
      35           0 :                 return; // this is possible because of initialization sequence
      36             :         }
      37             : 
      38             :         // Don't log if we need a flush
      39           0 :         if (state == ScState::Full) {
      40           0 :                 return;
      41             :         }
      42             : 
      43           0 :         auto currentRev = getRevolutionCounter();
      44             : 
      45           0 :         if (state == ScState::PreArm) {
      46             :                 // nothing to do - we just need to grab the rev counter once so we can detect a change
      47           0 :                 state = ScState::Armed;
      48           0 :         } else if (state == ScState::Armed) {
      49             :                 // If armed, wait for a NEW revolution to start
      50           0 :                 if (lastRevCount != currentRev) {
      51           0 :                         state = ScState::Logging;
      52             : 
      53             :                         // Reset logging and append header
      54           0 :                         scLogging.reset();
      55           0 :                         scLogging.appendPrintf(PROTOCOL_ANALOG_CHART LOG_DELIMITER);
      56             :                 }
      57           0 :         } else if (state == ScState::Logging) {
      58             :                 // If running and the revolution idx changes, terminate logging and wait for flush
      59           0 :                 if (lastRevCount != currentRev) {
      60           0 :                         state = ScState::Full;
      61             :                 }
      62             :         }
      63             : 
      64           0 :         lastRevCount = currentRev;
      65             : 
      66           0 :         if (state == ScState::Logging) {
      67           0 :                 if (scLogging.remainingSize() > 100) {
      68           0 :                         scLogging.appendPrintf( "%.2f|%.2f|", angle, value);
      69             :                 } else {
      70           0 :                         state = ScState::Full;
      71             :                 }
      72             :         }
      73             : #endif /* EFI_TEXT_LOGGING */
      74             : }
      75             : 
      76         353 : void initSensorChart(void) {
      77             : #if EFI_SIMULATOR
      78             :         printf("initSensorChart\n");
      79             : #endif
      80             : 
      81         353 :         initialized = true;
      82         353 : }
      83             : 
      84           0 : void publishSensorChartIfFull() {
      85           0 :         if (state != ScState::Full) {
      86           0 :                 return;
      87             :         }
      88             : 
      89           0 :         scLogging.appendPrintf(LOG_DELIMITER);
      90           0 :         scheduleLogging(&scLogging);
      91             : 
      92           0 :         state = ScState::Armed;
      93             : }
      94             : 
      95             : #endif /* EFI_SENSOR_CHART */

Generated by: LCOV version 1.14