LCOV - code coverage report
Current view: top level - App/Src - appSensorRead.cpp (source / functions) Coverage Total Hit
Test: filtered_coverage.info Lines: 54.3 % 46 25
Test Date: 2026-03-21 17:55:27 Functions: 83.3 % 6 5

            Line data    Source code
       1              : 
       2              : #include <string.h>
       3              : #include "xtoa.hpp"
       4              : #include "appSensorRead.hpp"
       5              : #include "appLogger.hpp"
       6              : #include "sysManager.hpp"
       7              : 
       8              : namespace FreeRTOS_Cpp
       9              : {
      10            4 :     appSensorRead::appSensorRead(IRTOS* rtos, ISensor* tempSensor, ISensor* humiditySensor, void* sysEvents, void* wdgEvents)
      11            4 :         : _rtos(rtos),_tempSensor(tempSensor),_humiditySensor(humiditySensor), _sysEvents(sysEvents), _wdgEvents(wdgEvents)
      12              :     {
      13              : 
      14            4 :     }
      15              : 
      16              : 
      17            1 :     void appSensorRead::App_FormatSensorMsg(char *pDest, 
      18              :                             uint32_t destLen, const char *pLabel, 
      19              :                             float val, const char *pUnit)
      20              :     {
      21              :         char valBuf[16];
      22              :         
      23              :         /* 1. Ensure the destination starts empty (MISRA 19.1) */
      24            1 :         pDest[0] = '\0';
      25              : 
      26              :         /* 2. Safely concatenate label */
      27            1 :         (void)strncat(pDest, pLabel, destLen - 1U);
      28            1 :         (void)strncat(pDest, ": ", destLen - strlen(pDest) - 1U);
      29              : 
      30              :         /* 3. Convert float to string in temporary buffer */
      31            1 :         xtoa::app_ftoa(val, valBuf, (uint32_t)sizeof(valBuf));
      32              : 
      33              :         /* 4. Concatenate value and unit */
      34            1 :         (void)strncat(pDest, valBuf, destLen - strlen(pDest) - 1U);
      35            1 :         (void)strncat(pDest, " ", destLen - strlen(pDest) - 1U);
      36            1 :         (void)strncat(pDest, pUnit, destLen - strlen(pDest) - 1U);
      37            1 :         (void)strncat(pDest, "\r\n", destLen - strlen(pDest) - 1U);
      38            1 :     }
      39              : 
      40            2 :     uint8_t appSensorRead::appSensorRead_Init(void)
      41              :     {
      42            2 :         uint8_t ret = 0;
      43              :         //In ret set bit 0 for Temperature Sensor Init status
      44            2 :         if (_tempSensor->init() != true) 
      45              :         {
      46            1 :             appLogger::logMessage("I2C Bus Error: TSENSOR Init Failed\r\n", 
      47              :                 sAPPLOGGER_EVENT_CODE_PRINT_MESSAGE);
      48              :         }
      49              :         else
      50              :         {
      51            1 :             ret |=  appSENSOR_TEMPERATURE;
      52              :         }
      53              : 
      54              :         //In ret set bit 1 for Temperature Sensor Init status
      55            2 :         if (_humiditySensor->init() != true) 
      56              :         {
      57            0 :             appLogger::logMessage("I2C Bus Error: HSENSOR Init Failed\r\n", 
      58              :                 sAPPLOGGER_EVENT_CODE_PRINT_MESSAGE);
      59              :         }
      60              :         else
      61              :         {
      62            2 :             ret |=  appSENSOR_HUMIDITY;
      63              :         }
      64              : 
      65            2 :         return ret;
      66              :     } 
      67              : 
      68            0 :     void appSensorRead::vSensorReadTask(void *pvParameters)
      69              :     {
      70            0 :         appSensorRead* self = static_cast<appSensorRead*>(pvParameters);
      71              :         sStorageEvent_t tEvent;
      72              :         sStorageEvent_t hEvent;
      73              :         
      74            0 :         tEvent.eventID =  EVENT_ID_T_SENSOR_DATA_POINT;
      75            0 :         tEvent.taskID = TASK_ID_SENSOR_READ;
      76            0 :         hEvent.eventID =  EVENT_ID_H_SENSOR_DATA_POINT;
      77            0 :         hEvent.taskID = TASK_ID_SENSOR_READ;
      78              :     
      79              :         for (;;)
      80              :         {
      81            0 :             uint32_t uxBits = self->_rtos->getEventBits(self->_sysEvents);
      82              :             
      83            0 :             if((uxBits & EVENT_BIT_INIT_SUCCESS) != 0)
      84              :             {
      85              :                 //Read temperature sensor
      86            0 :                 self->_currentTemp = self->_tempSensor->read();
      87            0 :                 self->_currentHumidity = self->_humiditySensor->read();
      88              : 
      89            0 :                 hEvent.timestamp = tEvent.timestamp = self->_rtos->getTickCount();
      90              : 
      91            0 :                 (void)memcpy(&tEvent.payload[0], &self->_currentTemp, sizeof(float));
      92            0 :                 (void)memcpy(&hEvent.payload[0], &self->_currentHumidity, sizeof(float));
      93              : 
      94            0 :                 if(self->bEnableTemperatureLogging)
      95              :                 {
      96            0 :                     appLogger::logEvent(&tEvent);
      97              :                 }
      98            0 :                 if(self->bEnableHumidityLogging)
      99              :                 {
     100            0 :                     appLogger::logEvent(&hEvent);
     101              :                 }
     102              :                 #if(0)
     103              :                 char pcMessage[128] = {0};
     104              :                 self->App_FormatSensorMsg(pcMessage, sizeof(pcMessage), "Temp", self->_currentTemp, "C");
     105              :                 appLogger::logMessage(pcMessage, sAPPLOGGER_EVENT_CODE_PRINT_MESSAGE);
     106              :                 self->App_FormatSensorMsg(pcMessage, sizeof(pcMessage),"Humidity", self->_currentHumidity, "%");
     107              :                 appLogger::logMessage(pcMessage, sAPPLOGGER_EVENT_CODE_PRINT_MESSAGE);
     108              :                 #endif
     109              :             }
     110              :             // Add a delay so we don't spam the queue infinitely
     111            0 :             self->_rtos->delay(systemManager::appSensorReadSleepDuration);
     112            0 :             self->_rtos->setEventBits(self->_wdgEvents, WATCHDOG_BIT_SENSOR_READ);
     113            0 :         }
     114              :     }
     115              : 
     116            3 :     uint32_t appSensorRead::getTempSensorID(void)
     117              :     {
     118            3 :         return appSENSOR_TEMPERATURE;
     119              :     }
     120              :     
     121            3 :     uint32_t appSensorRead::getHumiditySensorID(void)
     122              :     {
     123            3 :         return appSENSOR_HUMIDITY;
     124              :     }
     125              : }
        

Generated by: LCOV version 2.0-1