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
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"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40namespace dsme {
41
45class DSMEPlatform;
46
50class DSMEMessage : public IDSMEMessage {
51public:
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
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
240
245
249 bool free;
250private:
254 DSMEMessage() :
255 messageRSSI(0),
256 messageLQI(0),
257 receivedViaMCPS(false),
258 currentlySending(false),
259 retryCounter(0)
260 {}
261
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 */
327friend class DSMEPlatform;
328friend class DSMEMessageElement;
329friend class DSMEPlatformBase;
330friend 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
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: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
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
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:80
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
#define DSME_ASSERT(x)
openDSME DSME assert macro implementation
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