F´ Flight Software - C/C++ Documentation  NASA-v2.0.1
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
20  const U32 sequenceIndex,
21  const U32 byteOffset,
22  const U16 dataSize,
23  const U8 *const data
24  )
25  {
26  this->header.initialize(FilePacket::T_DATA, sequenceIndex);
27  this->byteOffset = byteOffset;
28  this->dataSize = dataSize;
29  this->data = data;
30  }
31 
33  bufferSize(void) const
34  {
35  return
36  this->header.bufferSize() +
37  sizeof(this->byteOffset) +
38  sizeof(this->dataSize) +
39  this->dataSize;
40  }
41 
43  toBuffer(Buffer& buffer) const
44  {
45  SerialBuffer serialBuffer(
46  buffer.getData(),
47  buffer.getSize()
48  );
49  return this->toSerialBuffer(serialBuffer);
50  }
51 
52  SerializeStatus FilePacket::DataPacket ::
53  fromSerialBuffer(SerialBuffer& serialBuffer)
54  {
55 
56  FW_ASSERT(this->header.type == T_DATA);
57 
58  SerializeStatus status = serialBuffer.deserialize(this->byteOffset);
59  if (status != FW_SERIALIZE_OK)
60  return status;
61 
62  status = serialBuffer.deserialize(this->dataSize);
63  if (status != FW_SERIALIZE_OK)
64  return status;
65 
66  if (serialBuffer.getBuffLeft() != this->dataSize)
68 
69  U8 *const addr = serialBuffer.getBuffAddr();
70  this->data = &addr[this->fixedLengthSize()];
71 
72  return FW_SERIALIZE_OK;
73 
74  }
75 
76  U32 FilePacket::DataPacket ::
77  fixedLengthSize(void) const
78  {
79  return
80  this->header.bufferSize() +
81  sizeof(this->byteOffset) +
82  sizeof(this->dataSize);
83  }
84 
85  SerializeStatus FilePacket::DataPacket ::
86  toSerialBuffer(SerialBuffer& serialBuffer) const
87  {
88 
89  FW_ASSERT(this->header.type == T_DATA);
90 
91  SerializeStatus status;
92 
93  status = this->header.toSerialBuffer(serialBuffer);
94  if (status != FW_SERIALIZE_OK)
95  return status;
96 
97  status = serialBuffer.serialize(this->byteOffset);
98  if (status != FW_SERIALIZE_OK)
99  return status;
100 
101  status = serialBuffer.serialize(this->dataSize);
102  if (status != FW_SERIALIZE_OK)
103  return status;
104 
105  status = serialBuffer.pushBytes(this->data, dataSize);
106 
107  return status;
108 
109  }
110 
111 }
Fw::FilePacket::DataPacket::bufferSize
U32 bufferSize(void) const
Compute the buffer size needed to hold this DataPacket.
Definition: DataPacket.cpp:33
Fw::FilePacket::DataPacket::header
Header header
The packet header.
Definition: FilePacket.hpp:169
Fw::SerialBuffer
A variable-length serializable buffer.
Definition: SerialBuffer.hpp:24
Fw::FilePacket::DataPacket::initialize
void initialize(const U32 sequenceIndex, const U32 byteOffset, const U16 dataSize, const U8 *const data)
Initialize a data packet.
Definition: DataPacket.cpp:19
Fw::SerializeStatus
SerializeStatus
forward declaration for string
Definition: Serializable.hpp:14
Fw::FW_DESERIALIZE_SIZE_MISMATCH
@ FW_DESERIALIZE_SIZE_MISMATCH
Data was left in in the buffer, but not enough to deserialize.
Definition: Serializable.hpp:20
Fw::Buffer::getData
U8 * getData() const
Definition: Buffer.cpp:56
Fw::SerialBuffer::getBuffAddr
U8 * getBuffAddr(void)
gets buffer address for data filling
Definition: SerialBuffer.cpp:36
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
Fw::Buffer
Definition: Buffer.hpp:43
Assert.hpp
Fw::FW_SERIALIZE_OK
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
Definition: Serializable.hpp:15
Fw::SerializeBufferBase::getBuffLeft
NATIVE_UINT_TYPE getBuffLeft() const
returns how much deserialization buffer is left
Definition: Serializable.cpp:614
Fw::Buffer::getSize
U32 getSize() const
Definition: Buffer.cpp:60
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:9
Fw::FilePacket::DataPacket::byteOffset
U32 byteOffset
The byte offset of the packet data into the destination file.
Definition: FilePacket.hpp:172
Fw::SerializeBufferBase::deserialize
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
Definition: Serializable.cpp:290
FilePacket.hpp
Fw::FilePacket::DataPacket::data
const U8 * data
Pointer to the file data.
Definition: FilePacket.hpp:178
Fw::FilePacket::Header::type
Type type
The packet type.
Definition: FilePacket.hpp:90
Fw::FilePacket::T_DATA
@ T_DATA
Definition: FilePacket.hpp:38
Fw::FilePacket::DataPacket::toBuffer
SerializeStatus toBuffer(Buffer &buffer) const
Convert this DataPacket to a Buffer.
Definition: DataPacket.cpp:43
Fw
Definition: Buffer.cpp:21
Fw::FilePacket::DataPacket::dataSize
U16 dataSize
The size of the file data in the packet.
Definition: FilePacket.hpp:175