Welcome to mirror list, hosted at ThFree Co, Russian Federation.

zcl.power.profile.h « zcl « include « stack « zigbee « STM32_WPAN « ST « Middlewares - github.com/Flipper-Zero/STM32CubeWB.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8040325219a76152da4482d79d0e5a517085b5c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/* Copyright [2019 - 2020] Exegin Technologies Limited. All rights reserved. */

#ifndef ZCL_PWR_PROF_H
#define ZCL_PWR_PROF_H

#include "zcl/zcl.h"

/* Attribute Identifiers */
enum {
    ZCL_POWER_PROF_SVR_ATTR_TOTAL_PROFILENUM = 0x0000,
    ZCL_POWER_PROF_SVR_ATTR_MULTIPLE_SCHED = 0x0001,
    ZCL_POWER_PROF_SVR_ATTR_ENERGY_FORMAT = 0x0002,
    ZCL_POWER_PROF_SVR_ATTR_ENERGY_REMOTE = 0x0003,
    ZCL_POWER_PROF_SVR_ATTR_SCHEDULE_MODE = 0x0004
};

/* Client Generated Commands */
enum {
    ZCL_PWR_PROF_CLI_PROFILE_REQ = 0x00,
    ZCL_PWR_PROF_CLI_STATE_REQ = 0x01,
    ZCL_PWR_PROF_CLI_PRICE_RSP = 0x02,
    ZCL_PWR_PROF_CLI_SCHED_PRICE_RSP = 0x03,
    ZCL_PWR_PROF_CLI_PHASES_NOTIFY = 0x04,
    ZCL_PWR_PROF_CLI_PHASES_RSP = 0x05,
    ZCL_PWR_PROF_CLI_SCHED_CONS_REQ = 0x06,
    ZCL_PWR_PROF_CLI_PHASES_SCHED_STATE_REQ = 0x07,
    ZCL_PWR_PROF_CLI_PRICE_EXT_RSP = 0x08
};

/* Server Generated Commands */
enum {
    ZCL_PWR_PROF_SVR_PROFILE_NOTIFY = 0x00,
    ZCL_PWR_PROF_SVR_PROFILE_RSP = 0x01,
    ZCL_PWR_PROF_SVR_STATE_RSP = 0x02,
    ZCL_PWR_PROF_SVR_GET_PRICE = 0x03,
    ZCL_PWR_PROF_SVR_STATE_NOTIFY = 0x04,
    ZCL_PWR_PROF_SVR_GET_SCHED_PRICE = 0x05,
    ZCL_PWR_PROF_SVR_PHASES_REQ = 0x06,
    ZCL_PWR_PROF_SVR_PHASES_RSP = 0x07,
    ZCL_PWR_PROF_SVR_PHASES_NOTIFY = 0x08,
    ZCL_PWR_PROF_SVR_CONSTRAINTS_NOTIFY = 0x09,
    ZCL_PWR_PROF_SVR_CONSTRAINTS_RSP = 0x0a,
    ZCL_PWR_PROF_SVR_GET_PRICE_EXT = 0x0b,
};

/* Energy Formatting Mask (ZCL_POWER_PROF_SVR_ATTR_ENERGY_FORMAT) */
#define ZCL_PWR_PROF_ENERGY_FORMAT_DIGITS_TRAIL_MASK    0x07U /* num trailing digits */
#define ZCL_PWR_PROF_ENERGY_FORMAT_DIGITS_TRAIL_OFFSET  0U
#define ZCL_PWR_PROF_ENERGY_FORMAT_DIGITS_LEAD_MASK     0x78U /* num leading digits */
#define ZCL_PWR_PROF_ENERGY_FORMAT_DIGITS_LEAD_OFFSET   3U
#define ZCL_PWR_PROF_ENERGY_FORMAT_SUPPRESS_LEADING     0x80U /* suppress leading zeroes */

/* ScheduleMode Mask (ZCL_POWER_PROF_SVR_ATTR_SCHEDULE_MODE) */
#define ZCL_PWR_PROF_SCHED_MODE_CHEAPEST                0x01U
#define ZCL_PWR_PROF_SCHED_MODE_GREENEST                0x02U

/* These are arbitrary limits to save memory. Theoretical max is 0xfe (254) */
#define ZCL_PWR_PROF_MAX_PROFILES                       16U
#define ZCL_PWR_PROF_MAX_ENERGY_PHASES                  16U

