fprime/Fw/Cmd/CmdPacket.cpp
Vince Woo 48e4720419
Created new SerialBufferBase as a parent of SerializeBufferBase (now renamed LinearBufferBase). (#4288)
* Created new SerialBufferBase as a parent of SerializeBufferBase. Renaming interface functions to be less confusing.

* Deprecating copyRawOffset. No direct use-cases in F' core.

* Make SerialBufferBase a true pure virtual interface.

* Changing Serializable to work with SerialBufferBase parent interface.

* Changing copyRaw and copyRawOffset to work with SerialBufferBase

* Updating documentation for SerialBufferBase usage

* Adding some documentation. Adding missing ASSERT in copyRaw. Fixing some bugs that new ASSERT uncovered.

* Renaming SerializeBufferBase to LinearBufferBase. Add a using declaration to maintain backwards compatability. Properly mark LinearBufferBase functions as override.

* Filling in the rest of the docstrings for the classes in Serializable

* Removing redundant virtual keyword on override function

* Applying clang formatting

* Incorporating PR comments

* Fix compile issues

* Bump version to alpha

* Format

* v

---------

Co-authored-by: M Starch <LeStarch@googlemail.com>
2025-11-06 16:23:20 -08:00

61 lines
1.4 KiB
C++

/*
* CmdPacket.cpp
*
* Created on: May 24, 2014
* Author: Timothy Canham
*/
#include <Fw/Cmd/CmdPacket.hpp>
#include <Fw/Types/Assert.hpp>
#include <cstdio>
namespace Fw {
CmdPacket::CmdPacket() : m_opcode(0) {
this->m_type = ComPacketType::FW_PACKET_COMMAND;
}
CmdPacket::~CmdPacket() {}
// New serialization interface methods
SerializeStatus CmdPacket::serializeTo(SerialBufferBase& buffer, Fw::Endianness mode) const {
// Shouldn't be called, no use case for serializing CmdPackets in FSW (currently)
FW_ASSERT(0);
return FW_SERIALIZE_OK; // for compiler
}
SerializeStatus CmdPacket::deserializeFrom(SerialBufferBase& buffer, Fw::Endianness mode) {
SerializeStatus stat = ComPacket::deserializeBase(buffer);
if (stat != FW_SERIALIZE_OK) {
return stat;
}
// double check packet type
if (this->m_type != ComPacketType::FW_PACKET_COMMAND) {
return FW_DESERIALIZE_TYPE_MISMATCH;
}
stat = buffer.deserializeTo(this->m_opcode, mode);
if (stat != FW_SERIALIZE_OK) {
return stat;
}
// if non-empty, copy data
if (buffer.getDeserializeSizeLeft()) {
// copy the serialized arguments to the buffer
stat = buffer.copyRaw(this->m_argBuffer, buffer.getDeserializeSizeLeft());
}
return stat;
}
FwOpcodeType CmdPacket::getOpCode() const {
return this->m_opcode;
}
CmdArgBuffer& CmdPacket::getArgBuffer() {
return this->m_argBuffer;
}
} /* namespace Fw */