rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Static Public Member Functions | Static Private Member Functions
TriggerStimulatorHelper Class Reference

#include <trigger_simulator.h>

Static Public Member Functions

static expected< uint32_t > findTriggerSyncPoint (TriggerWaveform &shape, const TriggerConfiguration &triggerConfiguration, TriggerDecoderBase &state)
 
static void assertSyncPosition (const TriggerConfiguration &triggerConfiguration, const uint32_t index, TriggerDecoderBase &state, TriggerWaveform &shape)
 

Static Private Member Functions

static void feedSimulatedEvent (const TriggerConfiguration &triggerConfiguration, TriggerDecoderBase &state, const TriggerWaveform &shape, int i)
 

Detailed Description

Definition at line 17 of file trigger_simulator.h.

Member Function Documentation

◆ assertSyncPosition()

void TriggerStimulatorHelper::assertSyncPosition ( const TriggerConfiguration triggerConfiguration,
const uint32_t  index,
TriggerDecoderBase state,
TriggerWaveform shape 
)
static

let's feed two more cycles to validate shape definition

Definition at line 94 of file trigger_simulator.cpp.

99 {
100
101// todo: is anything limiting this TEST_REVOLUTIONS? why does value '8' not work for example?
102#define TEST_REVOLUTIONS 6
103
104 /**
105 * let's feed two more cycles to validate shape definition
106 */
107 for (uint32_t i = syncIndex + 1; i <= syncIndex + TEST_REVOLUTIONS * shape.getSize(); i++) {
108 feedSimulatedEvent(triggerConfiguration, state, shape, i);
109 }
110
111 int revolutionCounter = state.getSynchronizationCounter();
112 if (revolutionCounter != TEST_REVOLUTIONS) {
113 warning(ObdCode::CUSTOM_OBD_TRIGGER_WAVEFORM, "sync failed/wrong gap parameters trigger=%s revolutionCounter=%d",
114 getTrigger_type_e(triggerConfiguration.TriggerType.type),
115 revolutionCounter);
116 shape.setShapeDefinitionError(true);
117 return;
118 }
119 shape.shapeDefinitionError = false;
120#if EFI_UNIT_TEST
121 if (printTriggerTrace) {
122 printf("Happy %s revolutionCounter=%d\r\n",
123 getTrigger_type_e(triggerConfiguration.TriggerType.type),
124 revolutionCounter);
125 }
126#endif /* EFI_UNIT_TEST */
127}
const char * getTrigger_type_e(trigger_type_e value)
trigger_config_s TriggerType
static void feedSimulatedEvent(const TriggerConfiguration &triggerConfiguration, TriggerDecoderBase &state, const TriggerWaveform &shape, int i)
void setShapeDefinitionError(bool value)
size_t getSize() const
bool warning(ObdCode code, const char *fmt,...)
@ CUSTOM_OBD_TRIGGER_WAVEFORM
state("state", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 1871, 1.0, -1.0, -1.0, "")
bool printTriggerTrace
printf("\n")

Referenced by TriggerDecoderBase::findTriggerZeroEventIndex().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ feedSimulatedEvent()

void TriggerStimulatorHelper::feedSimulatedEvent ( const TriggerConfiguration triggerConfiguration,
TriggerDecoderBase state,
const TriggerWaveform shape,
int  i 
)
staticprivate

Definition at line 41 of file trigger_simulator.cpp.

