RadioLib
Universal wireless communication library for Arduino
Loading...
Searching...
No Matches
LoRaWANPacMan.h
1#if !defined(_RADIOLIB_LORAWAN_PACMAN_H) && !RADIOLIB_EXCLUDE_LORAWAN
2#define _RADIOLIB_LORAWAN_PACMAN_H
3
4#include "LoRaWAN.h"
5
6// Number of known TSxxx packages
7#define RADIOLIB_LORAWAN_NUM_PACKAGES (8)
8
9// Package ID numbering as per TS008 (TS011 ID is made up)
10#define RADIOLIB_LORAWAN_PACKAGE_TS003 (1)
11#define RADIOLIB_LORAWAN_PACKAGE_TS004 (3)
12#define RADIOLIB_LORAWAN_PACKAGE_TS005 (2)
13#define RADIOLIB_LORAWAN_PACKAGE_TS006 (4)
14#define RADIOLIB_LORAWAN_PACKAGE_TS007 (0)
15#define RADIOLIB_LORAWAN_PACKAGE_TS009 (5)
16#define RADIOLIB_LORAWAN_PACKAGE_TS011 (6)
17
18// Package FPort (specified or recommended)
19#define RADIOLIB_LORAWAN_FPORT_TS003 (202)
20#define RADIOLIB_LORAWAN_FPORT_TS004 (201)
21#define RADIOLIB_LORAWAN_FPORT_TS005 (200)
22#define RADIOLIB_LORAWAN_FPORT_TS006 (203)
23#define RADIOLIB_LORAWAN_FPORT_TS007 (225)
24#define RADIOLIB_LORAWAN_FPORT_TS009 (224)
25#define RADIOLIB_LORAWAN_FPORT_TS011 (226)
26
27
28// Forward-declare the manager so it can be friended by LoRaWANPackage
30
35enum LoRaWANTaskType_t {
36 RADIOLIB_LORAWAN_TASK_NONE = 0,
37 RADIOLIB_LORAWAN_TASK_ACTION,
38 RADIOLIB_LORAWAN_TASK_UPLINK
39};
40
46 LoRaWANTaskType_t type; // NONE / ACTION / UPLINK
47 RadioLibTime_t time; // Time of the task (0 = immediate / no deadline)
48};
49
55 public:
56
57 typedef RadioLibTime_t (*GetSecondsCb_t)();
58
59 // copy constructor is removed to prevent users from creating copies of this class
60 LoRaWANPackage(const LoRaWANPackage& obj) = delete;
61
69 virtual size_t processData(const uint8_t* data, size_t len, LoRaWANEvent_t* event);
70
75 virtual LoRaWANTaskInfo hasTask();
76
80 virtual void doAction();
81
87 void getUplinkData(uint8_t* dataOut, size_t* lenOut);
88
94 if(this->getSeconds_cb != NULL) {
95 return(this->getSeconds_cb());
96 }
97 return(0);
98 }
99
100#if !RADIOLIB_GODMODE
101 protected:
102#endif
103
110 LoRaWANPackage(uint8_t ts, LoRaWANPackageManager* pacMan, LoRaWANNode* node, GetSecondsCb_t secondsCb);
111
112 uint8_t packageIdentifier;
113 uint8_t packageVersion;
114 uint8_t dataUp[255];
115 size_t lenUp = 0;
116
117 LoRaWANPackageManager* pacMan;
118 LoRaWANNode* lorawanNode;
119 GetSecondsCb_t getSeconds_cb;
120
121 // allow LoRaWANPackageManager to access the protected members
123};
124
130 public:
131
132 typedef RadioLibTime_t (*GetSecondsCb_t)();
133 typedef void (*SetSecondsCb_t)(RadioLibTime_t seconds);
134 typedef void (*DelaySecondsCb_t)(RadioLibTime_t seconds);
135 typedef void (*UplinkIntervalCb_t)(RadioLibTime_t intervalSeconds);
136 typedef void (*RebootCb_t)();
137
143 LoRaWANPackageManager(LoRaWANNode* node, GetSecondsCb_t secondsCb);
144
145 // Package enable methods
152 int16_t enableTS003(uint8_t fPort, SetSecondsCb_t setSecondsFunc);
153
154 // Package enablement methods
163 int16_t enableTS009(PhysicalLayer* radio, DelaySecondsCb_t delayCb, UplinkIntervalCb_t intervalCb, RebootCb_t rebootCb);
164
165 // TS003
170 void requestAppTime();
171
172 // TS009
177 bool getConfirmed();
178
186 int16_t processDownlink(const uint8_t* data, size_t len, LoRaWANEvent_t* eventDown);
187
193
201 bool getUplinkData(uint8_t* dataOut, size_t* lenOut, uint8_t* fPort);
202
207 bool doAction();
208
217 size_t processPackageManagerData(uint8_t* dataDown, size_t lenDown, uint8_t* ansOut, size_t* ansLen);
218
219 bool isEnabledFPort(uint8_t fPort) {
220 for(uint8_t i = 0; i < RADIOLIB_LORAWAN_NUM_PACKAGES; i++) {
221 if(this->enabledPackages[i] && this->packagePorts[i] == fPort) {
222 return(true);
223 }
224 }
225 return(false);
226 }
227
228#if !RADIOLIB_GODMODE
229 protected:
230#endif
231
232 LoRaWANNode* lorawanNode;
233 LoRaWANPackage* packages[RADIOLIB_LORAWAN_NUM_PACKAGES];
234 uint8_t packagePorts[RADIOLIB_LORAWAN_NUM_PACKAGES];
235 bool enabledPackages[RADIOLIB_LORAWAN_NUM_PACKAGES];
236
237 // Time handler functions
238 GetSecondsCb_t getSecondsCb;
239
240};
241
242#endif
LoRaWAN-compatible node (class A device).
Definition LoRaWAN.h:572
Common interface for all application packages.
Definition LoRaWANPacMan.h:54
virtual void doAction()
Perform an ACTION task (if any). Default no-op.
Definition LoRaWANPacMan.cpp:46
void getUplinkData(uint8_t *dataOut, size_t *lenOut)
Get uplink data for UPLINK tasks. Returns internal buffer.
Definition LoRaWANPacMan.cpp:23
virtual size_t processData(const uint8_t *data, size_t len, LoRaWANEvent_t *event)
Process a sequence of package commands and return how many bytes were consumed.
Definition LoRaWANPacMan.cpp:15
virtual LoRaWANTaskInfo hasTask()
Query the next scheduled task for this package.
Definition LoRaWANPacMan.cpp:33
RadioLibTime_t getSeconds()
Get current time via the stored callback.
Definition LoRaWANPacMan.h:93
Interface to manage multiple LoRaWAN application packages.
Definition LoRaWANPacMan.h:129
size_t processPackageManagerData(uint8_t *dataDown, size_t lenDown, uint8_t *ansOut, size_t *ansLen)
Process TS007 package management commands at the manager level.
bool getUplinkData(uint8_t *dataOut, size_t *lenOut, uint8_t *fPort)
Fetch uplink data from the first package reporting an UPLINK task.
Definition LoRaWANPacMan.cpp:211
bool doAction()
Execute the first applicable ACTION task (calls package->doAction()).
Definition LoRaWANPacMan.cpp:239
int16_t enableTS003(uint8_t fPort, SetSecondsCb_t setSecondsFunc)
Enable TS003 Application Time Synchronization package.
Definition LoRaWANPacMan.cpp:64
int16_t enableTS009(PhysicalLayer *radio, DelaySecondsCb_t delayCb, UplinkIntervalCb_t intervalCb, RebootCb_t rebootCb)
Enable TS009 Certification Protocol package.
Definition LoRaWANPacMan.cpp:92
void requestAppTime()
Send an application time request.
Definition LoRaWANPacMan.cpp:124
LoRaWANTaskInfo hasTask()
Query the next scheduled task across all packages and return the first.
Definition LoRaWANPacMan.cpp:179
int16_t processDownlink(const uint8_t *data, size_t len, LoRaWANEvent_t *eventDown)
Process a multi-package downlink payload (TS007 section 3.1).
Definition LoRaWANPacMan.cpp:141
bool getConfirmed()
Check whether subsequent uplinks should be confirmed.
Definition LoRaWANPacMan.cpp:133
Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN....
Definition PhysicalLayer.h:257
unsigned long RadioLibTime_t
Type used for durations in RadioLib.
Definition TypeDef.h:679
Structure to save extra information about uplink/downlink event.
Definition LoRaWAN.h:529
Structure displaying pending LoRaWAN task information.
Definition LoRaWANPacMan.h:45