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