46 {
47 efiAssertVoid(ObdCode::CUSTOM_ERR_6593, shape.getSize() > 0, "size not zero");
48 int stateIndex = index % shape.getSize();
49
50 int time = getSimulatedEventTime(shape, index);
51
52 const auto & multiChannelStateSequence = shape.wave;
53
54#if EFI_UNIT_TEST
55 int prevIndex = getPreviousIndex(stateIndex, shape.getSize());
56
57 pin_state_t primaryWheelState = multiChannelStateSequence.getChannelState(0, prevIndex);
58 pin_state_t newPrimaryWheelState = multiChannelStateSequence.getChannelState(0, stateIndex);
59
60 pin_state_t secondaryWheelState = multiChannelStateSequence.getChannelState(1, prevIndex);
61 pin_state_t newSecondaryWheelState = multiChannelStateSequence.getChannelState(1, stateIndex);
62
63// pin_state_t thirdWheelState = multiChannelStateSequence->getChannelState(2, prevIndex);
64// pin_state_t new3rdWheelState = multiChannelStateSequence->getChannelState(2, stateIndex);
65
67 printf("TriggerStimulator: simulatedEvent: %d>%d primary %d>%d secondary %d>%d\r\n", prevIndex, stateIndex, primaryWheelState, newPrimaryWheelState,
68 secondaryWheelState, newSecondaryWheelState );
69 }
70#endif /* EFI_UNIT_TEST */
71
72
73 // todo: code duplication with TriggerEmulatorHelper::handleEmulatorCallback?
74
77
78 for (size_t i = 0; i < PWM_PHASE_MAX_WAVE_PER_PWM; i++) {
79 if (needEvent(stateIndex, multiChannelStateSequence, i)) {
80 pin_state_t currentValue = multiChannelStateSequence.getChannelState(/*phaseIndex*/i, stateIndex);
81 trigger_event_e event = (currentValue == TriggerValue::RISE ? riseEvents : fallEvents)[i];
82 if (isUsefulSignal(event, shape)) {
83 state.decodeTriggerEvent(
84 "sim",
85 shape,
86 /* override */ nullptr,
87 triggerConfiguration,
88 event, time);
89 }
90 }
91 }
92}
MultiChannelStateSequenceWithData< PWM_PHASE_MAX_COUNT > wave
@ CUSTOM_ERR_6593
trigger_event_e
@ SHAFT_SECONDARY_RISING
@ SHAFT_SECONDARY_FALLING
@ SHAFT_PRIMARY_FALLING
@ SHAFT_PRIMARY_RISING
TriggerValue
int getPreviousIndex(const int currentIndex, const int size)
bool needEvent(const int currentIndex, const MultiChannelStateSequence &mcss, int channelIndex)
int getSimulatedEventTime(const TriggerWaveform &shape, int i)
bool isUsefulSignal(trigger_event_e signal, const TriggerWaveform &shape)
bool printTriggerDebug

Referenced by assertSyncPosition(), and findTriggerSyncPoint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ findTriggerSyncPoint()

expected< uint32_t > TriggerStimulatorHelper::findTriggerSyncPoint ( TriggerWaveform shape,
const TriggerConfiguration triggerConfiguration,
TriggerDecoderBase state 
)
static
Returns
trigger synchronization point index, or error code if not found

Definition at line 132 of file trigger_simulator.cpp.

135 {
136 for (int i = 0; i < 4 * PWM_PHASE_MAX_COUNT; i++) {
137 feedSimulatedEvent(triggerConfiguration, state, shape, i);
138
139 if (state.getShaftSynchronized()) {
140 return i;
141 }
142 }
143 shape.setShapeDefinitionError(true);
144
146 firmwareError(ObdCode::CUSTOM_ERR_CUSTOM_GAPS_BAD, "The custom trigger gaps are invalid for the current trigger type.");
147 } else {
148 firmwareError(ObdCode::CUSTOM_ERR_TRIGGER_SYNC, "findTriggerZeroEventIndex() failed");
149 }
150 return unexpected;
151}
static constexpr engine_configuration_s * engineConfiguration
void firmwareError(ObdCode code, const char *fmt,...)
@ CUSTOM_ERR_CUSTOM_GAPS_BAD
@ CUSTOM_ERR_TRIGGER_SYNC

Referenced by TriggerDecoderBase::findTriggerZeroEventIndex().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: