F´ Flight Software - C/C++ Documentation  devel
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 
24  {
25 
26  PRIVATE:
27 
28  // ----------------------------------------------------------------------
29  // Private enumerations
30  // ----------------------------------------------------------------------
31 
33  enum RunMode {
34  STOPPED, RUNNING
35  };
36 
38  enum StepMode {
39  AUTO, MANUAL
40  };
41 
42  public:
43 
44  // ----------------------------------------------------------------------
45  // Public classes
46  // ----------------------------------------------------------------------
47 
50  class Sequence {
51 
52  public:
53 
56  class Events {
57 
58  public:
59 
61  Events(
62  Sequence& sequence
63  );
64 
65  public:
66 
68  void fileCRCFailure(
69  const U32 storedCRC,
70  const U32 computedCRC
71  );
72 
74  void fileInvalid(
75  const CmdSequencer_FileReadStage::t stage,
76  const I32 error
77  );
78 
80  void fileNotFound();
81 
83  void fileReadError();
84 
86  void fileSizeError(
87  const U32 size
88  );
89 
91  void recordInvalid(
92  const U32 recordNumber,
93  const I32 error
94  );
95 
97  void recordMismatch(
98  const U32 numRecords,
99  const U32 extraBytes
100  );
101 
103  void timeBaseMismatch(
104  const TimeBase currTimeBase,
105  const TimeBase seqTimeBase
106  );
107 
109  void timeContextMismatch(
110  const FwTimeContextStoreType currTimeContext,
111  const FwTimeContextStoreType seqTimeContext
112  );
113 
114  PRIVATE:
115 
117  Sequence& m_sequence;
118 
119  };
120 
121  public:
122 
124  Sequence(
125  CmdSequencerComponentImpl& component
126  );
127 
129  virtual ~Sequence();
130 
131  public:
132 
135  class Header {
136 
137  public:
138 
139  enum Constants {
142  sizeof(U32) +
143  sizeof(U32) +
144  sizeof(FwTimeBaseStoreType) +
145  sizeof(FwTimeContextStoreType)
146  };
147 
148  public:
149 
151  Header();
152 
153  public:
154 
157  bool validateTime(
158  CmdSequencerComponentImpl& component
159  );
160 
161  public:
162 
165 
168 
171 
174 
175  };
176 
177  public:
178 
181  class Record {
182 
183  public:
184 
185  enum Descriptor {
189  };
190 
191  public:
192 
194  Record() :
196  {
197 
198  }
199 
200  public:
201 
204 
207 
210 
211  };
212 
213  public:
214 
216  void allocateBuffer(
217  NATIVE_INT_TYPE identifier,
218  Fw::MemAllocator& allocator,
219  NATIVE_UINT_TYPE bytes
220  );
221 
223  void deallocateBuffer(
224  Fw::MemAllocator& allocator
225  );
226 
228  void setFileName(const Fw::StringBase& fileName);
229 
233 
237 
241 
243  const Header& getHeader() const;
244 
247  virtual bool loadFile(
248  const Fw::StringBase& fileName
249  ) = 0;
250 
253  virtual bool hasMoreRecords() const = 0;
254 
257  virtual void nextRecord(
258  Record& record
259  ) = 0;
260 
264  virtual void reset() = 0;
265 
268  virtual void clear() = 0;
269 
270  PROTECTED:
271 
274 
277 
280 
283 
286 
289 
292 
295 
296  };
297 
301  public Sequence
302  {
303 
304  PRIVATE:
305 
306  enum Constants {
307  INITIAL_COMPUTED_VALUE = 0xFFFFFFFFU
308  };
309 
310  public:
311 
314  struct CRC {
315 
317  CRC();
318 
320  void init();
321 
323  void update(
324  const BYTE* buffer,
325  NATIVE_UINT_TYPE bufferSize
326  );
327 
329  void finalize();
330 
333 
335  U32 m_stored;
336 
337  };
338 
339  public:
340 
343  CmdSequencerComponentImpl& component
344  );
345 
346  public:
347 
350  bool loadFile(
351  const Fw::StringBase& fileName
352  );
353 
356  bool hasMoreRecords() const;
357 
360  void nextRecord(
361  Record& record
362  );
363 
367  void reset();
368 
371  void clear();
372 
373  PRIVATE:
374 
377  bool readFile();
378 
381  bool readOpenFile();
382 
386  bool readHeader();
387 
390  bool deserializeHeader();
391 
394  bool readRecordsAndCRC();
395 
398  bool extractCRC();
399 
402  bool validateCRC();
403 
406  Fw::SerializeStatus deserializeRecord(
407  Record& record
408  );
409 
412  Fw::SerializeStatus deserializeDescriptor(
413  Record::Descriptor& descriptor
414  );
415 
418  Fw::SerializeStatus deserializeTimeTag(
419  Fw::Time& timeTag
420  );
421 
424  Fw::SerializeStatus deserializeRecordSize(
425  U32& recordSize
426  );
427 
430  Fw::SerializeStatus copyCommand(
431  Fw::ComBuffer& comBuffer,
432  const U32 recordSize
433  );
434 
437  bool validateRecords();
438 
439  PRIVATE:
440 
442  CRC m_crc;
443 
445  Os::File m_sequenceFile;
446 
447  };
448 
449  PRIVATE:
450 
451  // ----------------------------------------------------------------------
452  // Private classes
453  // ----------------------------------------------------------------------
454 
457  class Timer {
458 
459  PRIVATE:
460 
462  typedef enum {
463  SET, CLEAR
464  } State;
465 
466  public:
467 
469  Timer() :
470  m_state(CLEAR)
471  {
472 
473  }
474 
476  void set(
477  Fw::Time time
478  ) {
479  this->m_state = SET;
480  this->expirationTime = time;
481  }
482 
484  void clear() {
485  this->m_state = CLEAR;
486  }
487 
490  bool isExpiredAt(
491  Fw::Time time
492  ) {
493  if (this->m_state == CLEAR) {
494  return false;
495  } else if (
496  Fw::Time::compare(this->expirationTime, time) == Fw::Time::GT
497  ) {
498  return false;
499  }
500  return true;
501  }
502 
503  PRIVATE:
504 
506  State m_state;
507 
509  Fw::Time expirationTime;
510 
511  };
512 
513 
514  public:
515 
516  // ----------------------------------------------------------------------
517  // Construction, initialization, and destruction
518  // ----------------------------------------------------------------------
519 
522  const char* compName
523  );
524 
528  void setTimeout(
529  const NATIVE_UINT_TYPE seconds
530  );
531 
536  void setSequenceFormat(
537  Sequence& sequence
538  );
539 
543  void allocateBuffer(
544  const NATIVE_INT_TYPE identifier,
545  Fw::MemAllocator& allocator,
546  const NATIVE_UINT_TYPE bytes
547  );
548 
551  void loadSequence(
552  const Fw::StringBase& fileName
553  );
554 
556  void deallocateBuffer(
557  Fw::MemAllocator& allocator
558  );
559 
562 
563  PRIVATE:
564 
565  // ----------------------------------------------------------------------
566  // Handler implementations for input ports
567  // ----------------------------------------------------------------------
568 
570  void cmdResponseIn_handler(
571  NATIVE_INT_TYPE portNum,
572  FwOpcodeType opcode,
573  U32 cmdSeq,
574  const Fw::CmdResponse& response
575  );
576 
578  void schedIn_handler(
579  NATIVE_INT_TYPE portNum,
580  NATIVE_UINT_TYPE order
581  );
582 
584  void seqRunIn_handler(
585  NATIVE_INT_TYPE portNum,
586  const Fw::StringBase& filename
587  );
588 
590  void pingIn_handler(
591  NATIVE_INT_TYPE portNum,
592  U32 key
593  );
594 
597  void seqCancelIn_handler(
598  const NATIVE_INT_TYPE portNum
599  );
600 
601  PRIVATE:
602 
603  // ----------------------------------------------------------------------
604  // Command handler implementations
605  // ----------------------------------------------------------------------
606 
609  void CS_AUTO_cmdHandler(
610  FwOpcodeType opcode,
611  U32 cmdSeq
612  );
613 
616  void CS_CANCEL_cmdHandler(
617  FwOpcodeType opCode,
618  U32 cmdSeq
619  );
620 
623  void CS_MANUAL_cmdHandler(
624  FwOpcodeType opcode,
625  U32 cmdSeq
626  );
627 
629  void CS_RUN_cmdHandler(
630  FwOpcodeType opCode,
631  U32 cmdSeq,
632  const Fw::CmdStringArg& fileName,
634  );
635 
638  void CS_START_cmdHandler(
639  FwOpcodeType opcode,
640  U32 cmdSeq
641  );
642 
646  void CS_STEP_cmdHandler(
647  FwOpcodeType opcode,
648  U32 cmdSeq
649  );
650 
653  void CS_VALIDATE_cmdHandler(
654  FwOpcodeType opCode,
655  U32 cmdSeq,
656  const Fw::CmdStringArg& fileName
657  );
658 
663  void CS_JOIN_WAIT_cmdHandler(
664  const FwOpcodeType opCode,
665  const U32 cmdSeq
666  );
667 
668  PRIVATE:
669 
670  // ----------------------------------------------------------------------
671  // Private helper methods
672  // ----------------------------------------------------------------------
673 
676  bool loadFile(
677  const Fw::StringBase& fileName
678  );
679 
681  void performCmd_Cancel();
682 
684  void performCmd_Step();
685 
687  void performCmd_Step_RELATIVE(
688  Fw::Time& currentTime
689  );
690 
692  void performCmd_Step_ABSOLUTE(
693  Fw::Time& currentTime
694  );
695 
697  void commandComplete(
698  const U32 opCode
699  );
700 
702  void sequenceComplete();
703 
705  void error();
706 
708  void commandError(
709  const U32 number,
710  const U32 opCode,
711  const U32 error
712  );
713 
716  bool requireRunMode(
717  RunMode mode
718  );
719 
721  void setCmdTimeout(
722  const Fw::Time &currentTime
723  );
724 
725  PRIVATE:
726 
727  // ----------------------------------------------------------------------
728  // Private member variables
729  // ----------------------------------------------------------------------
730 
732  FPrimeSequence m_FPrimeSequence;
733 
735  Sequence *m_sequence;
736 
738  U32 m_loadCmdCount;
739 
741  U32 m_cancelCmdCount;
742 
744  U32 m_errorCount;
745 
747  RunMode m_runMode;
748 
750  StepMode m_stepMode;
751 
753  Sequence::Record m_record;
754 
756  Timer m_cmdTimer;
757 
759  U32 m_executedCount;
760 
762  U32 m_totalExecutedCount;
763 
765  U32 m_sequencesCompletedCount;
766 
768  NATIVE_UINT_TYPE m_timeout;
769 
771  Timer m_cmdTimeoutTimer;
772 
774  Svc::CmdSequencer_BlockState::t m_blockState;
775  FwOpcodeType m_opCode;
776  U32 m_cmdSeq;
777  bool m_join_waiting;
778  };
779 
780 }
781 
782 #endif
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:55
U8 BYTE
byte type
Definition: BasicTypes.h:31
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:56
TimeBase
Definition: FpConfig.h:69
U16 FwTimeBaseStoreType
Definition: FpConfig.h:79
U32 FwOpcodeType
Definition: FpConfig.h:91
U8 FwTimeContextStoreType
Definition: FpConfig.h:83
Defines a base class for a memory allocator for classes.
Defines a file class to validate files or generate a file validator file.
Enum representing a command response.
External serialize buffer with no copy semantics.
Definition: Time.hpp:9
@ GT
Definition: Time.hpp:48
static Comparison compare(const Time &time1, const Time &time2)
Definition: Time.cpp:159
Auto-generated base for CmdSequencer component.
A sequence that uses the F Prime binary format.
FPrimeSequence(CmdSequencerComponentImpl &component)
Construct an FPrimeSequence.
bool loadFile(const Fw::StringBase &fileName)
void recordMismatch(const U32 numRecords, const U32 extraBytes)
Record mismatch.
Definition: Events.cpp:93
void timeBaseMismatch(const TimeBase currTimeBase, const TimeBase seqTimeBase)
Time base mismatch.
Definition: Events.cpp:106
void fileSizeError(const U32 size)
File size error.
Definition: Events.cpp:68
void fileCRCFailure(const U32 storedCRC, const U32 computedCRC)
File CRC failure.
Definition: Events.cpp:24
Events(Sequence &sequence)
Construct an Events object.
Definition: Events.cpp:17
void timeContextMismatch(const FwTimeContextStoreType currTimeContext, const FwTimeContextStoreType seqTimeContext)
Time context mismatch.
Definition: Events.cpp:119
void recordInvalid(const U32 recordNumber, const I32 error)
Record invalid.
Definition: Events.cpp:80
void fileInvalid(const CmdSequencer_FileReadStage::t stage, const I32 error)
File invalid.
Definition: Events.cpp:37
bool validateTime(CmdSequencerComponentImpl &component)
Definition: Sequence.cpp:42
FwTimeContextStoreType m_timeContext
The context of the sequence.
U32 m_numRecords
The number of records in the sequence.
TimeBase m_timeBase
The time base of the sequence.
Fw::Time m_timeTag
The time tag. NOTE: timeBase and context not filled in.
A sequence with unspecified binary format.
void allocateBuffer(NATIVE_INT_TYPE identifier, Fw::MemAllocator &allocator, NATIVE_UINT_TYPE bytes)
Give the sequence representation a memory buffer.
Definition: Sequence.cpp:77
virtual bool loadFile(const Fw::StringBase &fileName)=0
Fw::LogStringArg m_logFileName
Copy of file name for events.
virtual void nextRecord(Record &record)=0
Fw::ExternalSerializeBuffer m_buffer
Serialize buffer to hold the binary sequence data.
void deallocateBuffer(Fw::MemAllocator &allocator)
Deallocate the buffer.
Definition: Sequence.cpp:94
virtual bool hasMoreRecords() const =0
void setFileName(const Fw::StringBase &fileName)
Set the file name. Also sets the log file name.
Definition: Sequence.cpp:111
CmdSequencerComponentImpl & m_component
The enclosing component.
NATIVE_INT_TYPE m_allocatorId
The allocator ID.
const Header & getHeader() const
Get the sequence header.
Definition: Sequence.cpp:105
Fw::String m_stringFileName
Copy of file name for ports.
Sequence(CmdSequencerComponentImpl &component)
Construct a Sequence object.
Definition: Sequence.cpp:17
virtual ~Sequence()
Destroy a Sequence object.
Definition: Sequence.cpp:26
Fw::CmdStringArg m_fileName
The sequence file name.
~CmdSequencerComponentImpl()
Destroy a CmdDispatcherComponentBase.
void deallocateBuffer(Fw::MemAllocator &allocator)
Return allocated buffer. Call during shutdown.
CmdSequencerComponentImpl(const char *compName)
Construct a CmdSequencer.
void setTimeout(const NATIVE_UINT_TYPE seconds)
void loadSequence(const Fw::StringBase &fileName)
void setSequenceFormat(Sequence &sequence)
void allocateBuffer(const NATIVE_INT_TYPE identifier, Fw::MemAllocator &allocator, const NATIVE_UINT_TYPE bytes)
SerializeStatus
forward declaration for string
Container for computed and stored CRC values.
void update(const BYTE *buffer, NATIVE_UINT_TYPE bufferSize)
Update computed CRC.