F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
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
20namespace 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(
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
110 const FwTimeContextStoreType currTimeContext,
111 const FwTimeContextStoreType seqTimeContext
112 );
113
114 // No Records
115 void noRecords();
116
117 PRIVATE:
118
120 Sequence& m_sequence;
121
122 };
123
124 public:
125
127 Sequence(
128 CmdSequencerComponentImpl& component
129 );
130
132 virtual ~Sequence();
133
134 public:
135
138 class Header {
139
140 public:
141
145 sizeof(U32) +
146 sizeof(U32) +
147 sizeof(FwTimeBaseStoreType) +
149 };
150
151 public:
152
154 Header();
155
156 public:
157
160 bool validateTime(
161 CmdSequencerComponentImpl& component
162 );
163
164 public:
165
168
171
174
177
178 };
179
180 public:
181
184 class Record {
185
186 public:
187
193
194 public:
195
199 {
200
201 }
202
203 public:
204
207
210
213
214 };
215
216 public:
217
219 void allocateBuffer(
220 NATIVE_INT_TYPE identifier,
221 Fw::MemAllocator& allocator,
222 NATIVE_UINT_TYPE bytes
223 );
224
226 void deallocateBuffer(
227 Fw::MemAllocator& allocator
228 );
229
231 void setFileName(const Fw::StringBase& fileName);
232
236
240
244
246 const Header& getHeader() const;
247
250 virtual bool loadFile(
251 const Fw::StringBase& fileName
252 ) = 0;
253
256 virtual bool hasMoreRecords() const = 0;
257
260 virtual void nextRecord(
261 Record& record
262 ) = 0;
263
267 virtual void reset() = 0;
268
271 virtual void clear() = 0;
272
273 PROTECTED:
274
277
280
283
286
289
292
295
298
299 };
300
304 public Sequence
305 {
306
307 PRIVATE:
308
309 enum Constants {
310 INITIAL_COMPUTED_VALUE = 0xFFFFFFFFU
311 };
312
313 public:
314
317 struct CRC {
318
320 CRC();
321
323 void init();
324
326 void update(
327 const BYTE* buffer,
328 NATIVE_UINT_TYPE bufferSize
329 );
330
332 void finalize();
333
336
339
340 };
341
342 public:
343
346 CmdSequencerComponentImpl& component
347 );
348
349 public:
350
353 bool loadFile(
354 const Fw::StringBase& fileName
355 );
356
359 bool hasMoreRecords() const;
360
363 void nextRecord(
364 Record& record
365 );
366
370 void reset();
371
374 void clear();
375
376 PRIVATE:
377
380 bool readFile();
381
384 bool readOpenFile();
385
389 bool readHeader();
390
393 bool deserializeHeader();
394
397 bool readRecordsAndCRC();
398
401 bool extractCRC();
402
405 bool validateCRC();
406
409 Fw::SerializeStatus deserializeRecord(
410 Record& record
411 );
412
415 Fw::SerializeStatus deserializeDescriptor(
416 Record::Descriptor& descriptor
417 );
418
421 Fw::SerializeStatus deserializeTimeTag(
422 Fw::Time& timeTag
423 );
424
427 Fw::SerializeStatus deserializeRecordSize(
428 U32& recordSize
429 );
430
433 Fw::SerializeStatus copyCommand(
434 Fw::ComBuffer& comBuffer,
435 const U32 recordSize
436 );
437
440 bool validateRecords();
441
442 PRIVATE:
443
445 CRC m_crc;
446
448 Os::File m_sequenceFile;
449
450 };
451
452 PRIVATE:
453
454 // ----------------------------------------------------------------------
455 // Private classes
456 // ----------------------------------------------------------------------
457
460 class Timer {
461
462 PRIVATE:
463
465 typedef enum {
466 SET, CLEAR
467 } State;
468
469 public:
470
472 Timer() :
473 m_state(CLEAR)
474 {
475
476 }
477
479 void set(
480 Fw::Time time
481 ) {
482 this->m_state = SET;
483 this->expirationTime = time;
484 }
485
487 void clear() {
488 this->m_state = CLEAR;
489 }
490
493 bool isExpiredAt(
494 Fw::Time time
495 ) {
496 if (this->m_state == CLEAR) {
497 return false;
498 } else if (
499 Fw::Time::compare(this->expirationTime, time) == Fw::Time::GT
500 ) {
501 return false;
502 }
503 return true;
504 }
505
506 PRIVATE:
507
509 State m_state;
510
512 Fw::Time expirationTime;
513
514 };
515
516
517 public:
518
519 // ----------------------------------------------------------------------
520 // Construction, initialization, and destruction
521 // ----------------------------------------------------------------------
522
525 const char* compName
526 );
527
531 void setTimeout(
532 const NATIVE_UINT_TYPE seconds
533 );
534
540 Sequence& sequence
541 );
542
546 void allocateBuffer(
547 const NATIVE_INT_TYPE identifier,
548 Fw::MemAllocator& allocator,
549 const NATIVE_UINT_TYPE bytes
550 );
551
554 void loadSequence(
555 const Fw::StringBase& fileName
556 );
557
559 void deallocateBuffer(
560 Fw::MemAllocator& allocator
561 );
562
565
566 PRIVATE:
567
568 // ----------------------------------------------------------------------
569 // Handler implementations for input ports
570 // ----------------------------------------------------------------------
571
573 void cmdResponseIn_handler(
574 NATIVE_INT_TYPE portNum,
575 FwOpcodeType opcode,
576 U32 cmdSeq,
577 const Fw::CmdResponse& response
578 );
579
581 void schedIn_handler(
582 NATIVE_INT_TYPE portNum,
583 NATIVE_UINT_TYPE order
584 );
585
587 void seqRunIn_handler(
588 NATIVE_INT_TYPE portNum,
589 const Fw::StringBase& filename
590 );
591
593 void pingIn_handler(
594 NATIVE_INT_TYPE portNum,
595 U32 key
596 );
597
600 void seqCancelIn_handler(
601 const NATIVE_INT_TYPE portNum
602 );
603
604 PRIVATE:
605
606 // ----------------------------------------------------------------------
607 // Command handler implementations
608 // ----------------------------------------------------------------------
609
612 void CS_AUTO_cmdHandler(
613 FwOpcodeType opcode,
614 U32 cmdSeq
615 );
616
619 void CS_CANCEL_cmdHandler(
620 FwOpcodeType opCode,
621 U32 cmdSeq
622 );
623
626 void CS_MANUAL_cmdHandler(
627 FwOpcodeType opcode,
628 U32 cmdSeq
629 );
630
632 void CS_RUN_cmdHandler(
633 FwOpcodeType opCode,
634 U32 cmdSeq,
635 const Fw::CmdStringArg& fileName,
637 );
638
641 void CS_START_cmdHandler(
642 FwOpcodeType opcode,
643 U32 cmdSeq
644 );
645
649 void CS_STEP_cmdHandler(
650 FwOpcodeType opcode,
651 U32 cmdSeq
652 );
653
656 void CS_VALIDATE_cmdHandler(
657 FwOpcodeType opCode,
658 U32 cmdSeq,
659 const Fw::CmdStringArg& fileName
660 );
661
666 void CS_JOIN_WAIT_cmdHandler(
667 const FwOpcodeType opCode,
668 const U32 cmdSeq
669 );
670
671 PRIVATE:
672
673 // ----------------------------------------------------------------------
674 // Private helper methods
675 // ----------------------------------------------------------------------
676
679 bool loadFile(
680 const Fw::StringBase& fileName
681 );
682
684 void performCmd_Cancel();
685
687 void performCmd_Step();
688
690 void performCmd_Step_RELATIVE(
691 Fw::Time& currentTime
692 );
693
695 void performCmd_Step_ABSOLUTE(
696 Fw::Time& currentTime
697 );
698
700 void commandComplete(
701 const U32 opCode
702 );
703
705 void sequenceComplete();
706
708 void error();
709
711 void commandError(
712 const U32 number,
713 const U32 opCode,
714 const U32 error
715 );
716
719 bool requireRunMode(
720 RunMode mode
721 );
722
724 void setCmdTimeout(
725 const Fw::Time &currentTime
726 );
727
728 PRIVATE:
729
730 // ----------------------------------------------------------------------
731 // Private member variables
732 // ----------------------------------------------------------------------
733
735 FPrimeSequence m_FPrimeSequence;
736
738 Sequence *m_sequence;
739
741 U32 m_loadCmdCount;
742
744 U32 m_cancelCmdCount;
745
747 U32 m_errorCount;
748
750 RunMode m_runMode;
751
753 StepMode m_stepMode;
754
756 Sequence::Record m_record;
757
759 Timer m_cmdTimer;
760
762 U32 m_executedCount;
763
765 U32 m_totalExecutedCount;
766
768 U32 m_sequencesCompletedCount;
769
771 NATIVE_UINT_TYPE m_timeout;
772
774 Timer m_cmdTimeoutTimer;
775
778 FwOpcodeType m_opCode;
779 U32 m_cmdSeq;
780 bool m_join_waiting;
781 };
782
783}
784
785#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.
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.
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
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.
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.