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::StringBase& fileName);
214 
218 
222 
226 
228  const Header& getHeader() const;
229 
232  virtual bool loadFile(const Fw::StringBase& 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::StringBase& 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::Time::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::StringBase& 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  );
515 
517  void schedIn_handler(FwIndexType portNum,
518  U32 order
519  );
520 
522  void seqRunIn_handler(FwIndexType portNum,
523  const Fw::StringBase& filename
524  );
525 
527  void pingIn_handler(FwIndexType portNum,
528  U32 key
529  );
530 
533  void seqCancelIn_handler(const FwIndexType portNum
534  );
535 
536  private:
537  // ----------------------------------------------------------------------
538  // Command handler implementations
539  // ----------------------------------------------------------------------
540 
543  void CS_AUTO_cmdHandler(FwOpcodeType opcode,
544  U32 cmdSeq
545  );
546 
549  void CS_CANCEL_cmdHandler(FwOpcodeType opCode,
550  U32 cmdSeq
551  );
552 
555  void CS_MANUAL_cmdHandler(FwOpcodeType opcode,
556  U32 cmdSeq
557  );
558 
560  void CS_RUN_cmdHandler(FwOpcodeType opCode,
561  U32 cmdSeq,
562  const Fw::CmdStringArg& fileName,
564  );
565 
568  void CS_START_cmdHandler(FwOpcodeType opcode,
569  U32 cmdSeq
570  );
571 
575  void CS_STEP_cmdHandler(FwOpcodeType opcode,
576  U32 cmdSeq
577  );
578 
581  void CS_VALIDATE_cmdHandler(FwOpcodeType opCode,
582  U32 cmdSeq,
583  const Fw::CmdStringArg& fileName
584  );
585 
590  void CS_JOIN_WAIT_cmdHandler(const FwOpcodeType opCode,
591  const U32 cmdSeq
592  );
593 
594  private:
595  // ----------------------------------------------------------------------
596  // Private helper methods
597  // ----------------------------------------------------------------------
598 
601  bool loadFile(const Fw::StringBase& fileName
602  );
603 
605  void performCmd_Cancel();
606 
608  void performCmd_Step();
609 
611  void performCmd_Step_RELATIVE(Fw::Time& currentTime
612  );
613 
615  void performCmd_Step_ABSOLUTE(Fw::Time& currentTime
616  );
617 
619  void commandComplete(const FwOpcodeType opCode
620  );
621 
623  void sequenceComplete();
624 
626  void error();
627 
629  void commandError(const U32 number,
630  const FwOpcodeType opCode,
631  const U32 error
632  );
633 
636  bool requireRunMode(RunMode mode
637  );
638 
640  void setCmdTimeout(const Fw::Time& currentTime
641  );
642 
643  private:
644  // ----------------------------------------------------------------------
645  // Private member variables
646  // ----------------------------------------------------------------------
647 
649  FPrimeSequence m_FPrimeSequence;
650 
652  Sequence* m_sequence;
653 
655  U32 m_loadCmdCount;
656 
658  U32 m_cancelCmdCount;
659 
661  U32 m_errorCount;
662 
664  RunMode m_runMode;
665 
667  StepMode m_stepMode;
668 
670  Sequence::Record m_record;
671 
673  Timer m_cmdTimer;
674 
676  U32 m_executedCount;
677 
679  U32 m_totalExecutedCount;
680 
682  U32 m_sequencesCompletedCount;
683 
685  U32 m_timeout;
686 
688  Timer m_cmdTimeoutTimer;
689 
691  Svc::CmdSequencer_BlockState::t m_blockState;
692  FwOpcodeType m_opCode;
693  U32 m_cmdSeq;
694  bool m_join_waiting;
695 };
696 
697 } // namespace Svc
698 
699 #endif
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
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:54
void allocateBuffer(FwEnumStoreType identifier, Fw::MemAllocator &allocator, FwSizeType bytes)
Give the sequence representation a memory buffer.
Definition: Sequence.cpp:45
void setFileName(const Fw::StringBase &fileName)
Set the file name. Also sets the log file name.
Definition: Sequence.cpp:64
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
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
Sequence(CmdSequencerComponentImpl &component)
Construct a Sequence object.
Definition: Sequence.cpp:16
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:19
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:18
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:107
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.
void loadSequence(const Fw::StringBase &fileName)
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