forked from espressif/arduino-esp32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZigbeeEP.h
135 lines (110 loc) · 4.57 KB
/
ZigbeeEP.h
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
/* Common Class for Zigbee End point */
#pragma once
#include "ZigbeeCore.h"
#if SOC_IEEE802154_SUPPORTED && CONFIG_ZB_ENABLED
#include <Arduino.h>
/* Useful defines */
#define ZB_ARRAY_LENTH(arr) (sizeof(arr) / sizeof(arr[0]))
#define XYZ_TO_RGB(X, Y, Z, r, g, b) \
{ \
r = (float)(3.240479 * (X) - 1.537150 * (Y) - 0.498535 * (Z)); \
g = (float)(-0.969256 * (X) + 1.875992 * (Y) + 0.041556 * (Z)); \
b = (float)(0.055648 * (X) - 0.204043 * (Y) + 1.057311 * (Z)); \
if (r > 1) { \
r = 1; \
} \
if (g > 1) { \
g = 1; \
} \
if (b > 1) { \
b = 1; \
} \
}
#define RGB_TO_XYZ(r, g, b, X, Y, Z) \
{ \
X = (float)(0.412453 * (r) + 0.357580 * (g) + 0.180423 * (b)); \
Y = (float)(0.212671 * (r) + 0.715160 * (g) + 0.072169 * (b)); \
Z = (float)(0.019334 * (r) + 0.119193 * (g) + 0.950227 * (b)); \
}
typedef struct zbstring_s {
uint8_t len;
char data[];
} ESP_ZB_PACKED_STRUCT zbstring_t;
typedef struct zb_device_params_s {
esp_zb_ieee_addr_t ieee_addr;
uint8_t endpoint;
uint16_t short_addr;
} zb_device_params_t;
typedef enum {
ZB_POWER_SOURCE_UNKNOWN = 0x00,
ZB_POWER_SOURCE_MAINS = 0x01,
ZB_POWER_SOURCE_BATTERY = 0x03,
} zb_power_source_t;
/* Zigbee End Device Class */
class ZigbeeEP {
public:
ZigbeeEP(uint8_t endpoint = 10);
~ZigbeeEP();
// Set ep config and cluster list
void setEpConfig(esp_zb_endpoint_config_t ep_config, esp_zb_cluster_list_t *cluster_list) {
_ep_config = ep_config;
_cluster_list = cluster_list;
}
void setVersion(uint8_t version);
uint8_t getEndpoint() {
return _endpoint;
}
void printBoundDevices();
void printBoundDevices(Print &print);
std::list<zb_device_params_t *> getBoundDevices() const {
return _bound_devices;
}
static bool bound() {
return _is_bound;
}
static void allowMultipleBinding(bool bind) {
_allow_multiple_binding = bind;
}
// Manufacturer name and model implemented
void setManufacturerAndModel(const char *name, const char *model);
void setPowerSource(zb_power_source_t power_source, uint8_t percentage = 255);
void setBatteryPercentage(uint8_t percentage);
void reportBatteryPercentage();
// Methods to read manufacturer and model name from selected endpoint and short address
char *readManufacturer(uint8_t endpoint, uint16_t short_addr, esp_zb_ieee_addr_t ieee_addr);
char *readModel(uint8_t endpoint, uint16_t short_addr, esp_zb_ieee_addr_t ieee_addr);
bool epAllowMultipleBinding() {
return _allow_multiple_binding;
}
// findEndpoind may be implemented by EPs to find and bind devices
virtual void findEndpoint(esp_zb_zdo_match_desc_req_param_t *cmd_req) {};
//list of all handlers function calls, to be override by EPs implementation
virtual void zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) {};
virtual void zbAttributeRead(uint16_t cluster_id, const esp_zb_zcl_attribute_t *attribute) {};
virtual void zbReadBasicCluster(const esp_zb_zcl_attribute_t *attribute); //already implemented
virtual void zbIdentify(const esp_zb_zcl_set_attr_value_message_t *message);
virtual void zbIASZoneStatusChangeNotification(const esp_zb_zcl_ias_zone_status_change_notification_message_t *message) {};
void onIdentify(void (*callback)(uint16_t)) {
_on_identify = callback;
}
private:
char *_read_manufacturer;
char *_read_model;
void (*_on_identify)(uint16_t time);
protected:
uint8_t _endpoint;
esp_zb_ha_standard_devices_t _device_id;
esp_zb_endpoint_config_t _ep_config;
esp_zb_cluster_list_t *_cluster_list;
static bool _is_bound;
static bool _allow_multiple_binding;
std::list<zb_device_params_t *> _bound_devices;
SemaphoreHandle_t lock;
zb_power_source_t _power_source;
void addBoundDevice(zb_device_params_t *device) {
_bound_devices.push_back(device);
_is_bound = true;
}
friend class ZigbeeCore;
};
#endif //SOC_IEEE802154_SUPPORTED && CONFIG_ZB_ENABLED