| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 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 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 15 times.
|
2/2✓ Decision 'true' taken 51 times.
✓ Decision 'false' taken 15 times.
|
66 | for (int t = 0; t < error_codes_set.count; t++) |
| 30 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 48 times.
|
2/2✓ Decision 'true' taken 3 times.
✓ Decision 'false' taken 48 times.
|
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 |
6/6✓ Branch 0 taken 14 times.
✓ Branch 1 taken 92 times.
✓ Branch 3 taken 13 times.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 13 times.
✓ Branch 6 taken 93 times.
|
2/2✓ Decision 'true' taken 13 times.
✓ Decision 'false' taken 93 times.
|
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 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
2/2✓ Decision 'true' taken 2 times.
✓ Decision 'false' taken 2 times.
|
4 | if (pos >= 0) { |
| 45 | // shift all right elements to one pos left | |||
| 46 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2 times.
|
2/2✓ Decision 'true' taken 9 times.
✓ Decision 'false' taken 2 times.
|
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 | 531078 | bool hasErrorCodes(void) { | ||
| 61 | 531078 | return error_codes_set.count > 0; | ||
| 62 | } | |||
| 63 |