| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * CmdPacket.cpp | ||
| 3 | * | ||
| 4 | * Created on: May 24, 2014 | ||
| 5 | * Author: Timothy Canham | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <Fw/Cmd/CmdPacket.hpp> | ||
| 9 | #include <Fw/Types/Assert.hpp> | ||
| 10 | #include <cstdio> | ||
| 11 | |||
| 12 | namespace Fw { | ||
| 13 | |||
| 14 |
1/1✓ Branch 2 taken 145 times.
|
145 | CmdPacket::CmdPacket() : m_opcode(0) { |
| 15 | 145 | this->m_type = ComPacketType::FW_PACKET_COMMAND; | |
| 16 | 145 | } | |
| 17 | |||
| 18 | 290 | CmdPacket::~CmdPacket() {} | |
| 19 | |||
| 20 | // New serialization interface methods | ||
| 21 | ✗ | SerializeStatus CmdPacket::serializeTo(SerialBufferBase& buffer, Fw::Endianness mode) const { | |
| 22 | // Shouldn't be called, no use case for serializing CmdPackets in FSW (currently) | ||
| 23 | ✗ | FW_ASSERT(false); | |
| 24 | ✗ | return FW_SERIALIZE_OK; // for compiler | |
| 25 | } | ||
| 26 | |||
| 27 | 145 | SerializeStatus CmdPacket::deserializeFrom(SerialBufferBase& buffer, Fw::Endianness mode) { | |
| 28 | 145 | SerializeStatus stat = ComPacket::deserializeBase(buffer); | |
| 29 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 145 times.
|
145 | if (stat != FW_SERIALIZE_OK) { |
| 30 | ✗ | return stat; | |
| 31 | } | ||
| 32 | |||
| 33 | // double check packet type | ||
| 34 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 145 times.
|
145 | if (this->m_type != ComPacketType::FW_PACKET_COMMAND) { |
| 35 | ✗ | return FW_DESERIALIZE_TYPE_MISMATCH; | |
| 36 | } | ||
| 37 | |||
| 38 | 145 | stat = buffer.deserializeTo(this->m_opcode, mode); | |
| 39 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 145 times.
|
145 | if (stat != FW_SERIALIZE_OK) { |
| 40 | ✗ | return stat; | |
| 41 | } | ||
| 42 | |||
| 43 | // if non-empty, copy data | ||
| 44 |
2/2✓ Branch 1 taken 32 times.
✓ Branch 2 taken 113 times.
|
145 | if (buffer.getDeserializeSizeLeft()) { |
| 45 | // copy the serialized arguments to the buffer | ||
| 46 | 32 | stat = buffer.copyRaw(this->m_argBuffer, buffer.getDeserializeSizeLeft()); | |
| 47 | } else { | ||
| 48 | // copyRaw overwrites the argument buffer, so an argument-bearing command | ||
| 49 | // needs no clearing here, but a command without arguments would otherwise | ||
| 50 | // inherit whatever this packet held before. | ||
| 51 | 113 | this->m_argBuffer.resetSer(); | |
| 52 | } | ||
| 53 | |||
| 54 | 145 | return stat; | |
| 55 | } | ||
| 56 | |||
| 57 | 580 | FwOpcodeType CmdPacket::getOpCode() const { | |
| 58 | 580 | return this->m_opcode; | |
| 59 | } | ||
| 60 | |||
| 61 | 145 | CmdArgBuffer& CmdPacket::getArgBuffer() { | |
| 62 | 145 | return this->m_argBuffer; | |
| 63 | } | ||
| 64 | |||
| 65 | } /* namespace Fw */ | ||
| 66 |