F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
FpySequencerStateMachine.cpp
Go to the documentation of this file.
1 #include <new>
3 namespace Svc {
4 
5 // ----------------------------------------------------------------------
6 // Functions to implement for internal state machine actions
7 // ----------------------------------------------------------------------
8 
12 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_signalEntered(
13  SmId smId,
15 ) {
17 }
18 
25 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_setSequenceFilePath(
26  SmId smId,
29 ) {
30  Fw::ParamValid valid;
31  Fw::ParamString baseDir = this->paramGet_SEQ_BASE_DIR(valid);
32  if (baseDir.length() == 0) {
33  // the assignment here ensures the string is null terminated
34  // because it uses the string_copy method
35  // also, the filePath string in SequenceExecutionArgs is guaranteed
36  // to be truncated to FileNameStringSize chars, so it will not
37  // be truncated by this assignment
38  this->m_sequenceFilePath = value.get_filePath();
39  return;
40  }
41 
42  Fw::FormatStatus status;
43  // the result will get truncated to FileNameStringSize
44  status = this->m_sequenceFilePath.format("%s/%s", baseDir.toChar(), value.get_filePath().toChar());
45  if (status == Fw::FormatStatus::SUCCESS) {
46  return;
47  }
48 
49  // the only runtime-reachable non-success status is OVERFLOWED, which means the
50  // base dir and file name together are longer than the sequence file path buffer.
51  // the other statuses can only result from a bad format string literal, which is a
52  // coding error. let the user know the path was truncated; validate() will then fail
53  // to open the (truncated) path and report a FileOpenError.
54  FW_ASSERT(status == Fw::FormatStatus::OVERFLOWED, static_cast<I32>(status));
56 }
57 
62 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_setSequenceBlockState(
63  SmId smId,
66 ) {
67  this->m_sequenceBlockState = value.get_block();
68 }
69 
74 void FpySequencer ::Svc_FpySequencer_SequencerStateMachine_action_setSequenceArguments(
75  SmId smId,
78  this->m_sequenceArgs = value.get_buffer();
79 }
80 
85 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_report_seqSucceeded(
86  SmId smId,
88 ) {
89  this->m_tlm.sequencesSucceeded++;
90  this->log_ACTIVITY_HI_SequenceDone(this->m_sequenceFilePath);
91  if (this->isConnected_seqDoneOut_OutputPort(0)) {
92  // report that the sequence succeeded to internal callers
93  this->seqDoneOut_out(0, 0, 0, Fw::CmdResponse::OK);
94  }
95 }
96 
101 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_report_seqCancelled(
102  SmId smId,
104 ) {
105  this->m_tlm.sequencesCancelled++;
106  this->log_ACTIVITY_HI_SequenceCancelled(this->m_sequenceFilePath);
107  if (this->isConnected_seqDoneOut_OutputPort(0)) {
108  // report that the sequence failed to internal callers
110  }
111 }
112 
117 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_dispatchStatement(
118  SmId smId,
120 ) {
121  Signal result = this->dispatchStatement();
122  switch (result) {
125  break;
126  }
129  break;
130  }
133  break;
134  }
135  default: {
136  FW_ASSERT(0, static_cast<FwAssertArgType>(result));
137  }
138  }
139 }
140 
145 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_setGoalState_RUNNING(
146  SmId smId,
148 ) {
149  this->m_goalState = FpySequencer_GoalState::RUNNING;
150 }
151 
156 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_setGoalState_VALID(
157  SmId smId,
159 ) {
160  this->m_goalState = FpySequencer_GoalState::VALID;
161 }
162 
167 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_setGoalState_IDLE(
168  SmId smId,
170 ) {
171  this->m_goalState = FpySequencer_GoalState::IDLE;
172 }
173 
178 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_sendCmdResponse_OK(
179  SmId smId,
181 ) {
182  if (this->m_sequenceBlockState == BlockState::BLOCK) {
183  // respond if we were waiting on a response
184  this->cmdResponse_out(this->m_savedOpCode, this->m_savedCmdSeq, Fw::CmdResponse::OK);
185  }
186 }
187 
192 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_sendCmdResponse_EXECUTION_ERROR(
193  SmId smId,
195 ) {
196  if (this->m_sequenceBlockState == BlockState::BLOCK) {
197  // respond if we were waiting on a response
198  this->cmdResponse_out(this->m_savedOpCode, this->m_savedCmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
199  }
200 }
201 
206 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_resetRuntime(
207  SmId smId,
209 ) {
210  // explicitly call dtor
211  this->m_runtime.~Runtime();
212  new (&this->m_runtime) Runtime();
213 }
214 
220 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_validate(
221  SmId smId,
223 ) {
224  Fw::Success result = this->validate();
225  if (result == Fw::Success::FAILURE) {
227  return;
228  }
230 }
231 
235 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_checkShouldWake(
236  SmId smId,
238 ) {
239  Signal result = this->checkShouldWake();
240  switch (result) {
243  break;
244  }
247  break;
248  }
251  break;
252  }
253  default: {
254  FW_ASSERT(0, static_cast<FwAssertArgType>(result));
255  }
256  }
257 }
258 
262 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_checkStatementTimeout(
263  SmId smId,
265 ) {
266  Signal result = this->checkStatementTimeout();
267  switch (result) {
270  break;
271  }
274  break;
275  }
278  break;
279  }
280  default: {
281  FW_ASSERT(0, static_cast<FwAssertArgType>(result));
282  }
283  }
284 }
285 
289 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_incrementSequenceCounter(
290  SmId smId,
292 ) {
293  this->m_sequencesStarted++;
294 }
295 
299 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_pushArgsToStack(
300  SmId smId,
302 ) {
303  const Svc::SeqArgs& args = this->m_sequenceArgs;
304 
305  // Early return if no arguments provided
306  if (args.get_size() == 0) {
307  return;
308  }
309 
310  // Push args buffer to stack. Args are already serialized in big-endian format
311  // by F' serialization system, so no endianness conversion is needed.
312  this->m_runtime.stack.push(args.get_buffer(), static_cast<Fpy::StackSizeType>(args.get_size()));
313 }
314 
318 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_clearSequenceFile(
319  SmId smId,
321 ) {
322  this->m_sequenceFilePath = "";
323 }
324 
328 void FpySequencer ::Svc_FpySequencer_SequencerStateMachine_action_clearSequenceArguments(
329  SmId smId,
331  this->m_sequenceArgs = {0, 0};
332 }
333 
337 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_clearBreakpoint(
338  SmId smId,
340 ) {
341  this->m_breakpoint.breakpointInUse = false;
342  this->m_breakpoint.breakpointIndex = 0;
343  this->m_breakpoint.breakOnlyOnceOnBreakpoint = false;
344  this->m_breakpoint.breakBeforeNextLine = false;
345 }
346 
350 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_report_seqBroken(
351  SmId smId,
353 ) {
354  this->log_ACTIVITY_HI_SequencePaused(this->m_runtime.nextStatementIndex);
355 }
356 
360 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_setBreakpoint(
361  SmId smId,
364 ) {
365  this->m_breakpoint.breakpointInUse = value.get_breakOnBreakpoint();
366  this->m_breakpoint.breakOnlyOnceOnBreakpoint = value.get_breakOnlyOnceOnBreakpoint();
367  this->m_breakpoint.breakpointIndex = value.get_breakpointIndex();
369 }
370 
374 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_setBreakBeforeNextLine(
375  SmId smId,
377 ) {
378  this->m_breakpoint.breakBeforeNextLine = true;
379 }
380 
384 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_clearBreakBeforeNextLine(
385  SmId smId,
387 ) {
388  this->m_breakpoint.breakBeforeNextLine = false;
389 }
390 
394 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_report_seqFailed(
395  SmId smId,
397 ) {
398  if (this->isConnected_seqDoneOut_OutputPort(0)) {
399  // report that the sequence failed to internal callers
401  }
402 }
403 
407 void FpySequencer::Svc_FpySequencer_SequencerStateMachine_action_report_seqStarted(
408  SmId smId,
410 ) {
411  if (this->isConnected_seqStartOut_OutputPort(0)) {
412  // report that the sequence started to internal callers
413  // NOTE: Sequence Arguments would be cleared if a VALIDATION command is sent, not a full RUN command.
414  this->seqStartOut_out(0, this->m_sequenceFilePath, this->m_sequenceArgs);
415  }
416 }
417 // ----------------------------------------------------------------------
418 // Functions to implement for internal state machine guards
419 // ----------------------------------------------------------------------
420 
426  SmId smId,
428 ) const {
429  return this->m_goalState == FpySequencer_GoalState::RUNNING;
430 }
431 
437  SmId smId,
439 ) const {
440  // there are really two mechanisms for pausing the execution of the seq
441  // one is the "break on next line flag", and the other is the breakpoint
442  return this->m_breakpoint.breakBeforeNextLine ||
443  (this->m_breakpoint.breakpointInUse &&
444  this->m_breakpoint.breakpointIndex == this->m_runtime.nextStatementIndex);
445 }
446 
451  SmId smId,
453 ) const {
454  return this->m_breakpoint.breakOnlyOnceOnBreakpoint;
455 }
456 } // namespace Svc
void sequencer_sendSignal_result_dispatchStatement_noMoreStatements()
Send signal result_dispatchStatement_noMoreStatements to state machine sequencer. ...
void sequencer_sendSignal_result_checkShouldWake_keepSleeping()
Send signal result_checkShouldWake_keepSleeping to state machine sequencer.
called in dispatchStatement method when a statement was unable to be sent out
void log_ACTIVITY_HI_SequencePaused(U32 stmtIdx) const
Log event SequencePaused.
called in dispatchStatement method when there were no more statements in the sequence ...
U32 get_breakpointIndex() const
Get member breakpointIndex.
void sequencer_sendSignal_result_dispatchStatement_success()
Send signal result_dispatchStatement_success to state machine sequencer.
bool Svc_FpySequencer_SequencerStateMachine_guard_goalStateIs_RUNNING(SmId smId, Svc_FpySequencer_SequencerStateMachine::Signal signal) const override
void sequencer_sendSignal_result_checkShouldWake_wakeup()
Send signal result_checkShouldWake_wakeup to state machine sequencer.
void log_WARNING_HI_SequenceFilePathTooLong(const Fw::StringBase &baseDir, const Fw::StringBase &fileName) const
Log event SequenceFilePathTooLong.
Format overflowed.
void sequencer_sendSignal_result_success()
Send signal result_success to state machine sequencer.
void sequencer_sendSignal_result_dispatchStatement_failure()
Send signal result_dispatchStatement_failure to state machine sequencer.
called in dispatchStatement method when a statement was successfully dispatched
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
Type_of_buffer & get_buffer()
Get member buffer.
const char * toChar() const
bool Svc_FpySequencer_SequencerStateMachine_guard_shouldBreak(SmId smId, Svc_FpySequencer_SequencerStateMachine::Signal signal) const override
const char * toChar() const
Convert to a C-style char*.
void sequencer_sendSignal_result_checkStatementTimeout_noTimeout()
Send signal result_checkStatementTimeout_noTimeout to state machine sequencer.
FwSizeType get_size() const
Get member size.
Representing failure.
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:39
Command successfully executed.
void seqDoneOut_out(FwIndexType portNum, FwOpcodeType opCode, U32 cmdSeq, const Fw::CmdResponse &response) const
Invoke output port seqDoneOut.
void log_ACTIVITY_HI_BreakpointSet(U32 breakpointIdx, bool breakOnce) const
Log event BreakpointSet.
void sequencer_sendSignal_result_timeOpFailed()
Send signal result_timeOpFailed to state machine sequencer.
Command had execution error.
void sequencer_sendSignal_result_checkStatementTimeout_statementTimeout()
Send signal result_checkStatementTimeout_statementTimeout to state machine sequencer.
void log_ACTIVITY_HI_SequenceCancelled(const Fw::StringBase &filePath) const
Log event SequenceCancelled.
Fw::ParamString paramGet_SEQ_BASE_DIR(Fw::ParamValid &valid)
bool Svc_FpySequencer_SequencerStateMachine_guard_breakOnce(SmId smId, Svc_FpySequencer_SequencerStateMachine::Signal signal) const override
RateGroupDivider component implementation.
virtual SizeType length() const
Get the length of the string.
Enum representing parameter validity.
void sequencer_sendSignal_result_failure()
Send signal result_failure to state machine sequencer.
bool isConnected_seqStartOut_OutputPort(FwIndexType portNum) const
void seqStartOut_out(FwIndexType portNum, const Fw::StringBase &filename, const Svc::SeqArgs &args) const
Invoke output port seqStartOut.
void sequencer_sendSignal_entered()
Send signal entered to state machine sequencer.
bool get_breakOnlyOnceOnBreakpoint() const
Get member breakOnlyOnceOnBreakpoint.
void log_ACTIVITY_HI_SequenceDone(const Fw::StringBase &filePath) const
Log event SequenceDone.
bool get_breakOnBreakpoint() const
Get member breakOnBreakpoint.
FpySequencer_SequencerStateMachineStateMachineBase::Signal Signal
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Success/Failure.
bool isConnected_seqDoneOut_OutputPort(FwIndexType portNum) const
U32 StackSizeType
the type which everything referencing a size or offset on the stack is represented in ...
FormatStatus
status of string format calls
Definition: format.hpp:18