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 {
24 class CmdSequencerTester;
25 }
26 namespace Immediate {
27 class CmdSequencerTester;
28 }
29 namespace ImmediateEOS {
30 class CmdSequencerTester;
31 }
32 namespace Mixed {
33 class CmdSequencerTester;
34 }
35 namespace MixedRelativeBase {
36 class CmdSequencerTester;
37 }
38 namespace Relative {
39 class CmdSequencerTester;
40 }
41 namespace JoinWait {
42 class CmdSequencerTester;
43 }
44 
46  friend class CmdSequencerTester;
54 
55  private:
56  // ----------------------------------------------------------------------
57  // Private enumerations
58  // ----------------------------------------------------------------------
59 
61  enum RunMode { STOPPED, RUNNING };
62 
64  enum StepMode { AUTO, MANUAL };
65 
66  public:
67  // ----------------------------------------------------------------------
68  // Public classes
69  // ----------------------------------------------------------------------
70 
73  class Sequence {
74  public:
77  class Events {
78  public:
80  Events(Sequence& sequence
81  );
82 
83  public:
85  void fileCRCFailure(const U32 storedCRC,
86  const U32 computedCRC
87  );
88 
91  const I32 error
92  );
93 
95  void fileNotFound();
96 
98  void fileReadError();
99 
101  void fileSizeError(const U32 size
102  );
103 
105  void recordInvalid(const U32 recordNumber,
106  const I32 error
107  );
108 
110  void recordMismatch(const U32 numRecords,
111  const U32 extraBytes
112  );
113 
115  void timeBaseMismatch(const TimeBase currTimeBase,
116  const TimeBase seqTimeBase
117  );
118 
120  void timeContextMismatch(const FwTimeContextStoreType currTimeContext,
121  const FwTimeContextStoreType seqTimeContext
122  );
123 
124  // No Records
125  void noRecords();
126 
127  private:
129  Sequence& m_sequence;
130  };
131 
132  public:
135  );
136 
138  virtual ~Sequence();
139 
140  public:
143  class Header {
144  public:
145  enum Constants {
148  sizeof(U32) + sizeof(U32) + sizeof(FwTimeBaseStoreType) + sizeof(FwTimeContextStoreType)
149  };
150 
151  public:
153  Header();
154 
155  public:
158  bool validateTime(CmdSequencerComponentImpl& component
159  );
160 
161  public:
164 
167 
170 
173  };
174 
175  public:
178  class Record {
179  public:
180  enum Descriptor {
184  };
185 
186  public:
189 
190  public:
193 
196 
199  };
200 
201  public:
203  void allocateBuffer(FwEnumStoreType identifier,
204  Fw::MemAllocator& allocator,
205  FwSizeType bytes
206  );
207 
209  void deallocateBuffer(Fw::MemAllocator& allocator
210  );
211 
213  void setFileName(const Fw::ConstStringBase& fileName);
214 
218 
222 
226 
228  const Header& getHeader() const;
229 
232  virtual bool loadFile(const Fw::ConstStringBase& fileName
233  ) = 0;
234 
237  virtual bool hasMoreRecords() const = 0;
238 
241  virtual void nextRecord(Record& record
242  ) = 0;
243 
247  virtual void reset() = 0;
248 
251  virtual void clear() = 0;
252 
253  protected:
256 
259 
262 
265 
268 
271 
274 
277  };
278 
281  class FPrimeSequence : public Sequence {
282  private:
283  enum Constants { INITIAL_COMPUTED_VALUE = 0xFFFFFFFFU };
284 
285  public:
288  struct CRC {
290  CRC();
291 
293  void init();
294 
296  void update(const BYTE* buffer,
297  FwSizeType bufferSize
298  );
299 
301  void finalize();
302 
305 
307  U32 m_stored;
308  };
309 
310  public:
313  );
314 
315  public:
318  bool loadFile(const Fw::ConstStringBase& fileName
319  );
320 
323  bool hasMoreRecords() const;
324 
327  void nextRecord(Record& record
328  );
329 
333  void reset();
334 
337  void clear();
338 
339  private:
342  bool readFile();
343 
346  bool readOpenFile();
347 
351  bool readHeader();
352 
355  bool deserializeHeader();
356 
359  bool readRecordsAndCRC();
360 
363  bool extractCRC();
364 
367  bool validateCRC();
368 
371  Fw::SerializeStatus deserializeRecord(Record& record
372  );
373 
376  Fw::SerializeStatus deserializeDescriptor(Record::Descriptor& descriptor
377  );
378 
381  Fw::SerializeStatus deserializeTimeTag(Fw::Time& timeTag
382  );
383 
386  Fw::SerializeStatus deserializeRecordSize(U32& recordSize
387  );
388 
391  Fw::SerializeStatus copyCommand(Fw::ComBuffer& comBuffer,
392  const U32 recordSize
393  );
394 
397  bool validateRecords();
398 
399  private:
401  CRC m_crc;
402 
404  Os::File m_sequenceFile;
405  };
406 
407  private:
408  // ----------------------------------------------------------------------
409  // Private classes
410  // ----------------------------------------------------------------------
411 
414  class Timer {
415  friend class CmdSequencerTester;
416  friend class Svc::ImmediateBase::CmdSequencerTester;
417  friend class Svc::Immediate::CmdSequencerTester;
418  friend class Svc::ImmediateEOS::CmdSequencerTester;
419  friend class Svc::Mixed::CmdSequencerTester;
420  friend class Svc::MixedRelativeBase::CmdSequencerTester;
421  friend class Svc::Relative::CmdSequencerTester;
422  friend class Svc::JoinWait::CmdSequencerTester;
423 
424  private:
426  typedef enum { SET, CLEAR } State;
427 
428  public:
430  Timer() : m_state(CLEAR) {}
431 
433  void set(Fw::Time time
434  ) {
435  this->m_state = SET;
436  this->expirationTime = time;
437  }
438 
440  void clear() { this->m_state = CLEAR; }
441 
444  bool isExpiredAt(Fw::Time time
445  ) {
446  if (this->m_state == CLEAR) {
447  return false;
448  } else if (Fw::Time::compare(this->expirationTime, time) == Fw::TimeComparison::GT) {
449  return false;
450  }
451  return true;
452  }
453 
454  private:
456  State m_state;
457 
459  Fw::Time expirationTime;
460  };
461 
462  public:
463  // ----------------------------------------------------------------------
464  // Construction, initialization, and destruction
465  // ----------------------------------------------------------------------
466 
468  CmdSequencerComponentImpl(const char* compName
469  );
470 
474  void setTimeout(const U32 seconds
475  );
476 
481  void setSequenceFormat(Sequence& sequence
482  );
483 
487  void allocateBuffer(const FwEnumStoreType identifier,
488  Fw::MemAllocator& allocator,
489  const FwSizeType bytes
490  );
491 
494  void loadSequence(const Fw::ConstStringBase& fileName
495  );
496 
498  void deallocateBuffer(Fw::MemAllocator& allocator
499  );
500 
503 
504  private:
505  // ----------------------------------------------------------------------
506  // Handler implementations for input ports
507  // ----------------------------------------------------------------------
508 
510  void cmdResponseIn_handler(FwIndexType portNum,
511  FwOpcodeType opcode,
512  U32 cmdSeq,
513  const Fw::CmdResponse& response
514  ) override;
515 
517  void schedIn_handler(FwIndexType portNum,
518  U32 order
519  ) override;
520 
522  void seqRunIn_handler(FwIndexType portNum,
523  const Fw::StringBase& filename
524  ) override;
525 
529  void seqDispatchIn_handler(FwIndexType portNum,
530  Fw::StringBase& file_name
531  ) override;
532 
534  void pingIn_handler(FwIndexType portNum,
535  U32 key
536  ) override;
537 
540  void seqCancelIn_handler(const FwIndexType portNum
541  ) override;
542 
543  private:
544  // ----------------------------------------------------------------------
545  // Command handler implementations
546  // ----------------------------------------------------------------------
547 
550  void CS_AUTO_cmdHandler(FwOpcodeType opcode,
551  U32 cmdSeq
552  ) override;
553 
556  void CS_CANCEL_cmdHandler(FwOpcodeType opCode,
557  U32 cmdSeq
558  ) override;
559 
562  void CS_MANUAL_cmdHandler(FwOpcodeType opcode,
563  U32 cmdSeq
564  ) override;
565 
567  void CS_RUN_cmdHandler(FwOpcodeType opCode,
568  U32 cmdSeq,
569  const Fw::CmdStringArg& fileName,
571  ) override;
572 
575  void CS_START_cmdHandler(FwOpcodeType opcode,
576  U32 cmdSeq
577  ) override;
578 
582  void CS_STEP_cmdHandler(FwOpcodeType opcode,
583  U32 cmdSeq
584  ) override;
585 
588  void CS_VALIDATE_cmdHandler(FwOpcodeType opCode,
589  U32 cmdSeq,
590  const Fw::CmdStringArg& fileName
591  ) override;
592 
597  void CS_JOIN_WAIT_cmdHandler(const FwOpcodeType opCode,
598  const U32 cmdSeq
599  ) override;
600 
601  private:
602  // ----------------------------------------------------------------------
603  // Private helper methods
604  // ----------------------------------------------------------------------
605 
608  bool loadFile(const Fw::ConstStringBase& fileName
609  );
610 
612  void performCmd_Cancel();
613 
615  void performCmd_Step();
616 
618  void performCmd_Step_RELATIVE(Fw::Time& currentTime
619  );
620 
622  void performCmd_Step_ABSOLUTE(Fw::Time& currentTime
623  );
624 
626  void commandComplete(const FwOpcodeType opCode
627  );
628 
630  void sequenceComplete();
631 
633  void error();
634 
636  void commandError(const U32 number,
637  const FwOpcodeType opCode,
638  const U32 error
639  );
640 
643  bool requireRunMode(RunMode mode
644  );
645 
647  void setCmdTimeout(const Fw::Time& currentTime
648  );
649 
651  void doSequenceRun(const Fw::StringBase& fileName);
652 
653  private:
654  // ----------------------------------------------------------------------
655  // Private member variables
656  // ----------------------------------------------------------------------
657 
659  FPrimeSequence m_FPrimeSequence;
660 
662  Sequence* m_sequence;
663 
665  U32 m_loadCmdCount;
666 
668  U32 m_cancelCmdCount;
669 
671  U32 m_errorCount;
672 
674  RunMode m_runMode;
675 
677  StepMode m_stepMode;
678 
680  Sequence::Record m_record;
681 
683  Timer m_cmdTimer;
684 
686  U32 m_executedCount;
687 
689  U32 m_totalExecutedCount;
690 
692  U32 m_sequencesCompletedCount;
693 
695  U32 m_timeout;
696 
698  Timer m_cmdTimeoutTimer;
699 
701  Svc::CmdSequencer_BlockState::t m_blockState;
702  FwOpcodeType m_opCode;
703  U32 m_cmdSeq;
704  bool m_join_waiting;
705 };
706 
707 } // namespace Svc
708 
709 #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.
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
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:109
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.
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