F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
Sequence.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Sequence.cpp
3 // \author Bocchino/Canham
4 // \brief Implementation file for CmdSequencer::Sequence
5 //
6 // Copyright (C) 2009-2018 California Institute of Technology.
7 // ALL RIGHTS RESERVED. United States Government Sponsorship
8 // acknowledged.
9 // ======================================================================
10 
11 #include <Fw/Types/Assert.hpp>
13 
14 namespace Svc {
15 
18  m_component(component),
19  m_events(*this),
20  m_allocatorId(0)
21  {
22 
23  }
24 
26  ~Sequence()
27  {
28 
29  }
30 
32  Header() :
33  m_fileSize(0),
34  m_numRecords(0),
35  m_timeBase(TB_DONT_CARE),
36  m_timeContext(FW_CONTEXT_DONT_CARE)
37  {
38 
39  }
40 
43  {
44  Fw::Time validTime = component.getTime();
45  Events& events = component.m_sequence->m_events;
46  // Time base
47  const TimeBase validTimeBase = validTime.getTimeBase();
48  if (
49  (this->m_timeBase != validTimeBase) and
50  (this->m_timeBase != TB_DONT_CARE)
51  ) {
52  events.timeBaseMismatch(
53  validTimeBase,
54  this->m_timeBase
55  );
56  return false;
57  }
58  // Time context
59  const FwTimeContextStoreType validContext = validTime.getContext();
60  if (
61  (this->m_timeContext != validContext) and
62  (this->m_timeContext != FW_CONTEXT_DONT_CARE)
63  ) {
64  events.timeContextMismatch(
65  validContext,
66  this->m_timeContext
67  );
68  return false;
69  }
70  // Canonicalize time
71  this->m_timeBase = validTimeBase;
72  this->m_timeContext = validContext;
73  return true;
74  }
75 
78  NATIVE_INT_TYPE identifier,
79  Fw::MemAllocator& allocator,
80  NATIVE_UINT_TYPE bytes
81  )
82  {
83  // has to be at least as big as a header
85  bool recoverable;
86  this->m_allocatorId = identifier;
87  this->m_buffer.setExtBuffer(
88  static_cast<U8*>(allocator.allocate(static_cast<NATIVE_UINT_TYPE>(identifier),bytes,recoverable)),
89  bytes
90  );
91  }
92 
95  {
96  allocator.deallocate(
97  static_cast<NATIVE_UINT_TYPE>(this->m_allocatorId),
98  this->m_buffer.getBuffAddr()
99  );
100  this->m_buffer.clear();
101  }
102 
105  getHeader() const
106  {
107  return this->m_header;
108  }
109 
111  setFileName(const Fw::StringBase& fileName)
112  {
113  this->m_fileName = fileName;
114  this->m_logFileName = fileName;
115  this->m_stringFileName = fileName;
116  }
117 
119  getFileName()
120  {
121  return this->m_fileName;
122  }
123 
126  {
127  return this->m_logFileName;
128  }
129 
132  {
133  return this->m_stringFileName;
134  }
135 
136 }
137 
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:55
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:30
PlatformUIntType NATIVE_UINT_TYPE
Definition: BasicTypes.h:56
TimeBase
Definition: FpConfig.h:69
@ TB_DONT_CARE
Don't care value for sequences. If FwTimeBaseStoreType is changed, value should be changed.
Definition: FpConfig.h:73
#define FW_CONTEXT_DONT_CARE
Don't care value for time contexts in sequences.
Definition: FpConfig.h:76
U8 FwTimeContextStoreType
Definition: FpConfig.h:83
U8 * getBuffAddr()
gets buffer address for data filling
void setExtBuffer(U8 *buffPtr, Serializable::SizeType size)
void clear()
clear external buffer
virtual void deallocate(const NATIVE_UINT_TYPE identifier, void *ptr)=0
Deallocate memory.
virtual void * allocate(const NATIVE_UINT_TYPE identifier, NATIVE_UINT_TYPE &size, bool &recoverable)=0
Allocate memory.
Definition: Time.hpp:9
FwTimeContextStoreType getContext() const
Definition: Time.cpp:147
TimeBase getTimeBase() const
Definition: Time.cpp:143
void timeBaseMismatch(const TimeBase currTimeBase, const TimeBase seqTimeBase)
Time base mismatch.
Definition: Events.cpp:106
void timeContextMismatch(const FwTimeContextStoreType currTimeContext, const FwTimeContextStoreType seqTimeContext)
Time context mismatch.
Definition: Events.cpp:119
bool validateTime(CmdSequencerComponentImpl &component)
Definition: Sequence.cpp:42
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.
Fw::ExternalSerializeBuffer m_buffer
Serialize buffer to hold the binary sequence data.
void deallocateBuffer(Fw::MemAllocator &allocator)
Deallocate the buffer.
Definition: Sequence.cpp:94
void setFileName(const Fw::StringBase &fileName)
Set the file name. Also sets the log file name.
Definition: Sequence.cpp:111
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.