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