enum ZbZclPowerProfState {
    ZCL_PWR_PROF_STATE_PROFILE_IDLE = 0x00,
    ZCL_PWR_PROF_STATE_PROFILE_PROGRAMMED = 0x01,
    ZCL_PWR_PROF_STATE_PHASE_RUNNING = 0x03,
    ZCL_PWR_PROF_STATE_PHASE_PAUSED = 0x04,
    ZCL_PWR_PROF_STATE_PHASE_WAITING_START = 0x05,
    ZCL_PWR_PROF_STATE_PHASE_WAITING_PAUSED = 0x06,
    ZCL_PWR_PROF_STATE_PROFILE_ENDED = 0x07
};

struct ZbZclPowerProfPhase {
    uint8_t energy_phase_id;
    uint8_t macro_phase_id;
    uint16_t expect_duration;
    uint16_t peak_power;
    uint16_t energy;
    uint16_t max_activation_delay;
};

/* PowerProfileNotification and PowerProfileResponse share the same payload format. */
struct ZbZclPowerProfSvrProfileRsp {
    uint8_t total_profile_num;
    uint8_t power_profile_id;
    uint8_t num_transferred_phases;
    struct ZbZclPowerProfPhase phase_list[ZCL_PWR_PROF_MAX_ENERGY_PHASES];
};

struct ZbZclPowerProfileRecord {
    uint8_t power_profile_id;
    uint8_t energy_phase_id;
    uint8_t remote_control;
    enum ZbZclPowerProfState state;
};

/* PowerProfileStateResponse */
struct ZbZclPowerProfSvrStateRsp {
    uint8_t profile_count;
    struct ZbZclPowerProfileRecord record_list[ZCL_PWR_PROF_MAX_PROFILES];
};

/* PowerProfileRequest */
struct ZbZclPowerProfCliProfileReq {
    uint8_t profile_id;
};

struct ZbZclPowerProfSchedPhase {
    uint8_t energy_phase_id;
    uint16_t sched_time;
};

struct ZbZclPowerProfCliPhasesNotify {
    uint8_t power_profile_id;
    uint8_t num_phases;
    struct ZbZclPowerProfSchedPhase sched_list[ZCL_PWR_PROF_MAX_ENERGY_PHASES];
};

struct ZbZclPowerProfCliPriceRsp {
    uint8_t power_profile_id;
    uint16_t currency;
    uint32_t price;
    uint8_t trailing_digit;
};

struct ZbZclPowerProfCliSchedPriceRsp {
    uint16_t currency;
    uint32_t price;
    uint8_t trailing_digit;
};

/* ZCL_PWR_PROF_SVR_PHASES_RSP / ZCL_PWR_PROF_SVR_PHASES_NOTIFY */
struct ZbZclPowerProfSvrPhasesRsp {
    uint8_t power_profile_id;
    uint8_t num_sched_energy_phases;
};

/* ZCL_PWR_PROF_SVR_CONSTRAINTS_NOTIFY */
struct ZbZclPowerProfSvrConstraintsNotify {
    uint8_t power_profile_id;
    uint16_t start_after;
    uint16_t stop_before;
};

/* GetPowerProfilePriceExtended Command options field */
#define ZCL_PWR_PROF_PRICE_EXT_OPT_START_TIME_PRESENT   0x01U
#define ZCL_PWR_PROF_PRICE_EXT_OPT_EST_PRICE            0x02U

/* ZCL_PWR_PROF_SVR_GET_PRICE_EXT */
struct ZbZclPowerProfSvrGetPriceExtReq {
    uint8_t options; /* e.g. ZCL_PWR_PROF_PRICE_EXT_OPT_START_TIME_PRESENT */
    uint8_t power_profile_id;
    uint16_t start_time; /* optional (ZCL_PWR_PROF_PRICE_EXT_OPT_START_TIME_PRESENT) */
};

/* Power Profile Client Callbacks
 * If application sends a response, the callback return code should be set to
 * ZCL_STATUS_SUCCESS_NO_DEFAULT_RESPONSE to prevent a Default Response from also being sent.
 */
struct ZbZclPowerProfClientCallbacks {
    /* ZCL_PWR_PROF_SVR_PROFILE_NOTIFY */
    enum ZclStatusCodeT (*profile_notify)(struct ZbZclClusterT *cluster,
        struct ZbZclPowerProfSvrProfileRsp *notify, struct ZbZclAddrInfoT *srcInfo, void *arg);

