Loading...
Searching...
No Matches
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
23
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"
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39namespace dsme {
40
44class DSMEPlatform;
45
49class DSMEMessage : public IDSMEMessage {
50public:
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
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
239
244
248 bool free;
249private:
253 DSMEMessage() :
254 messageRSSI(0),
255 messageLQI(0),
256 receivedViaMCPS(false),
257 currentlySending(false),
258 retryCounter(0)
259 {}
260
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 */
326friend class DSMEPlatform;
327friend class DSMEMessageElement;
328friend class DSMEPlatformBase;
329friend 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
void increaseRetryCounter() override
increase retry counter for current message
uint8_t getRetryCounter() override
get retry counter
void setCurrentlySending(bool currentlySending) override
indicate that the message is being sent
bool free
whether the message is free
uint8_t getLQI() override
get LQI of the message
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
void setReceivedViaMCPS(bool receivedViaMCPS) override
indicated that message was received via MCPS
int loadBuffer(size_t len)
preallocate buffer with a given length
bool firstTry
whether the message is being sent on the first try
bool getReceivedViaMCPS() override
check whether the message was received via MCPS
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
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
IEEE802154eMACHeader & getHeader() override
get IEEE 802.15.4 header
void dispatchMessage()
dispatch the message to upper layers
iolist_t * getIolPayload()
get the IOLIST representation of the message
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
void releaseMessage()
release the message
uint8_t * getPayload()
get buffer associated to the current payload
DSMEPlatform interface implementation for GNRC.
#define DSME_ASSERT(x)
openDSME DSME assert macro implementation
struct gnrc_pktsnip gnrc_pktsnip_t
Type to represent parts (either headers or payload) of a packet, called snips.
struct iolist iolist_t
iolist forward declaration
Definition iolist.h:33
iolist scatter / gather IO
Interface definition for the global network buffer.