F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TlmPacket.cpp
Go to the documentation of this file.
1/*
2 * TlmPacket.cpp
3 *
4 * Created on: May 24, 2014
5 * Author: Timothy Canham
6 */
9#include <Fw/Types/Assert.hpp>
10
11namespace Fw {
12
13 TlmPacket::TlmPacket() : m_numEntries(0) {
14 this->m_type = FW_PACKET_TELEM;
15 this->m_tlmBuffer.resetSer();
16 }
17
20
22 this->m_tlmBuffer.resetSer();
23 // reset packet count
24 this->m_numEntries = 0;
25 // make sure packet type is correct before serializing. It should
26 // never be anything but FW_PACKET_TELEM, so assert.
27 FW_ASSERT(FW_PACKET_TELEM == this->m_type,this->m_type);
28 // serialize descriptor
29 // The function serializeBase inherited from ComPacket converts this->m_type
30 // to type FwPacketDescriptorType and serializes the result into this->m_tlmBuffer.
31 return this->serializeBase(this->m_tlmBuffer);
32 }
33
35 this->m_tlmBuffer.resetDeser();
36 // deserialize descriptor
37 // The function deserializeBase inherited from ComPacket deserializes a
38 // value of type FwPacketDescriptorType from this->m_tlmBuffer and stores it
39 // into this->m_type.
40 Fw::SerializeStatus stat = this->deserializeBase(this->m_tlmBuffer);
41 if (stat != Fw::FW_SERIALIZE_OK) {
42 return stat;
43 }
44 // make sure that this->m_tlmBuffer stores a telemetry packet
45 if (this->m_type != FW_PACKET_TELEM) {
47 }
48
50 }
51
53 return this->m_numEntries;
54 }
55
57 return this->m_tlmBuffer;
58 }
59
61 this->m_tlmBuffer = buffer;
62 }
63
65 // check to make sure there is room for all the fields
66 NATIVE_UINT_TYPE left = this->m_tlmBuffer.getBuffCapacity()-this->m_tlmBuffer.getBuffLength();
67 if (
68 (sizeof(FwChanIdType) + Time::SERIALIZED_SIZE + buffer.getBuffLength()) > left
69 ) {
71 }
72
73 // serialize items into buffer
74
75 // id
76 SerializeStatus stat = this->m_tlmBuffer.serialize(id);
77 if (stat != Fw::FW_SERIALIZE_OK) {
78 return stat;
79 }
80
81 // time tag
82 stat = this->m_tlmBuffer.serialize(timeTag);
83 if (stat != Fw::FW_SERIALIZE_OK) {
84 return stat;
85 }
86
87 // telemetry buffer
88 stat = this->m_tlmBuffer.serialize(buffer.getBuffAddr(),buffer.getBuffLength(),true);
89 if (stat != Fw::FW_SERIALIZE_OK) {
90 return stat;
91 }
92
93 // increment number of packets
94 this->m_numEntries++;
95
97 }
98
99 // extract telemetry value
101
102 // deserialize items out of buffer
103
104 // id
105 SerializeStatus stat = this->m_tlmBuffer.deserialize(id);
106 if (stat != Fw::FW_SERIALIZE_OK) {
107 return stat;
108 }
109
110 // time tag
111 stat = this->m_tlmBuffer.deserialize(timeTag);
112 if (stat != Fw::FW_SERIALIZE_OK) {
113 return stat;
114 }
115
116 // telemetry buffer
117 stat = this->m_tlmBuffer.deserialize(buffer.getBuffAddr(),bufferSize,true);
118 if (stat != Fw::FW_SERIALIZE_OK) {
119 return stat;
120 }
121
122 // set buffer size
123 stat = buffer.setBuffLen(bufferSize);
124 if (stat != Fw::FW_SERIALIZE_OK) {
125 return stat;
126 }
127
128 return Fw::FW_SERIALIZE_OK;
129
130 }
131
133 // serialize the number of packets
134 SerializeStatus stat = buffer.serialize(this->m_numEntries);
135 if (stat != Fw::FW_SERIALIZE_OK) {
136 return stat;
137 }
138 // Serialize the ComBuffer
139 return buffer.serialize(this->m_tlmBuffer.getBuffAddr(),m_tlmBuffer.getBuffLength(),true);
140 }
141
143
144 // deserialize the number of packets
145 SerializeStatus stat = buffer.deserialize(this->m_numEntries);
146 if (stat != Fw::FW_SERIALIZE_OK) {
147 return stat;
148 }
149 // deserialize the channel value entry buffers
150 NATIVE_UINT_TYPE size = buffer.getBuffLeft();
151 stat = buffer.deserialize(this->m_tlmBuffer.getBuffAddr(),size,true);
152 if (stat == FW_SERIALIZE_OK) {
153 // Shouldn't fail
154 stat = this->m_tlmBuffer.setBuffLen(size);
155 FW_ASSERT(stat == FW_SERIALIZE_OK,static_cast<NATIVE_INT_TYPE>(stat));
156 }
157 return stat;
158 }
159
160} /* namespace Fw */
#define FW_ASSERT(...)
Definition Assert.hpp:7
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
U32 FwChanIdType
Definition FpConfig.h:59
NATIVE_UINT_TYPE getBuffCapacity() const
returns capacity, not current size, of buffer
Definition ComBuffer.cpp:32
U8 * getBuffAddr()
gets buffer address for data filling
Definition ComBuffer.cpp:40
SerializeStatus serializeBase(SerializeBufferBase &buffer) const
Definition ComPacket.cpp:18
ComPacketType m_type
Definition ComPacket.hpp:35
SerializeStatus deserializeBase(SerializeBufferBase &buffer)
Definition ComPacket.cpp:22
NATIVE_UINT_TYPE getBuffLeft() const
returns how much deserialization buffer is left
void resetDeser()
reset deserialization to beginning
SerializeStatus setBuffLen(NATIVE_UINT_TYPE length)
sets buffer length manually after filling with data
void resetSer()
reset to beginning of buffer to reuse for serialization
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
NATIVE_UINT_TYPE getBuffLength() const
returns current buffer size
@ SERIALIZED_SIZE
Definition Time.hpp:13
U8 * getBuffAddr()
gets buffer address for data filling
Definition TlmBuffer.cpp:40
void setBuffer(Fw::ComBuffer &buffer)
set the internal buffer for deserializing values
Definition TlmPacket.cpp:60
virtual ~TlmPacket()
Destructor.
Definition TlmPacket.cpp:18
TlmPacket()
Constructor.
Definition TlmPacket.cpp:13
SerializeStatus extractValue(FwChanIdType &id, Time &timeTag, TlmBuffer &buffer, NATIVE_UINT_TYPE bufferSize)
SerializeStatus resetPktDeser()
Reset deserialization. This should be done before extracting values.
Definition TlmPacket.cpp:34
SerializeStatus deserialize(SerializeBufferBase &buffer)
Deserialize the packet. For use internally in software. To extract channels, use setBuffer() and extr...
NATIVE_UINT_TYPE getNumEntries()
get the number of packets added via addValue()
Definition TlmPacket.cpp:52
SerializeStatus resetPktSer()
Reset serialization of values. This should be done when starting to accumulate a new set of values.
Definition TlmPacket.cpp:21
Fw::ComBuffer & getBuffer()
get buffer to send to the ground
Definition TlmPacket.cpp:56
SerializeStatus serialize(SerializeBufferBase &buffer) const
Serialize the packet before sending. For use internally in software. To send to the ground,...
SerializeStatus addValue(FwChanIdType id, Time &timeTag, TlmBuffer &buffer)
Add telemetry value to buffer.
Definition TlmPacket.cpp:64
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
@ FW_DESERIALIZE_TYPE_MISMATCH
Deserialized type ID didn't match.
@ FW_SERIALIZE_NO_ROOM_LEFT
No room left in the buffer to serialize data.