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"
20 
21 namespace Svc {
22 
23 // Forward declaration for UTs
24 namespace ImmediateBase {
25 class CmdSequencerTester;
26 }
27 namespace Immediate {
28 class CmdSequencerTester;
29 }
30 namespace ImmediateEOS {
31 class CmdSequencerTester;
32 }
33 namespace Mixed {
34 class CmdSequencerTester;
35 }
36 namespace MixedRelativeBase {
37 class CmdSequencerTester;
38 }
39 namespace Relative {
40 class CmdSequencerTester;
41 }
42 namespace JoinWait {
43 class CmdSequencerTester;
44 }
45 
47  friend class CmdSequencerTester;
55 
56  private:
57  // ----------------------------------------------------------------------
58  // Private enumerations
59  // ----------------------------------------------------------------------
60 
62  enum RunMode { STOPPED, RUNNING };
63 
65  enum StepMode { AUTO, MANUAL };
66 
67  public:
68  // ----------------------------------------------------------------------
69  // Public classes
70  // ----------------------------------------------------------------------
71 
74  class Sequence {
75  public:
78  class Events {
79  public:
81  Events(Sequence& sequence
82  );
83 
84  public:
86  void fileCRCFailure(const U32 storedCRC,
87  const U32 computedCRC
88  );
89 
92  const I32 error
93  );
94 
96  void fileNotFound();
97 
99  void fileReadError();
100 
102  void fileSizeError(const U32 size
103  );
104 
106  void recordInvalid(const U32 recordNumber,
107  const I32 error
108  );
109 
111  void recordMismatch(const U32 numRecords,
112  const U32 extraBytes
113  );
114 
116  void timeBaseMismatch(const TimeBase currTimeBase,
117  const TimeBase seqTimeBase
118  );
119 
121  void timeContextMismatch(const FwTimeContextStoreType currTimeContext,
122  const FwTimeContextStoreType seqTimeContext
123  );
124 
125  // No Records
126  void noRecords();
127 
128  private:
130  Sequence& m_sequence;
131  };
132 
133  public:
136  );
137 
139  virtual ~Sequence();
140 
141  public:
144  class Header {
145  public:
146  enum Constants {
149  sizeof(U32) + sizeof(U32) + sizeof(FwTimeBaseStoreType) + sizeof(FwTimeContextStoreType)
150  };
151 
152  public:
154  Header();
155 
156  public:
159  bool validateTime(CmdSequencerComponentImpl& component
160  );
161 
162  public:
165 
168 
171 
174  };
175 
176  public:
179  class Record {
180  public:
181  enum Descriptor {
185  };
186 
187  public:
190 
191  public:
194 
197 
200  };
201 
202  public:
204  void allocateBuffer(FwEnumStoreType identifier,
205  Fw::MemAllocator& allocator,
206  FwSizeType bytes
207  );
208 
210  void deallocateBuffer(Fw::MemAllocator& allocator
211  );
212 
214  void setFileName(const Fw::ConstStringBase& fileName);
215 
219 
223 
227 
229  const Header& getHeader() const;
230 
233  virtual bool loadFile(const Fw::ConstStringBase& fileName
234  ) = 0;
235 
238  virtual bool hasMoreRecords() const = 0;
239 
242  virtual void nextRecord(Record& record
243  ) = 0;
244 
248  virtual void reset() = 0;
249 
252  virtual void clear() = 0;
253 
254  protected:
257 
260 
263 
266 
269 
272 
275 
278  };
279 
282  class FPrimeSequence : public Sequence {
283  private:
284  enum Constants { INITIAL_COMPUTED_VALUE = 0xFFFFFFFFU };
285 
286  public:
289  struct CRC {
291  CRC();
292 
294  void init();
295 
297  void update(const BYTE* buffer,
298  FwSizeType bufferSize
299  );
300 
302  void finalize();
303 
306 
308  U32 m_stored;
309  };
310 
311  public:
314  );
315 
316  public:
319  bool loadFile(const Fw::ConstStringBase& fileName
320  );
321 
324  bool hasMoreRecords() const;
325 
328  void nextRecord(Record& record
329  );
330 
334  void reset();
335 
338  void clear();
339 
340  private:
343  bool readFile();
344 
347  bool readOpenFile();
348 
352  bool readHeader();
353 
356  bool deserializeHeader();
357 
360  bool readRecordsAndCRC();
361 
364  bool extractCRC();
365 
368  bool validateCRC();
369 
372  Fw::SerializeStatus deserializeRecord(Record& record
373  );
374 
377  Fw::SerializeStatus deserializeDescriptor(Record::Descriptor& descriptor
378  );
379 
382  Fw::SerializeStatus deserializeTimeTag(Fw::Time& timeTag
383  );
384 
387  Fw::SerializeStatus deserializeRecordSize(U32& recordSize
388  );
389 
392  Fw::SerializeStatus copyCommand(Fw::ComBuffer& comBuffer,
393  const U32 recordSize
394  );
395 
398  bool validateRecords();
399 
400  private:
402  CRC m_crc;
403 
405  Os::File m_sequenceFile;
406  };
407 
408  private:
409  // ----------------------------------------------------------------------
410  // Private classes
411  // ----------------------------------------------------------------------
412 
415  class Timer {
416  friend class CmdSequencerTester;
417  friend class Svc::ImmediateBase::CmdSequencerTester;
418  friend class Svc::Immediate::CmdSequencerTester;
419  friend class Svc::ImmediateEOS::CmdSequencerTester;
420  friend class Svc::Mixed::CmdSequencerTester;
421  friend class Svc::MixedRelativeBase::CmdSequencerTester;
422  friend class Svc::Relative::CmdSequencerTester;
423  friend class Svc::JoinWait::CmdSequencerTester;
424 
425  private:
427  typedef enum { SET, CLEAR } State;
428 
429  public:
431  Timer() : m_state(CLEAR) {}
432 
434  void set(Fw::Time time
435  ) {
436  this->m_state = SET;
437  this->expirationTime = time;
438  }
439 
441  void clear() { this->m_state = CLEAR; }
442 
445  bool isExpiredAt(Fw::Time time
446  ) {
447  if (this->m_state == CLEAR) {
448  return false;
449  } else if (Fw::Time::compare(this->expirationTime, time) == Fw::TimeComparison::GT) {
450  return false;
451  }
452  return true;
453  }
454 
455  private:
457  State m_state;
458 
460  Fw::Time expirationTime;
461  };
462 
463  public:
464  // ----------------------------------------------------------------------
465  // Construction, initialization, and destruction
466  // ----------------------------------------------------------------------
467 
469  CmdSequencerComponentImpl(const char* compName
470  );
471 
475  void setTimeout(const U32 seconds
476  );
477 
482  void setSequenceFormat(Sequence& sequence
483  );
484 
488  void allocateBuffer(const FwEnumStoreType identifier,
489  Fw::MemAllocator& allocator,
490  const FwSizeType bytes
491  );
492 
495  void loadSequence(const Fw::ConstStringBase& fileName
496  );
497 
499  void deallocateBuffer(Fw::MemAllocator& allocator
500  );
501 
504 
505  private:
506  // ----------------------------------------------------------------------
507  // Handler implementations for input ports
508  // ----------------------------------------------------------------------
509 
511  void cmdResponseIn_handler(FwIndexType portNum,
512  FwOpcodeType opcode,
513  U32 cmdSeq,
514  const Fw::CmdResponse& response
515  ) override;
516 
518  void schedIn_handler(FwIndexType portNum,
519  U32 order
520  ) override;
521 
523  void seqRunIn_handler(FwIndexType portNum,
524  const Fw::StringBase& filename,
525  const Svc::SeqArgs& args
526  ) override;
527 
531  void seqDispatchIn_handler(FwIndexType portNum,
532  Fw::StringBase& file_name
533  ) override;
534 
536  void pingIn_handler(FwIndexType portNum,
537  U32 key
538  ) override;
539 
542  void seqCancelIn_handler(const FwIndexType portNum
543  ) override;
544 
545  private:
546  // ----------------------------------------------------------------------
547  // Command handler implementations
548  // ----------------------------------------------------------------------
549 
552  void CS_AUTO_cmdHandler(FwOpcodeType opcode,
553  U32 cmdSeq
554  ) override;
555 
558  void CS_CANCEL_cmdHandler(FwOpcodeType opCode,
559  U32 cmdSeq
560  ) override;
561 
564  void CS_MANUAL_cmdHandler(FwOpcodeType opcode,
565  U32 cmdSeq
566  ) override;
567 
569  void CS_RUN_cmdHandler(FwOpcodeType opCode,
570  U32 cmdSeq,
571  const Fw::CmdStringArg& fileName,
572  Svc::BlockState block
573  ) override;
574 
577  void CS_START_cmdHandler(FwOpcodeType opcode,
578  U32 cmdSeq
579  ) override;
580 
584  void CS_STEP_cmdHandler(FwOpcodeType opcode,
585  U32 cmdSeq
586  ) override;
587 
590  void CS_VALIDATE_cmdHandler(FwOpcodeType opCode,
591  U32 cmdSeq,
592  const Fw::CmdStringArg& fileName
593  ) override;
594 
599  void CS_JOIN_WAIT_cmdHandler(const FwOpcodeType opCode,
600  const U32 cmdSeq
601  ) override;
602 
603  private:
604  // ----------------------------------------------------------------------
605  // Private helper methods
606  // ----------------------------------------------------------------------
607 
610  bool loadFile(const Fw::ConstStringBase& fileName
611  );
612 
614  void performCmd_Cancel();
615 
617  void performCmd_Step();
618 
620  void performCmd_Step_RELATIVE(Fw::Time& currentTime
621  );
622 
624  void performCmd_Step_ABSOLUTE(Fw::Time& currentTime
625  );
626 
628  void commandComplete(const FwOpcodeType opCode
629  );
630 
632  void sequenceComplete();
633 
635  void error();
636 
638  void commandError(const U32 number,
639  const FwOpcodeType opCode,
640  const U32 error
641  );
642 
645  bool requireRunMode(RunMode mode
646  );
647 
649  void setCmdTimeout(const Fw::Time& currentTime
650  );
651 
653  void doSequenceRun(const Fw::StringBase& fileName);
654 
655  private:
656  // ----------------------------------------------------------------------
657  // Private member variables
658  // ----------------------------------------------------------------------
659 
661  FPrimeSequence m_FPrimeSequence;
662 
664  Sequence* m_sequence;
665 
667  U32 m_loadCmdCount;
668 
670  U32 m_cancelCmdCount;
671 
673  U32 m_errorCount;
674 
676  RunMode m_runMode;
677 
679  StepMode m_stepMode;
680 
682  Sequence::Record m_record;
683 
685  Timer m_cmdTimer;
686 
688  U32 m_executedCount;
689 
691  U32 m_totalExecutedCount;
692 
694  U32 m_sequencesCompletedCount;
695 
697  U32 m_timeout;
698 
700  Timer m_cmdTimeoutTimer;
701 
703  Svc::BlockState::t m_blockState;
704  FwOpcodeType m_opCode;
705  U32 m_cmdSeq;
706  bool m_join_waiting;
707 };
708 
709 } // namespace Svc
710 
711 #endif
void loadSequence(const Fw::ConstStringBase &fileName)
friend class Svc::Mixed::CmdSequencerTester
void recordMismatch(const U32 numRecords, const U32 extraBytes)
Record mismatch.
Definition: Events.cpp:61
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:16
I32 FwEnumStoreType
CmdSequencerComponentImpl(const char *compName)
Construct a CmdSequencer.
friend class Svc::ImmediateBase::CmdSequencerTester
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:54
void allocateBuffer(FwEnumStoreType identifier, Fw::MemAllocator &allocator, FwSizeType bytes)
Give the sequence representation a memory buffer.
Definition: Sequence.cpp:45
SerializeStatus
forward declaration for string
void timeContextMismatch(const FwTimeContextStoreType currTimeContext, const FwTimeContextStoreType seqTimeContext)
Time context mismatch.
Definition: Events.cpp:76
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.
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.
enum T t
For backwards compatibility.
void timeBaseMismatch(const TimeBase currTimeBase, const TimeBase seqTimeBase)
Time base mismatch.
Definition: Events.cpp:68
bool loadFile(const Fw::ConstStringBase &fileName)
void deallocateBuffer(Fw::MemAllocator &allocator)
Deallocate the buffer.
Definition: Sequence.cpp:55
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:25
External serialize buffer with no copy semantics.
FpySequencer_SequencerStateMachineStateMachineBase::State State
Sequencer blocking 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:47
void setFileName(const Fw::ConstStringBase &fileName)
Set the file name. Also sets the log file name.
Definition: Sequence.cpp:64
virtual bool loadFile(const Fw::ConstStringBase &fileName)=0
Sequence(CmdSequencerComponentImpl &component)
Construct a Sequence object.
Definition: Sequence.cpp:16
friend class Svc::MixedRelativeBase::CmdSequencerTester
static TimeComparison compare(const Time &time1, const Time &time2)
Definition: Time.cpp:139
void deallocateBuffer(Fw::MemAllocator &allocator)
Return allocated buffer. Call during shutdown.
Memory Allocation base class.
A sequence that uses the F Prime binary format.
virtual ~Sequence()
Destroy a Sequence object.
Definition: Sequence.cpp:19
Defines a file class to validate files or generate a file validator file.
A read-only abstract superclass for StringBase.
enum T t
For backwards compatibility.
void fileCRCFailure(const U32 storedCRC, const U32 computedCRC)
File CRC failure.
Definition: Events.cpp:18
PlatformIndexType FwIndexType
CmdSequencerComponentImpl & m_component
The enclosing component.
Auto-generated base for CmdSequencer component.
RateGroupDivider component implementation.
virtual void nextRecord(Record &record)=0
friend class Svc::Relative::CmdSequencerTester
U8 BYTE
byte type
Definition: BasicTypes.h:56
Defines a base class for a memory allocator for classes.
U16 FwTimeBaseStoreType
The type used to serialize a time base value.
Define enumeration for Time base types.
bool validateTime(CmdSequencerComponentImpl &component)
Definition: Sequence.cpp:24
Fw::String m_stringFileName
Copy of file name for ports.
const Header & getHeader() const
Get the sequence header.
Definition: Sequence.cpp:60