Initial prototype for optimized Telegesis read/write layer.
[contrib/iotivity.git] / plugins / zigbee_wrapper / telegesis_wrapper / include / telegesis_wrapper.h
1 //******************************************************************
2 //
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 /**
22  * @file
23  *
24  * This API only works with:
25  *      Telegesis ETRX357
26  *      CICIE R310 B110615
27  *
28  */
29
30 #ifndef TELEGESISWRAPPER_H_
31 #define TELEGESISWRAPPER_H_
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif // __cplusplus
36
37 #include "octypes.h"
38 #include "twtypes.h"
39
40 #include <stdint.h>
41 #include <time.h>
42 #include <stdbool.h>
43
44 /**
45  *
46  * Defines a cluster id.
47  *
48  */
49 typedef struct
50 {
51     char clusterId[SIZE_CLUSTERID];
52 } TWClusterId;
53
54 /**
55  *
56  * Defines a list of ZigBee device's clusters.
57  *
58  */
59 typedef struct
60 {
61     TWClusterId* clusterIds;
62     int count;
63 } TWClusterList;
64
65 /**
66  *
67  * Defines an endpoint of a ZigBee device.
68  *
69  */
70 typedef struct
71 {
72     char endpointId[SIZE_ENDPOINTID];
73     TWClusterList* clusterList;
74 } TWEndpoint;
75
76 /**
77  *
78  * Defines a list of endpoints of a ZigBee device.
79  *
80  */
81 typedef struct
82 {
83     TWEndpoint* endpoints;
84     int count;
85 } TWEndpointList;
86
87 /**
88  *
89  * Defines a discovered ZigBee device.
90  *
91  */
92 typedef struct
93 {
94     char eui[SIZE_EUI];
95     char nodeId[SIZE_NODEID];
96     TWEndpoint* endpointOfInterest;
97 } TWDevice;
98
99 /**
100  *
101  * Defines a ZigBee device list.
102  *
103  */
104 typedef struct
105 {
106     TWDevice* deviceList;
107     int count;
108 } TWDeviceList;
109
110 /**
111  *
112  * Defines a ZigBee device update.
113  *
114  */
115 typedef struct
116 {
117     char nodeId[SIZE_NODEID];
118     char endpoint[SIZE_ENDPOINTID];
119     char status[SIZE_ZONESTATUS];
120     char extendedStatus[SIZE_ZONESTATUS_EXTENDED];
121     char zoneId[SIZE_ZONEID];               //optional
122     char delay[SIZE_UPDATE_DELAY_TIME];     //optional - amount of time in quarter of seconds
123 } TWUpdate;
124
125 typedef struct
126 {
127     char zoneId[SIZE_ZONEID];
128     char zoneType[SIZE_ZONETYPE];
129     char eui[SIZE_EUI];
130 } TWEnrollee;
131
132 typedef void (*TWDeviceFoundCallback)(TWDevice* device);
133 typedef void (*TWEnrollmentSucceedCallback)(TWEnrollee* enrollee);
134 typedef void (*TWDeviceStatusUpdateCallback)(TWUpdate* update);
135
136 /**
137  *
138  * Initializes the Telegesis module.
139  *
140  * @param[in] deviceDevPath The device path at which this Telegesis module exists.
141  *
142  */
143 OCStackResult TWInitialize(const char* deviceDevPath);
144
145 /**
146  *
147  * Initiates necessary operations to find ZigBee devices.
148  *
149  */
150 OCStackResult TWDiscover();
151
152 /**
153  *
154  * Gets a value at the specified parameters.
155  *
156  * @param[in] extendedUniqueId The extended unique id of the device.
157  * @param[in] nodeId The node id of the device.
158  * @param[in] endpointId The endpoint id from which the attribute belongs.
159  * @param[in] clusterId The cluster id from which the attribute belongs.
160  * @param[in] attributeId The attribute id from which the attribute belongs.
161  * @param[out] outValue The value at the specified attribute.
162  * @param[out] outValueLength The length of the value.
163  *
164  */
165 OCStackResult TWGetAttribute(char* extendedUniqueId, char* nodeId, char* endpointId,
166                              char* clusterId, char* attributeId,
167                              char** outValue, uint8_t* outValueLength);
168
169 /**
170  *
171  * Sets a value at the specified parameters.
172  *
173  * @param[in] extendedUniqueId The extended unique id of the device.
174  * @param[in] nodeId The node id of the device.
175  * @param[in] endpointId The endpoint id from which the attribute belongs.
176  * @param[in] clusterId The cluster id from which the attribute belongs.
177  * @param[in] attributeId The attribute id from which the attribute belongs.
178  * @param[in] attributeType The attribute type of the attribute.
179  * @param[in] newValue The value to set at the specified attribute.
180  *
181  */
182 OCStackResult TWSetAttribute(char* extendedUniqueId, char* nodeId, char* endpointId,
183                              char* clusterId, char* attributeId, char* attributeType,
184                              char* newValue);
185
186 /**
187  *
188  * Switches a device to On/Off.
189  *
190  * @param[in] nodeId The node id of the device.
191  * @param[in] endpointId The endpoint id from which the attribute belongs.
192  * @param[in] newState Use "0" for OFF, "1" for ON, NULL for toggling.
193  *
194  */
195 OCStackResult TWSwitchOnOff(char* nodeId, char* endpointId, char* newState);
196
197 /**
198  *
199  * Move to a level. All parameters are null-terminated.
200  *
201  * @param[in] nodeId The node id of the device.
202  * @param[in] endpointId The endpoint id from which the attribute belongs.
203  * @param[in] onOfState A boolean type number represents if the command
204  *                      is used with On/Off. If it is set to 0, it means the command is
205  *                      implemented as Move to Level command. If it is set to 1, it
206  *                      means the command will be implemented Move to Level
207  *                      (with On/Off) command.
208  *
209  * @param[in] level The The meaning of ‘level’ is device dependent
210  *                  e.g. for a light it may mean brightness level.
211
212  * @param[in] transTime The time taken to move to the new level
213  *
214  */
215 OCStackResult TWMoveToLevel(char* nodeId, char* endpointId,
216                             char* onOffState, char* level, char* transTime);
217
218 /**
219  *
220  * Switches door lock state.
221  *
222  * @param[in] nodeId The node id of the device.
223  * @param[in] endpointId The endpoint id from which the attribute belongs.
224  * @param[in] newState Use "0" to Unlock, "1" to Lock ON.
225  *
226  */
227 OCStackResult TWSwitchDoorLockState(char* nodeId, char* endpointId, char* newState);
228
229 /**
230  *
231  * Sets discovery callback.
232  * This callback will be called when TWDiscover() discovers ZigBee device(s).
233  *
234  */
235 OCStackResult TWSetDiscoveryCallback(const TWDeviceFoundCallback callback);
236
237 /**
238  *
239  * Sets status update callback.
240  * This callback will be called when there is an update on remote ZigBee devices.
241  *
242  */
243 OCStackResult TWSetStatusUpdateCallback(TWDeviceStatusUpdateCallback callback);
244
245 /**
246  *
247  * Attempts to listen to status change updates of a remote zone device.
248  * A callback TWEnrollSucceedCallback will be invoked when this registration is fulfill.
249  * @param[in] nodeId The node id of the remote zone device.
250  * @param[in] endpointId The node id of the remote zone device.
251  *
252  *
253  */
254 OCStackResult TWListenForStatusUpdates(char* nodeId, char* endpointId);
255
256 /**
257  *
258  * Uninitializes the Telegesis module.
259  *
260  */
261 OCStackResult TWUninitialize();
262
263
264 #ifdef __cplusplus
265 }
266 #endif // __cplusplus
267
268 #endif /* TELEGESISWRAPPER_H_ */