GCC Code Coverage Report


Directory: ./
File: Fw/Cmd/CmdPacket.cpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 21 24 87.5%
Functions: 5 6 83.3%
Branches: 10 11 90.9%

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 14 taken 70 times.
70 CmdPacket::CmdPacket() : m_opcode(0) {
15 70 this->m_type = ComPacketType::FW_PACKET_COMMAND;
16 70 }
17
18 140 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 71 SerializeStatus CmdPacket::deserializeFrom(SerialBufferBase& buffer, Fw::Endianness mode) {
28 71 SerializeStatus stat = ComPacket::deserializeBase(buffer);
29
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 68 times.
71 if (stat != FW_SERIALIZE_OK) {
30 3 return stat;
31 }
32
33 // double check packet type
34
3/4
✗ Branch 4 not taken.
✓ Branch 5 taken 68 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 66 times.
68 if (this->m_type != ComPacketType::FW_PACKET_COMMAND) {
35 2 return FW_DESERIALIZE_TYPE_MISMATCH;
36 }
37
38 66 stat = buffer.deserializeTo(this->m_opcode, mode);
39
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 64 times.
66 if (stat != FW_SERIALIZE_OK) {
40 2 return stat;
41 }
42
43 // if non-empty, copy data
44
2/2
✓ Branch 7 taken 41 times.
✓ Branch 8 taken 23 times.
64 if (buffer.getDeserializeSizeLeft()) {
45 // copy the serialized arguments to the buffer
46 41 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 23 this->m_argBuffer.resetSer();
52 }
53
54 64 return stat;
55 }
56
57 211 FwOpcodeType CmdPacket::getOpCode() const {
58 211 return this->m_opcode;
59 }
60
61 54 CmdArgBuffer& CmdPacket::getArgBuffer() {
62 54 return this->m_argBuffer;
63 }
64
65 } /* namespace Fw */
66