    /* ZCL_PWR_PROF_SVR_GET_PRICE */
    enum ZclStatusCodeT (*get_price)(struct ZbZclClusterT *cluster,
        struct ZbZclPowerProfCliProfileReq *req, struct ZbZclAddrInfoT *srcInfo, void *arg);

    /* ZCL_PWR_PROF_SVR_STATE_NOTIFY */
    enum ZclStatusCodeT (*state_notify)(struct ZbZclClusterT *cluster,
        struct ZbZclPowerProfSvrStateRsp *notify, struct ZbZclAddrInfoT *srcInfo, void *arg);

    /* ZCL_PWR_PROF_SVR_GET_SCHED_PRICE */
    enum ZclStatusCodeT (*get_sched_price)(struct ZbZclClusterT *cluster,
        struct ZbZclAddrInfoT *srcInfo, void *arg);

    /* ZCL_PWR_PROF_SVR_PHASES_REQ */
    enum ZclStatusCodeT (*phases_req)(struct ZbZclClusterT *cluster,
        struct ZbZclPowerProfCliProfileReq *req, struct ZbZclAddrInfoT *srcInfo, void *arg);

    /* ZCL_PWR_PROF_SVR_PHASES_NOTIFY */
    enum ZclStatusCodeT (*phases_notify)(struct ZbZclClusterT *cluster,
        struct ZbZclPowerProfSvrPhasesRsp *notify, struct ZbZclAddrInfoT *srcInfo, void *arg);

    /* ZCL_PWR_PROF_SVR_CONSTRAINTS_NOTIFY */
    enum ZclStatusCodeT (*constraints_notify)(struct ZbZclClusterT *cluster,
        struct ZbZclPowerProfSvrConstraintsNotify *notify, struct ZbZclAddrInfoT *srcInfo, void *arg);

    /* ZCL_PWR_PROF_SVR_GET_PRICE_EXT */
    enum ZclStatusCodeT (*get_price_ext)(struct ZbZclClusterT *cluster,
        struct ZbZclPowerProfSvrGetPriceExtReq *req, struct ZbZclAddrInfoT *srcInfo, void *arg);
};

struct ZbZclClusterT * ZbZclPowerProfClientAlloc(struct ZigBeeT *zb, uint8_t endpoint,
    struct ZbZclPowerProfClientCallbacks *callbacks, void *arg);

/* ZCL_PWR_PROF_CLI_PROFILE_REQ */
enum ZclStatusCodeT ZbZclPowerProfClientProfileReq(struct ZbZclClusterT *clusterPtr,
    struct ZbZclPowerProfCliProfileReq *req, const struct ZbApsAddrT *dst,
    void (*callback)(struct ZbZclCommandRspT *rsp, void *arg), void *arg);

/* ZCL_PWR_PROF_CLI_STATE_REQ */
enum ZclStatusCodeT ZbZclPowerProfClientStateReq(struct ZbZclClusterT *clusterPtr,
    const struct ZbApsAddrT *dst,
    void (*callback)(struct ZbZclCommandRspT *rsp, void *arg), void *arg);

/* ZCL_PWR_PROF_CLI_PRICE_RSP */
enum ZclStatusCodeT ZbZclPowerProfClientPriceRsp(struct ZbZclClusterT *clusterPtr,
    struct ZbZclAddrInfoT *dst, struct ZbZclPowerProfCliPriceRsp *rsp,
    void (*callback)(struct ZbApsdeDataConfT *conf, void *arg), void *arg);

/* ZCL_PWR_PROF_CLI_SCHED_PRICE_RSP */
enum ZclStatusCodeT ZbZclPowerProfClientSchedPriceRsp(struct ZbZclClusterT *clusterPtr,
    struct ZbZclAddrInfoT *dst, struct ZbZclPowerProfCliSchedPriceRsp *rsp,
    void (*callback)(struct ZbApsdeDataConfT *conf, void *arg), void *arg);

/* ZCL_PWR_PROF_CLI_PHASES_NOTIFY */
enum ZclStatusCodeT ZbZclPowerProfClientPhasesNotify(struct ZbZclClusterT *clusterPtr,
    struct ZbZclPowerProfCliPhasesNotify *notify, struct ZbApsAddrT *dst,
    void (*callback)(struct ZbApsdeDataConfT *conf, void *arg), void *arg);

