F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
CmdPacket.cpp
Go to the documentation of this file.
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  CmdPacket::CmdPacket() : m_opcode(0) {
15  this->m_type = FW_PACKET_COMMAND;
16  }
17 
19  }
20 
22 
23  // Shouldn't be called
24  FW_ASSERT(0);
25  return FW_SERIALIZE_OK; // for compiler
26 
27  }
28 
30 
32  if (stat != FW_SERIALIZE_OK) {
33  return stat;
34  }
35 
36  // double check packet type
37  if (this->m_type != FW_PACKET_COMMAND) {
39  }
40 
41  stat = buffer.deserialize(this->m_opcode);
42  if (stat != FW_SERIALIZE_OK) {
43  return stat;
44  }
45 
46  // if non-empty, copy data
47  if (buffer.getBuffLeft()) {
48  // copy the serialized arguments to the buffer
49  stat = buffer.copyRaw(this->m_argBuffer,buffer.getBuffLeft());
50  }
51 
52  return stat;
53  }
54 
56  return this->m_opcode;
57  }
58 
60  return this->m_argBuffer;
61  }
62 
63 
64 
65 } /* namespace Fw */
#define FW_ASSERT(...)
Definition: Assert.hpp:14
U32 FwOpcodeType
Definition: FpConfig.h:91
virtual ~CmdPacket()
Definition: CmdPacket.cpp:18
FwOpcodeType getOpCode() const
Definition: CmdPacket.cpp:55
SerializeStatus deserialize(SerializeBufferBase &buffer)
deserialize to contents
Definition: CmdPacket.cpp:29
SerializeStatus serialize(SerializeBufferBase &buffer) const
serialize contents
Definition: CmdPacket.cpp:21
CmdArgBuffer m_argBuffer
Definition: CmdPacket.hpp:29
CmdArgBuffer & getArgBuffer()
Definition: CmdPacket.cpp:59
FwOpcodeType m_opcode
Definition: CmdPacket.hpp:28
ComPacketType m_type
Definition: ComPacket.hpp:36
SerializeStatus deserializeBase(SerializeBufferBase &buffer)
Definition: ComPacket.cpp:22
Serializable::SizeType getBuffLeft() const
returns how much deserialization buffer is left
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
SerializeStatus copyRaw(SerializeBufferBase &dest, Serializable::SizeType size)
directly copies buffer without looking for a size in the stream.
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
@ FW_DESERIALIZE_TYPE_MISMATCH
Deserialized type ID didn't match.