OpenZWave Library  1.5.0
Defs.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // Defs.h
4 //
5 // Basic types and preprocessor directives
6 //
7 // Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
8 //
9 // SOFTWARE NOTICE AND LICENSE
10 //
11 // This file is part of OpenZWave.
12 //
13 // OpenZWave is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU Lesser General Public License as published
15 // by the Free Software Foundation, either version 3 of the License,
16 // or (at your option) any later version.
17 //
18 // OpenZWave is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Lesser General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public License
24 // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
25 //
26 //-----------------------------------------------------------------------------
27 
28 #ifndef _Defs_H
29 #define _Defs_H
30 #include <assert.h>
31 #include <stdio.h>
32 #include <string>
33 #include <stdint.h>
34 
35 
36 
37 // Compilation export flags
38 #if (defined _WINDOWS || defined WIN32 || defined _MSC_VER) && !defined MINGW
39 # if defined OPENZWAVE_MAKEDLL // Create the dynamic library.
40 # define OPENZWAVE_EXPORT __declspec(dllexport)
41 # elif defined OPENZWAVE_USEDLL // Use the dynamic library
42 # define OPENZWAVE_EXPORT __declspec(dllimport)
43 # else // Create/Use the static library
44 # define OPENZWAVE_EXPORT
45 # endif
46 // Disable export warnings
47 # define OPENZWAVE_EXPORT_WARNINGS_OFF __pragma( warning(push) )\
48  __pragma( warning(disable: 4251) ) \
49  __pragma( warning(disable: 4275) )
50 # define OPENZWAVE_EXPORT_WARNINGS_ON __pragma( warning(pop) )
51 #else
52 # define OPENZWAVE_EXPORT
53 # define OPENZWAVE_EXPORT_WARNINGS_OFF
54 # define OPENZWAVE_EXPORT_WARNINGS_ON
55 #endif
56 
57 #ifdef __GNUC__
58 #define DEPRECATED __attribute__((deprecated))
59 #elif defined(_MSC_VER)
60 #define DEPRECATED __declspec(deprecated)
61 #else
62 #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
63 #define DEPRECATED
64 #endif
65 
66 
67 #ifdef _MSC_VER
68 #define OPENZWAVE_DEPRECATED_WARNINGS_OFF __pragma( warning(push) )\
69  __pragma( warning(disable: 4996) )
70 #else
71 #define OPENZWAVE_DEPRECATED_WARNINGS_OFF _Pragma ( "GCC diagnostic push" )\
72  _Pragma ( "GCC diagnostic ignored \"-Wdeprecated-declarations\"" )
73 #endif
74 
75 #ifdef _MSC_VER
76 #define OPENZWAVE_DEPRECATED_WARNINGS_ON __pragma( warning(pop) )
77 #else
78 #define OPENZWAVE_DEPRECATED_WARNINGS_ON _Pragma ( "GCC diagnostic pop" )
79 #endif
80 
81 
82 
83 #ifdef NULL
84 #undef NULL
85 #endif
86 #define NULL 0
87 
88 // Basic types
89 typedef signed char int8;
90 typedef unsigned char uint8;
91 
92 typedef signed short int16;
93 typedef unsigned short uint16;
94 
95 typedef signed int int32;
96 typedef unsigned int uint32;
97 
98 #ifdef _MSC_VER
99 typedef signed __int64 int64;
100 typedef unsigned __int64 uint64;
101 #endif
102 
103 #ifdef __GNUC__
104 typedef signed long long int64;
105 typedef unsigned long long uint64;
106 #endif
107 
108 typedef float float32;
109 typedef double float64;
110 
111 typedef struct ozwversion {
112  uint32_t _v; /* major << 16 | minor */
113 } ozwversion;
114 
120 static inline uint16_t version_major(struct ozwversion v) {
121  return (v._v & 0xFFFF0000) >> 16;
122 }
123 
129 static inline uint16_t version_minor(const struct ozwversion &v) {
130  return v._v & 0xFFFF;
131 }
132 
139 static inline struct ozwversion version(uint16_t major, uint16_t minor)
140 {
141  struct ozwversion v;
142  v._v = (uint32_t)(major << 16) | (uint32_t)minor;
143  return v;
144 }
145 
159 static inline int version_cmp(struct ozwversion a, struct ozwversion b)
160 {
161  return (a._v == b._v) ? 0 : (a._v > b._v) ? 1 : - 1;
162 }
163 
164 #include "OZWException.h"
165 #if defined(_MSC_VER)
166 # define __MYFUNCTION__ __FUNCTION__
167 #else
168 # define __MYFUNCTION__ __FILE__
169 #endif
170 // Exceptions : define OPENZWAVE_ENABLE_EXCEPTIONS in compiler flags to enable exceptions instead of exit function
171 #ifdef OPENZWAVE_ENABLE_EXCEPTIONS
172 
173 # define OZW_FATAL_ERROR(exitCode, msg) Log::Write( LogLevel_Error,"Exception: %s:%d - %d - %s", std::string(__MYFUNCTION__).substr(std::string(__MYFUNCTION__).find_last_of("/\\") + 1).c_str(), __LINE__, exitCode, msg); \
174  throw OZWException(__MYFUNCTION__, __LINE__, exitCode, msg)
175 # define OZW_ERROR(exitCode, msg) Log::Write( LogLevel_Warning,"Exception: %s:%d - %d - %s", std::string(__MYFUNCTION__).substr(std::string(__MYFUNCTION__).find_last_of("/\\") + 1).c_str(), __LINE__, exitCode, msg); \
176  throw OZWException(__MYFUNCTION__, __LINE__, exitCode, msg)
177 
178 #else
179 
180 # define OZW_FATAL_ERROR(exitCode, msg) Log::Write( LogLevel_Error,"Exception: %s:%d - %d - %s", std::string(__MYFUNCTION__).substr(std::string(__MYFUNCTION__).find_last_of("/\\") + 1).c_str(), __LINE__, exitCode, msg); \
181  std::cerr << "Error: "<< std::string(__MYFUNCTION__).substr(std::string(__MYFUNCTION__).find_last_of("/\\") + 1) << ":" << __LINE__ << " - " << msg << std::endl; exit(exitCode)
182 # define OZW_ERROR(exitCode, msg) Log::Write( LogLevel_Warning,"Exception: %s:%d - %d - %s", std::string(__MYFUNCTION__).substr(std::string(__MYFUNCTION__).find_last_of("/\\") + 1).c_str(), __LINE__, exitCode, msg);
183 
184 #endif
185 
186 // Declare the OpenZWave namespace
187 namespace std {}
188 namespace OpenZWave
189 {
190  // Include the STL namespace
191  using namespace std;
192 }
193 
194 // Modifications for Microsoft compilers
195 #ifdef _MSC_VER
196 
197 // Fix for namespace-related compiler bug
198 namespace OpenZWave
199 {
200 }
201 
202 // Rename safe versions of sprintf etc
203 #define snprintf sprintf_s
204 #define strcasecmp _stricmp
205 #define sscanf sscanf_s
206 
207 #endif
208 
209 // Modifications for MiNGW32 compiler
210 #ifdef MINGW
211 
212 // Replace "safe" versions of sprintf
213 #define sprintf_s snprintf
214 
215 // seems some MINGW versions don't have a errno_t
216 #ifndef errno_t
217 #define errno_t int
218 #endif
219 
220 #define fopen_s fopen
221 
222 
223 #endif
224 
225 //#define MAX_TRIES 3 // Retry sends up to 3 times
226 #define MAX_TRIES 1 // set this to one, as I believe now that a ACK failure is indication that the device is offline, hence additional attempts will not work.
227 #define MAX_MAX_TRIES 7 // Don't exceed this retry limit
228 #define ACK_TIMEOUT 1000 // How long to wait for an ACK
229 #define BYTE_TIMEOUT 150
230 //#define RETRY_TIMEOUT 40000 // Retry send after 40 seconds
231 #define RETRY_TIMEOUT 10000 // Retry send after 10 seconds (we might need to keep this below 10 for Security CC to function correctly)
232 
233 #define SOF 0x01
234 #define ACK 0x06
235 #define NAK 0x15
236 #define CAN 0x18
237 
238 #define NUM_NODE_BITFIELD_BYTES 29 // 29 bytes = 232 bits, one for each possible node in the network.
239 
240 #define REQUEST 0x00
241 #define RESPONSE 0x01
242 
243 #define ZW_CLOCK_SET 0x30
244 
245 #define TRANSMIT_OPTION_ACK 0x01
246 #define TRANSMIT_OPTION_LOW_POWER 0x02
247 #define TRANSMIT_OPTION_AUTO_ROUTE 0x04
248 #define TRANSMIT_OPTION_NO_ROUTE 0x10
249 #define TRANSMIT_OPTION_EXPLORE 0x20
250 
251 #define TRANSMIT_COMPLETE_OK 0x00
252 #define TRANSMIT_COMPLETE_NO_ACK 0x01
253 #define TRANSMIT_COMPLETE_FAIL 0x02
254 #define TRANSMIT_COMPLETE_NOT_IDLE 0x03
255 #define TRANSMIT_COMPLETE_NOROUTE 0x04
256 
257 #define RECEIVE_STATUS_ROUTED_BUSY 0x01
258 #define RECEIVE_STATUS_TYPE_BROAD 0x04
259 
260 #define FUNC_ID_SERIAL_API_GET_INIT_DATA 0x02
261 #define FUNC_ID_SERIAL_API_APPL_NODE_INFORMATION 0x03
262 #define FUNC_ID_APPLICATION_COMMAND_HANDLER 0x04
263 #define FUNC_ID_ZW_GET_CONTROLLER_CAPABILITIES 0x05
264 #define FUNC_ID_SERIAL_API_SET_TIMEOUTS 0x06
265 #define FUNC_ID_SERIAL_API_GET_CAPABILITIES 0x07
266 #define FUNC_ID_SERIAL_API_SOFT_RESET 0x08
267 
268 #define FUNC_ID_ZW_SEND_NODE_INFORMATION 0x12
269 #define FUNC_ID_ZW_SEND_DATA 0x13
270 #define FUNC_ID_ZW_GET_VERSION 0x15
271 #define FUNC_ID_ZW_R_F_POWER_LEVEL_SET 0x17
272 #define FUNC_ID_ZW_GET_RANDOM 0x1c
273 #define FUNC_ID_ZW_MEMORY_GET_ID 0x20
274 #define FUNC_ID_MEMORY_GET_BYTE 0x21
275 #define FUNC_ID_ZW_READ_MEMORY 0x23
276 
277 #define FUNC_ID_ZW_SET_LEARN_NODE_STATE 0x40 // Not implemented
278 #define FUNC_ID_ZW_GET_NODE_PROTOCOL_INFO 0x41 // Get protocol info (baud rate, listening, etc.) for a given node
279 #define FUNC_ID_ZW_SET_DEFAULT 0x42 // Reset controller and node info to default (original) values
280 #define FUNC_ID_ZW_NEW_CONTROLLER 0x43 // Not implemented
281 #define FUNC_ID_ZW_REPLICATION_COMMAND_COMPLETE 0x44 // Replication send data complete
282 #define FUNC_ID_ZW_REPLICATION_SEND_DATA 0x45 // Replication send data
283 #define FUNC_ID_ZW_ASSIGN_RETURN_ROUTE 0x46 // Assign a return route from the specified node to the controller
284 #define FUNC_ID_ZW_DELETE_RETURN_ROUTE 0x47 // Delete all return routes from the specified node
285 #define FUNC_ID_ZW_REQUEST_NODE_NEIGHBOR_UPDATE 0x48 // Ask the specified node to update its neighbors (then read them from the controller)
286 #define FUNC_ID_ZW_APPLICATION_UPDATE 0x49 // Get a list of supported (and controller) command classes
287 #define FUNC_ID_ZW_ADD_NODE_TO_NETWORK 0x4a // Control the addnode (or addcontroller) process...start, stop, etc.
288 #define FUNC_ID_ZW_REMOVE_NODE_FROM_NETWORK 0x4b // Control the removenode (or removecontroller) process...start, stop, etc.
289 #define FUNC_ID_ZW_CREATE_NEW_PRIMARY 0x4c // Control the createnewprimary process...start, stop, etc.
290 #define FUNC_ID_ZW_CONTROLLER_CHANGE 0x4d // Control the transferprimary process...start, stop, etc.
291 #define FUNC_ID_ZW_SET_LEARN_MODE 0x50 // Put a controller into learn mode for replication/ receipt of configuration info
292 #define FUNC_ID_ZW_ASSIGN_SUC_RETURN_ROUTE 0x51 // Assign a return route to the SUC
293 #define FUNC_ID_ZW_ENABLE_SUC 0x52 // Make a controller a Static Update Controller
294 #define FUNC_ID_ZW_REQUEST_NETWORK_UPDATE 0x53 // Network update for a SUC(?)
295 #define FUNC_ID_ZW_SET_SUC_NODE_ID 0x54 // Identify a Static Update Controller node id
296 #define FUNC_ID_ZW_DELETE_SUC_RETURN_ROUTE 0x55 // Remove return routes to the SUC
297 #define FUNC_ID_ZW_GET_SUC_NODE_ID 0x56 // Try to retrieve a Static Update Controller node id (zero if no SUC present)
298 #define FUNC_ID_ZW_REQUEST_NODE_NEIGHBOR_UPDATE_OPTIONS 0x5a // Allow options for request node neighbor update
299 #define FUNC_ID_ZW_EXPLORE_REQUEST_INCLUSION 0x5e // supports NWI
300 #define FUNC_ID_ZW_REQUEST_NODE_INFO 0x60 // Get info (supported command classes) for the specified node
301 #define FUNC_ID_ZW_REMOVE_FAILED_NODE_ID 0x61 // Mark a specified node id as failed
302 #define FUNC_ID_ZW_IS_FAILED_NODE_ID 0x62 // Check to see if a specified node has failed
303 #define FUNC_ID_ZW_REPLACE_FAILED_NODE 0x63 // Remove a failed node from the controller's list (?)
304 #define FUNC_ID_ZW_GET_ROUTING_INFO 0x80 // Get a specified node's neighbor information from the controller
305 #define FUNC_ID_SERIAL_API_SLAVE_NODE_INFO 0xA0 // Set application virtual slave node information
306 #define FUNC_ID_APPLICATION_SLAVE_COMMAND_HANDLER 0xA1 // Slave command handler
307 #define FUNC_ID_ZW_SEND_SLAVE_NODE_INFO 0xA2 // Send a slave node information frame
308 #define FUNC_ID_ZW_SEND_SLAVE_DATA 0xA3 // Send data from slave
309 #define FUNC_ID_ZW_SET_SLAVE_LEARN_MODE 0xA4 // Enter slave learn mode
310 #define FUNC_ID_ZW_GET_VIRTUAL_NODES 0xA5 // Return all virtual nodes
311 #define FUNC_ID_ZW_IS_VIRTUAL_NODE 0xA6 // Virtual node test
312 #define FUNC_ID_ZW_SET_PROMISCUOUS_MODE 0xD0 // Set controller into promiscuous mode to listen to all frames
313 #define FUNC_ID_PROMISCUOUS_APPLICATION_COMMAND_HANDLER 0xD1
314 
315 #define ADD_NODE_ANY 0x01
316 #define ADD_NODE_CONTROLLER 0x02
317 #define ADD_NODE_SLAVE 0x03
318 #define ADD_NODE_EXISTING 0x04
319 #define ADD_NODE_STOP 0x05
320 #define ADD_NODE_STOP_FAILED 0x06
321 
322 #define ADD_NODE_STATUS_LEARN_READY 0x01
323 #define ADD_NODE_STATUS_NODE_FOUND 0x02
324 #define ADD_NODE_STATUS_ADDING_SLAVE 0x03
325 #define ADD_NODE_STATUS_ADDING_CONTROLLER 0x04
326 #define ADD_NODE_STATUS_PROTOCOL_DONE 0x05
327 #define ADD_NODE_STATUS_DONE 0x06
328 #define ADD_NODE_STATUS_FAILED 0x07
329 
330 #define REMOVE_NODE_ANY 0x01
331 #define REMOVE_NODE_CONTROLLER 0x02
332 #define REMOVE_NODE_SLAVE 0x03
333 #define REMOVE_NODE_STOP 0x05
334 
335 #define REMOVE_NODE_STATUS_LEARN_READY 0x01
336 #define REMOVE_NODE_STATUS_NODE_FOUND 0x02
337 #define REMOVE_NODE_STATUS_REMOVING_SLAVE 0x03
338 #define REMOVE_NODE_STATUS_REMOVING_CONTROLLER 0x04
339 #define REMOVE_NODE_STATUS_DONE 0x06
340 #define REMOVE_NODE_STATUS_FAILED 0x07
341 
342 #define CREATE_PRIMARY_START 0x02
343 #define CREATE_PRIMARY_STOP 0x05
344 #define CREATE_PRIMARY_STOP_FAILED 0x06
345 
346 #define CONTROLLER_CHANGE_START 0x02
347 #define CONTROLLER_CHANGE_STOP 0x05
348 #define CONTROLLER_CHANGE_STOP_FAILED 0x06
349 
350 #define LEARN_MODE_STARTED 0x01
351 #define LEARN_MODE_DONE 0x06
352 #define LEARN_MODE_FAILED 0x07
353 #define LEARN_MODE_DELETED 0x80
354 
355 #define REQUEST_NEIGHBOR_UPDATE_STARTED 0x21
356 #define REQUEST_NEIGHBOR_UPDATE_DONE 0x22
357 #define REQUEST_NEIGHBOR_UPDATE_FAILED 0x23
358 
359 #define FAILED_NODE_OK 0x00
360 #define FAILED_NODE_REMOVED 0x01
361 #define FAILED_NODE_NOT_REMOVED 0x02
362 
363 #define FAILED_NODE_REPLACE_WAITING 0x03
364 #define FAILED_NODE_REPLACE_DONE 0x04
365 #define FAILED_NODE_REPLACE_FAILED 0x05
366 
367 #define FAILED_NODE_REMOVE_STARTED 0x00
368 #define FAILED_NODE_NOT_PRIMARY_CONTROLLER 0x02
369 #define FAILED_NODE_NO_CALLBACK_FUNCTION 0x04
370 #define FAILED_NODE_NOT_FOUND 0x08
371 #define FAILED_NODE_REMOVE_PROCESS_BUSY 0x10
372 #define FAILED_NODE_REMOVE_FAIL 0x20
373 
374 #define SUC_UPDATE_DONE 0x00
375 #define SUC_UPDATE_ABORT 0x01
376 #define SUC_UPDATE_WAIT 0x02
377 #define SUC_UPDATE_DISABLED 0x03
378 #define SUC_UPDATE_OVERFLOW 0x04
379 
380 #define SUC_FUNC_BASIC_SUC 0x00
381 #define SUC_FUNC_NODEID_SERVER 0x01
382 
383 #define UPDATE_STATE_NODE_INFO_RECEIVED 0x84
384 #define UPDATE_STATE_NODE_INFO_REQ_DONE 0x82
385 #define UPDATE_STATE_NODE_INFO_REQ_FAILED 0x81
386 #define UPDATE_STATE_ROUTING_PENDING 0x80
387 #define UPDATE_STATE_NEW_ID_ASSIGNED 0x40
388 #define UPDATE_STATE_DELETE_DONE 0x20
389 #define UPDATE_STATE_SUC_ID 0x10
390 
391 #define APPLICATION_NODEINFO_LISTENING 0x01
392 #define APPLICATION_NODEINFO_OPTIONAL_FUNCTIONALITY 0x02
393 
394 #define SLAVE_ASSIGN_COMPLETE 0x00
395 #define SLAVE_ASSIGN_NODEID_DONE 0x01 // Node ID has been assigned
396 #define SLAVE_ASSIGN_RANGE_INFO_UPDATE 0x02 // Node is doing neighbor discovery
397 
398 #define SLAVE_LEARN_MODE_DISABLE 0x00 // disable add/remove virtual slave nodes
399 #define SLAVE_LEARN_MODE_ENABLE 0x01 // enable ability to include/exclude virtual slave nodes
400 #define SLAVE_LEARN_MODE_ADD 0x02 // add node directly but only if primary/inclusion controller
401 #define SLAVE_LEARN_MODE_REMOVE 0x03 // remove node directly but only if primary/inclusion controller
402 
403 #define OPTION_HIGH_POWER 0x80
404 #define OPTION_NWI 0x40 // NWI Inclusion
405 //Device request related
406 #define BASIC_SET 0x01
407 #define BASIC_REPORT 0x03
408 
409 #define COMMAND_CLASS_BASIC 0x20
410 #define COMMAND_CLASS_CONTROLLER_REPLICATION 0x21
411 #define COMMAND_CLASS_APPLICATION_STATUS 0x22
412 #define COMMAND_CLASS_HAIL 0x82
413 
414 /* library types */
415 #define ZW_LIB_CONTROLLER_STATIC 0x01
416 #define ZW_LIB_CONTROLLER 0x02
417 #define ZW_LIB_SLAVE_ENHANCED 0x03
418 #define ZW_LIB_SLAVE 0x04
419 #define ZW_LIB_INSTALLER 0x05
420 #define ZW_LIB_SLAVE_ROUTING 0x06
421 #define ZW_LIB_CONTROLLER_BRIDGE 0x07
422 #define ZW_LIB_DUT 0x08
423 
424 
425 
426 #endif // _Defs_H
Definition: Bitfield.h:34
float float32
Definition: Defs.h:108
unsigned short uint16
Definition: Defs.h:93
uint32_t _v
Definition: Defs.h:112
signed short int16
Definition: Defs.h:92
signed char int8
Definition: Defs.h:89
signed int int32
Definition: Defs.h:95
unsigned int uint32
Definition: Defs.h:96
struct ozwversion ozwversion
Definition: Defs.h:111
double float64
Definition: Defs.h:109
unsigned char uint8
Definition: Defs.h:90