OpenZWave Library 1.6.0
Loading...
Searching...
No Matches
Driver.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2//
3// Driver.h
4//
5// Communicates with a Z-Wave network
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 _Driver_H
29#define _Driver_H
30
31#include <string>
32#include <map>
33#include <list>
34
35#include "Defs.h"
36#include "Group.h"
38#include "Node.h"
39#include "platform/Event.h"
40#include "platform/Mutex.h"
41#include "platform/TimeStamp.h"
42#include "aes/aescpp.h"
43
44namespace OpenZWave
45{
46 class Msg;
47 class Value;
48 class Event;
49 class Mutex;
50 class Controller;
51 class Thread;
52 class ControllerReplication;
53 class Notification;
54 class DNSThread;
55 struct DNSLookup;
56 class TimerThread;
57 class i_HttpClient;
58 struct HttpDownload;
59 class ManufacturerSpecificDB;
60
65 {
66 friend class Manager;
67 friend class Node;
68 friend class Group;
69 friend class CommandClass;
71 friend class DNSThread;
72 friend class i_HttpClient;
73 friend class Value;
74 friend class ValueStore;
75 friend class ValueButton;
76 friend class Association;
77 friend class Basic;
80 friend class NodeNaming;
81 friend class NoOperation;
82 friend class SceneActivation;
83 friend class WakeUp;
84 friend class ApplicationStatus; /* for Notification messages */
85 friend class Security;
86 friend class Msg;
88 friend class TimerThread;
89
90 //-----------------------------------------------------------------------------
91 // Controller Interfaces
92 //-----------------------------------------------------------------------------
93 public:
95 {
96 ControllerInterface_Unknown = 0,
98 ControllerInterface_Hid
99 };
100
101 //-----------------------------------------------------------------------------
102 // Construction / Destruction
103 //-----------------------------------------------------------------------------
104 private:
108 Driver( string const& _controllerPath, ControllerInterface const& _interface );
113 virtual ~Driver();
114
118 void Start();
122 static void DriverThreadEntryPoint( Event* _exitEvent, void* _context );
141 void DriverThreadProc( Event* _exitEvent );
155 bool Init( uint32 _attempts );
156
161 void RemoveQueues( uint8 const _nodeId );
162
163 Thread* m_driverThread;
164 DNSThread* m_dns;
165 Thread* m_dnsThread;
166 Mutex* m_initMutex;
167 bool m_exit;
168 bool m_init;
169 bool m_awakeNodesQueried;
170 bool m_allNodesQueried;
171 bool m_notifytransactions;
172 TimeStamp m_startTime;
174 //-----------------------------------------------------------------------------
175 // Configuration
176 //-----------------------------------------------------------------------------
177 private:
178 void RequestConfig(); // Get the network configuration from the Z-Wave network
179 bool ReadCache(); // Read the configuration from a file
180 void WriteCache(); // Save the configuration to a file
181
182 //-----------------------------------------------------------------------------
183 // Timer
184 //-----------------------------------------------------------------------------
185 private:
186 TimerThread* m_timer;
187 Thread* m_timerThread;
189 public:
190 TimerThread* GetTimer() { return m_timer; }
191
192 //-----------------------------------------------------------------------------
193 // Controller
194 //-----------------------------------------------------------------------------
195 private:
196 // Controller Capabilities (return in FUNC_ID_ZW_GET_CONTROLLER_CAPABILITIES)
197 enum
198 {
199 ControllerCaps_Secondary = 0x01,
200 ControllerCaps_OnOtherNetwork = 0x02,
201 ControllerCaps_SIS = 0x04,
202 ControllerCaps_RealPrimary = 0x08,
203 ControllerCaps_SUC = 0x10
204 };
205
206 // Init Capabilities (return in FUNC_ID_SERIAL_API_GET_INIT_DATA)
207 enum
208 {
209 InitCaps_Slave = 0x01,
210 InitCaps_TimerSupport = 0x02,
211 InitCaps_Secondary = 0x04,
212 InitCaps_SUC = 0x08
213 };
214
215 bool IsPrimaryController()const{ return ((m_initCaps & InitCaps_Secondary) == 0); }
216 bool IsStaticUpdateController()const{ return ((m_initCaps & InitCaps_SUC) != 0); }
217 bool IsBridgeController()const{ return (m_libraryType == 7); }
218 bool IsInclusionController()const{ return ((m_controllerCaps & ControllerCaps_SIS) != 0); }
219
220 bool HasExtendedTxStatus()const{ return m_hasExtendedTxStatus; }
221
222 uint32 GetHomeId()const{ return m_homeId; }
223 uint8 GetControllerNodeId()const{ return m_Controller_nodeId; }
224 uint8 GetSUCNodeId()const{ return m_SUCNodeId; }
225 uint16 GetManufacturerId()const{ return m_manufacturerId; }
226 uint16 GetProductType()const{ return m_productType; }
227 uint16 GetProductId()const{ return m_productId; }
228 string GetControllerPath()const{ return m_controllerPath; }
229 ControllerInterface GetControllerInterfaceType()const{ return m_controllerInterfaceType; }
230 string GetLibraryVersion()const{ return m_libraryVersion; }
231 string GetLibraryTypeName()const{ return m_libraryTypeName; }
232 int32 GetSendQueueCount()const
233 {
234 int32 count = 0;
235 for( int32 i=0; i<MsgQueue_Count; ++i )
236 {
237 count += (int32) (m_msgQueue[i].size());
238 }
239 return count;
240 }
241
251 Node* GetNodeUnsafe( uint8 _nodeId );
261 Node* GetNode( uint8 _nodeId );
265 //void LockNodes();
269 //void ReleaseNodes();
270
271 ControllerInterface m_controllerInterfaceType; // Specifies the controller's hardware interface
272 string m_controllerPath; // name or path used to open the controller hardware.
273 Controller* m_controller; // Handles communications with the controller hardware.
274 uint32 m_homeId; // Home ID of the Z-Wave controller. Not valid until the DriverReady notification has been received.
275
276 string m_libraryVersion; // Version of the Z-Wave Library used by the controller.
277 string m_libraryTypeName; // Name describing the library type.
278 uint8 m_libraryType; // Type of library used by the controller.
279
280 uint8 m_serialAPIVersion[2];
281 uint16 m_manufacturerId;
282 uint16 m_productType;
283 uint16 m_productId;
284 uint8 m_apiMask[32];
285
286 uint8 m_initVersion; // Version of the Serial API used by the controller.
287 uint8 m_initCaps; // Set of flags indicating the serial API capabilities (See IsSlave, HasTimerSupport, IsPrimaryController and IsStaticUpdateController above).
288 uint8 m_controllerCaps; // Set of flags indicating the controller's capabilities (See IsInclusionController above).
289 bool m_hasExtendedTxStatus; // True if the controller accepted SERIAL_API_SETUP_CMD_TX_STATUS_REPORT
290 uint8 m_Controller_nodeId; // Z-Wave Controller's own node ID.
291 Node* m_nodes[256]; // Array containing all the node objects.
292 Mutex* m_nodeMutex; // Serializes access to node data
293
294 ControllerReplication* m_controllerReplication; // Controller replication is handled separately from the other command classes, due to older hand-held controllers using invalid node IDs.
295
296 uint8 m_transmitOptions;
297
298 //-----------------------------------------------------------------------------
299 // Receiving Z-Wave messages
300 //-----------------------------------------------------------------------------
301 private:
302 bool ReadMsg();
303 void ProcessMsg( uint8* _data, uint8 _length );
304
305 void HandleGetVersionResponse( uint8* _data );
306 void HandleGetRandomResponse( uint8* _data );
307 void HandleSerialAPISetupResponse( uint8* _data );
308 void HandleGetControllerCapabilitiesResponse( uint8* _data );
309 void HandleGetSerialAPICapabilitiesResponse( uint8* _data );
310 void HandleSerialAPISoftResetResponse( uint8* _data );
311 void HandleEnableSUCResponse( uint8* _data );
312 void HandleSetSUCNodeIdResponse( uint8* _data );
313 void HandleGetSUCNodeIdResponse( uint8* _data );
314 void HandleMemoryGetIdResponse( uint8* _data );
327 void HandleSerialAPIGetInitDataResponse( uint8* _data );
328 void HandleGetNodeProtocolInfoResponse( uint8* _data );
329 bool HandleRemoveFailedNodeResponse( uint8* _data );
330 void HandleIsFailedNodeResponse( uint8* _data );
331 bool HandleReplaceFailedNodeResponse( uint8* _data );
332 bool HandleAssignReturnRouteResponse( uint8* _data );
333 bool HandleDeleteReturnRouteResponse( uint8* _data );
334 void HandleSendNodeInformationRequest( uint8* _data );
335 void HandleSendDataResponse( uint8* _data, bool _replication );
336 bool HandleNetworkUpdateResponse( uint8* _data );
337 void HandleGetRoutingInfoResponse( uint8* _data );
338
339 void HandleSendDataRequest( uint8* _data, uint8 _length, bool _replication );
340 void HandleAddNodeToNetworkRequest( uint8* _data );
341 void HandleCreateNewPrimaryRequest( uint8* _data );
342 void HandleControllerChangeRequest( uint8* _data );
343 void HandleSetLearnModeRequest( uint8* _data );
344 void HandleRemoveFailedNodeRequest( uint8* _data );
345 void HandleReplaceFailedNodeRequest( uint8* _data );
346 void HandleRemoveNodeFromNetworkRequest( uint8* _data );
347 void HandleApplicationCommandHandlerRequest( uint8* _data, bool encrypted );
348 void HandlePromiscuousApplicationCommandHandlerRequest( uint8* _data );
349 void HandleAssignReturnRouteRequest( uint8* _data );
350 void HandleDeleteReturnRouteRequest( uint8* _data );
351 void HandleNodeNeighborUpdateRequest( uint8* _data );
352 void HandleNetworkUpdateRequest( uint8* _data );
353 bool HandleApplicationUpdateRequest( uint8* _data );
354 bool HandleRfPowerLevelSetResponse( uint8* _data );
355 bool HandleSerialApiSetTimeoutsResponse( uint8* _data );
356 bool HandleMemoryGetByteResponse( uint8* _data );
357 bool HandleReadMemoryResponse( uint8* _data );
358 void HandleGetVirtualNodesResponse( uint8* _data );
359 bool HandleSetSlaveLearnModeResponse( uint8* _data );
360 void HandleSetSlaveLearnModeRequest( uint8* _data );
361 bool HandleSendSlaveNodeInfoResponse( uint8* _data );
362 void HandleSendSlaveNodeInfoRequest( uint8* _data );
363 void HandleApplicationSlaveCommandRequest( uint8* _data );
364 void HandleSerialAPIResetRequest( uint8* _data );
365
366 void CommonAddNodeStatusRequestHandler( uint8 _funcId, uint8* _data );
367
368 bool m_waitingForAck; // True when we are waiting for an ACK from the dongle
369 uint8 m_expectedCallbackId; // If non-zero, we wait for a message with this callback Id
370 uint8 m_expectedReply; // If non-zero, we wait for a message with this function Id
371 uint8 m_expectedCommandClassId; // If the expected reply is FUNC_ID_APPLICATION_COMMAND_HANDLER, this value stores the command class we're waiting to hear from
372 uint8 m_expectedNodeId; // If we are waiting for a FUNC_ID_APPLICATION_COMMAND_HANDLER, make sure we only accept it from this node.
373
374 //-----------------------------------------------------------------------------
375 // Polling Z-Wave devices
376 //-----------------------------------------------------------------------------
377 private:
378 int32 GetPollInterval(){ return m_pollInterval ; }
379 void SetPollInterval( int32 _milliseconds, bool _bIntervalBetweenPolls ){ m_pollInterval = _milliseconds; m_bIntervalBetweenPolls = _bIntervalBetweenPolls; }
380 bool EnablePoll( const ValueID &_valueId, uint8 _intensity = 1 );
381 bool DisablePoll( const ValueID &_valueId );
382 bool isPolled( const ValueID &_valueId );
383 void SetPollIntensity( const ValueID &_valueId, uint8 _intensity );
384 static void PollThreadEntryPoint( Event* _exitEvent, void* _context );
385 void PollThreadProc( Event* _exitEvent );
386
387 Thread* m_pollThread; // Thread for polling devices on the Z-Wave network
388 struct PollEntry
389 {
390 ValueID m_id;
391 uint8 m_pollCounter;
392 };
394 list<PollEntry> m_pollList; // List of nodes that need to be polled
396 Mutex* m_pollMutex; // Serialize access to the polling list
397 int32 m_pollInterval; // Time interval during which all nodes must be polled
398 bool m_bIntervalBetweenPolls; // if true, the library intersperses m_pollInterval between polls; if false, the library attempts to complete all polls within m_pollInterval
399
400 //-----------------------------------------------------------------------------
401 // Retrieving Node information
402 //-----------------------------------------------------------------------------
403 public:
404 uint8 GetNodeNumber( Msg const* _msg )const{ return ( _msg == NULL ? 0 : _msg->GetTargetNodeId() ); }
405
406 private:
418 void InitNode( uint8 const _nodeId, bool newNode = false, bool secure = false, uint8 const *_protocolInfo = NULL, uint8 const _length = 0);
419
420 void InitAllNodes(); // Delete all nodes and fetch the data from the Z-Wave network again.
421
422 bool IsNodeListeningDevice( uint8 const _nodeId );
423 bool IsNodeFrequentListeningDevice( uint8 const _nodeId );
424 bool IsNodeBeamingDevice( uint8 const _nodeId );
425 bool IsNodeRoutingDevice( uint8 const _nodeId );
426 bool IsNodeSecurityDevice( uint8 const _nodeId );
427 uint32 GetNodeMaxBaudRate( uint8 const _nodeId );
428 uint8 GetNodeVersion( uint8 const _nodeId );
429 uint8 GetNodeSecurity( uint8 const _nodeId );
430 uint8 GetNodeBasic( uint8 const _nodeId );
431 uint8 GetNodeGeneric( uint8 const _nodeId );
432 uint8 GetNodeSpecific( uint8 const _nodeId );
433 string GetNodeType( uint8 const _nodeId );
434 uint32 GetNodeNeighbors( uint8 const _nodeId, uint8** o_neighbors );
435
436 string GetNodeManufacturerName( uint8 const _nodeId );
437 string GetNodeProductName( uint8 const _nodeId );
438 string GetNodeName( uint8 const _nodeId );
439 string GetNodeLocation( uint8 const _nodeId );
440 uint16 GetNodeDeviceType( uint8 const _nodeId );
441 string GetNodeDeviceTypeString( uint8 const _nodeId );
442 uint8 GetNodeRole( uint8 const _nodeId );
443 string GetNodeRoleString( uint8 const _nodeId );
444 uint8 GetNodePlusType( uint8 const _nodeId );
445 string GetNodePlusTypeString ( uint8 const _nodeId );
446 bool IsNodeZWavePlus( uint8 const _nodeId );
447
448
449 uint16 GetNodeManufacturerId( uint8 const _nodeId );
450 uint16 GetNodeProductType( uint8 const _nodeId );
451 uint16 GetNodeProductId( uint8 const _nodeId );
452 void SetNodeManufacturerName( uint8 const _nodeId, string const& _manufacturerName );
453 void SetNodeProductName( uint8 const _nodeId, string const& _productName );
454 void SetNodeName( uint8 const _nodeId, string const& _nodeName );
455 void SetNodeLocation( uint8 const _nodeId, string const& _location );
456 void SetNodeLevel( uint8 const _nodeId, uint8 const _level );
457 void SetNodeOn( uint8 const _nodeId );
458 void SetNodeOff( uint8 const _nodeId );
459
460 Value* GetValue( ValueID const& _id );
461
462 bool IsAPICallSupported( uint8 const _apinum )const{ return (( m_apiMask[( _apinum - 1 ) >> 3] & ( 1 << (( _apinum - 1 ) & 0x07 ))) != 0 ); }
463 void SetAPICall( uint8 const _apinum, bool _toSet )
464 {
465 if( _toSet )
466 {
467 m_apiMask[( _apinum - 1 ) >> 3] |= ( 1 << (( _apinum - 1 ) & 0x07 ));
468 }
469 else
470 {
471 m_apiMask[( _apinum - 1 ) >> 3] &= ~( 1 << (( _apinum - 1 ) & 0x07 ));
472 }
473 }
474 uint8 NodeFromMessage( uint8 const* buffer );
475
476 //-----------------------------------------------------------------------------
477 // Controller commands
478 //-----------------------------------------------------------------------------
479 public:
505
525
546
547 typedef void (*pfnControllerCallback_t)( ControllerState _state, ControllerError _err, void* _context );
548
549 private:
550 // The public interface is provided via the wrappers in the Manager class
551 void ResetController( Event* _evt );
552 void SoftReset();
553 void RequestNodeNeighbors( uint8 const _nodeId, uint32 const _requestFlags );
554
555 bool BeginControllerCommand( ControllerCommand _command, pfnControllerCallback_t _callback, void* _context, bool _highPower, uint8 _nodeId, uint8 _arg );
556 bool CancelControllerCommand();
557 void AddNodeStop( uint8 const _funcId ); // Handle different controller behaviors
558
559 struct ControllerCommandItem
560 {
561 ControllerState m_controllerState;
562 bool m_controllerStateChanged;
563 bool m_controllerCommandDone;
564 ControllerCommand m_controllerCommand;
565 pfnControllerCallback_t m_controllerCallback;
566 ControllerError m_controllerReturnError;
567 void* m_controllerCallbackContext;
568 bool m_highPower;
569 bool m_controllerAdded;
570 uint8 m_controllerCommandNode;
571 uint8 m_controllerCommandArg;
572 uint8 m_controllerDeviceProtocolInfo[254];
573 uint8 m_controllerDeviceProtocolInfoLength;
574 };
575
576 ControllerCommandItem* m_currentControllerCommand;
577
578 void DoControllerCommand();
579 void UpdateControllerState( ControllerState const _state, ControllerError const _error = ControllerError_None );
580
581 uint8 m_SUCNodeId;
582
583 void UpdateNodeRoutes( uint8 const_nodeId, bool _doUpdate = false );
584
585 Event* m_controllerResetEvent;
586
587 //-----------------------------------------------------------------------------
588 // Sending Z-Wave messages
589 //-----------------------------------------------------------------------------
590 public:
592 {
593 MsgQueue_Command = 0,
600 MsgQueue_Count // Number of message queues
601 };
602
603 void SendMsg( Msg* _msg, MsgQueue const _queue );
604
608 uint8 GetTransmitOptions()const{ return m_transmitOptions; }
609
610 private:
628 bool WriteNextMsg( MsgQueue const _queue ); // Extracts the first message from the queue, and makes it the current one.
629 bool WriteMsg( string const &str); // Sends the current message to the Z-Wave network
630 void RemoveCurrentMsg(); // Deletes the current message and cleans up the callback etc states
631 bool MoveMessagesToWakeUpQueue( uint8 const _targetNodeId, bool const _move ); // If a node does not respond, and is of a type that can sleep, this method is used to move all its pending messages to another queue ready for when it wakes up next.
632 bool HandleErrorResponse( uint8 const _error, uint8 const _nodeId, char const* _funcStr, bool _sleepCheck = false ); // Handle data errors and process consistently. If message is moved to wake-up queue, return true.
633 bool IsExpectedReply( uint8 const _nodeId ); // Determine if reply message is the one we are expecting
634 void SendQueryStageComplete( uint8 const _nodeId, Node::QueryStage const _stage );
635 void RetryQueryStageComplete( uint8 const _nodeId, Node::QueryStage const _stage );
636 void CheckCompletedNodeQueries(); // Send notifications if all awake and/or sleeping nodes have completed their queries
637
638 // Requests to be sent to nodes are assigned to one of five queues.
639 // From highest to lowest priority, these are
640 //
641 // 0) The security queue, for handling encrypted messages. This is the
642 // highest priority send queue, because the security process inserts
643 // messages to handle the encryption process that must be sent before
644 // a new message can be wrapped.
645 //
646 // 1) The command queue, for controller commands. This is the 2nd highest
647 // priority send queue, because the controller command processes are not
648 // permitted to be interrupted by other requests.
649 //
650 // 2) The controller queue exists to handle multi-step controller commands. These
651 // typically require user interaction or affect the network in some way.
652 //
653 // 3) The No Operation command class queue. This is used for device probing
654 // at startup as well as network diagnostics.
655 //
656 // 4) The wakeup queue. This holds messages that have been held for a
657 // sleeping device that has now woken up. These get a high priority
658 // because such devices do not stay awake for very long.
659 //
660 // 5) The send queue. This is for normal messages, usually triggered by
661 // a user interaction with the application.
662 //
663 // 6) The query queue. For node query messages sent when a new node is
664 // discovered. The query process generates a large number of requests,
665 // so the query queue has a low priority to avoid making the system
666 // unresponsive.
667 //
668 // 7) The poll queue. Requests to devices that need their state polling
669 // at regular intervals. These are of the lowest priority, and are only
670 // sent when nothing else is going on
671 //
672 enum MsgQueueCmd
673 {
674 MsgQueueCmd_SendMsg = 0,
675 MsgQueueCmd_QueryStageComplete,
676 MsgQueueCmd_Controller,
677 MsgQueueCmd_ReloadNode
678 };
679
680 class MsgQueueItem
681 {
682 public:
683 MsgQueueItem() :
684 m_msg(NULL),
685 m_nodeId(0),
686 m_queryStage(Node::QueryStage_None),
687 m_retry(false),
688 m_cci(NULL)
689 {}
690
691 bool operator == ( MsgQueueItem const& _other )const
692 {
693 if( _other.m_command == m_command )
694 {
695 if( m_command == MsgQueueCmd_SendMsg )
696 {
697 return( (*_other.m_msg) == (*m_msg) );
698 }
699 else if( m_command == MsgQueueCmd_QueryStageComplete )
700 {
701 return( (_other.m_nodeId == m_nodeId) && (_other.m_queryStage == m_queryStage) );
702 }
703 else if( m_command == MsgQueueCmd_Controller )
704 {
705 return( (_other.m_cci->m_controllerCommand == m_cci->m_controllerCommand) && (_other.m_cci->m_controllerCallback == m_cci->m_controllerCallback) );
706 }
707 else if (m_command == MsgQueueCmd_ReloadNode )
708 {
709 return (_other.m_nodeId == m_nodeId);
710 }
711
712 }
713
714 return false;
715 }
716
717 MsgQueueCmd m_command;
718 Msg* m_msg;
719 uint8 m_nodeId;
720 Node::QueryStage m_queryStage;
721 bool m_retry;
722 ControllerCommandItem* m_cci;
723 };
724
726 list<MsgQueueItem> m_msgQueue[MsgQueue_Count];
728 Event* m_queueEvent[MsgQueue_Count]; // Events for each queue, which are signaled when the queue is not empty
729 Mutex* m_sendMutex; // Serialize access to the queues
730 Msg* m_currentMsg;
731 MsgQueue m_currentMsgQueueSource; // identifies which queue held m_currentMsg
732 TimeStamp m_resendTimeStamp;
733
734 //-----------------------------------------------------------------------------
735 // Network functions
736 //-----------------------------------------------------------------------------
737 private:
738 void TestNetwork( uint8 const _nodeId, uint32 const _count );
739
740 //-----------------------------------------------------------------------------
741 // Virtual Node commands
742 //-----------------------------------------------------------------------------
743 public:
748 private:
749 uint32 GetVirtualNeighbors( uint8** o_neighbors );
750 void RequestVirtualNeighbors( MsgQueue const _queue );
751 bool IsVirtualNode( uint8 const _nodeId )const{ return (( m_virtualNeighbors[( _nodeId - 1 ) >> 3] & 1 << (( _nodeId - 1 ) & 0x07 )) != 0 ); }
752 void SendVirtualNodeInfo( uint8 const _fromNodeId, uint8 const _ToNodeId );
753 void SendSlaveLearnModeOff();
754 void SaveButtons();
755 void ReadButtons( uint8 const _nodeId );
756
757 bool m_virtualNeighborsReceived;
758 uint8 m_virtualNeighbors[NUM_NODE_BITFIELD_BYTES]; // Bitmask containing virtual neighbors
759
760 //-----------------------------------------------------------------------------
761 // SwitchAll
762 //-----------------------------------------------------------------------------
763 private:
764 // The public interface is provided via the wrappers in the Manager class
765 void SwitchAllOn();
766 void SwitchAllOff();
767
768 //-----------------------------------------------------------------------------
769 // Configuration Parameters (wrappers for the Node methods)
770 //-----------------------------------------------------------------------------
771 private:
772 // The public interface is provided via the wrappers in the Manager class
773 bool SetConfigParam( uint8 const _nodeId, uint8 const _param, int32 _value, uint8 const _size );
774 void RequestConfigParam( uint8 const _nodeId, uint8 const _param );
775
776 //-----------------------------------------------------------------------------
777 // Groups (wrappers for the Node methods)
778 //-----------------------------------------------------------------------------
779 private:
780 // The public interface is provided via the wrappers in the Manager class
781 uint8 GetNumGroups( uint8 const _nodeId );
782 uint32 GetAssociations( uint8 const _nodeId, uint8 const _groupIdx, uint8** o_associations );
783 uint32 GetAssociations( uint8 const _nodeId, uint8 const _groupIdx, InstanceAssociation** o_associations );
784 uint8 GetMaxAssociations( uint8 const _nodeId, uint8 const _groupIdx );
785 bool IsMultiInstance( uint8 const _nodeId, uint8 const _groupIdx );
786 string GetGroupLabel( uint8 const _nodeId, uint8 const _groupIdx );
787 void AddAssociation( uint8 const _nodeId, uint8 const _groupIdx, uint8 const _targetNodeId, uint8 const _instance = 0x00 );
788 void RemoveAssociation( uint8 const _nodeId, uint8 const _groupIdx, uint8 const _targetNodeId, uint8 const _instance = 0x00 );
789
790 //-----------------------------------------------------------------------------
791 // Notifications
792 //-----------------------------------------------------------------------------
793 private:
794 void QueueNotification( Notification* _notification ); // Adds a notification to the list. Notifications are queued until a point in the thread where we know we do not have any nodes locked.
795 void NotifyWatchers(); // Passes the notifications to all the registered watcher callbacks in turn.
796
798 list<Notification*> m_notifications;
800 Event* m_notificationsEvent;
801
802 //-----------------------------------------------------------------------------
803 // Statistics
804 //-----------------------------------------------------------------------------
805 public:
807 {
808 uint32 m_SOFCnt; // Number of SOF bytes received
809 uint32 m_ACKWaiting; // Number of unsolicited messages while waiting for an ACK
810 uint32 m_readAborts; // Number of times read were aborted due to timeouts
811 uint32 m_badChecksum; // Number of bad checksums
812 uint32 m_readCnt; // Number of messages successfully read
813 uint32 m_writeCnt; // Number of messages successfully sent
814 uint32 m_CANCnt; // Number of CAN bytes received
815 uint32 m_NAKCnt; // Number of NAK bytes received
816 uint32 m_ACKCnt; // Number of ACK bytes received
817 uint32 m_OOFCnt; // Number of bytes out of framing
818 uint32 m_dropped; // Number of messages dropped & not delivered
819 uint32 m_retries; // Number of messages retransmitted
820 uint32 m_callbacks; // Number of unexpected callbacks
821 uint32 m_badroutes; // Number of failed messages due to bad route response
822 uint32 m_noack; // Number of no ACK returned errors
823 uint32 m_netbusy; // Number of network busy/failure messages
824 uint32 m_notidle; // Number of RF Network Busy messages
825 uint32 m_txverified; // Number of TX Verified messages
826 uint32 m_nondelivery; // Number of messages not delivered to network
827 uint32 m_routedbusy; // Number of messages received with routed busy status
828 uint32 m_broadcastReadCnt; // Number of broadcasts read
829 uint32 m_broadcastWriteCnt; // Number of broadcasts sent
830 };
831 void LogDriverStatistics();
832
833 private:
834 void GetDriverStatistics( DriverData* _data );
835 void GetNodeStatistics( uint8 const _nodeId, Node::NodeData* _data );
836
837 uint32 m_SOFCnt; // Number of SOF bytes received
838 uint32 m_ACKWaiting; // Number of unsolicited messages while waiting for an ACK
839 uint32 m_readAborts; // Number of times read were aborted due to timeouts
840 uint32 m_badChecksum; // Number of bad checksums
841 uint32 m_readCnt; // Number of messages successfully read
842 uint32 m_writeCnt; // Number of messages successfully sent
843 uint32 m_CANCnt; // Number of CAN bytes received
844 uint32 m_NAKCnt; // Number of NAK bytes received
845 uint32 m_ACKCnt; // Number of ACK bytes received
846 uint32 m_OOFCnt; // Number of bytes out of framing
847 uint32 m_dropped; // Number of messages dropped & not delivered
848 uint32 m_retries; // Number of retransmitted messages
849 uint32 m_callbacks; // Number of unexpected callbacks
850 uint32 m_badroutes; // Number of failed messages due to bad route response
851 uint32 m_noack; // Number of no ACK returned errors
852 uint32 m_netbusy; // Number of network busy/failure messages
853 uint32 m_notidle; // Number of not idle messages
854 uint32 m_txverified; // Number of TX Verified messages
855 uint32 m_nondelivery; // Number of messages not delivered to network
856 uint32 m_routedbusy; // Number of messages received with routed busy status
857 uint32 m_broadcastReadCnt; // Number of broadcasts read
858 uint32 m_broadcastWriteCnt; // Number of broadcasts sent
859 //time_t m_commandStart; // Start time of last command
860 //time_t m_timeoutLost; // Cumulative time lost to timeouts
861
862
863 //-----------------------------------------------------------------------------
864 // Security Command Class Related (Version 1.1)
865 //-----------------------------------------------------------------------------
866 public:
867 aes_encrypt_ctx *GetAuthKey();
868 aes_encrypt_ctx *GetEncKey();
869 bool isNetworkKeySet();
870
871 private:
872 bool initNetworkKeys(bool newnode);
873 uint8 *GetNetworkKey();
874 bool SendEncryptedMessage();
875 bool SendNonceRequest(string logmsg);
876 void SendNonceKey(uint8 nodeId, uint8 *nonce);
877 aes_encrypt_ctx *AuthKey;
878 aes_encrypt_ctx *EncryptKey;
879 uint8 m_nonceReportSent;
880 uint8 m_nonceReportSentAttempt;
881 bool m_inclusionkeySet;
882
883 //-----------------------------------------------------------------------------
884 // Event Signaling for DNS and HTTP Threads
885 //-----------------------------------------------------------------------------
886 private:
887 struct EventMsg {
888 enum EventType {
889 Event_DNS = 1,
890 Event_Http
891 };
892 EventType type;
893 union {
894 DNSLookup *lookup;
895 HttpDownload *httpdownload;
896 } event;
897 };
898
899 void SubmitEventMsg(EventMsg *);
900 void ProcessEventMsg();
901
902
904 list<EventMsg *> m_eventQueueMsg;
906 Event* m_queueMsgEvent; // Events for each queue, which are signalled when the queue is not empty
907 Mutex* m_eventMutex; // Serialize access to the queues
908
909
910 //-----------------------------------------------------------------------------
911 // DNS Related
912 //-----------------------------------------------------------------------------
913
914 public:
915 bool CheckNodeConfigRevision(Node *);
916 bool CheckMFSConfigRevision();
917 void ReloadNode(uint8 const _nodeId);
918
919 private:
920 void processConfigRevision(DNSLookup *);
921
922 //-----------------------------------------------------------------------------
923 // HTTP Client Related
924 //-----------------------------------------------------------------------------
925
926 public:
927 bool setHttpClient(i_HttpClient *client);
928 private:
929 bool startConfigDownload(uint16 _manufacturerId, uint16 _productType, uint16 _productId, string configfile, uint8 node = 0);
930 bool startMFSDownload(string configfile);
931 bool refreshNodeConfig(uint8 node);
932 void processDownload(HttpDownload *);
933 i_HttpClient *m_httpClient;
934
935 //-----------------------------------------------------------------------------
936 // Metadata Related
937 //-----------------------------------------------------------------------------
938
939 public:
940 string const GetMetaData( uint8 const _nodeId, Node::MetaDataFields _metadata );
941 Node::ChangeLogEntry const GetChangeLog( uint8 const _nodeId, uint32_t revision);
942
943
944 //-----------------------------------------------------------------------------
945 // ManufacturerSpecificDB Related
946 //-----------------------------------------------------------------------------
947
948 public:
949 ManufacturerSpecificDB *GetManufacturerSpecificDB();
950 bool downloadConfigRevision(Node *);
951 bool downloadMFSRevision();
952 private:
953 ManufacturerSpecificDB *m_mfs;
954
955 };
956
957} // namespace OpenZWave
958
959#endif // _Driver_H
unsigned short uint16
Definition Defs.h:92
#define NULL
Definition Defs.h:85
unsigned int uint32
Definition Defs.h:95
signed int int32
Definition Defs.h:94
#define NUM_NODE_BITFIELD_BYTES
Definition Defs.h:241
#define OPENZWAVE_EXPORT_WARNINGS_ON
Definition Defs.h:53
#define OPENZWAVE_EXPORT
Definition Defs.h:51
#define OPENZWAVE_EXPORT_WARNINGS_OFF
Definition Defs.h:52
unsigned char uint8
Definition Defs.h:89
Implements COMMAND_CLASS_APPLICATION_STATUS (0x22), a Z-Wave device command class.
Definition ApplicationStatus.h:39
Implements COMMAND_CLASS_ASSOCIATION (0x85), a Z-Wave device command class.
Definition Association.h:40
Implements COMMAND_CLASS_BASIC (0x20), a Z-Wave device command class.
Definition Basic.h:41
Base class for all Z-Wave command classes.
Definition CommandClass.h:56
Implements COMMAND_CLASS_CONTROLLER_REPLICATION (0x21), a Z-Wave device command class.
Definition ControllerReplication.h:39
the DNSThread provides Async DNS lookups for checking revision numbers of Config Files against the of...
Definition DNSThread.h:68
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition Driver.h:65
uint8 GetNodeNumber(Msg const *_msg) const
Definition Driver.h:404
ControllerError
Definition Driver.h:531
@ ControllerError_Busy
Definition Driver.h:541
@ ControllerError_Disabled
Definition Driver.h:543
@ ControllerError_NotSecondary
Definition Driver.h:537
@ ControllerError_NotPrimary
Definition Driver.h:538
@ ControllerError_IsPrimary
Definition Driver.h:539
@ ControllerError_Failed
Definition Driver.h:542
@ ControllerError_NodeNotFound
Definition Driver.h:534
@ ControllerError_NotBridge
Definition Driver.h:535
@ ControllerError_NotSUC
Definition Driver.h:536
@ ControllerError_ButtonNotFound
Definition Driver.h:533
@ ControllerError_NotFound
Definition Driver.h:540
uint8 GetTransmitOptions() const
Definition Driver.h:608
ControllerState
Definition Driver.h:512
@ ControllerState_Failed
Definition Driver.h:521
@ ControllerState_NodeOK
Definition Driver.h:522
@ ControllerState_Completed
Definition Driver.h:520
@ ControllerState_Waiting
Definition Driver.h:517
@ ControllerState_InProgress
Definition Driver.h:519
@ ControllerState_Cancel
Definition Driver.h:515
@ ControllerState_Sleeping
Definition Driver.h:518
@ ControllerState_Starting
Definition Driver.h:514
@ ControllerState_Error
Definition Driver.h:516
MsgQueue
Definition Driver.h:592
@ MsgQueue_Query
Definition Driver.h:598
@ MsgQueue_Send
Definition Driver.h:597
@ MsgQueue_Controller
Definition Driver.h:595
@ MsgQueue_NoOp
Definition Driver.h:594
@ MsgQueue_Poll
Definition Driver.h:599
@ MsgQueue_WakeUp
Definition Driver.h:596
ControllerInterface
Definition Driver.h:95
@ ControllerInterface_Serial
Definition Driver.h:97
ControllerCommand
Definition Driver.h:486
@ ControllerCommand_RemoveFailedNode
Definition Driver.h:492
@ ControllerCommand_AssignReturnRoute
Definition Driver.h:498
@ ControllerCommand_RequestNetworkUpdate
Definition Driver.h:496
@ ControllerCommand_RemoveDevice
Definition Driver.h:491
@ ControllerCommand_ReplicationSend
Definition Driver.h:501
@ ControllerCommand_RequestNodeNeighborUpdate
Definition Driver.h:497
@ ControllerCommand_TransferPrimaryRole
Definition Driver.h:495
@ ControllerCommand_ReplaceFailedNode
Definition Driver.h:494
@ ControllerCommand_CreateNewPrimary
Definition Driver.h:489
@ ControllerCommand_DeleteAllReturnRoutes
Definition Driver.h:499
@ ControllerCommand_SendNodeInformation
Definition Driver.h:500
@ ControllerCommand_ReceiveConfiguration
Definition Driver.h:490
@ ControllerCommand_CreateButton
Definition Driver.h:502
@ ControllerCommand_HasNodeFailed
Definition Driver.h:493
@ ControllerCommand_AddDevice
Definition Driver.h:488
TimerThread * GetTimer()
Definition Driver.h:190
Platform-independent definition of event objects.
Definition Event.h:41
Manages a group of devices (various nodes associated with each other).
Definition Group.h:50
The main public interface to OpenZWave.
Definition Manager.h:111
The _ManufacturerSpecificDB class handles the Config File Database that we use to configure devices.
Definition ManufacturerSpecificDB.h:106
Implements COMMAND_CLASS_MANUFACTURER_SPECIFIC (0x72), a Z-Wave device command class.
Definition ManufacturerSpecific.h:40
Message object to be passed to and from devices on the Z-Wave network.
Definition Msg.h:45
uint8 GetTargetNodeId() const
Identifies the Node ID of the "target" node (if any) for this function.
Definition Msg.h:67
Implements COMMAND_CLASS_MULTI_CHANNEL_ASSOCIATION (0x8E), a Z-Wave device command class.
Definition MultiChannelAssociation.h:41
Implements a platform-independent mutex–for serializing access to a shared resource.
Definition Mutex.h:41
Implements COMMAND_CLASS_NO_OPERATION (0x00), a Z-Wave device command class.
Definition NoOperation.h:39
Implements COMMAND_CLASS_NODE_NAMING (0x77), a Z-Wave device command class.
Definition NodeNaming.h:55
The Node class describes a Z-Wave node object...typically a device on the Z-Wave network.
Definition Node.h:66
QueryStage
Definition Node.h:137
Implements COMMAND_CLASS_SCENEACTIVATION (0x2B), a Z-Wave device command class.
Definition SceneActivation.h:42
Implements COMMAND_CLASS_SECURITY (0x98), a Z-Wave device command class.
Definition Security.h:65
Implements a platform-independent thread management class.
Definition Thread.h:44
Implements a platform-independent TimeStamp.
Definition TimeStamp.h:41
The TimerThread class makes it possible to schedule events to happen at a certain time in the future.
Definition TimerThread.h:56
Button value.
Definition ValueButton.h:47
Provides a unique ID for a value reported by a Z-Wave device.
Definition ValueID.h:63
Container that holds all of the values associated with a given node.
Definition ValueStore.h:45
Base class for values associated with a node.
Definition Value.h:49
Implements COMMAND_CLASS_WAKE_UP (0x84), a Z-Wave device command class.
Definition WakeUp.h:46
Definition Http.h:70
Definition Bitfield.h:35
Definition DNSThread.h:54
Definition Driver.h:807
uint32 m_noack
Definition Driver.h:822
uint32 m_retries
Definition Driver.h:819
uint32 m_badroutes
Definition Driver.h:821
uint32 m_netbusy
Definition Driver.h:823
uint32 m_readAborts
Definition Driver.h:810
uint32 m_CANCnt
Definition Driver.h:814
uint32 m_broadcastWriteCnt
Definition Driver.h:829
uint32 m_nondelivery
Definition Driver.h:826
uint32 m_writeCnt
Definition Driver.h:813
uint32 m_callbacks
Definition Driver.h:820
uint32 m_routedbusy
Definition Driver.h:827
uint32 m_dropped
Definition Driver.h:818
uint32 m_ACKCnt
Definition Driver.h:816
uint32 m_SOFCnt
Definition Driver.h:808
uint32 m_badChecksum
Definition Driver.h:811
uint32 m_OOFCnt
Definition Driver.h:817
uint32 m_broadcastReadCnt
Definition Driver.h:828
uint32 m_readCnt
Definition Driver.h:812
uint32 m_ACKWaiting
Definition Driver.h:809
uint32 m_notidle
Definition Driver.h:824
uint32 m_txverified
Definition Driver.h:825
uint32 m_NAKCnt
Definition Driver.h:815
Definition Http.h:47
Definition Node.h:659