RadioLib
Universal wireless communication library for Arduino
Loading...
Searching...
No Matches
LoRaWANPackageTS003.h
1#if !defined(_RADIOLIB_LORAWAN_PACKAGE_TS003_H) && !RADIOLIB_EXCLUDE_LORAWAN
2#define _RADIOLIB_LORAWAN_PACKAGE_TS003_H
3
4#include "LoRaWANPacMan.h"
5
6// The major benefit of using this package compared to using the DeviceTimeReq MAC
7// command is that, most of the time, the Application Server is not required to answer the
8// AppTimeReq command from the end-device. A downlink is only required when the end
9// device clock is outside the accuracy requirement that is targeted by the application. In
10// contrast, every DeviceTimeReq MAC command sent by the end-device requires an answer
11// from the Network Server.
12
13#define RADIOLIB_LORAWAN_TS003_PACKAGE_VERSION (0x00)
14#define RADIOLIB_LORAWAN_TS003_APP_TIME (0x01)
15#define RADIOLIB_LORAWAN_TS003_APP_TIME_PERIODICITY (0x02)
16#define RADIOLIB_LORAWAN_TS003_FORCE_DEVICE_RESYNC (0x03)
17
22class LoRaWANPackageTS003 : public LoRaWANPackage {
23 public:
24
25 // copy constructor is removed to prevent users from creating copies of this class
26 LoRaWANPackageTS003(const LoRaWANPackageTS003& obj) = delete;
27
37 size_t processData(const uint8_t* dataDown, size_t lenDown, uint8_t* dataOut, size_t* lenOut, LoRaWANEvent_t* event) override;
38
44 int16_t requestAppTime(bool force = false);
45
51 void setSecondsCb(SetSecondsCb_t setSecondsCb);
52
60 bool handleTask(RadioLibTime_t* tNext, bool* uplinkDue) override;
61
68 size_t buildUplink(uint8_t* dataOut) override;
69
70#if !RADIOLIB_GODMODE
71 protected:
72#endif
73
74 // build an AppTimeReq into the provided buffer; returns the number of bytes written
75 size_t buildAppTimeReq(uint8_t* dataOut);
76
77 SetSecondsCb_t setSeconds; // callback to configure current GPS time in seconds since epoch
78 uint8_t tokenReq; // validation of AppTimeReq response
79 uint8_t transmissions; // maximum number of AppTimeReq (re)transmissions
80 uint32_t periodicity; // requested interval between AppTimeReq transmissions (s)
81 RadioLibTime_t nextAppReqTime; // next scheduled AppTimeReq transmission
82 bool forceReq; // set the force bit on the next AppTimeReq
83
84#if !RADIOLIB_GODMODE
85 private:
86#endif
87 // private constructor, to not allow the user to create additional instances of this package
94 LoRaWANPackageTS003(LoRaWANPackageManager* pacMan, RadioLibHal* hal, LoRaWANNode* node, GetSecondsCb_t secondsCb);
95
96 // allow LoRaWANPackageManager to access the private constructor
97 friend LoRaWANPackageManager;
98};
99
100#endif
LoRaWAN-compatible node (class A device).
Definition LoRaWAN.h:557
void(* SetSecondsCb_t)(RadioLibTime_t)
Set the setSeconds callback function.
Definition LoRaWANPackageTS003.h:50
bool handleTask(RadioLibTime_t *tNext, bool *uplinkDue) override
Report when the next AppTimeReq is due and whether one is due now. Does not build the payload (see bu...
Definition LoRaWANPackageTS003.cpp:15
int16_t requestAppTime(bool force=false)
Schedule an application time request to be sent at the next opportunity.
Definition LoRaWANPackageTS003.cpp:170
size_t buildUplink(uint8_t *dataOut) override
Build the due AppTimeReq with the current time and advance the schedule. Called at the moment of tran...
Definition LoRaWANPackageTS003.cpp:42
size_t processData(const uint8_t *dataDown, size_t lenDown, uint8_t *dataOut, size_t *lenOut, LoRaWANEvent_t *event) override
Process a single TS003 command, writing any answer into the provided buffer.
Definition LoRaWANPackageTS003.cpp:69
Hardware abstraction library base interface.
Definition Hal.h:18
unsigned long RadioLibTime_t
Type used for durations in RadioLib.
Definition TypeDef.h:783
Structure to save extra information about uplink/downlink event.
Definition LoRaWAN.h:514