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