F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
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
16namespace Fw {
17
18 void FilePacket::DataPacket ::
19 initialize(
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
32 U32 FilePacket::DataPacket ::
33 bufferSize() const
34 {
35 return
36 this->header.bufferSize() +
37 sizeof(this->byteOffset) +
38 sizeof(this->dataSize) +
39 this->dataSize;
40 }
41
42 SerializeStatus FilePacket::DataPacket ::
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() 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}
#define FW_ASSERT(...)
Definition Assert.hpp:7
uint8_t U8
8-bit unsigned integer
Definition BasicTypes.h:26
U8 * getData() const
Definition Buffer.cpp:60
U32 getSize() const
Definition Buffer.cpp:64
A variable-length serializable buffer.
U8 * getBuffAddr()
gets buffer address for data filling
NATIVE_UINT_TYPE getBuffLeft() const
returns how much deserialization buffer is left
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
Definition Buffer.cpp:21
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
@ FW_DESERIALIZE_SIZE_MISMATCH
Data was left in the buffer, but not enough to deserialize.