/* ZCL_PWR_PROF_CLI_PHASES_RSP */
enum ZclStatusCodeT ZbZclPowerProfClientPhasesResponse(struct ZbZclClusterT *clusterPtr,
    struct ZbZclPowerProfCliPhasesNotify *notify, struct ZbZclAddrInfoT *dst,
    void (*callback)(struct ZbApsdeDataConfT *conf, void *arg), void *arg);

/* ZCL_PWR_PROF_CLI_SCHED_CONS_REQ */
enum ZclStatusCodeT ZbZclPowerProfClientSchedConsReq(struct ZbZclClusterT *clusterPtr,
    struct ZbZclPowerProfCliProfileReq *req, const struct ZbApsAddrT *dst,
    void (*callback)(struct ZbZclCommandRspT *rsp, void *arg), void *arg);

/* ZCL_PWR_PROF_CLI_PHASES_SCHED_STATE_REQ */
enum ZclStatusCodeT ZbZclPowerProfClientPhasesSchedStateReq(struct ZbZclClusterT *clusterPtr,
    struct ZbZclPowerProfCliProfileReq *req, const struct ZbApsAddrT *dst,
    void (*callback)(struct ZbZclCommandRspT *rsp, void *arg), void *arg);

/* ZCL_PWR_PROF_CLI_PRICE_EXT_RSP */
enum ZclStatusCodeT ZbZclPowerProfClientPriceExtRsp(struct ZbZclClusterT *clusterPtr,
    struct ZbZclAddrInfoT *dst, struct ZbZclPowerProfCliPriceRsp *rsp,
    void (*callback)(struct ZbApsdeDataConfT *conf, void *arg), void *arg);

/* Power Profile Server Callbacks
 * If application sends a response, the callback return code should be set to
 * ZCL_STATUS_SUCCESS_NO_DEFAULT_RESPONSE to prevent a Default Response from also being sent.
 */
struct ZbZclPowerProfServerCallbacks {
    /* ZCL_PWR_PROF_CLI_PROFILE_REQ */
    enum ZclStatusCodeT (*profile_req)(struct ZbZclClusterT *cluster,
        struct ZbZclPowerProfCliProfileReq *req, struct ZbZclAddrInfoT *srcInfo, void *arg);

    /* ZCL_PWR_PROF_CLI_STATE_REQ */
    enum ZclStatusCodeT (*state_req)(struct ZbZclClusterT *cluster,
        struct ZbZclAddrInfoT *srcInfo, void *arg);

    /* ZCL_PWR_PROF_CLI_PHASES_NOTIFY */
    enum ZclStatusCodeT (*phases_notify)(struct ZbZclClusterT *cluster,
        struct ZbZclPowerProfCliPhasesNotify *req, struct ZbZclAddrInfoT *srcInfo, void *arg);

    /* ZCL_PWR_PROF_CLI_SCHED_CONS_REQ */
    enum ZclStatusCodeT (*sched_contraints_req)(struct ZbZclClusterT *cluster,
        struct ZbZclPowerProfCliProfileReq *req, struct ZbZclAddrInfoT *srcInfo, void *arg);

    /* ZCL_PWR_PROF_CLI_PHASES_SCHED_STATE_REQ */
    enum ZclStatusCodeT (*phases_sched_state_req)(struct ZbZclClusterT *cluster,
        struct ZbZclPowerProfCliProfileReq *req, struct ZbZclAddrInfoT *srcInfo, void *arg);
};

struct ZbZclClusterT * ZbZclPowerProfServerAlloc(struct ZigBeeT *zb, uint8_t endpoint,
    struct ZbZclPowerProfServerCallbacks *callbacks, void *arg);

/* ZCL_PWR_PROF_SVR_PROFILE_NOTIFY */
enum ZclStatusCodeT ZbZclPowerProfServerProfileNotify(struct ZbZclClusterT *clusterPtr,
    struct ZbApsAddrT *dst, struct ZbZclPowerProfSvrProfileRsp *notify,
    void (*callback)(struct ZbApsdeDataConfT *conf, void *arg), void *arg);

