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 FwDpPriorityType 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& operator=(const DpContainer& src) = default;
90 
91  public:
92  // ----------------------------------------------------------------------
93  // Public member functions
94  // ----------------------------------------------------------------------
95 
98  FwDpIdType getId() const { return this->m_id; }
99 
102  FwSizeType getDataSize() const { return this->m_dataSize; }
103 
106  Fw::Buffer getBuffer() const { return this->m_buffer; }
107 
110 
113  FwDpPriorityType getPriority() const { return this->m_priority; }
114 
117  Fw::Time getTimeTag() const { return this->m_timeTag; }
118 
120  Fw::DpState getState() const { return this->m_dpState; }
121 
125 
127  DpState getDpState() const { return this->m_dpState; }
128 
135 
138  void serializeHeader();
139 
141  void setId(FwDpIdType id
142  ) {
143  this->m_id = id;
144  }
145 
148  ) {
149  this->m_priority = priority;
150  }
151 
153  void setTimeTag(Fw::Time timeTag
154  ) {
155  this->m_timeTag = timeTag;
156  }
157 
160  ) {
161  this->m_procTypes = procTypes;
162  }
163 
165  void setDpState(DpState dpState
166  ) {
167  this->m_dpState = dpState;
168  }
169 
171  void setDataSize(FwSizeType dataSize
172  ) {
173  this->m_dataSize = dataSize;
174  }
175 
177  void setBuffer(const Buffer& buffer
178  );
179 
182  this->m_buffer = Fw::Buffer();
183  this->m_dataBuffer.clear();
184  this->m_dataSize = 0;
185  }
186 
190 
194 
196  void setHeaderHash(const Utils::HashBuffer& hash
197  );
198 
200  void updateHeaderHash();
201 
204  Utils::HashBuffer& computedHash
205  ) const;
206 
209  // Data hash goes after the header, the header hash, and the data
210  return Header::SIZE + HASH_DIGEST_LENGTH + this->m_dataSize;
211  }
212 
216 
220 
222  void setDataHash(Utils::HashBuffer hash
223  );
224 
226  void updateDataHash();
227 
230  Utils::HashBuffer& computedHash
231  ) const;
232 
233  public:
234  // ----------------------------------------------------------------------
235  // Public static functions
236  // ----------------------------------------------------------------------
237 
239  static constexpr FwSizeType getPacketSizeForDataSize(FwSizeType dataSize
240  ) {
241  return Header::SIZE + dataSize + 2 * HASH_DIGEST_LENGTH;
242  }
243 
244  private:
245  // ----------------------------------------------------------------------
246  // Private member functions
247  // ----------------------------------------------------------------------
248 
250  void initUserDataField();
251 
252  public:
253  // ----------------------------------------------------------------------
254  // Public member variables
255  // ----------------------------------------------------------------------
256 
259 
260  protected:
261  // ----------------------------------------------------------------------
262  // Protected member variables
263  // ----------------------------------------------------------------------
264 
268 
271 
274 
277 
280 
283 
286 
291 };
292 
293 } // end namespace Fw
294 
295 #endif
DpState getDpState() const
Get the data product state.
A data product Container.
Definition: DpContainer.hpp:26
void clear()
clear external buffer
#define HASH_DIGEST_LENGTH
Definition: CRC32.hpp:18
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.
FwIdType FwPacketDescriptorType
The type of a com packet descriptor.
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
U8 SerialType
The serial representation type.
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
static constexpr FwDpPriorityType PRIORITY_OFFSET
The offset for the priority field.
Definition: DpContainer.hpp:43
DpState m_dpState
The data product state.
The size of the serial representation.
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:53
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.
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.
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
Definition: DpContainer.hpp:98
FwSizeType getDataSize() const
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