Skip to content

Commit 79b7a49

Browse files
committed
Add DDF functions to sync time
1 parent 88480c7 commit 79b7a49

File tree

9 files changed

+550
-248
lines changed

9 files changed

+550
-248
lines changed

de_web_plugin.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4378,7 +4378,11 @@ void DeRestPluginPrivate::checkSensorNodeReachable(Sensor *sensor, const deCONZ:
43784378

43794379
updated = true;
43804380
}
4381-
if (!DEV_TestStrict())
4381+
4382+
auto *device = DEV_GetDevice(m_devices, sensor->address().ext());
4383+
const bool devManaged = device && device->managed();
4384+
4385+
if (!DEV_TestStrict() && !devManaged)
43824386
{
43834387
if (sensor->type() == QLatin1String("ZHATime") && !sensor->mustRead(READ_TIME))
43844388
{
@@ -11184,7 +11188,10 @@ bool DeRestPluginPrivate::processZclAttributes(Sensor *sensorNode)
1118411188
}
1118511189
}
1118611190

11187-
if (!DEV_TestStrict())
11191+
auto *device = DEV_GetDevice(m_devices, sensorNode->address().ext());
11192+
const bool devManaged = device && device->managed();
11193+
11194+
if (!DEV_TestStrict() && !devManaged)
1118811195
{
1118911196
if (sensorNode->mustRead(READ_TIME) && tNow > sensorNode->nextReadTime(READ_TIME))
1119011197
{
@@ -16894,7 +16901,7 @@ void DeRestPlugin::idleTimerFired()
1689416901
}
1689516902
}
1689616903

