30 CmdSequencerComponentBase(name),
31 m_FPrimeSequence(*this),
32 m_sequence(&this->m_FPrimeSequence),
39 m_totalExecutedCount(0),
40 m_sequencesCompletedCount(0),
48 CmdSequencerComponentBase::init(queueDepth, instance);
52 this->m_timeout = timeout;
58 this->m_sequence = &sequence;
74 FW_ASSERT(this->m_runMode == STOPPED, this->m_runMode);
75 if (not this->loadFile(fileName)) {
76 this->m_sequence->
clear();
94 void CmdSequencerComponentImpl::CS_RUN_cmdHandler(
99 if (not this->requireRunMode(STOPPED)) {
100 this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_EXECUTION_ERROR);
105 if (not this->loadFile(fileName)) {
106 this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_EXECUTION_ERROR);
110 this->m_executedCount = 0;
113 if (AUTO == this->m_stepMode) {
114 this->m_runMode = RUNNING;
115 this->performCmd_Step();
118 this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_OK);
121 void CmdSequencerComponentImpl::CS_VALIDATE_cmdHandler(
127 if (!this->requireRunMode(STOPPED)) {
128 this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_EXECUTION_ERROR);
133 if (not this->loadFile(fileName)) {
134 this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_EXECUTION_ERROR);
139 this->m_sequence->
clear();
141 this->log_ACTIVITY_HI_CS_SequenceValid(this->m_sequence->
getLogFileName());
143 this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_OK);
148 void CmdSequencerComponentImpl::seqRunIn_handler(
153 if (!this->requireRunMode(STOPPED)) {
154 this->seqDone_out(0,0,0,Fw::COMMAND_EXECUTION_ERROR);
160 if (filename !=
"") {
162 const bool status = this->loadFile(cmdStr);
164 this->seqDone_out(0,0,0,Fw::COMMAND_EXECUTION_ERROR);
170 this->log_WARNING_LO_CS_NoSequenceActive();
172 this->seqDone_out(0,0,0,Fw::COMMAND_EXECUTION_ERROR);
176 this->m_executedCount = 0;
179 if (AUTO == this->m_stepMode) {
180 this->m_runMode = RUNNING;
181 this->performCmd_Step();
184 this->log_ACTIVITY_HI_CS_PortSequenceStarted(this->m_sequence->
getLogFileName());
187 void CmdSequencerComponentImpl::CS_CANCEL_cmdHandler(
189 if (RUNNING == this->m_runMode) {
190 this->performCmd_Cancel();
191 this->log_ACTIVITY_HI_CS_SequenceCanceled(this->m_sequence->
getLogFileName());
192 ++this->m_cancelCmdCount;
193 this->tlmWrite_CS_CancelCommands(this->m_cancelCmdCount);
195 this->log_WARNING_LO_CS_NoSequenceActive();
197 this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_OK);
204 bool CmdSequencerComponentImpl ::
207 const bool status = this->m_sequence->
loadFile(fileName);
210 this->log_ACTIVITY_LO_CS_SequenceLoaded(logFileName);
211 ++this->m_loadCmdCount;
212 this->tlmWrite_CS_LoadCommands(this->m_loadCmdCount);
217 void CmdSequencerComponentImpl::error(
void) {
218 ++this->m_errorCount;
219 this->tlmWrite_CS_Errors(m_errorCount);
222 void CmdSequencerComponentImpl::performCmd_Cancel(
void) {
223 this->m_sequence->
reset();
224 this->m_runMode = STOPPED;
225 this->m_cmdTimer.clear();
226 this->m_cmdTimeoutTimer.clear();
227 this->m_executedCount = 0;
229 if (this->isConnected_seqDone_OutputPort(0)) {
230 this->seqDone_out(0,0,0,Fw::COMMAND_EXECUTION_ERROR);
235 void CmdSequencerComponentImpl ::
236 cmdResponseIn_handler(
240 Fw::CommandResponse response
243 if (this->m_runMode == STOPPED) {
245 this->log_WARNING_HI_CS_UnexpectedCompletion(opcode);
248 this->m_cmdTimeoutTimer.clear();
249 if (response != Fw::COMMAND_OK) {
250 this->commandError(this->m_executedCount, opcode, response);
251 this->performCmd_Cancel();
252 }
else if (this->m_runMode == RUNNING && this->m_stepMode == AUTO) {
254 this->commandComplete(opcode);
257 this->m_runMode = STOPPED;
258 this->sequenceComplete();
260 this->performCmd_Step();
264 this->commandComplete(opcode);
266 this->m_runMode = STOPPED;
267 this->sequenceComplete();
273 void CmdSequencerComponentImpl ::
277 Fw::Time currTime = this->getTime();
279 if (this->m_cmdTimer.isExpiredAt(currTime)) {
280 this->comCmdOut_out(0, m_record.
m_command, 0);
281 this->m_cmdTimer.clear();
283 this->setCmdTimeout(currTime);
284 }
else if (this->m_cmdTimeoutTimer.isExpiredAt(this->getTime())) {
285 this->log_WARNING_HI_CS_SequenceTimeout(
287 this->m_executedCount
290 this->performCmd_Cancel();
294 void CmdSequencerComponentImpl ::
299 this->log_WARNING_LO_CS_NoSequenceActive();
300 this->cmdResponse_out(opcode, cmdSeq, Fw::COMMAND_EXECUTION_ERROR);
303 if (!this->requireRunMode(STOPPED)) {
304 this->cmdResponse_out(opcode, cmdSeq, Fw::COMMAND_EXECUTION_ERROR);
307 this->m_runMode = RUNNING;
308 this->performCmd_Step();
309 this->log_ACTIVITY_HI_CS_CmdStarted(this->m_sequence->
getLogFileName());
310 this->cmdResponse_out(opcode, cmdSeq, Fw::COMMAND_OK);
313 void CmdSequencerComponentImpl ::
316 if (this->requireRunMode(RUNNING)) {
317 this->performCmd_Step();
319 if (this->m_runMode != STOPPED) {
320 this->log_ACTIVITY_HI_CS_CmdStepped(
322 this->m_executedCount
325 this->cmdResponse_out(opcode, cmdSeq, Fw::COMMAND_OK);
327 this->cmdResponse_out(opcode, cmdSeq, Fw::COMMAND_EXECUTION_ERROR);
331 void CmdSequencerComponentImpl ::
334 if (this->requireRunMode(STOPPED)) {
335 this->m_stepMode = AUTO;
336 this->log_ACTIVITY_HI_CS_ModeSwitched(SEQ_AUTO_MODE);
337 this->cmdResponse_out(opcode, cmdSeq, Fw::COMMAND_OK);
339 this->cmdResponse_out(opcode, cmdSeq, Fw::COMMAND_EXECUTION_ERROR);
343 void CmdSequencerComponentImpl ::
346 if (this->requireRunMode(STOPPED)) {
347 this->m_stepMode = MANUAL;
348 this->log_ACTIVITY_HI_CS_ModeSwitched(SEQ_STEP_MODE);
349 this->cmdResponse_out(opcode, cmdSeq, Fw::COMMAND_OK);
351 this->cmdResponse_out(opcode, cmdSeq, Fw::COMMAND_EXECUTION_ERROR);
359 bool CmdSequencerComponentImpl::requireRunMode(RunMode mode) {
360 if (this->m_runMode == mode) {
363 this->log_WARNING_HI_CS_InvalidMode();
368 void CmdSequencerComponentImpl ::
375 this->log_WARNING_HI_CS_CommandError(
384 void CmdSequencerComponentImpl::performCmd_Step(
void) {
388 const Sequence::Header& header = this->m_sequence->
getHeader();
392 Fw::Time currentTime = this->getTime();
395 this->m_runMode = STOPPED;
396 this->sequenceComplete();
399 this->performCmd_Step_RELATIVE(currentTime);
402 this->performCmd_Step_ABSOLUTE(currentTime);
409 void CmdSequencerComponentImpl::sequenceComplete(
void) {
410 ++this->m_sequencesCompletedCount;
412 this->m_sequence->
clear();
413 this->log_ACTIVITY_HI_CS_SequenceComplete(this->m_sequence->
getLogFileName());
414 this->tlmWrite_CS_SequencesCompleted(this->m_sequencesCompletedCount);
415 this->m_executedCount = 0;
417 if (this->isConnected_seqDone_OutputPort(0)) {
418 this->seqDone_out(0,0,0,Fw::COMMAND_OK);
422 void CmdSequencerComponentImpl::commandComplete(
const U32 opcode) {
423 this->log_ACTIVITY_LO_CS_CommandComplete(
425 this->m_executedCount,
428 ++this->m_executedCount;
429 ++this->m_totalExecutedCount;
430 this->tlmWrite_CS_CommandsExecuted(this->m_totalExecutedCount);
433 void CmdSequencerComponentImpl ::
434 performCmd_Step_RELATIVE(
Fw::Time& currentTime)
437 this->performCmd_Step_ABSOLUTE(currentTime);
440 void CmdSequencerComponentImpl ::
441 performCmd_Step_ABSOLUTE(
Fw::Time& currentTime)
443 if (currentTime >= this->m_record.
m_timeTag) {
444 this->comCmdOut_out(0, m_record.
m_command, 0);
445 this->setCmdTimeout(currentTime);
447 this->m_cmdTimer.set(this->m_record.
m_timeTag);
451 void CmdSequencerComponentImpl ::
458 this->pingOut_out(0,key);
461 void CmdSequencerComponentImpl ::
462 setCmdTimeout(
const Fw::Time ¤tTime)
465 if ((this->m_timeout > 0) and (AUTO == this->m_stepMode)) {
467 expTime.
add(this->m_timeout,0);
468 this->m_cmdTimeoutTimer.set(expTime);