F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
CmdSequencerImpl.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title CmdSequencerImpl.hpp
3 // \author Bocchino/Canham
4 // \brief hpp file for CmdSequencer component implementation class
5 //
6 // Copyright (C) 2009-2018 California Institute of Technology.
7 // ALL RIGHTS RESERVED. United States Government Sponsorship
8 // acknowledged.
9 // ======================================================================
10 
11 #ifndef Svc_CmdSequencerImpl_HPP
12 #define Svc_CmdSequencerImpl_HPP
13 
14 #include "Fw/Com/ComBuffer.hpp"
16 #include "Os/File.hpp"
17 #include "Os/ValidateFile.hpp"
19 
20 namespace Svc {
21 
22  // Forward declaration for UTs
23  namespace ImmediateBase{ class CmdSequencerTester; }
24  namespace Immediate{ class CmdSequencerTester; }
25  namespace ImmediateEOS{ class CmdSequencerTester; }
26  namespace Mixed{ class CmdSequencerTester; }
27  namespace MixedRelativeBase{ class CmdSequencerTester; }
28  namespace Relative{ class CmdSequencerTester; }
29  namespace JoinWait{ class CmdSequencerTester; }
30 
33  {
34 
35 
36  friend class CmdSequencerTester;
44 
45  private:
46 
47  // ----------------------------------------------------------------------
48  // Private enumerations
49  // ----------------------------------------------------------------------
50 
52  enum RunMode {
53  STOPPED, RUNNING
54  };
55 
57  enum StepMode {
58  AUTO, MANUAL
59  };
60 
61  public:
62 
63  // ----------------------------------------------------------------------
64  // Public classes
65  // ----------------------------------------------------------------------
66 
69  class Sequence {
70 
71  public:
72 
75  class Events {
76 
77  public:
78 
80  Events(
81  Sequence& sequence
82  );
83 
84  public:
85 
87  void fileCRCFailure(
88  const U32 storedCRC,
89  const U32 computedCRC
90  );
91 
93  void fileInvalid(
94  const CmdSequencer_FileReadStage::t stage,
95  const I32 error
96  );
97 
99  void fileNotFound();
100 
102  void fileReadError();
103 
105  void fileSizeError(
106  const U32 size
107  );
108 
110  void recordInvalid(
111  const U32 recordNumber,
112  const I32 error
113  );
114 
116  void recordMismatch(
117  const U32 numRecords,
118  const U32 extraBytes
119  );
120 
122  void timeBaseMismatch(
123  const TimeBase currTimeBase,
124  const TimeBase seqTimeBase
125  );
126 
128  void timeContextMismatch(
129  const FwTimeContextStoreType currTimeContext,
130  const FwTimeContextStoreType seqTimeContext
131  );
132 
133  // No Records
134  void noRecords();
135 
136  private:
137 
139  Sequence& m_sequence;
140 
141  };
142 
143  public:
144 
146  Sequence(
147  CmdSequencerComponentImpl& component
148  );
149 
151  virtual ~Sequence();
152 
153  public:
154 
157  class Header {
158 
159  public:
160 
161  enum Constants {
164  sizeof(U32) +
165  sizeof(U32) +
166  sizeof(FwTimeBaseStoreType) +
167  sizeof(FwTimeContextStoreType)
168  };
169 
170  public:
171 
173  Header();
174 
175  public:
176 
179  bool validateTime(
180  CmdSequencerComponentImpl& component
181  );
182 
183  public:
184 
187 
190 
193 
196 
197  };
198 
199  public:
200 
203  class Record {
204 
205  public:
206 
207  enum Descriptor {
211  };
212 
213  public:
214 
216  Record() :
218  {
219 
220  }
221 
222  public:
223 
226 
229 
232 
233  };
234 
235  public:
236 
238  void allocateBuffer(
239  FwEnumStoreType identifier,
240  Fw::MemAllocator& allocator,
241  FwSizeType bytes
242  );
243 
245  void deallocateBuffer(
246  Fw::MemAllocator& allocator
247  );
248 
250  void setFileName(const Fw::StringBase& fileName);
251 
255 
259 
263 
265  const Header& getHeader() const;
266 
269  virtual bool loadFile(
270  const Fw::StringBase& fileName
271  ) = 0;
272 
275  virtual bool hasMoreRecords() const = 0;
276 
279  virtual void nextRecord(
280  Record& record
281  ) = 0;
282 
286  virtual void reset() = 0;
287 
290  virtual void clear() = 0;
291 
292  protected:
293 
296 
299 
302 
305 
308 
311 
314 
317 
318  };
319 
323  public Sequence
324  {
325 
326  private:
327 
328  enum Constants {
329  INITIAL_COMPUTED_VALUE = 0xFFFFFFFFU
330  };
331 
332  public:
333 
336  struct CRC {
337 
339  CRC();
340 
342  void init();
343 
345  void update(
346  const BYTE* buffer,
347  FwSizeType bufferSize
348  );
349 
351  void finalize();
352 
355 
357  U32 m_stored;
358 
359  };
360 
361  public:
362 
365  CmdSequencerComponentImpl& component
366  );
367 
368  public:
369 
372  bool loadFile(
373  const Fw::StringBase& fileName
374  );
375 
378  bool hasMoreRecords() const;
379 
382  void nextRecord(
383  Record& record
384  );
385 
389  void reset();
390 
393  void clear();
394 
395  private:
396 
399  bool readFile();
400 
403  bool readOpenFile();
404 
408  bool readHeader();
409 
412  bool deserializeHeader();
413 
416  bool readRecordsAndCRC();
417 
420  bool extractCRC();
421 
424  bool validateCRC();
425 
428  Fw::SerializeStatus deserializeRecord(
429  Record& record
430  );
431 
434  Fw::SerializeStatus deserializeDescriptor(
435  Record::Descriptor& descriptor
436  );
437 
440  Fw::SerializeStatus deserializeTimeTag(
441  Fw::Time& timeTag
442  );
443 
446  Fw::SerializeStatus deserializeRecordSize(
447  U32& recordSize
448  );
449 
452  Fw::SerializeStatus copyCommand(
453  Fw::ComBuffer& comBuffer,
454  const U32 recordSize
455  );
456 
459  bool validateRecords();
460 
461  private:
462 
464  CRC m_crc;
465 
467  Os::File m_sequenceFile;
468 
469  };
470 
471  private:
472 
473  // ----------------------------------------------------------------------
474  // Private classes
475  // ----------------------------------------------------------------------
476 
479  class Timer {
480 
481  friend class CmdSequencerTester;
482  friend class Svc::ImmediateBase::CmdSequencerTester;
483  friend class Svc::Immediate::CmdSequencerTester;
484  friend class Svc::ImmediateEOS::CmdSequencerTester;
485  friend class Svc::Mixed::CmdSequencerTester;
486  friend class Svc::MixedRelativeBase::CmdSequencerTester;
487  friend class Svc::Relative::CmdSequencerTester;
488  friend class Svc::JoinWait::CmdSequencerTester;
489 
490 
491  private:
492 
494  typedef enum {
495  SET, CLEAR
496  } State;
497 
498  public:
499 
501  Timer() :
502  m_state(CLEAR)
503  {
504 
505  }
506 
508  void set(
509  Fw::Time time
510  ) {
511  this->m_state = SET;
512  this->expirationTime = time;
513  }
514 
516  void clear() {
517  this->m_state = CLEAR;
518  }
519 
522  bool isExpiredAt(
523  Fw::Time time
524  ) {
525  if (this->m_state == CLEAR) {
526  return false;
527  } else if (
528  Fw::Time::compare(this->expirationTime, time) == Fw::Time::GT
529  ) {
530  return false;
531  }
532  return true;
533  }
534 
535  private:
536 
538  State m_state;
539 
541  Fw::Time expirationTime;
542 
543  };
544 
545 
546  public:
547 
548  // ----------------------------------------------------------------------
549  // Construction, initialization, and destruction
550  // ----------------------------------------------------------------------
551 
554  const char* compName
555  );
556 
560  void setTimeout(
561  const U32 seconds
562  );
563 
568  void setSequenceFormat(
569  Sequence& sequence
570  );
571 
575  void allocateBuffer(
576  const FwEnumStoreType identifier,
577  Fw::MemAllocator& allocator,
578  const FwSizeType bytes
579  );
580 
583  void loadSequence(
584  const Fw::StringBase& fileName
585  );
586 
588  void deallocateBuffer(
589  Fw::MemAllocator& allocator
590  );
591 
594 
595  private:
596 
597  // ----------------------------------------------------------------------
598  // Handler implementations for input ports
599  // ----------------------------------------------------------------------
600 
602  void cmdResponseIn_handler(
603  FwIndexType portNum,
604  FwOpcodeType opcode,
605  U32 cmdSeq,
606  const Fw::CmdResponse& response
607  );
608 
610  void schedIn_handler(
611  FwIndexType portNum,
612  U32 order
613  );
614 
616  void seqRunIn_handler(
617  FwIndexType portNum,
618  const Fw::StringBase& filename
619  );
620 
622  void pingIn_handler(
623  FwIndexType portNum,
624  U32 key
625  );
626 
629  void seqCancelIn_handler(
630  const FwIndexType portNum
631  );
632 
633  private:
634 
635  // ----------------------------------------------------------------------
636  // Command handler implementations
637  // ----------------------------------------------------------------------
638 
641  void CS_AUTO_cmdHandler(
642  FwOpcodeType opcode,
643  U32 cmdSeq
644  );
645 
648  void CS_CANCEL_cmdHandler(
649  FwOpcodeType opCode,
650  U32 cmdSeq
651  );
652 
655  void CS_MANUAL_cmdHandler(
656  FwOpcodeType opcode,
657  U32 cmdSeq
658  );
659 
661  void CS_RUN_cmdHandler(
662  FwOpcodeType opCode,
663  U32 cmdSeq,
664  const Fw::CmdStringArg& fileName,
666  );
667 
670  void CS_START_cmdHandler(
671  FwOpcodeType opcode,
672  U32 cmdSeq
673  );
674 
678  void CS_STEP_cmdHandler(
679  FwOpcodeType opcode,
680  U32 cmdSeq
681  );
682 
685  void CS_VALIDATE_cmdHandler(
686  FwOpcodeType opCode,
687  U32 cmdSeq,
688  const Fw::CmdStringArg& fileName
689  );
690 
695  void CS_JOIN_WAIT_cmdHandler(
696  const FwOpcodeType opCode,
697  const U32 cmdSeq
698  );
699 
700  private:
701 
702  // ----------------------------------------------------------------------
703  // Private helper methods
704  // ----------------------------------------------------------------------
705 
708  bool loadFile(
709  const Fw::StringBase& fileName
710  );
711 
713  void performCmd_Cancel();
714 
716  void performCmd_Step();
717 
719  void performCmd_Step_RELATIVE(
720  Fw::Time& currentTime
721  );
722 
724  void performCmd_Step_ABSOLUTE(
725  Fw::Time& currentTime
726  );
727 
729  void commandComplete(
730  const FwOpcodeType opCode
731  );
732 
734  void sequenceComplete();
735 
737  void error();
738 
740  void commandError(
741  const U32 number,
742  const FwOpcodeType opCode,
743  const U32 error
744  );
745 
748  bool requireRunMode(
749  RunMode mode
750  );
751 
753  void setCmdTimeout(
754  const Fw::Time &currentTime
755  );
756 
757  private:
758 
759  // ----------------------------------------------------------------------
760  // Private member variables
761  // ----------------------------------------------------------------------
762 
764  FPrimeSequence m_FPrimeSequence;
765 
767  Sequence *m_sequence;
768 
770  U32 m_loadCmdCount;
771 
773  U32 m_cancelCmdCount;
774 
776  U32 m_errorCount;
777 
779  RunMode m_runMode;
780 
782  StepMode m_stepMode;
783 
785  Sequence::Record m_record;
786 
788  Timer m_cmdTimer;
789 
791  U32 m_executedCount;
792 
794  U32 m_totalExecutedCount;
795 
797  U32 m_sequencesCompletedCount;
798 
800  U32 m_timeout;
801 
803  Timer m_cmdTimeoutTimer;
804 
806  Svc::CmdSequencer_BlockState::t m_blockState;
807  FwOpcodeType m_opCode;
808  U32 m_cmdSeq;
809  bool m_join_waiting;
810  };
811 
812 }
813 
814 #endif
Definition: Time.hpp:9
friend class Svc::Mixed::CmdSequencerTester
void recordMismatch(const U32 numRecords, const U32 extraBytes)
Record mismatch.
Definition: Events.cpp:93
void setSequenceFormat(Sequence &sequence)
FwIdType FwOpcodeType
The type of a command opcode.
TimeBase m_timeBase
The time base of the sequence.
PlatformSizeType FwSizeType
Events(Sequence &sequence)
Construct an Events object.
Definition: Events.cpp:17
I32 FwEnumStoreType
CmdSequencerComponentImpl(const char *compName)
Construct a CmdSequencer.
friend class Svc::ImmediateBase::CmdSequencerTester
bool loadFile(const Fw::StringBase &fileName)
U32 m_numRecords
The number of records in the sequence.
Fw::Time m_timeTag
The time tag. NOTE: timeBase and context not filled in.
Enum representing a command response.
friend class Svc::JoinWait::CmdSequencerTester
U8 FwTimeContextStoreType
The type used to serialize a time context value.
void recordInvalid(const U32 recordNumber, const I32 error)
Record invalid.
Definition: Events.cpp:80
void allocateBuffer(FwEnumStoreType identifier, Fw::MemAllocator &allocator, FwSizeType bytes)
Give the sequence representation a memory buffer.
Definition: Sequence.cpp:77
void setFileName(const Fw::StringBase &fileName)
Set the file name. Also sets the log file name.
Definition: Sequence.cpp:111
SerializeStatus
forward declaration for string
void timeContextMismatch(const FwTimeContextStoreType currTimeContext, const FwTimeContextStoreType seqTimeContext)
Time context mismatch.
Definition: Events.cpp:119
virtual bool hasMoreRecords() const =0
friend class Svc::Immediate::CmdSequencerTester
Fw::ExternalSerializeBuffer m_buffer
Serialize buffer to hold the binary sequence data.
~CmdSequencerComponentImpl()
Destroy a CmdDispatcherComponentBase.
Fw::CmdStringArg m_fileName
The sequence file name.
Container for computed and stored CRC values.
TimeBase
Definition: FpConfig.h:29
FwTimeContextStoreType m_timeContext
The context of the sequence.
Fw::LogStringArg m_logFileName
Copy of file name for events.
FwEnumStoreType m_allocatorId
The allocator ID.
void allocateBuffer(const FwEnumStoreType identifier, Fw::MemAllocator &allocator, const FwSizeType bytes)
A sequence with unspecified binary format.
void timeBaseMismatch(const TimeBase currTimeBase, const TimeBase seqTimeBase)
Time base mismatch.
Definition: Events.cpp:106
void deallocateBuffer(Fw::MemAllocator &allocator)
Deallocate the buffer.
Definition: Sequence.cpp:94
void update(const BYTE *buffer, FwSizeType bufferSize)
Update computed CRC.
void fileInvalid(const CmdSequencer_FileReadStage::t stage, const I32 error)
File invalid.
Definition: Events.cpp:37
External serialize buffer with no copy semantics.
FpySequencer_SequencerStateMachineStateMachineBase::State State
friend class Svc::ImmediateEOS::CmdSequencerTester
FPrimeSequence(CmdSequencerComponentImpl &component)
Construct an FPrimeSequence.
void setTimeout(const U32 seconds)
void fileSizeError(const U32 size)
File size error.
Definition: Events.cpp:68
Sequence(CmdSequencerComponentImpl &component)
Construct a Sequence object.
Definition: Sequence.cpp:17
friend class Svc::MixedRelativeBase::CmdSequencerTester
void deallocateBuffer(Fw::MemAllocator &allocator)
Return allocated buffer. Call during shutdown.
A sequence that uses the F Prime binary format.
virtual bool loadFile(const Fw::StringBase &fileName)=0
virtual ~Sequence()
Destroy a Sequence object.
Definition: Sequence.cpp:26
Defines a file class to validate files or generate a file validator file.
void fileCRCFailure(const U32 storedCRC, const U32 computedCRC)
File CRC failure.
Definition: Events.cpp:24
PlatformIndexType FwIndexType
CmdSequencerComponentImpl & m_component
The enclosing component.
Auto-generated base for CmdSequencer component.
static Comparison compare(const Time &time1, const Time &time2)
Definition: Time.cpp:159
RateGroupDivider component implementation.
virtual void nextRecord(Record &record)=0
friend class Svc::Relative::CmdSequencerTester
U8 BYTE
byte type
Definition: BasicTypes.h:59
Defines a base class for a memory allocator for classes.
void loadSequence(const Fw::StringBase &fileName)
U16 FwTimeBaseStoreType
The type used to serialize a time base value.
bool validateTime(CmdSequencerComponentImpl &component)
Definition: Sequence.cpp:42
Fw::String m_stringFileName
Copy of file name for ports.
const Header & getHeader() const
Get the sequence header.
Definition: Sequence.cpp:105