16897-
if (!DEV_TestStrict())
16904+
if (!DEV_TestStrict() && !devManaged)
1689816905
{
1689916906
if (*ci == TIME_CLUSTER_ID)
1690016907
{

device.cpp

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*
99
*/
1010

11-
#include <QBasicTimer>
1211
#include <QElapsedTimer>
1312
#include <QTimer>
1413
#include <QTimerEvent>
@@ -23,17 +22,6 @@
2322
#include "event.h"
2423
#include "event_emitter.h"
2524
#include "utils/utils.h"
26-
#include "zcl/zcl.h"
27-
#include "zdp/zdp.h"
28-
29-
#define STATE_LEVEL_BINDING StateLevel1
30-
#define STATE_LEVEL_POLL StateLevel2
31-
32-
#define MGMT_BIND_SUPPORT_UNKNOWN -1
33-
#define MGMT_BIND_SUPPORTED 1
34-
#define MGMT_BIND_NOT_SUPPORTED 0
35-
36-
typedef void (*DeviceStateHandler)(Device *, const Event &);
3725

3826
/*! Device state machine description can be found in the wiki:
3927
@@ -60,104 +48,13 @@ void DEV_PollNextStateHandler(Device *device, const Event &event);
6048
void DEV_PollBusyStateHandler(Device *device, const Event &event);
6149
void DEV_DeadStateHandler(Device *device, const Event &event);
6250

63-
// enable domain specific string literals
64-
using namespace deCONZ::literals;
65-
66-
constexpr int RxOnWhenIdleResponseTime = 2000; // Expect shorter response delay for rxOnWhenIdle devices
67-
constexpr int RxOffWhenIdleResponseTime = 8000; // 7680 ms + some space for timeout
68-
constexpr int MaxConfirmTimeout = 20000; // If for some reason no APS-DATA.confirm is received (should almost
69-
constexpr int BindingAutoCheckInterval = 1000 * 60 * 60;
70-
constexpr int MaxPollItemRetries = 3;
71-
constexpr int MaxSubResources = 8;
72-
7351
static int devManaged = -1;
7452

75-
struct DEV_PollItem
76-
{
77-
explicit DEV_PollItem(const Resource *r, const ResourceItem *i, const QVariant &p) :
78-
resource(r), item(i), readParameters(p) {}
79-
size_t retry = 0;
80-
const Resource *resource = nullptr;
81-
const ResourceItem *item = nullptr;
82-
QVariant readParameters;
83-
};
84-
8553
// special value for ReportTracker::lastConfigureCheck during zcl configure reporting step
8654
constexpr int64_t MarkZclConfigureBusy = 21;
8755

88-
struct ReportTracker
89-
{
90-
deCONZ::SteadyTimeRef lastReport;
91-
deCONZ::SteadyTimeRef lastConfigureCheck;
92-
uint16_t clusterId = 0;
93-
uint16_t attributeId = 0;
94-
uint8_t endpoint = 0;
95-
};
96-
97-
struct BindingTracker
98-
{
99-
deCONZ::SteadyTimeRef tBound;
100-
};
101-
102-
struct BindingContext
103-
{
104-
size_t bindingCheckRound = 0;
105-
size_t bindingIter = 0;
106-
size_t reportIter = 0;
107-
int mgmtBindSupported = MGMT_BIND_SUPPORT_UNKNOWN;
108-
uint8_t mgmtBindStartIndex = 0;
109-
std::vector<BindingTracker> bindingTrackers;
110-
std::vector<DDF_Binding> bindings;
111-
std::vector<ReportTracker> reportTrackers;
112-
ZCL_ReadReportConfigurationParam readReportParam;
113-
ZCL_Result zclResult;
114-
ZDP_Result zdpResult;
115-
};
116-
11756
static ReportTracker &DEV_GetOrCreateReportTracker(Device *device, uint16_t clusterId, uint16_t attrId, uint8_t endpoint);
11857

119-
class DevicePrivate
120-
{
121-
public:
122-
void setState(DeviceStateHandler newState, DEV_StateLevel level = StateLevel0);
123-
void startStateTimer(int IntervalMs, DEV_StateLevel level);
124-
void stopStateTimer(DEV_StateLevel level);
125-
bool hasRxOnWhenIdle() const;
126-
127-
Device *q = nullptr; //! reference to public interface
128-
deCONZ::ApsController *apsCtrl = nullptr; //! opaque instance pointer forwarded to external functions
129-
130-
/*! sub-devices are not yet referenced via pointers since these may become dangling.
131-
This is a helper to query the actual sub-device Resource* on demand via Resource::Handle.
132-
*/
133-
std::array<Resource::Handle, MaxSubResources> subResourceHandles;
134-
std::vector<Resource*> subResources;
135-
const deCONZ::Node *node = nullptr; //! a reference to the deCONZ core node
136-
DeviceKey deviceKey = 0; //! for physical devices this is the MAC address
137-
138-
/*! The currently active state handler function(s).
139-
Indexes >0 represent sub states of StateLevel0 running in parallel.
140-
*/
141-
std::array<DeviceStateHandler, StateLevelMax> state{};
142-
143-
std::array<QBasicTimer, StateLevelMax> timer; //! internal single shot timer one for each state level
144-
QElapsedTimer awake; //! time to track when an end-device was last awake
145-
BindingContext binding; //! only used by binding sub state machine
146-
std::vector<DEV_PollItem> pollItems; //! queue of items to poll
147-
bool managed = false; //! a managed device doesn't rely on legacy implementation of polling etc.
148-
ZDP_Result zdpResult; //! keep track of a running ZDP request
149-
DA_ReadResult readResult; //! keep track of a running "read" request
150-
151-
int maxResponseTime = RxOffWhenIdleResponseTime;
152-
153-
struct
154-
{
155-
unsigned char hasDdf : 1;
156-
unsigned char initialRun : 1;
157-
unsigned char reserved : 6;
158-
} flags{};
159-
};
160-
16158
//! Forward device attribute changes to core.
16259
void DEV_ForwardNodeChange(Device *device, const QString &key, const QString &value)
16360
{

device.h

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@
1212
#define DEVICE_H
1313

1414
#include <memory>
15+
#include <QBasicTimer>
1516
#include <QObject>
1617
#include "resource.h"
18+
#include "zcl/zcl.h"
19+
#include "zdp/zdp.h"
20+
21+
#define STATE_LEVEL_BINDING StateLevel1
22+
#define STATE_LEVEL_POLL StateLevel2
23+
24+
#define MGMT_BIND_SUPPORT_UNKNOWN -1
25+
#define MGMT_BIND_SUPPORTED 1
26+
#define MGMT_BIND_NOT_SUPPORTED 0
1727

1828
class Event;
1929
class EventEmitter;
@@ -40,6 +50,55 @@ enum DEV_StateLevel {
4050
StateLevelMax
4151
};
4252

53+
// enable domain specific string literals
54+
using namespace deCONZ::literals;
55+
56+
constexpr int RxOnWhenIdleResponseTime = 2000; // Expect shorter response delay for rxOnWhenIdle devices
57+
constexpr int RxOffWhenIdleResponseTime = 8000; // 7680 ms + some space for timeout
58+
constexpr int MaxConfirmTimeout = 20000; // If for some reason no APS-DATA.confirm is received (should almost
59+
constexpr int BindingAutoCheckInterval = 1000 * 60 * 60;
60+
constexpr int MaxPollItemRetries = 3;
61+
constexpr int MaxSubResources = 8;
62+
63+
struct DEV_PollItem
64+
{
65+
explicit DEV_PollItem(const Resource *r, const ResourceItem *i, const QVariant &p) :
66+
resource(r), item(i), readParameters(p) {}
67+
size_t retry = 0;
68+
const Resource *resource = nullptr;
69+
const ResourceItem *item = nullptr;
70+
QVariant readParameters;
71+
};
72+
73+
struct ReportTracker
74+
{
75+
deCONZ::SteadyTimeRef lastReport;
76+
deCONZ::SteadyTimeRef lastConfigureCheck;
77+
uint16_t clusterId = 0;
78+
uint16_t attributeId = 0;
79+
uint8_t endpoint = 0;
80+
};
81+
82+
struct BindingTracker
83+
{
84+
deCONZ::SteadyTimeRef tBound;
85+
};
86+
87+
struct BindingContext
88+
{
89+
size_t bindingCheckRound = 0;
90+
size_t bindingIter = 0;
91+
size_t reportIter = 0;
92+
int mgmtBindSupported = MGMT_BIND_SUPPORT_UNKNOWN;
93+
uint8_t mgmtBindStartIndex = 0;
94+
std::vector<BindingTracker> bindingTrackers;
95+
std::vector<DDF_Binding> bindings;
96+
std::vector<ReportTracker> reportTrackers;
97+
ZCL_ReadReportConfigurationParam readReportParam;
98+
ZCL_Result zclResult;
99+
ZDP_Result zdpResult;
100+
};
101+
43102
/*! \class Device
44103
45104
A generic per device supervisor for routers and end-devices.
@@ -117,6 +176,50 @@ class Device : public QObject,
117176
void eventNotify(const Event&); //! The device emits an event, which needs to be enqueued in a higher layer.
118177
};
119178

179+
typedef void (*DeviceStateHandler)(Device *, const Event &);
180+
181+
class DevicePrivate
182+
{
183+
public:
184+
void setState(DeviceStateHandler newState, DEV_StateLevel level = StateLevel0);
185+
void startStateTimer(int IntervalMs, DEV_StateLevel level);
186+
void stopStateTimer(DEV_StateLevel level);
187+
bool hasRxOnWhenIdle() const;
188+
189+
Device *q = nullptr; //! reference to public interface
190+
deCONZ::ApsController *apsCtrl = nullptr; //! opaque instance pointer forwarded to external functions
191+
192+
/*! sub-devices are not yet referenced via pointers since these may become dangling.
193+
This is a helper to query the actual sub-device Resource* on demand via Resource::Handle.
194+
*/
195+
std::array<Resource::Handle, MaxSubResources> subResourceHandles;
196+
std::vector<Resource*> subResources;
197+
const deCONZ::Node *node = nullptr; //! a reference to the deCONZ core node
198+
DeviceKey deviceKey = 0; //! for physical devices this is the MAC address
199+
200+
/*! The currently active state handler function(s).
201+
Indexes >0 represent sub states of StateLevel0 running in parallel.
202+
*/
203+
std::array<DeviceStateHandler, StateLevelMax> state{};
204+
205+
std::array<QBasicTimer, StateLevelMax> timer; //! internal single shot timer one for each state level
206+
QElapsedTimer awake; //! time to track when an end-device was last awake
207+
BindingContext binding; //! only used by binding sub state machine
208+
std::vector<DEV_PollItem> pollItems; //! queue of items to poll
209+
bool managed = false; //! a managed device doesn't rely on legacy implementation of polling etc.
210+
ZDP_Result zdpResult; //! keep track of a running ZDP request
211+
DA_ReadResult readResult; //! keep track of a running "read" request
212+
213+
int maxResponseTime = RxOffWhenIdleResponseTime;
214+
215+
struct
216+
{
217+
unsigned char hasDdf : 1;
218+
unsigned char initialRun : 1;
219+
unsigned char reserved : 6;
220+
} flags{};
221+
};
222+
120223
using DeviceContainer = std::vector<std::unique_ptr<Device>>;
121224

122225
Resource *DEV_GetSubDevice(Device *device, const char *prefix, const QString &identifier);

0 commit comments

Comments
 (0)