F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Tlv.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Tlv.hpp
3 // \author Brian Campuzano
4 // \brief hpp file for CFDP TLV types
5 // ======================================================================
6 
7 #ifndef Svc_Ccsds_Cfdp_Tlv_HPP
8 #define Svc_Ccsds_Cfdp_Tlv_HPP
9 
10 #include <Fw/FPrimeBasicTypes.hpp>
12 #include <config/CfdpCfg.hpp>
14 
15 namespace Svc {
16 namespace Ccsds {
17 namespace Cfdp {
18 
19 // CFDP TLV Types
20 // Blue Book section 5.4, table 5-3
21 enum class TlvType : U8 {
22  TLV_TYPE_FILESTORE_REQUEST = 0, // Filestore request
23  TLV_TYPE_FILESTORE_RESPONSE = 1, // Filestore response
24  TLV_TYPE_MESSAGE_TO_USER = 2, // Message to user
25  TLV_TYPE_FAULT_HANDLER_OVERRIDE = 4, // Fault handler override
26  TLV_TYPE_FLOW_LABEL = 5, // Flow label
27  TLV_TYPE_ENTITY_ID = 6 // Entity ID
28 };
29 
31 class TlvData {
32  private:
33  union {
34  EntityId m_eid; // Valid when type=ENTITY_ID
35  U8 m_rawData[256]; // Valid for other types (max 255 bytes + null term)
36  };
37  U8 m_dataLength; // Actual length of data
38 
39  public:
40  TlvData();
41 
42  // Set entity ID (for TLV type 6)
43  void setEntityId(EntityId eid);
44 
45  // Set raw data (for other TLV types)
46  void setData(const U8* data, U8 length);
47 
48  // Get entity ID
49  EntityId getEntityId() const;
50 
51  // Get raw data pointer
52  const U8* getData() const;
53 
54  // Get data length
55  U8 getLength() const;
56 };
57 
59 class Tlv {
60  private:
61  TlvType m_type;
62  TlvData m_data;
63 
64  public:
65  Tlv();
66 
67  // Initialize with entity ID
68  void initialize(EntityId eid);
69 
70  // Initialize with raw data
71  void initialize(TlvType type, const U8* data, U8 length);
72 
73  // Getters
74  TlvType getType() const;
75  const TlvData& getData() const;
76 
77  // Compute encoded size
78  U32 getEncodedSize() const;
79 
80  // Encode to SerialBuffer
82 
83  // Decode from SerialBuffer
85 };
86 
88 class TlvList {
89  private:
90  U8 m_numTlv;
91  Tlv m_tlvs[MaxTlv];
92 
93  public:
94  TlvList();
95 
96  // Add a TLV (returns false if list is full)
97  bool appendTlv(const Tlv& tlv);
98 
99  // Clear all TLVs
100  void clear();
101 
102  // Get number of TLVs
103  U8 getNumTlv() const;
104 
105  // Get TLV at index
106  const Tlv& getTlv(U8 index) const;
107 
108  // Compute total encoded size of all TLVs
109  U32 getEncodedSize() const;
110 
111  // Encode all TLVs to SerialBuffer
113 
114  // Decode all TLVs from SerialBuffer (reads until buffer exhausted)
116 };
117 
118 } // namespace Cfdp
119 } // namespace Ccsds
120 } // namespace Svc
121 
122 #endif // Svc_Ccsds_Cfdp_Tlv_HPP
bool appendTlv(const Tlv &tlv)
Definition: Tlv.cpp:188
const TlvData & getData() const
Definition: Tlv.cpp:73
U32 EntityId
Entity id size.
Fw::SerializeStatus toSerialBuffer(Fw::SerialBufferBase &serialBuffer) const
Definition: Tlv.cpp:219
List of TLVs.
Definition: Tlv.hpp:88
TlvType getType() const
Definition: Tlv.cpp:69
const Tlv & getTlv(U8 index) const
Definition: Tlv.cpp:206
SerializeStatus
forward declaration for string
U32 getEncodedSize() const
Definition: Tlv.cpp:77
Fw::SerializeStatus fromSerialBuffer(Fw::SerialBufferBase &serialBuffer)
Definition: Tlv.cpp:120
U8 getLength() const
Definition: Tlv.cpp:47
U8 getNumTlv() const
Definition: Tlv.cpp:202
Fw::SerializeStatus fromSerialBuffer(Fw::SerialBufferBase &serialBuffer)
Definition: Tlv.cpp:233
void setEntityId(EntityId eid)
Definition: Tlv.cpp:24
Single TLV entry.
Definition: Tlv.hpp:59
const U8 * getData() const
Definition: Tlv.cpp:43
TLV data storage.
Definition: Tlv.hpp:31
void setData(const U8 *data, U8 length)
Definition: Tlv.cpp:31
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
EntityId getEntityId() const
Definition: Tlv.cpp:39
Fw::SerializeStatus toSerialBuffer(Fw::SerialBufferBase &serialBuffer) const
Definition: Tlv.cpp:82
RateGroupDivider component implementation.
U32 getEncodedSize() const
Definition: Tlv.cpp:211
void initialize(EntityId eid)
Definition: Tlv.cpp:59