F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
DpContainer.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title DpContainer.hpp
3 // \author bocchino
4 // \brief hpp file for DpContainer
5 // ======================================================================
6 
7 #ifndef Fw_DpContainer_HPP
8 #define Fw_DpContainer_HPP
9 
10 #include "Fw/Buffer/Buffer.hpp"
11 #include "Fw/Dp/DpStateEnumAc.hpp"
12 #include "Fw/Time/Time.hpp"
14 #include "Utils/Hash/Hash.hpp"
17 
18 // Forward declare for UTs
19 namespace Fw {
20 class DpContainerTester;
21 }
22 
23 namespace Fw {
24 
26 class DpContainer {
27  friend class Fw::DpContainerTester;
28 
29  public:
30  // ----------------------------------------------------------------------
31  // Constants and Types
32  // ----------------------------------------------------------------------
33 
35  struct Header {
39  static constexpr FwSizeType PACKET_DESCRIPTOR_OFFSET = 0;
43  static constexpr FwSizeType PRIORITY_OFFSET = ID_OFFSET + sizeof(FwDpIdType);
55  static constexpr FwSizeType SIZE = DATA_SIZE_OFFSET + sizeof(FwSizeStoreType);
56  };
57 
66 
67  public:
68  // ----------------------------------------------------------------------
69  // Constructors and destructors
70  // ----------------------------------------------------------------------
71 
74  const Fw::Buffer& buffer
75  );
76 
78  DpContainer();
79 
81  virtual ~DpContainer() {}
82 
83  protected:
84  // ----------------------------------------------------------------------
85  // Protected operators
86  // ----------------------------------------------------------------------
87 
89  DpContainer(const DpContainer& src) = default;
90 
92  DpContainer& operator=(const DpContainer& src) = default;
93 
94  public:
95  // ----------------------------------------------------------------------
96  // Public member functions
97  // ----------------------------------------------------------------------
98 
101  FwDpIdType getId() const { return this->m_id; }
102 
105  FwSizeType getDataSize() const { return this->m_dataSize; }
106 
109  Fw::Buffer getBuffer() const { return this->m_buffer; }
110 
113 
116  FwDpPriorityType getPriority() const { return this->m_priority; }
117 
120  Fw::Time getTimeTag() const { return this->m_timeTag; }
121 
123  Fw::DpState getState() const { return this->m_dpState; }
124 
128 
130  DpState getDpState() const { return this->m_dpState; }
131 
138 
141  void serializeHeader();
142 
144  void setId(FwDpIdType id
145  ) {
146  this->m_id = id;
147  }
148 
151  ) {
152  this->m_priority = priority;
153  }
154 
156  void setTimeTag(Fw::Time timeTag
157  ) {
158  this->m_timeTag = timeTag;
159  }
160 
163  ) {
164  this->m_procTypes = procTypes;
165  }
166 
168  void setDpState(DpState dpState
169  ) {
170  this->m_dpState = dpState;
171  }
172 
174  void setDataSize(FwSizeType dataSize
175  ) {
176  this->m_dataSize = dataSize;
177  }
178 
180  void setBuffer(const Buffer& buffer
181  );
182 
185  void shrinkBufferSize();
186 
189  this->m_buffer = Fw::Buffer();
190  this->m_dataBuffer.clear();
191  this->m_dataSize = 0;
192  }
193 
197 
201 
203  void setHeaderHash(const Utils::HashBuffer& hash
204  );
205 
207  void updateHeaderHash();
208 
211  Utils::HashBuffer& computedHash
212  ) const;
213 
216  // Data hash goes after the header, the header hash, and the data
217  return Header::SIZE + HASH_DIGEST_LENGTH + this->m_dataSize;
218  }
219 
223 
227 
229  void setDataHash(Utils::HashBuffer hash
230  );
231 
233  void updateDataHash();
234 
237  Utils::HashBuffer& computedHash
238  ) const;
239 
240  public:
241  // ----------------------------------------------------------------------
242  // Public static functions
243  // ----------------------------------------------------------------------
244 
246  static constexpr FwSizeType getPacketSizeForDataSize(FwSizeType dataSize
247  ) {
248  return Header::SIZE + dataSize + 2 * HASH_DIGEST_LENGTH;
249  }
250 
251  private:
252  // ----------------------------------------------------------------------
253  // Private member functions
254  // ----------------------------------------------------------------------
255 
257  void initUserDataField();
258 
259  public:
260  // ----------------------------------------------------------------------
261  // Public member variables
262  // ----------------------------------------------------------------------
263 
266 
267  protected:
268  // ----------------------------------------------------------------------
269  // Protected member variables
270  // ----------------------------------------------------------------------
271 
275 
278 
281 
284 
287 
290 
293 
298 };
299 
300 } // end namespace Fw
301 
302 #endif
DpState getDpState() const
Get the data product state.
A data product Container.
Definition: DpContainer.hpp:26
U16 FwPacketDescriptorType
The width of packet descriptors when they are serialized by the framework.
void clear()
Clear external buffer.
FwDpPriorityType getPriority() const
void setId(FwDpIdType id)
Set the id.
void setTimeTag(Fw::Time timeTag)
Set the time tag.
Header::UserData m_userData
The user data.
U8[DpCfg::CONTAINER_USER_DATA_SIZE] UserData
The type of user data.
Definition: DpContainer.hpp:37
A DpContainer packet header.
Definition: DpContainer.hpp:35
PlatformSizeType FwSizeType
void setHeaderHash(const Utils::HashBuffer &hash)
Set the header hash.
U32 FwDpPriorityType
The type of a data product priority.
void setDataSize(FwSizeType dataSize)
Set the data size.
static constexpr FwSizeType DP_STATE_OFFSET
The offset of the data product state field.
Definition: DpContainer.hpp:51
static constexpr FwSizeType MIN_PACKET_SIZE
Definition: DpContainer.hpp:65
Time m_timeTag
The time tag.
void setDpState(DpState dpState)
Set the data product state.
void setDataHash(Utils::HashBuffer hash)
Set the data hash.
static constexpr FwSizeType PACKET_DESCRIPTOR_OFFSET
The offset for the packet descriptor field.
Definition: DpContainer.hpp:39
void setProcTypes(DpCfg::ProcType::SerialType procTypes)
Set the processing types bit mask.
Fw::ExternalSerializeBufferWithMemberCopy m_dataBuffer
static constexpr FwSizeType PROC_TYPES_OFFSET
The offset for the processing types field.
Definition: DpContainer.hpp:47
Utils::HashBuffer getHeaderHash() const
static constexpr FwSizeType HEADER_HASH_OFFSET
The header hash offset.
Definition: DpContainer.hpp:59
void setBuffer(const Buffer &buffer)
Set the packet buffer.
SerializeStatus
forward declaration for string
FwSizeType m_dataSize
The data size.
FwDpPriorityType m_priority
The priority.
U16 FwSizeStoreType
The type used to serialize a size value.
static constexpr FwSizeType TIME_TAG_OFFSET
The offset for the time tag field.
Definition: DpContainer.hpp:45
virtual ~DpContainer()
Destructor.
Definition: DpContainer.hpp:81
void updateHeaderHash()
Compute and set the header hash.
Utils::HashBuffer getDataHash() const
void invalidateBuffer()
Invalidate the packet buffer.
T
The raw enum type.
Utils::HashBuffer computeDataHash() const
Fw::Time getTimeTag() const
#define HASH_DIGEST_LENGTH
Definition: Crc32.hpp:26
void shrinkBufferSize()
DpState m_dpState
The data product state.
FwSizeType getDataHashOffset() const
Get the data hash offset.
static constexpr FwSizeType getPacketSizeForDataSize(FwSizeType dataSize)
Get the packet size for a given data size.
FwSizeType getPacketSize() const
Get the packet size corresponding to the data size.
Fw::Buffer getBuffer() const
static constexpr FwSizeType DATA_SIZE_OFFSET
The offset for the data size field.
Definition: DpContainer.hpp:53
Success::T checkDataHash(Utils::HashBuffer &storedHash, Utils::HashBuffer &computedHash) const
Check the data hash.
static constexpr FwSizeType DATA_OFFSET
The data offset.
Definition: DpContainer.hpp:61
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
U8 SerialType
The serial representation type.
static constexpr FwSizeType PRIORITY_OFFSET
The offset for the priority field.
Definition: DpContainer.hpp:43
static constexpr FwSizeType ID_OFFSET
The offset for the id field.
Definition: DpContainer.hpp:41
Utils::HashBuffer computeHeaderHash() const
DpContainer & operator=(const DpContainer &src)=default
Copy assignment operator.
DpCfg::ProcType::SerialType getProcTypes() const
FwIdType FwDpIdType
The type of a data product identifier.
void updateDataHash()
Update the data hash.
Fw::DpState getState() const
Get the product state.
DpCfg::ProcType::SerialType m_procTypes
The processing types.
The size of the serial representation.
FwDpIdType m_id
void serializeHeader()
Definition: DpContainer.cpp:89
static constexpr FwSizeType SIZE
The header size.
Definition: DpContainer.hpp:55
A container class for holding a hash buffer.
Definition: HashBuffer.hpp:26
Success::T checkHeaderHash(Utils::HashBuffer &storedHash, Utils::HashBuffer &computedHash) const
Check the header hash.
External serialize buffer with member copy semantics.
static constexpr FwSizeType USER_DATA_OFFSET
The offset for the user data field.
Definition: DpContainer.hpp:49
Fw::SerializeStatus deserializeHeader()
Definition: DpContainer.cpp:38
FwDpIdType getId() const
FwSizeType getDataSize() const
Implementation of malloc based allocator.
friend class Fw::DpContainerTester
Definition: DpContainer.hpp:27
void setPriority(FwDpPriorityType priority)
Set the priority.
Buffer m_buffer
The packet buffer.
DpContainer()
Constructor for container with default initialization.
Definition: DpContainer.cpp:28