| Line | Branch | Exec | Source |
|---|---|---|---|
| 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> | ||
| 9 | #include <Fw/Types/Serializable.hpp> | ||
| 10 | |||
| 11 | namespace Fw { | ||
| 12 | |||
| 13 |
1/1✓ Branch 10 taken 6 times.
|
6 | TlmPacket::TlmPacket() : m_numEntries(0) { |
| 14 | 6 | this->m_type = ComPacketType::FW_PACKET_TELEM; | |
| 15 |
1/1✓ Branch 6 taken 6 times.
|
6 | this->m_tlmBuffer.resetSer(); |
| 16 | 6 | } | |
| 17 | |||
| 18 | 12 | TlmPacket::~TlmPacket() {} | |
| 19 | |||
| 20 | 3 | SerializeStatus TlmPacket::resetPktSer() { | |
| 21 | 3 | this->m_tlmBuffer.resetSer(); | |
| 22 | // reset packet count | ||
| 23 | 3 | 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 | 3 | 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 | 3 | return this->serializeBase(this->m_tlmBuffer); | |
| 31 | } | ||
| 32 | |||
| 33 | 2 | SerializeStatus TlmPacket::resetPktDeser() { | |
| 34 | 2 | 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 | 2 | Fw::SerializeStatus stat = this->deserializeBase(this->m_tlmBuffer); | |
| 40 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (stat != Fw::FW_SERIALIZE_OK) { |
| 41 | ✗ | return stat; | |
| 42 | } | ||
| 43 | // make sure that this->m_tlmBuffer stores a telemetry packet | ||
| 44 |
2/4✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
|
2 | if (this->m_type != ComPacketType::FW_PACKET_TELEM) { |
| 45 | ✗ | return Fw::FW_DESERIALIZE_TYPE_MISMATCH; | |
| 46 | } | ||
| 47 | |||
| 48 | 2 | return Fw::FW_SERIALIZE_OK; | |
| 49 | } | ||
| 50 | |||
| 51 | ✗ | FwSizeType TlmPacket::getNumEntries() { | |
| 52 | ✗ | return this->m_numEntries; | |
| 53 | } | ||
| 54 | |||
| 55 | 2 | Fw::ComBuffer& TlmPacket::getBuffer() { | |
| 56 | 2 | return this->m_tlmBuffer; | |
| 57 | } | ||
| 58 | |||
| 59 | 2 | void TlmPacket::setBuffer(Fw::ComBuffer& buffer) { | |
| 60 | 2 | this->m_tlmBuffer = buffer; | |
| 61 | 2 | } | |
| 62 | |||
| 63 | 29 | SerializeStatus TlmPacket::addValue(FwChanIdType id, Time& timeTag, TlmBuffer& buffer) { | |
| 64 | // check to make sure there is room for all the fields | ||
| 65 | 29 | FwSizeType left = this->m_tlmBuffer.getCapacity() - this->m_tlmBuffer.getSize(); | |
| 66 |
2/2✓ Branch 5 taken 1 times.
✓ Branch 6 taken 28 times.
|
29 | if ((sizeof(FwChanIdType) + Time::SERIALIZED_SIZE + buffer.getSize()) > left) { |
| 67 | 1 | return Fw::FW_SERIALIZE_NO_ROOM_LEFT; | |
| 68 | } | ||
| 69 | |||
| 70 | // serialize items into buffer | ||
| 71 | |||
| 72 | // id | ||
| 73 | 28 | SerializeStatus stat = this->m_tlmBuffer.serializeFrom(id); | |
| 74 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | if (stat != Fw::FW_SERIALIZE_OK) { |
| 75 | ✗ | return stat; | |
| 76 | } | ||
| 77 | |||
| 78 | // time tag | ||
| 79 | 28 | stat = this->m_tlmBuffer.serializeFrom(timeTag); | |
| 80 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | if (stat != Fw::FW_SERIALIZE_OK) { |
| 81 | ✗ | return stat; | |
| 82 | } | ||
| 83 | |||
| 84 | // telemetry buffer | ||
| 85 | 28 | stat = this->m_tlmBuffer.serializeFrom(buffer.getBuffAddr(), buffer.getSize(), Fw::Serialization::OMIT_LENGTH); | |
| 86 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | if (stat != Fw::FW_SERIALIZE_OK) { |
| 87 | ✗ | return stat; | |
| 88 | } | ||
| 89 | |||
| 90 | // increment number of packets | ||
| 91 | 28 | this->m_numEntries++; | |
| 92 | |||
| 93 | 28 | return Fw::FW_SERIALIZE_OK; | |
| 94 | } | ||
| 95 | |||
| 96 | // extract telemetry value | ||
| 97 | 28 | SerializeStatus TlmPacket::extractValue(FwChanIdType& id, Time& timeTag, TlmBuffer& buffer, FwSizeType bufferSize) { | |
| 98 | // deserialize items out of buffer | ||
| 99 | |||
| 100 | // id | ||
| 101 | 28 | SerializeStatus stat = this->m_tlmBuffer.deserializeTo(id); | |
| 102 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 27 times.
|
28 | if (stat != Fw::FW_SERIALIZE_OK) { |
| 103 | 1 | return stat; | |
| 104 | } | ||
| 105 | |||
| 106 | // time tag | ||
| 107 | 27 | stat = this->m_tlmBuffer.deserializeTo(timeTag); | |
| 108 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
|
27 | if (stat != Fw::FW_SERIALIZE_OK) { |
| 109 | ✗ | return stat; | |
| 110 | } | ||
| 111 | |||
| 112 | // telemetry buffer | ||
| 113 | 27 | stat = this->m_tlmBuffer.deserializeTo(buffer.getBuffAddr(), bufferSize, Fw::Serialization::OMIT_LENGTH); | |
| 114 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
|
27 | if (stat != Fw::FW_SERIALIZE_OK) { |
| 115 | ✗ | return stat; | |
| 116 | } | ||
| 117 | |||
| 118 | // set buffer size | ||
| 119 | 27 | stat = buffer.setBuffLen(bufferSize); | |
| 120 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27 times.
|
27 | if (stat != Fw::FW_SERIALIZE_OK) { |
| 121 | ✗ | return stat; | |
| 122 | } | ||
| 123 | |||
| 124 | 27 | return Fw::FW_SERIALIZE_OK; | |
| 125 | } | ||
| 126 | |||
| 127 | 1 | SerializeStatus TlmPacket::serializeTo(SerialBufferBase& buffer, Fw::Endianness mode) const { | |
| 128 | // serialize the number of packets | ||
| 129 | 1 | SerializeStatus stat = buffer.serializeFrom(this->m_numEntries, mode); | |
| 130 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (stat != Fw::FW_SERIALIZE_OK) { |
| 131 | ✗ | return stat; | |
| 132 | } | ||
| 133 | // Serialize the ComBuffer | ||
| 134 | 1 | return buffer.serializeFrom(this->m_tlmBuffer.getBuffAddr(), m_tlmBuffer.getSize(), Fw::Serialization::OMIT_LENGTH); | |
| 135 | } | ||
| 136 | |||
| 137 | 1 | SerializeStatus TlmPacket::deserializeFrom(SerialBufferBase& buffer, Fw::Endianness mode) { | |
| 138 | // deserialize the number of packets | ||
| 139 |
1/1✓ Branch 10 taken 1 times.
|
1 | SerializeStatus stat = buffer.deserializeTo(this->m_numEntries, mode); |
| 140 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (stat != Fw::FW_SERIALIZE_OK) { |
| 141 | ✗ | return stat; | |
| 142 | } | ||
| 143 | // deserialize the channel value entry buffers | ||
| 144 |
1/1✓ Branch 8 taken 1 times.
|
1 | FwSizeType size = buffer.getDeserializeSizeLeft(); |
| 145 |
1/2✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
1 | if (size > this->m_tlmBuffer.getCapacity()) { |
| 146 | 1 | return FW_DESERIALIZE_SIZE_MISMATCH; | |
| 147 | } | ||
| 148 | ✗ | stat = buffer.deserializeTo(this->m_tlmBuffer.getBuffAddr(), size, Fw::Serialization::OMIT_LENGTH); | |
| 149 | ✗ | if (stat == FW_SERIALIZE_OK) { | |
| 150 | // Shouldn't fail | ||
| 151 | ✗ | stat = this->m_tlmBuffer.setBuffLen(size); | |
| 152 | ✗ | FW_ASSERT(stat == FW_SERIALIZE_OK, static_cast<FwAssertArgType>(stat)); | |
| 153 | } | ||
| 154 | ✗ | return stat; | |
| 155 | } | ||
| 156 | |||
| 157 | } /* namespace Fw */ | ||
| 158 |