F´ Flight Software - C/C++ Documentation  NASA-v2.0.1
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FilePacket.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title FilePacket.cpp
3 // \author bocchino
4 // \brief cpp file for FilePacket
5 //
6 // \copyright
7 // Copyright 2009-2016, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
14 #include "Fw/Types/Assert.hpp"
15 
16 namespace Fw {
17 
18  // ----------------------------------------------------------------------
19  // Public instance methods
20  // ----------------------------------------------------------------------
21 
23  fromBuffer(const Buffer& buffer)
24  {
25  SerialBuffer serialBuffer(
26  const_cast<Buffer&>(buffer).getData(),
27  const_cast<Buffer&>(buffer).getSize()
28  );
29  serialBuffer.fill();
30  const SerializeStatus status = this->fromSerialBuffer(serialBuffer);
31  return status;
32  }
33 
35  asHeader(void) const
36  {
37  return this->header;
38  }
39 
41  asStartPacket(void) const
42  {
43  FW_ASSERT(this->header.type == T_START);
44  return this->startPacket;
45  }
46 
48  asDataPacket(void) const
49  {
50  FW_ASSERT(this->header.type == T_DATA);
51  return this->dataPacket;
52  }
53 
55  asEndPacket(void) const
56  {
57  FW_ASSERT(this->header.type == T_END);
58  return this->endPacket;
59  }
60 
62  asCancelPacket(void) const
63  {
64  FW_ASSERT(this->header.type == T_CANCEL);
65  return this->cancelPacket;
66  }
67 
68  void FilePacket ::
69  fromStartPacket(const StartPacket& startPacket)
70  {
71  this->startPacket = startPacket;
72  this->header.type = T_START;
73  }
74 
75  void FilePacket ::
76  fromDataPacket(const DataPacket& dataPacket)
77  {
78  this->dataPacket = dataPacket;
79  this->header.type = T_DATA;
80  }
81 
82  void FilePacket ::
83  fromEndPacket(const EndPacket& endPacket)
84  {
85  this->endPacket = endPacket;
86  this->header.type = T_END;
87  }
88 
89  void FilePacket ::
90  fromCancelPacket(const CancelPacket& cancelPacket)
91  {
92  this->cancelPacket = cancelPacket;
93  this->header.type = T_CANCEL;
94  }
95 
96  U32 FilePacket ::
97  bufferSize(void) const
98  {
99  switch (this->header.type) {
100  case T_START:
101  return this->startPacket.bufferSize();
102  case T_DATA:
103  return this->dataPacket.bufferSize();
104  case T_END:
105  return this->endPacket.bufferSize();
106  case T_CANCEL:
107  return this->cancelPacket.bufferSize();
108  case T_NONE:
109  return 0;
110  default:
111  FW_ASSERT(0);
112  return 0;
113  }
114  }
115 
117  toBuffer(Buffer& buffer) const
118  {
119  switch (this->header.type) {
120  case T_START:
121  return this->startPacket.toBuffer(buffer);
122  case T_DATA:
123  return this->dataPacket.toBuffer(buffer);
124  case T_END:
125  return this->endPacket.toBuffer(buffer);
126  case T_CANCEL:
127  return this->cancelPacket.toBuffer(buffer);
128  default:
129  FW_ASSERT(0);
130  return static_cast<SerializeStatus>(0);
131  }
132  }
133 
134  // ----------------------------------------------------------------------
135  // Private instance methods
136  // ----------------------------------------------------------------------
137 
138  SerializeStatus FilePacket ::
139  fromSerialBuffer(SerialBuffer& serialBuffer)
140  {
141  SerializeStatus status;
142  status = this->header.fromSerialBuffer(serialBuffer);
143  if (status != FW_SERIALIZE_OK)
144  return status;
145  switch (this->header.type) {
146  case T_START:
147  status = this->startPacket.fromSerialBuffer(serialBuffer);
148  break;
149  case T_DATA:
150  status = this->dataPacket.fromSerialBuffer(serialBuffer);
151  break;
152  case T_END:
153  status = this->endPacket.fromSerialBuffer(serialBuffer);
154  break;
155  case T_CANCEL:
156  status = this->cancelPacket.fromSerialBuffer(serialBuffer);
157  break;
158  case T_NONE:
160  break;
161  default:
162  FW_ASSERT(0,status);
163  break;
164  }
165  return status;
166  }
167 
168 }
Fw::FilePacket::DataPacket::bufferSize
U32 bufferSize(void) const
Compute the buffer size needed to hold this DataPacket.
Definition: DataPacket.cpp:33
Fw::FilePacket::EndPacket::bufferSize
U32 bufferSize(void) const
Compute the buffer size needed to hold this EndPacket.
Definition: EndPacket.cpp:31
Fw::SerialBuffer
A variable-length serializable buffer.
Definition: SerialBuffer.hpp:24
Fw::FilePacket::asHeader
const Header & asHeader(void) const
Definition: FilePacket.cpp:35
Fw::SerializeStatus
SerializeStatus
forward declaration for string
Definition: Serializable.hpp:14
Fw::FilePacket::toBuffer
SerializeStatus toBuffer(Buffer &buffer) const
Definition: FilePacket.cpp:117
Fw::FilePacket::asEndPacket
const EndPacket & asEndPacket(void) const
Definition: FilePacket.cpp:55
Fw::FilePacket::CancelPacket
The type of a cancel packet.
Definition: FilePacket.hpp:259
Fw::FilePacket::StartPacket
The type of a start packet.
Definition: FilePacket.hpp:118
Fw::FilePacket::asStartPacket
const StartPacket & asStartPacket(void) const
Definition: FilePacket.cpp:41
Fw::FilePacket::DataPacket
The type of a data packet.
Definition: FilePacket.hpp:162
Fw::FilePacket::fromDataPacket
void fromDataPacket(const DataPacket &dataPacket)
Definition: FilePacket.cpp:76
Fw::FilePacket::Header
The type of a packet header.
Definition: FilePacket.hpp:83
Fw::Buffer
Definition: Buffer.hpp:43
Fw::FilePacket::T_CANCEL
@ T_CANCEL
Definition: FilePacket.hpp:40
Fw::FilePacket::EndPacket
The type of an end packet.
Definition: FilePacket.hpp:216
Assert.hpp
Fw::FW_SERIALIZE_OK
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
Definition: Serializable.hpp:15
Fw::FilePacket::T_NONE
@ T_NONE
Definition: FilePacket.hpp:41
Fw::FilePacket::bufferSize
U32 bufferSize(void) const
Definition: FilePacket.cpp:97
Fw::FilePacket::fromStartPacket
void fromStartPacket(const StartPacket &startPacket)
Definition: FilePacket.cpp:69
Fw::FilePacket::T_START
@ T_START
Definition: FilePacket.hpp:37
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:9
Fw::FilePacket::StartPacket::bufferSize
U32 bufferSize(void) const
Compute the buffer size needed to hold this StartPacket.
Definition: StartPacket.cpp:33
Fw::FilePacket::asDataPacket
const DataPacket & asDataPacket(void) const
Definition: FilePacket.cpp:48
Fw::FW_DESERIALIZE_TYPE_MISMATCH
@ FW_DESERIALIZE_TYPE_MISMATCH
Deserialized type ID didn't match.
Definition: Serializable.hpp:21
Fw::FilePacket::asCancelPacket
const CancelPacket & asCancelPacket(void) const
Definition: FilePacket.cpp:62
Fw::FilePacket::StartPacket::toBuffer
SerializeStatus toBuffer(Buffer &buffer) const
Convert this StartPacket to a Buffer.
Definition: StartPacket.cpp:42
Fw::FilePacket::fromEndPacket
void fromEndPacket(const EndPacket &endPacket)
Definition: FilePacket.cpp:83
Fw::FilePacket::CancelPacket::toBuffer
SerializeStatus toBuffer(Buffer &buffer) const
Convert this CancelPacket to a Buffer.
Definition: CancelPacket.cpp:31
Fw::FilePacket::T_END
@ T_END
Definition: FilePacket.hpp:39
FilePacket.hpp
Fw::FilePacket::EndPacket::toBuffer
SerializeStatus toBuffer(Buffer &buffer) const
Convert this EndPacket to a Buffer.
Definition: EndPacket.cpp:37
Fw::SerialBuffer::fill
void fill(void)
Fill the buffer to capacity with preexisting data.
Definition: SerialBuffer.cpp:48
Fw::FilePacket::fromBuffer
SerializeStatus fromBuffer(const Buffer &buffer)
Definition: FilePacket.cpp:23
Fw::FilePacket::Header::type
Type type
The packet type.
Definition: FilePacket.hpp:90
Fw::FilePacket::CancelPacket::bufferSize
U32 bufferSize(void) const
Compute the buffer size needed to hold this CancelPacket.
Definition: CancelPacket.cpp:25
Fw::FilePacket::T_DATA
@ T_DATA
Definition: FilePacket.hpp:38
Fw::FilePacket::DataPacket::toBuffer
SerializeStatus toBuffer(Buffer &buffer) const
Convert this DataPacket to a Buffer.
Definition: DataPacket.cpp:43
Fw
Definition: Buffer.cpp:21
Fw::FilePacket::fromCancelPacket
void fromCancelPacket(const CancelPacket &cancelPacket)
Definition: FilePacket.cpp:90