8
8
*
9
9
*/
10
10
11
- #include < QBasicTimer>
12
11
#include < QElapsedTimer>
13
12
#include < QTimer>
14
13
#include < QTimerEvent>
23
22
#include " event.h"
24
23
#include " event_emitter.h"
25
24
#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 &);
37
25
38
26
/* ! Device state machine description can be found in the wiki:
39
27
@@ -60,104 +48,13 @@ void DEV_PollNextStateHandler(Device *device, const Event &event);
60
48
void DEV_PollBusyStateHandler (Device *device, const Event &event);
61
49
void DEV_DeadStateHandler (Device *device, const Event &event);
62
50
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
-
73
51
static int devManaged = -1 ;
74
52
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
-
85
53
// special value for ReportTracker::lastConfigureCheck during zcl configure reporting step
86
54
constexpr int64_t MarkZclConfigureBusy = 21 ;
87
55
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
-
117
56
static ReportTracker &DEV_GetOrCreateReportTracker (Device *device, uint16_t clusterId, uint16_t attrId, uint8_t endpoint);
118
57
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
-
161
58
// ! Forward device attribute changes to core.
162
59
void DEV_ForwardNodeChange (Device *device, const QString &key, const QString &value)
163
60
{
0 commit comments