LCOV - code coverage report
Current view: top level - firmware/controllers/gauges - malfunction_central.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 24 26 92.3 %
Date: 2024-04-25 02:23:43 Functions: 5 6 83.3 %

          Line data    Source code
       1             : /**
       2             :  * @file malfunction_central.c
       3             :  * @brief This data structure holds current malfunction codes
       4             :  *
       5             :  * todo: make this a class
       6             :  *
       7             :  * @date Dec 20, 2013
       8             :  * @author Andrey Belomutskiy, (c) 2012-2020
       9             :  */
      10             : 
      11             : #include "pch.h"
      12             : 
      13             : #include "malfunction_central.h"
      14             : 
      15             : static error_codes_set_s error_codes_set;
      16             : 
      17           4 : void clearWarnings(void) {
      18           4 :         error_codes_set.count = 0;
      19           4 : }
      20             : 
      21             : // TODO: wow this is not used by real firmware?!
      22             : #if EFI_UNIT_TEST
      23             : /**
      24             :  * Search if code is present
      25             :  * @return -1 if code not found
      26             :  */
      27          18 : static int find_position(ObdCode e_code) {
      28             :         // cycle for searching element equal seaching code
      29          66 :         for (int t = 0; t < error_codes_set.count; t++)
      30          51 :                 if (error_codes_set.error_codes[t] == e_code)
      31           3 :                         return t;                       // we found position where this code is present
      32          15 :         return -1;                                                                                                              // -1 if code not found
      33             : }
      34             : 
      35         106 : void addError(ObdCode errorCode) {
      36         106 :         if (error_codes_set.count < MAX_ERROR_CODES_COUNT && find_position(errorCode) == -1) {
      37          13 :                 error_codes_set.error_codes[error_codes_set.count] = errorCode;
      38          13 :                 error_codes_set.count++;
      39             :         }
      40         106 : }
      41             : 
      42           4 : void removeError(ObdCode errorCode) {
      43           4 :         int pos = find_position(errorCode);
      44           4 :         if (pos >= 0) {
      45             :                 // shift all right elements to one pos left
      46          11 :                 for (int t = pos; t < error_codes_set.count - 1; t++) {
      47           9 :                         error_codes_set.error_codes[t] = error_codes_set.error_codes[t + 1];
      48             :                 }
      49             : 
      50           2 :                 error_codes_set.error_codes[--error_codes_set.count] = (ObdCode)0;                              // place 0
      51             :         }
      52           4 : }
      53             : #endif // EFI_UNIT_TEST
      54             : 
      55           8 : void getErrorCodes(error_codes_set_s * copy) {
      56           8 :         copy->count = error_codes_set.count;
      57           8 :         copyArray(copy->error_codes, error_codes_set.error_codes);
      58           8 : }
      59             : 
      60           0 : bool hasErrorCodes(void) {
      61           0 :         return error_codes_set.count > 0;
      62             : }

Generated by: LCOV version 1.14