F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
DataPacket.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title DataPacket.cpp
3 // \author bocchino
4 // \brief cpp file for FilePacket::DataPacket
5 //
6 // \copyright
7 // Copyright 2009-2016, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
14 #include <Fw/Types/Assert.hpp>
15 
16 namespace Fw {
17 
18 void FilePacket::DataPacket ::initialize(const U32 sequenceIndex,
19  const U32 byteOffset,
20  const U16 dataSize,
21  const U8* const data) {
22  this->m_header.initialize(FilePacket::T_DATA, sequenceIndex);
23  this->m_byteOffset = byteOffset;
24  this->m_dataSize = dataSize;
25  this->m_data = data;
26 }
27 
29  return static_cast<U32>(this->m_header.bufferSize() + sizeof(this->m_byteOffset) + sizeof(this->m_dataSize) +
30  this->m_dataSize);
31 }
32 
34  SerialBuffer serialBuffer(buffer.getData(), buffer.getSize());
35  return this->toSerialBuffer(serialBuffer);
36 }
37 
38 SerializeStatus FilePacket::DataPacket ::fromSerialBuffer(SerialBuffer& serialBuffer) {
39  FW_ASSERT(this->m_header.m_type == T_DATA);
40 
41  SerializeStatus status = serialBuffer.deserializeTo(this->m_byteOffset);
42  if (status != FW_SERIALIZE_OK) {
43  return status;
44  }
45 
46  status = serialBuffer.deserializeTo(this->m_dataSize);
47  if (status != FW_SERIALIZE_OK) {
48  return status;
49  }
50 
51  if (serialBuffer.getBuffLeft() != this->m_dataSize) {
53  }
54 
55  U8* const addr = serialBuffer.getBuffAddr();
56  this->m_data = &addr[this->fixedLengthSize()];
57 
58  return FW_SERIALIZE_OK;
59 }
60 
61 U32 FilePacket::DataPacket ::fixedLengthSize() const {
62  return static_cast<U32>(this->m_header.bufferSize() + sizeof(this->m_byteOffset) + sizeof(this->m_dataSize));
63 }
64 
65 SerializeStatus FilePacket::DataPacket ::toSerialBuffer(SerialBuffer& serialBuffer) const {
66  FW_ASSERT(this->m_header.m_type == T_DATA);
67 
68  SerializeStatus status;
69 
70  status = this->m_header.toSerialBuffer(serialBuffer);
71  if (status != FW_SERIALIZE_OK) {
72  return status;
73  }
74 
75  status = serialBuffer.serializeFrom(this->m_byteOffset);
76  if (status != FW_SERIALIZE_OK) {
77  return status;
78  }
79 
80  status = serialBuffer.serializeFrom(this->m_dataSize);
81  if (status != FW_SERIALIZE_OK) {
82  return status;
83  }
84 
85  status = serialBuffer.pushBytes(this->m_data, this->m_dataSize);
86 
87  return status;
88 }
89 
90 } // namespace Fw
Serialization/Deserialization operation was successful.
A variable-length serializable buffer.
SerializeStatus toBuffer(Buffer &buffer) const
Convert this DataPacket to a Buffer.
Definition: DataPacket.cpp:33
U8 * getData() const
Definition: Buffer.cpp:56
SerializeStatus
forward declaration for string
Serializable::SizeType getBuffLeft() const
returns how much deserialization buffer is left
Data was left in the buffer, but not enough to deserialize.
U32 bufferSize() const
Compute the buffer size needed to hold this DataPacket.
Definition: DataPacket.cpp:28
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
FwSizeType getSize() const
Definition: Buffer.cpp:60
U8 * getBuffAddr()
gets buffer address for data filling
void initialize(const U32 sequenceIndex, const U32 byteOffset, const U16 dataSize, const U8 *const data)
Initialize a data packet.
Definition: DataPacket.cpp:18
#define FW_ASSERT(...)
Definition: Assert.hpp:14
SerializeStatus deserializeTo(U8 &val)
deserialize 8-bit unsigned int