F´ Flight Software - C/C++ Documentation NASA-v1.6.0
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"
18#include "Svc/CmdSequencer/CmdSequencerComponentAc.hpp"
19
20namespace Svc {
21
23 public CmdSequencerComponentBase
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
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
142 sizeof(U32) +
143 sizeof(U32) +
144 sizeof(FwTimeBaseStoreType) +
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
189 };
190
191 public:
192
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::CmdStringArg& fileName);
229
233
237
239 const Header& getHeader() const;
240
243 virtual bool loadFile(
244 const Fw::CmdStringArg& fileName
245 ) = 0;
246
249 virtual bool hasMoreRecords() const = 0;
250
253 virtual void nextRecord(
254 Record& record
255 ) = 0;
256
260 virtual void reset() = 0;
261
264 virtual void clear() = 0;
265
266 PROTECTED:
267
270
273
276
279
282
285
288
289 };
290
294 public Sequence
295 {
296
297 PRIVATE:
298
299 enum Constants {
300 INITIAL_COMPUTED_VALUE = 0xFFFFFFFFU
301 };
302
303 public:
304
307 struct CRC {
308
310 CRC();
311
313 void init();
314
316 void update(
317 const BYTE* buffer,
318 NATIVE_UINT_TYPE bufferSize
319 );
320
322 void finalize();
323
326
329
330 };
331
332 public:
333
336 CmdSequencerComponentImpl& component
337 );
338
339 public:
340
343 bool loadFile(
344 const Fw::CmdStringArg& fileName
345 );
346
349 bool hasMoreRecords() const;
350
353 void nextRecord(
354 Record& record
355 );
356
360 void reset();
361
364 void clear();
365
366 PRIVATE:
367
370 bool readFile();
371
374 bool readOpenFile();
375
379 bool readHeader();
380
383 bool deserializeHeader();
384
387 bool readRecordsAndCRC();
388
391 bool extractCRC();
392
395 bool validateCRC();
396
399 Fw::SerializeStatus deserializeRecord(
400 Record& record
401 );
402
405 Fw::SerializeStatus deserializeDescriptor(
406 Record::Descriptor& descriptor
407 );
408
411 Fw::SerializeStatus deserializeTimeTag(
412 Fw::Time& timeTag
413 );
414
417 Fw::SerializeStatus deserializeRecordSize(
418 U32& recordSize
419 );
420
423 Fw::SerializeStatus copyCommand(
424 Fw::ComBuffer& comBuffer,
425 const U32 recordSize
426 );
427
430 bool validateRecords();
431
432 PRIVATE:
433
435 CRC m_crc;
436
438 Os::File m_sequenceFile;
439
440 };
441
442 PRIVATE:
443
444 // ----------------------------------------------------------------------
445 // Private classes
446 // ----------------------------------------------------------------------
447
450 class Timer {
451
452 PRIVATE:
453
455 typedef enum {
456 SET, CLEAR
457 } State;
458
459 public:
460
462 Timer() :
463 m_state(CLEAR)
464 {
465
466 }
467
469 void set(
470 Fw::Time time
471 ) {
472 this->m_state = SET;
473 this->expirationTime = time;
474 }
475
477 void clear() {
478 this->m_state = CLEAR;
479 }
480
483 bool isExpiredAt(
484 Fw::Time time
485 ) {
486 if (this->m_state == CLEAR) {
487 return false;
488 } else if (
489 Fw::Time::compare(this->expirationTime, time) == Fw::Time::GT
490 ) {
491 return false;
492 }
493 return true;
494 }
495
496 PRIVATE:
497
499 State m_state;
500
502 Fw::Time expirationTime;
503
504 };
505
506
507 public:
508
509 // ----------------------------------------------------------------------
510 // Construction, initialization, and destruction
511 // ----------------------------------------------------------------------
512
515 const char* compName
516 );
517
519 void init(
520 const NATIVE_INT_TYPE queueDepth,
521 const NATIVE_INT_TYPE instance
522 );
523
527 void setTimeout(
528 const NATIVE_UINT_TYPE seconds
529 );
530
536 Sequence& sequence
537 );
538
542 void allocateBuffer(
543 const NATIVE_INT_TYPE identifier,
544 Fw::MemAllocator& allocator,
545 const NATIVE_UINT_TYPE bytes
546 );
547
550 void loadSequence(
551 const Fw::String& fileName
552 );
553
555 void deallocateBuffer(
556 Fw::MemAllocator& allocator
557 );
558
561
562 PRIVATE:
563
564 // ----------------------------------------------------------------------
565 // Handler implementations for input ports
566 // ----------------------------------------------------------------------
567
569 void cmdResponseIn_handler(
570 NATIVE_INT_TYPE portNum,
571 FwOpcodeType opcode,
572 U32 cmdSeq,
573 const Fw::CmdResponse& response
574 );
575
577 void schedIn_handler(
578 NATIVE_INT_TYPE portNum,
579 NATIVE_UINT_TYPE order
580 );
581
583 void seqRunIn_handler(
584 NATIVE_INT_TYPE portNum,
585 Fw::String &filename
586 );
587
589 void pingIn_handler(
590 NATIVE_INT_TYPE portNum,
591 U32 key
592 );
593
596 void seqCancelIn_handler(
597 const NATIVE_INT_TYPE portNum
598 );
599
600 PRIVATE:
601
602 // ----------------------------------------------------------------------
603 // Command handler implementations
604 // ----------------------------------------------------------------------
605
608 void CS_AUTO_cmdHandler(
609 FwOpcodeType opcode,
610 U32 cmdSeq
611 );
612
615 void CS_CANCEL_cmdHandler(
616 FwOpcodeType opCode,
617 U32 cmdSeq
618 );
619
622 void CS_MANUAL_cmdHandler(
623 FwOpcodeType opcode,
624 U32 cmdSeq
625 );
626
628 void CS_RUN_cmdHandler(
629 FwOpcodeType opCode,
630 U32 cmdSeq,
631 const Fw::CmdStringArg& fileName,
632 Svc::CmdSequencer_BlockState block
633 );
634
637 void CS_START_cmdHandler(
638 FwOpcodeType opcode,
639 U32 cmdSeq
640 );
641
645 void CS_STEP_cmdHandler(
646 FwOpcodeType opcode,
647 U32 cmdSeq
648 );
649
652 void CS_VALIDATE_cmdHandler(
653 FwOpcodeType opCode,
654 U32 cmdSeq,
655 const Fw::CmdStringArg& fileName
656 );
657
662 void CS_JOIN_WAIT_cmdHandler(
663 const FwOpcodeType opCode,
664 const U32 cmdSeq
665 );
666
667 PRIVATE:
668
669 // ----------------------------------------------------------------------
670 // Private helper methods
671 // ----------------------------------------------------------------------
672
675 bool loadFile(
676 const Fw::CmdStringArg& fileName
677 );
678
680 void performCmd_Cancel();
681
683 void performCmd_Step();
684
686 void performCmd_Step_RELATIVE(
687 Fw::Time& currentTime
688 );
689
691 void performCmd_Step_ABSOLUTE(
692 Fw::Time& currentTime
693 );
694
696 void commandComplete(
697 const U32 opCode
698 );
699
701 void sequenceComplete();
702
704 void error();
705
707 void commandError(
708 const U32 number,
709 const U32 opCode,
710 const U32 error
711 );
712
715 bool requireRunMode(
716 RunMode mode
717 );
718
720 void setCmdTimeout(
721 const Fw::Time &currentTime
722 );
723
724 PRIVATE:
725
726 // ----------------------------------------------------------------------
727 // Private member variables
728 // ----------------------------------------------------------------------
729
731 FPrimeSequence m_FPrimeSequence;
732
734 Sequence *m_sequence;
735
737 U32 m_loadCmdCount;
738
740 U32 m_cancelCmdCount;
741
743 U32 m_errorCount;
744
746 RunMode m_runMode;
747
749 StepMode m_stepMode;
750
752 Sequence::Record m_record;
753
755 Timer m_cmdTimer;
756
758 U32 m_executedCount;
759
761 U32 m_totalExecutedCount;
762
764 U32 m_sequencesCompletedCount;
765
767 NATIVE_UINT_TYPE m_timeout;
768
770 Timer m_cmdTimeoutTimer;
771
773 Svc::CmdSequencer_BlockState::t m_blockState;
774 FwOpcodeType m_opCode;
775 U32 m_cmdSeq;
776 bool m_join_waiting;
777 };
778
779}
780
781#endif
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
U8 BYTE
byte type
Definition BasicTypes.h:27
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
TimeBase
Definition FpConfig.h:38
U16 FwTimeBaseStoreType
Definition FpConfig.h:47
U32 FwOpcodeType
Definition FpConfig.h:56
U8 FwTimeContextStoreType
Definition FpConfig.h:50
Defines a base class for a memory allocator for classes.
Defines a file class to validate files or generate a file validator file.
static Comparison compare(const Time &time1, const Time &time2)
Definition Time.cpp:159
A sequence that uses the F Prime binary format.
bool loadFile(const Fw::CmdStringArg &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
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
CmdSequencerComponentImpl & m_component
The enclosing component.
virtual bool loadFile(const Fw::CmdStringArg &fileName)=0
NATIVE_INT_TYPE m_allocatorId
The allocator ID.
const Header & getHeader() const
Get the sequence header.
Definition Sequence.cpp:105
void setFileName(const Fw::CmdStringArg &fileName)
Set the file name. Also sets the log file name.
Definition Sequence.cpp:111
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.
void init(const NATIVE_INT_TYPE queueDepth, const NATIVE_INT_TYPE instance)
Initialize a CmdSequencer.
CmdSequencerComponentImpl(const char *compName)
Construct a CmdSequencer.
void setTimeout(const NATIVE_UINT_TYPE seconds)
void setSequenceFormat(Sequence &sequence)
void loadSequence(const Fw::String &fileName)
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.