MeshNet  1.0.0
meshFrame.h
Go to the documentation of this file.
1 
12 #ifndef MESH_FRAME_H
13 #define MESH_FRAME_H
14 
15 #include "meshPacketFlags.h"
16 #include "meshVariableArray.h"
17 
18 struct MeshFrame;
19 
21  MeshFrameHeader() = default;
22 
28  MeshFrameHeader(const uint8_t* data, uint8_t dataSize);
29 
35 
40 
45  uint8_t ID = 0;
46 
50  inline uint16_t GetUniquePacketID() const {
51  return (uint16_t)ID << 8 | Source;
52  }
53 
58 
62  uint8_t CarriageCount = 0;
63 
67  inline bool HasError() const {
69  }
70 
74  void Clear();
75 
81  inline bool IsSamePacket(const MeshFrameHeader& frameHeader) const {
82  return BSSID == frameHeader.BSSID && ID == frameHeader.ID && Source == frameHeader.Source;
83  }
84 
90  inline bool IsSamePacket(const MeshFrame& frame) const;
91 
96  inline uint8_t GetRawLength() const {
97  return 7 + FrameControl.IsCarriageFrame();
98  }
99 
105  inline static uint8_t GetRawLength(bool includeCarriageCount) {
106  return 7 + includeCarriageCount;
107  }
108 
115  bool FromRaw(const uint8_t* data, uint8_t dataSize);
116 
123  bool ToRaw(uint8_t* data, uint8_t& dataSize) const;
124 };
125 
126 struct MeshFrame {
127 
128  MeshFrame();
129 
135  MeshFrame(const uint8_t* data, uint8_t dataSize);
136 
140  MeshFrame(const MeshFrame& mf);
141 
145  MeshFrame(MeshFrame&& mf) noexcept;
146 
150  ~MeshFrame();
151 
155  MeshFrame& operator=(const MeshFrame& mf);
156 
160  MeshFrame& operator=(MeshFrame&& mf) noexcept;
161 
166 
170  inline uint8_t Length() const {
171  return DataSize;
172  }
173 
174  uint8_t operator [](uint8_t i) const {
175  return Data[i];
176  }
177 
178  uint8_t& operator [](uint8_t i) {
179  return Data[i];
180  }
181 
185  inline bool HasError() const {
186  return FrameHeader.HasError();
187  }
188 
193  inline uint8_t GetRawLength() const {
194  return DataSize + FrameHeader.GetRawLength();
195  }
196 
203  bool FromRaw(const uint8_t* data, uint8_t dataSize);
204 
211  bool ToRaw(uint8_t* data, uint8_t& dataSize) const;
212 
218  uint8_t GetDataByteAt(uint8_t index) const;
219 
226  bool SetDataByteAt(uint8_t index, uint8_t value);
227 
234  bool SetData(const uint8_t* data, const uint8_t dataLength);
235 
241  void GetData(uint8_t* data, uint8_t& dataLength) const;
242 
249  bool ResizeData(uint8_t size, bool doNotCopy = false);
250 
254  void ClearData();
255 
259  void Clear();
260 
266  bool copyFrom(const MeshFrame& another);
267 
274  void moveFrom(MeshFrame& another);
275 
279  inline const uint8_t* d_ptr() const {
280  return Data;
281  }
282 
283  //Operators, that allows setting and reading frame header
284  void operator=(const MeshFrameHeader& val) {
285  FrameHeader = val;
286  }
287 
288  operator MeshFrameHeader() const { return FrameHeader; }
289  operator MeshFrameHeader() { return FrameHeader; }
290 
296  inline bool IsSamePacket(const MeshFrameHeader& frameHeader) const{
297  return FrameHeader.BSSID == frameHeader.BSSID && FrameHeader.ID == frameHeader.ID && FrameHeader.Source == frameHeader.Source;
298  }
299 
305  inline bool IsSamePacket(const MeshFrame& frame) const {
306  return IsSamePacket(frame.FrameHeader);
307  }
308 
309 protected:
313  uint8_t DataSize = 0;
314 
318  uint8_t* Data = NULL;
319 };
320 
321 #endif // !MESH_FRAME_H
MeshFrame::operator=
void operator=(const MeshFrameHeader &val)
Definition: meshFrame.h:284
MeshFrameHeader::HasError
bool HasError() const
Checks if frame is not valid.
Definition: meshFrame.h:67
MeshFrame::GetData
void GetData(uint8_t *data, uint8_t &dataLength) const
Gets data.
Definition: meshFrame.cpp:141
MeshFrameHeader::ToRaw
bool ToRaw(uint8_t *data, uint8_t &dataSize) const
Converts frame header to raw data.
Definition: meshFrame.cpp:38
MeshFrameHeader::Source
uint8_t Source
Address of message source node.
Definition: meshFrame.h:57
MeshFrame::Data
uint8_t * Data
Frame data.
Definition: meshFrame.h:318
MeshFrameControl
Structure, that contains bit flags used for Frame Control in MeshPacket. Size of this structure is al...
Definition: meshPacketFlags.h:25
MeshFrameHeader::GetRawLength
static uint8_t GetRawLength(bool includeCarriageCount)
Gets size of raw data length of header only.
Definition: meshFrame.h:105
MeshFrame::operator[]
uint8_t operator[](uint8_t i) const
Definition: meshFrame.h:174
MeshFrameHeader::CarriageCount
uint8_t CarriageCount
Count of remaining frames in carriage.
Definition: meshFrame.h:62
MeshFrame::IsSamePacket
bool IsSamePacket(const MeshFrameHeader &frameHeader) const
Checks if two frames are from same packet.
Definition: meshFrame.h:296
MeshFrameHeader::MeshFrameHeader
MeshFrameHeader()=default
MeshFrame::HasError
bool HasError() const
Checks if frame is not valid.
Definition: meshFrame.h:185
MeshFrame::d_ptr
const uint8_t * d_ptr() const
Pointer to data.
Definition: meshFrame.h:279
MeshFrameHeader::FrameControl
MeshFrameControl FrameControl
Contains flags, that controls frame.
Definition: meshFrame.h:34
MeshFrame::Length
uint8_t Length() const
Length of data.
Definition: meshFrame.h:170
MeshFrame::SetDataByteAt
bool SetDataByteAt(uint8_t index, uint8_t value)
Sets data byte at specified index.
Definition: meshFrame.cpp:156
MeshFrameControl::IsCarriageHeader
bool IsCarriageHeader() const
Checks, if frame is header part of carriage.
Definition: meshPacketFlags.h:88
MeshFrame::operator=
MeshFrame & operator=(const MeshFrame &mf)
Copy assignment operator.
Definition: meshFrame.cpp:83
MeshFrameHeader::IsSamePacket
bool IsSamePacket(const MeshFrameHeader &frameHeader) const
Checks if two frames are from same packet.
Definition: meshFrame.h:81
MeshFrame
Definition: meshFrame.h:126
MeshFrame::GetRawLength
uint8_t GetRawLength() const
Gets size of raw data length.
Definition: meshFrame.h:193
MeshFrame::~MeshFrame
~MeshFrame()
Destructor.
Definition: meshFrame.cpp:79
MeshFrameHeader::Clear
void Clear()
Clears all data in frame header.
Definition: meshFrame.cpp:7
MeshFrame::MeshFrame
MeshFrame()
Definition: meshFrame.cpp:63
MeshFrame::IsSamePacket
bool IsSamePacket(const MeshFrame &frame) const
Checks if two frames are from same packet.
Definition: meshFrame.h:305
MeshFrame::SetData
bool SetData(const uint8_t *data, const uint8_t dataLength)
Sets data data.
Definition: meshFrame.cpp:127
MeshFrame::GetDataByteAt
uint8_t GetDataByteAt(uint8_t index) const
Reads data byte at specified index.
Definition: meshFrame.cpp:148
MeshFrame::ToRaw
bool ToRaw(uint8_t *data, uint8_t &dataSize) const
Converts structure to raw data.
Definition: meshFrame.cpp:101
MeshFrameHeader::ID
uint8_t ID
Unique packet ID.
Definition: meshFrame.h:45
MeshFrameHeader::BSSID
MeshMAC BSSID
Mesh network identifier.
Definition: meshFrame.h:39
MeshFrame::ClearData
void ClearData()
Clears frame data.
Definition: meshFrame.cpp:192
MeshFrame::ResizeData
bool ResizeData(uint8_t size, bool doNotCopy=false)
Resizes data.
Definition: meshFrame.cpp:165
meshPacketFlags.h
This file contains structures, that encodes flags in packet.
MeshMAC
Structure that represents physical MAC address used in MeshNEt protocol. MeshMAC address unlike MAC a...
Definition: meshHelper.h:207
MeshFrame::FromRaw
bool FromRaw(const uint8_t *data, uint8_t dataSize)
Fills frame fields from raw data.
Definition: meshFrame.cpp:93
IS_VALID_MESH_SRC_ADDRESS
#define IS_VALID_MESH_SRC_ADDRESS(address)
Checks if mesh "source" address from packet or frame header is valid. Accepted values from 0 to MAX_M...
Definition: meshConfig.h:88
MeshFrame::moveFrom
void moveFrom(MeshFrame &another)
Copyies data from another frame to current frame and clears data in another frame.
Definition: meshFrame.cpp:214
INVALID_MESH_ADDRESS
#define INVALID_MESH_ADDRESS
Address, that is invalid and cannot be used.
Definition: meshConfig.h:56
MeshFrame::copyFrom
bool copyFrom(const MeshFrame &another)
Copyies data from another frame to current frame.
Definition: meshFrame.cpp:205
meshVariableArray.h
This file contains class which safetly handles allocation and deallocation of memory....
MeshFrameHeader::GetUniquePacketID
uint16_t GetUniquePacketID() const
Gets unique packed identifier which is composed from ID and source address.
Definition: meshFrame.h:50
MeshFrame::FrameHeader
MeshFrameHeader FrameHeader
Frame header, that contains frame describing informations.
Definition: meshFrame.h:165
MeshFrame::DataSize
uint8_t DataSize
Size of frame data.
Definition: meshFrame.h:313
MeshFrameControl::IsCarriageFrame
bool IsCarriageFrame() const
Checks, if frame is part of carriage.
Definition: meshPacketFlags.h:81
MeshFrameHeader::GetRawLength
uint8_t GetRawLength() const
Gets size of raw data length of header only.
Definition: meshFrame.h:96
MeshFrameHeader::FromRaw
bool FromRaw(const uint8_t *data, uint8_t dataSize)
Fills frame header fields only from raw data, frame data are ignored.
Definition: meshFrame.cpp:19
MeshFrame::Clear
void Clear()
Clears all data in frame.
Definition: meshFrame.cpp:200
MeshFrameHeader
Definition: meshFrame.h:20