rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
state_sequence.cpp
Go to the documentation of this file.
1/**
2 * @file state_sequence.cpp
3 *
4 * @date May 18, 2014
5 * @author Andrey Belomutskiy, (c) 2012-2020
6 */
7
8#include "pch.h"
9#include "state_sequence.h"
10#include "trigger_structure.h"
11
12void MultiChannelStateSequence::checkSwitchTimes(const float scale) const {
13 efiAssertVoid(ObdCode::CUSTOM_ERR_WAVE_1, phaseCount > 0, "StateSequence cannot be empty");
14 if (getSwitchTime(phaseCount - 1) != 1) {
15#if EFI_UNIT_TEST
16 for (int index = 0;index < phaseCount;index ++) {
17 printf("switch time index=%d angle=%f\n", index, getSwitchTime(index));
18 }
19#endif // EFI_UNIT_TEST
20
21 firmwareError(ObdCode::CUSTOM_ERR_WAVE_1, "[count=%d] last switch time has to be 1/%f not %.2f/%f",
23 scale, getSwitchTime(phaseCount - 1),
24 scale * getSwitchTime(phaseCount - 1));
25 return;
26 }
27 for (int i = 0; i < phaseCount - 1; i++) {
28 if (getSwitchTime(i) >= getSwitchTime(i + 1)) {
29 firmwareError(ObdCode::CUSTOM_ERR_WAVE_2, "invalid switchTimes @%d: %.2f/%.2f",
30 i, getSwitchTime(i), getSwitchTime(i + 1));
31 }
32 }
33}
34
36 for (int i = phaseCount - 1; i >= 0; i--) {
37 if (angle > getSwitchTime(i))
38 return i + 1;
39 }
40 return 0;
41}
42
43expected<int> MultiChannelStateSequence::findAngleMatch(const float angle) const {
44 for (int i = 0; i < phaseCount; i++) {
45 if (isSameF(getSwitchTime(i), angle))
46 return i;
47 }
48 return unexpected;
49}
void checkSwitchTimes(float scale) const
virtual float getSwitchTime(int phaseIndex) const =0
int findInsertionAngle(float angle) const
expected< int > findAngleMatch(float angle) const
void firmwareError(ObdCode code, const char *fmt,...)
@ CUSTOM_ERR_WAVE_1
@ CUSTOM_ERR_WAVE_2
printf("\n")