paqueteCnC
Loading...
Searching...
No Matches
packet.h
Go to the documentation of this file.
1
20#ifndef Packet_H
21#define Packet_H
22
23#include <array>
24#include <vector>
25
26class Packet {
27public:
28
29 // *** constants ***
30 inline static constexpr uint16_t APP_DATA_SIZE = 256; // inline for appdata array size
31
32 // main header + data header + data + error control
33 inline static constexpr uint16_t PACKET_SIZE = 6 + 3 + 256 + 2;
34
35 enum class SequenceFlags : uint8_t {
36 INITIAL = 0b01,
37 INBETWEEN = 0b00,
38 FINAL = 0b10,
39 STAND_ALONE = 0b11
40 };
41
42 // Because bool can be 32 bits but i need it to always be 1 byte.
43 enum class Bool8Enum : uint8_t {
44 TRUE = 1,
45 FALSE = 0
46 };
47
48 Packet();
49 Packet(
50 const uint8_t versionNumber,
51 const Bool8Enum dataFieldHeader,
52 const uint8_t appIdSource,
53 const uint8_t appIdDestination,
54 const SequenceFlags sequenceControlFlags,
55 const uint16_t sequenceControlCount,
56 const uint16_t length,
57 const Bool8Enum ccsds,
58 const uint8_t pusVersion,
59 const Bool8Enum ack,
60 const uint8_t serviceType,
61 const uint8_t serviceSubtype,
62 const std::array<std::byte, APP_DATA_SIZE>& appData,
63 const std::array<std::byte, 2> packetErrorControl
64 );
65 Packet(const Packet& other);
66
67 uint8_t getVersionNumber() const;
68 void setVersionNumber(const uint8_t versionNumber);
69
70 Bool8Enum getDataFieldHeader() const;
71 void setDataFieldHeader(const Bool8Enum newValue);
72
73 uint8_t getAppIdSource() const;
74 void setAppIdSource(const uint8_t newAddress);
75
76 uint8_t getAppIdDestination() const;
77 void setAppIdDestination(const uint8_t newAddress);
78
79 SequenceFlags getSequenceControlFlags() const;
80 void setSequenceControlFlags(const SequenceFlags newFlags);
81
82 uint16_t getSequenceControlCount() const;
83 void setSequenceControlCount(const uint16_t newCount);
84
85 uint16_t getLength() const;
86 void setLength(const uint16_t amountOfBytes);
87
88 Bool8Enum getCCSDS() const;
89 void setCCSDS(const Bool8Enum ccsds);
90
91 uint8_t getPUSVersion() const;
92 void setPUSVersion(const uint8_t pusVersion);
93
94 Bool8Enum getAck() const;
95 void setAck(const Bool8Enum newValue);
96
97 uint8_t getServiceType() const;
98 void setServiceType(const uint8_t typeId);
99
100 uint8_t getServiceSubtype() const;
101 void setServiceSubtype(const uint8_t subtypeId);
102
103 std::array<std::byte, 2> getPacketErrorControl() const;
104 void setPacketErrorControl(const std::array<std::byte, 2> crc);
105
106 // It sets the object pointed to by ptrAppData to the value of appData_ .
107 // The receptor array must be of size APP_DATA_SIZE
108 std::array<std::byte, APP_DATA_SIZE> getAppData();
109 void setAppData(const std::array<std::byte, APP_DATA_SIZE>& ptrNewAppData);
110
111 // To avoid the client making copies of app data to substitute old app data.
112 // It modifies the index for appending.
113 void pushData(const std::byte bytesToPush);
114 void pushData(const uint16_t bytesToPush);
115 void pushData(const std::array<std::byte, 2> bytesToPush);
116 void pushData(const std::vector<std::byte>& bytesToPush);
117
118private:
119 // main header
120 uint8_t versionNumber_;
121 Bool8Enum dataFieldHeader_;
122 uint8_t appIdSource_;
123 uint8_t appIdDestination_;
124 SequenceFlags sequenceControlFlags_;
125 uint16_t sequenceControlCount_;
126 uint16_t length_; // amount of octets within app. data
127
128 // data field header (optional)
129 Bool8Enum ccsds_;
130 uint8_t pusVersion_;
131 Bool8Enum ack_;
132 uint8_t serviceType_;
133 uint8_t serviceSubtype_;
134
135 // data
136 std::array<std::byte, APP_DATA_SIZE> appData_;
137 uint8_t appDataIndex_; // for app. data appending
138
139 // special field at the end of the packet
140 std::array<std::byte, 2> packetErrorControl_;
141};
142
143#endif
Definition: packet.h:26