/* ZCL_PWR_PROF_SVR_PROFILE_RSP */
enum ZclStatusCodeT ZbZclPowerProfServerProfileRsp(struct ZbZclClusterT *clusterPtr,
    struct ZbZclAddrInfoT *dst, struct ZbZclPowerProfSvrProfileRsp *rsp,
    void (*callback)(struct ZbApsdeDataConfT *conf, void *arg), void *arg);

/* ZCL_PWR_PROF_SVR_STATE_RSP */
enum ZclStatusCodeT ZbZclPowerProfServerStateRsp(struct ZbZclClusterT *clusterPtr,
    struct ZbZclAddrInfoT *dst, struct ZbZclPowerProfSvrStateRsp *rsp,
    void (*callback)(struct ZbApsdeDataConfT *conf, void *arg), void *arg);

/* ZCL_PWR_PROF_SVR_GET_PRICE */
enum ZclStatusCodeT ZbZclPowerProfServerGetPriceReq(struct ZbZclClusterT *clusterPtr,
    struct ZbZclPowerProfCliProfileReq *req, const struct ZbApsAddrT *dst,
    void (*callback)(struct ZbZclCommandRspT *rsp, void *arg), void *arg);

/* ZCL_PWR_PROF_SVR_STATE_NOTIFY */
enum ZclStatusCodeT ZbZclPowerProfServerStateNotify(struct ZbZclClusterT *clusterPtr,
    struct ZbApsAddrT *dst, struct ZbZclPowerProfSvrStateRsp *notify,
    void (*callback)(struct ZbApsdeDataConfT *conf, void *arg), void *arg);

/* ZCL_PWR_PROF_SVR_GET_SCHED_PRICE */
enum ZclStatusCodeT ZbZclPowerProfServerGetSchedPriceReq(struct ZbZclClusterT *clusterPtr,
    const struct ZbApsAddrT *dst, void (*callback)(struct ZbZclCommandRspT *rsp, void *arg), void *arg);

/* ZCL_PWR_PROF_SVR_PHASES_REQ */
enum ZclStatusCodeT ZbZclPowerProfServerPhasesReq(struct ZbZclClusterT *clusterPtr,
    struct ZbZclPowerProfCliProfileReq *req, const struct ZbApsAddrT *dst,
    void (*callback)(struct ZbZclCommandRspT *rsp, void *arg), void *arg);

/* ZCL_PWR_PROF_SVR_PHASES_RSP */
enum ZclStatusCodeT ZbZclPowerProfServerPhasesRsp(struct ZbZclClusterT *clusterPtr,
    struct ZbZclAddrInfoT *dst, struct ZbZclPowerProfSvrPhasesRsp *rsp,
    void (*callback)(struct ZbApsdeDataConfT *conf, void *arg), void *arg);

/* ZCL_PWR_PROF_SVR_PHASES_NOTIFY */
enum ZclStatusCodeT ZbZclPowerProfServerPhasesNotify(struct ZbZclClusterT *clusterPtr,
    struct ZbApsAddrT *dst, struct ZbZclPowerProfSvrPhasesRsp *notify,
    void (*callback)(struct ZbApsdeDataConfT *conf, void *arg), void *arg);

/* ZCL_PWR_PROF_SVR_CONSTRAINTS_NOTIFY */
enum ZclStatusCodeT ZbZclPowerProfServerConstraintsNotify(struct ZbZclClusterT *clusterPtr,
    struct ZbApsAddrT *dst, struct ZbZclPowerProfSvrConstraintsNotify *notify,
    void (*callback)(struct ZbApsdeDataConfT *conf, void *arg), void *arg);

/* ZCL_PWR_PROF_SVR_CONSTRAINTS_RSP */
enum ZclStatusCodeT ZbZclPowerProfServerConstraintsRsp(struct ZbZclClusterT *clusterPtr,
    struct ZbZclAddrInfoT *dst, struct ZbZclPowerProfSvrConstraintsNotify *rsp,
    void (*callback)(struct ZbApsdeDataConfT *conf, void *arg), void *arg);

/* ZCL_PWR_PROF_SVR_GET_PRICE_EXT */
enum ZclStatusCodeT ZbZclPowerProfServerGetPriceReqExtReq(struct ZbZclClusterT *clusterPtr,
    struct ZbZclPowerProfSvrGetPriceExtReq *req, const struct ZbApsAddrT *dst,
    void (*callback)(struct ZbZclCommandRspT *rsp, void *arg), void *arg);

#endif /* ZCL_PWR_PROF_H */