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 
9 #pragma once
10 
24 #include <stdint.h>
25 #include <string.h>
26 
27 #include "dsmeLayer/messages/IEEE802154eMACHeader.h"
28 #include "interfaces/IDSMEMessage.h"
29 #include "iolist.h"
30 #include "mac_services/dataStructures/DSMEMessageElement.h"
31 #include "net/gnrc/pktbuf.h"
32 #include "opendsme/dsme_settings.h"
33 #include "opendsme/dsme_platform.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 namespace dsme {
40 
44 class DSMEPlatform;
45 
49 class DSMEMessage : public IDSMEMessage {
50 public:
51  /************* IDSMEMessage implementation *************/
52 
56  void prependFrom(DSMEMessageElement *msg) override;
57 
61  void decapsulateTo(DSMEMessageElement *msg) override;
62 
66  void copyTo(DSMEMessageElement *msg);
67 
71  bool hasPayload() override
72  {
73  return this->pkt != NULL && this->pkt->size > 0;
74  }
75 
80  {
81  return startOfFrameDelimiterSymbolCounter;
82  }
83 
87  void setStartOfFrameDelimiterSymbolCounter(uint32_t symbolCounter) override
88  {
89  startOfFrameDelimiterSymbolCounter = symbolCounter;
90  }
91 
95  uint16_t getTotalSymbols() override
96  {
97  DSME_ASSERT(pkt);
98  /* Hardcoded to O-QPSK */
99  uint16_t bytes = macHdr.getSerializationLength()
100  + pkt->size
101  + 2 /* FCS */
102  + 4 /* Preamble */
103  + 1 /* SFD */
104  + 1; /* PHY Header */
105 
106  return bytes * 2; /* 4 bit per symbol */
107  }
108 
113  uint8_t getMPDUSymbols() override;
114 
118  IEEE802154eMACHeader& getHeader() override
119  {
120  return macHdr;
121  }
122 
126  uint8_t getLQI() override
127  {
128  return messageLQI;
129  }
130 
134  bool getReceivedViaMCPS() override
135  {
136  return receivedViaMCPS;
137  }
138 
142  void setReceivedViaMCPS(bool receivedViaMCPS) override
143  {
144  this->receivedViaMCPS = receivedViaMCPS;
145  }
146 
150  bool getCurrentlySending() override
151  {
152  return currentlySending;
153  }
154 
158  void setCurrentlySending(bool currentlySending) override
159  {
160  this->currentlySending = currentlySending;
161  }
162 
166  void increaseRetryCounter() override
167  {
168  this->retryCounter++;
169  }
170 
174  uint8_t getRetryCounter() override
175  {
176  return this->retryCounter;
177  }
178 
183  {
184  DSME_ASSERT(pkt);
185  return pkt->size;
186  }
187 
191  int8_t getRSSI() override
192  {
193  return this->messageRSSI;
194  }
195 
199  int loadBuffer(size_t len);
200 
204  int loadBuffer(iolist_t *pkt);
205 
209  uint8_t *getPayload()
210  {
211  DSME_ASSERT(pkt);
212  return (uint8_t *)pkt->data;
213  }
214 
218  int dropHdr(size_t len);
219 
224 
229 
234 
238  void clearMessage();
239 
243  bool firstTry;
244 
248  bool free;
249 private:
253  DSMEMessage() :
254  messageRSSI(0),
255  messageLQI(0),
256  receivedViaMCPS(false),
257  currentlySending(false),
258  retryCounter(0)
259  {}
260 
264  ~DSMEMessage()
265  {}
266 
270  void prepare()
271  {
272  currentlySending = false;
273  firstTry = true;
274  receivedViaMCPS = false;
275  retryCounter = 0;
276 
277  macHdr.reset();
278  }
279 
283  IEEE802154eMACHeader macHdr;
284 
288  uint8_t messageRSSI;
289 
293  uint8_t messageLQI;
294 
298  gnrc_pktsnip_t *pkt;
299 
303  uint32_t startOfFrameDelimiterSymbolCounter;
304 
308  bool receivedViaMCPS;
309 
313  bool currentlySending;
314 
318  uint8_t retryCounter;
319 
323  gnrc_netif_t *netif;
324 
325 /* declare related classes as friends */
326 friend class DSMEPlatform;
327 friend class DSMEMessageElement;
328 friend class DSMEPlatformBase;
329 friend class DSMEMessageBuffer;
330 };
331 
332 }
333 
334 #ifdef __cplusplus
335 }
336 #endif
337 
DSME Message interface implementation for GNRC.
Definition: DSMEMessage.h:49
bool hasPayload() override
check whether the message has payload
Definition: DSMEMessage.h:71
IEEE802154eMACHeader & getHeader() override
get IEEE 802.15.4 header
Definition: DSMEMessage.h:118
void increaseRetryCounter() override
increase retry counter for current message
Definition: DSMEMessage.h:166
uint8_t getRetryCounter() override
get retry counter
Definition: DSMEMessage.h:174
void setCurrentlySending(bool currentlySending) override
indicate that the message is being sent
Definition: DSMEMessage.h:158
bool free
whether the message is free
Definition: DSMEMessage.h:248
uint8_t getLQI() override
get LQI of the message
Definition: DSMEMessage.h:126
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:191
void setReceivedViaMCPS(bool receivedViaMCPS) override
indicated that message was received via MCPS
Definition: DSMEMessage.h:142
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:243
iolist_t * getIolPayload()
get the IOLIST representation of the message
bool getReceivedViaMCPS() override
check whether the message was received via MCPS
Definition: DSMEMessage.h:134
void setStartOfFrameDelimiterSymbolCounter(uint32_t symbolCounter) override
set the symbol counter at the end of the SFD
Definition: DSMEMessage.h:87
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:182
uint16_t getTotalSymbols() override
get the total number of symbols in current frame
Definition: DSMEMessage.h:95
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:79
void prependFrom(DSMEMessageElement *msg) override
prepend a header to current message
bool getCurrentlySending() override
whether the message is being sent
Definition: DSMEMessage.h:150
void releaseMessage()
release the message
uint8_t * getPayload()
get buffer associated to the current payload
Definition: DSMEMessage.h:209
#define DSME_ASSERT(x)
openDSME DSME assert macro implementation
Definition: dsme_platform.h:29
iolist scatter / gather IO
Interface definition for the global network buffer.
Representation of a network interface.
Definition: netif.h:132
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:38