DSMEMessage.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 HAW Hamburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
22 #ifndef OPENDSME_DSMEMESSAGE_H
23 #define OPENDSME_DSMEMESSAGE_H
24 
25 #include <stdint.h>
26 #include <string.h>
27 
28 #include "dsmeLayer/messages/IEEE802154eMACHeader.h"
29 #include "interfaces/IDSMEMessage.h"
30 #include "iolist.h"
31 #include "mac_services/dataStructures/DSMEMessageElement.h"
32 #include "net/gnrc/pktbuf.h"
33 #include "opendsme/dsme_settings.h"
34 #include "opendsme/dsme_platform.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 namespace dsme {
41 
45 class DSMEPlatform;
46 
50 class DSMEMessage : public IDSMEMessage {
51 public:
52  /************* IDSMEMessage implementation *************/
53 
57  void prependFrom(DSMEMessageElement *msg) override;
58 
62  void decapsulateTo(DSMEMessageElement *msg) override;
63 
67  void copyTo(DSMEMessageElement *msg);
68 
72  bool hasPayload() override
73  {
74  return this->pkt != NULL && this->pkt->size > 0;
75  }
76 
81  {
82  return startOfFrameDelimiterSymbolCounter;
83  }
84 
88  void setStartOfFrameDelimiterSymbolCounter(uint32_t symbolCounter) override
89  {
90  startOfFrameDelimiterSymbolCounter = symbolCounter;
91  }
92 
96  uint16_t getTotalSymbols() override
97  {
98  DSME_ASSERT(pkt);
99  /* Hardcoded to O-QPSK */
100  uint16_t bytes = macHdr.getSerializationLength()
101  + pkt->size
102  + 2 /* FCS */
103  + 4 /* Preamble */
104  + 1 /* SFD */
105  + 1; /* PHY Header */
106 
107  return bytes * 2; /* 4 bit per symbol */
108  }
109 
114  uint8_t getMPDUSymbols() override;
115 
119  IEEE802154eMACHeader& getHeader() override
120  {
121  return macHdr;
122  }
123 
127  uint8_t getLQI() override
128  {
129  return messageLQI;
130  }
131 
135  bool getReceivedViaMCPS() override
136  {
137  return receivedViaMCPS;
138  }
139 
143  void setReceivedViaMCPS(bool receivedViaMCPS) override
144  {
145  this->receivedViaMCPS = receivedViaMCPS;
146  }
147 
151  bool getCurrentlySending() override
152  {
153  return currentlySending;
154  }
155 
159  void setCurrentlySending(bool currentlySending) override
160  {
161  this->currentlySending = currentlySending;
162  }
163 
167  void increaseRetryCounter() override
168  {
169  this->retryCounter++;
170  }
171 
175  uint8_t getRetryCounter() override
176  {
177  return this->retryCounter;
178  }
179 
184  {
185  DSME_ASSERT(pkt);
186  return pkt->size;
187  }
188 
192  int8_t getRSSI() override
193  {
194  return this->messageRSSI;
195  }
196 
200  int loadBuffer(size_t len);
201 
205  int loadBuffer(iolist_t *pkt);
206 
210  uint8_t *getPayload()
211  {
212  DSME_ASSERT(pkt);
213  return (uint8_t *)pkt->data;
214  }
215 
219  int dropHdr(size_t len);
220 
225 
230 
235 
239  void clearMessage();
240 
244  bool firstTry;
245 
249  bool free;
250 private:
254  DSMEMessage() :
255  messageRSSI(0),
256  messageLQI(0),
257  receivedViaMCPS(false),
258  currentlySending(false),
259  retryCounter(0)
260  {}
261 
265  ~DSMEMessage()
266  {}
267 
271  void prepare()
272  {
273  currentlySending = false;
274  firstTry = true;
275  receivedViaMCPS = false;
276  retryCounter = 0;
277 
278  macHdr.reset();
279  }
280 
284  IEEE802154eMACHeader macHdr;
285 
289  uint8_t messageRSSI;
290 
294  uint8_t messageLQI;
295 
299  gnrc_pktsnip_t *pkt;
300 
304  uint32_t startOfFrameDelimiterSymbolCounter;
305 
309  bool receivedViaMCPS;
310 
314  bool currentlySending;
315 
319  uint8_t retryCounter;
320 
324  gnrc_netif_t *netif;
325 
326 /* declare related classes as friends */
327 friend class DSMEPlatform;
328 friend class DSMEMessageElement;
329 friend class DSMEPlatformBase;
330 friend class DSMEMessageBuffer;
331 };
332 
333 }
334 
335 #ifdef __cplusplus
336 }
337 #endif
338 
339 #endif /* OPENDSME_DSMEMESSAGE_H */
DSME Message interface implementation for GNRC.
Definition: DSMEMessage.h:50
bool hasPayload() override
check whether the message has payload
Definition: DSMEMessage.h:72
IEEE802154eMACHeader & getHeader() override
get IEEE 802.15.4 header
Definition: DSMEMessage.h:119
void increaseRetryCounter() override
increase retry counter for current message
Definition: DSMEMessage.h:167
uint8_t getRetryCounter() override
get retry counter
Definition: DSMEMessage.h:175
void setCurrentlySending(bool currentlySending) override
indicate that the message is being sent
Definition: DSMEMessage.h:159
bool free
whether the message is free
Definition: DSMEMessage.h:249
uint8_t getLQI() override
get LQI of the message
Definition: DSMEMessage.h:127
void clearMessage()
clear the message
int dropHdr(size_t len)
drop a number of bytes from the header
void copyTo(DSMEMessageElement *msg)
copy payload to DSME Message Element
int8_t getRSSI() override
get RSSI of frame
Definition: DSMEMessage.h:192
void setReceivedViaMCPS(bool receivedViaMCPS) override
indicated that message was received via MCPS
Definition: DSMEMessage.h:143
int loadBuffer(size_t len)
preallocate buffer with a given length
bool firstTry
whether the message is being sent on the first try
Definition: DSMEMessage.h:244
iolist_t * getIolPayload()
get the IOLIST representation of the message
bool getReceivedViaMCPS() override
check whether the message was received via MCPS
Definition: DSMEMessage.h:135
void setStartOfFrameDelimiterSymbolCounter(uint32_t symbolCounter) override
set the symbol counter at the end of the SFD
Definition: DSMEMessage.h:88
int loadBuffer(iolist_t *pkt)
load a GNRC packet into the internal openDSME message representation
void decapsulateTo(DSMEMessageElement *msg) override
decapsulate header to a message
uint8_t getPayloadLength()
get payload length
Definition: DSMEMessage.h:183
uint16_t getTotalSymbols() override
get the total number of symbols in current frame
Definition: DSMEMessage.h:96
uint8_t getMPDUSymbols() override
get number of MPDU Symbols
void dispatchMessage()
dispatch the message to upper layers
uint32_t getStartOfFrameDelimiterSymbolCounter() override
get the symbol counter at the end of the SFD
Definition: DSMEMessage.h:80
void prependFrom(DSMEMessageElement *msg) override
prepend a header to current message
bool getCurrentlySending() override
whether the message is being sent
Definition: DSMEMessage.h:151
void releaseMessage()
release the message
uint8_t * getPayload()
get buffer associated to the current payload
Definition: DSMEMessage.h:210
#define DSME_ASSERT(x)
openDSME DSME assert macro implementation
Definition: dsme_platform.h:30
iolist scatter / gather IO
Interface definition for the global network buffer.
Representation of a network interface.
Definition: netif.h:135
Type to represent parts (either headers or payload) of a packet, called snips.
Definition: pkt.h:108
void * data
pointer to the data of the snip
Definition: pkt.h:111
size_t size
the length of the snip in byte
Definition: pkt.h:112
iolist structure definition
Definition: iolist.h:39