OpenZWave Library  1.6.885
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;
76  class ManufacturerSpecificDB;
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 
332  string m_libraryVersion; // Version of the Z-Wave Library used by the controller.
333  string m_libraryTypeName; // Name describing the library type.
334  uint8 m_libraryType; // Type of library used by the controller.
335 
336  uint8 m_serialAPIVersion[2];
337  uint16 m_manufacturerId;
338  uint16 m_productType;
339  uint16 m_productId;
340  uint8 m_apiMask[32];
341 
342  uint8 m_initVersion; // Version of the Serial API used by the controller.
343  uint8 m_initCaps; // Set of flags indicating the serial API capabilities (See IsSlave, HasTimerSupport, IsPrimaryController and IsStaticUpdateController above).
344  uint8 m_controllerCaps; // Set of flags indicating the controller's capabilities (See IsInclusionController above).
345  bool m_hasExtendedTxStatus; // True if the controller accepted SERIAL_API_SETUP_CMD_TX_STATUS_REPORT
346  uint8 m_Controller_nodeId; // Z-Wave Controller's own node ID.
347  Node* m_nodes[256]; // Array containing all the node objects.
348  Internal::Platform::Mutex* m_nodeMutex; // Serializes access to node data
349 
350  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.
351 
352  uint8 m_transmitOptions;
353 
354  //-----------------------------------------------------------------------------
355  // Receiving Z-Wave messages
356  //-----------------------------------------------------------------------------
357  private:
358  bool ReadMsg();
359  void ProcessMsg(uint8* _data, uint8 _length);
360 
361  void HandleGetVersionResponse(uint8* _data);
362  void HandleGetRandomResponse(uint8* _data);
363  void HandleSerialAPISetupResponse(uint8* _data);
364  void HandleGetControllerCapabilitiesResponse(uint8* _data);
365  void HandleGetSerialAPICapabilitiesResponse(uint8* _data);
366  void HandleSerialAPISoftResetResponse(uint8* _data);
367  void HandleEnableSUCResponse(uint8* _data);
368  void HandleSetSUCNodeIdResponse(uint8* _data);
369  void HandleGetSUCNodeIdResponse(uint8* _data);
370  void HandleMemoryGetIdResponse(uint8* _data);
383  void HandleSerialAPIGetInitDataResponse(uint8* _data);
384  void HandleGetNodeProtocolInfoResponse(uint8* _data);
385  bool HandleRemoveFailedNodeResponse(uint8* _data);
386  void HandleIsFailedNodeResponse(uint8* _data);
387  bool HandleReplaceFailedNodeResponse(uint8* _data);
388  bool HandleAssignReturnRouteResponse(uint8* _data);
389  bool HandleDeleteReturnRouteResponse(uint8* _data);
390  void HandleSendNodeInformationRequest(uint8* _data);
391  void HandleSendDataResponse(uint8* _data, bool _replication);
392  bool HandleNetworkUpdateResponse(uint8* _data);
393  void HandleGetRoutingInfoResponse(uint8* _data);
394 
395  void HandleSendDataRequest(uint8* _data, uint8 _length, bool _replication);
396  void HandleAddNodeToNetworkRequest(uint8* _data);
397  void HandleCreateNewPrimaryRequest(uint8* _data);
398  void HandleControllerChangeRequest(uint8* _data);
399  void HandleSetLearnModeRequest(uint8* _data);
400  void HandleRemoveFailedNodeRequest(uint8* _data);
401  void HandleReplaceFailedNodeRequest(uint8* _data);
402  void HandleRemoveNodeFromNetworkRequest(uint8* _data);
403  void HandleApplicationCommandHandlerRequest(uint8* _data, bool encrypted);
404  void HandlePromiscuousApplicationCommandHandlerRequest(uint8* _data);
405  void HandleAssignReturnRouteRequest(uint8* _data);
406  void HandleDeleteReturnRouteRequest(uint8* _data);
407  void HandleNodeNeighborUpdateRequest(uint8* _data);
408  void HandleNetworkUpdateRequest(uint8* _data);
409  bool HandleApplicationUpdateRequest(uint8* _data);
410  bool HandleRfPowerLevelSetResponse(uint8* _data);
411  bool HandleSerialApiSetTimeoutsResponse(uint8* _data);
412  bool HandleMemoryGetByteResponse(uint8* _data);
413  bool HandleReadMemoryResponse(uint8* _data);
414  void HandleGetVirtualNodesResponse(uint8* _data);
415  bool HandleSetSlaveLearnModeResponse(uint8* _data);
416  void HandleSetSlaveLearnModeRequest(uint8* _data);
417  bool HandleSendSlaveNodeInfoResponse(uint8* _data);
418  void HandleSendSlaveNodeInfoRequest(uint8* _data);
419  void HandleApplicationSlaveCommandRequest(uint8* _data);
420  void HandleSerialAPIResetRequest(uint8* _data);
421 
422  void CommonAddNodeStatusRequestHandler(uint8 _funcId, uint8* _data);
423 
424  bool m_waitingForAck; // True when we are waiting for an ACK from the dongle
425  uint8 m_expectedCallbackId; // If non-zero, we wait for a message with this callback Id
426  uint8 m_expectedReply; // If non-zero, we wait for a message with this function Id
427  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
428  uint8 m_expectedNodeId; // If we are waiting for a FUNC_ID_APPLICATION_COMMAND_HANDLER, make sure we only accept it from this node.
429 
430  //-----------------------------------------------------------------------------
431  // Polling Z-Wave devices
432  //-----------------------------------------------------------------------------
433  private:
434  int32 GetPollInterval()
435  {
436  return m_pollInterval;
437  }
438  void SetPollInterval(int32 _milliseconds, bool _bIntervalBetweenPolls)
439  {
440  m_pollInterval = _milliseconds;
441  m_bIntervalBetweenPolls = _bIntervalBetweenPolls;
442  }
443  bool EnablePoll(const ValueID &_valueId, uint8 _intensity = 1);
444  bool DisablePoll(const ValueID &_valueId);
445  bool isPolled(const ValueID &_valueId);
446  void SetPollIntensity(const ValueID &_valueId, uint8 _intensity);
447  static void PollThreadEntryPoint(Internal::Platform::Event* _exitEvent, void* _context);
448  void PollThreadProc(Internal::Platform::Event* _exitEvent);
449 
450  Internal::Platform::Thread* m_pollThread; // Thread for polling devices on the Z-Wave network
451  struct PollEntry
452  {
453  ValueID m_id;
454  uint8 m_pollCounter;
456  list<PollEntry> m_pollList; // List of nodes that need to be polled
458  Internal::Platform::Mutex* m_pollMutex; // Serialize access to the polling list
459  int32 m_pollInterval; // Time interval during which all nodes must be polled
460  bool m_bIntervalBetweenPolls; // if true, the library intersperses m_pollInterval between polls; if false, the library attempts to complete all polls within m_pollInterval
461 
462  //-----------------------------------------------------------------------------
463  // Retrieving Node information
464  //-----------------------------------------------------------------------------
465  public:
466  uint8 GetNodeNumber(Internal::Msg const* _msg) const
467  {
468  return (_msg == NULL ? 0 : _msg->GetTargetNodeId());
469  }
470 
471  private:
483  void InitNode(uint8 const _nodeId, bool newNode = false, bool secure = false, uint8 const *_protocolInfo = NULL, uint8 const _length = 0);
484 
485  void InitAllNodes(); // Delete all nodes and fetch the data from the Z-Wave network again.
486 
487  bool IsNodeListeningDevice(uint8 const _nodeId);
488  bool IsNodeFrequentListeningDevice(uint8 const _nodeId);
489  bool IsNodeBeamingDevice(uint8 const _nodeId);
490  bool IsNodeRoutingDevice(uint8 const _nodeId);
491  bool IsNodeSecurityDevice(uint8 const _nodeId);
492  uint32 GetNodeMaxBaudRate(uint8 const _nodeId);
493  uint8 GetNodeVersion(uint8 const _nodeId);
494  uint8 GetNodeSecurity(uint8 const _nodeId);
495  uint8 GetNodeBasic(uint8 const _nodeId);
496  uint8 GetNodeGeneric(uint8 const _nodeId);
497  uint8 GetNodeSpecific(uint8 const _nodeId);
498  string GetNodeType(uint8 const _nodeId);
499  uint32 GetNodeNeighbors(uint8 const _nodeId, uint8** o_neighbors);
500 
501  string GetNodeManufacturerName(uint8 const _nodeId);
502  string GetNodeProductName(uint8 const _nodeId);
503  string GetNodeName(uint8 const _nodeId);
504  string GetNodeLocation(uint8 const _nodeId);
505  uint16 GetNodeDeviceType(uint8 const _nodeId);
506  string GetNodeDeviceTypeString(uint8 const _nodeId);
507  uint8 GetNodeRole(uint8 const _nodeId);
508  string GetNodeRoleString(uint8 const _nodeId);
509  uint8 GetNodePlusType(uint8 const _nodeId);
510  string GetNodePlusTypeString(uint8 const _nodeId);
511  bool IsNodeZWavePlus(uint8 const _nodeId);
512 
513  uint16 GetNodeManufacturerId(uint8 const _nodeId);
514  uint16 GetNodeProductType(uint8 const _nodeId);
515  uint16 GetNodeProductId(uint8 const _nodeId);
516  void SetNodeManufacturerName(uint8 const _nodeId, string const& _manufacturerName);
517  void SetNodeProductName(uint8 const _nodeId, string const& _productName);
518  void SetNodeName(uint8 const _nodeId, string const& _nodeName);
519  void SetNodeLocation(uint8 const _nodeId, string const& _location);
520  void SetNodeLevel(uint8 const _nodeId, uint8 const _level);
521  void SetNodeOn(uint8 const _nodeId);
522  void SetNodeOff(uint8 const _nodeId);
523 
524  Internal::VC::Value* GetValue(ValueID const& _id);
525 
526  bool IsAPICallSupported(uint8 const _apinum) const
527  {
528  return ((m_apiMask[(_apinum - 1) >> 3] & (1 << ((_apinum - 1) & 0x07))) != 0);
529  }
530  void SetAPICall(uint8 const _apinum, bool _toSet)
531  {
532  if (_toSet)
533  {
534  m_apiMask[(_apinum - 1) >> 3] |= (1 << ((_apinum - 1) & 0x07));
535  }
536  else
537  {
538  m_apiMask[(_apinum - 1) >> 3] &= ~(1 << ((_apinum - 1) & 0x07));
539  }
540  }
541  uint8 NodeFromMessage(uint8 const* buffer);
542 
543  //-----------------------------------------------------------------------------
544  // Controller commands
545  //-----------------------------------------------------------------------------
546  public:
553  {
554  ControllerCommand_None = 0,
570  ControllerCommand_DeleteButton
571  };
572 
579  {
580  ControllerState_Normal = 0,
590  ControllerState_NodeFailed
591  };
592 
598  {
599  ControllerError_None = 0,
611  ControllerError_Overflow
612  };
613 
614  typedef void (*pfnControllerCallback_t)(ControllerState _state, ControllerError _err, void* _context);
615 
616  private:
617  // The public interface is provided via the wrappers in the Manager class
618  void ResetController(Internal::Platform::Event* _evt);
619  void SoftReset();
620  void RequestNodeNeighbors(uint8 const _nodeId, uint32 const _requestFlags);
621 
622  bool BeginControllerCommand(ControllerCommand _command, pfnControllerCallback_t _callback, void* _context, bool _highPower, uint8 _nodeId, uint8 _arg);
623  bool CancelControllerCommand();
624  void AddNodeStop(uint8 const _funcId); // Handle different controller behaviors
625 
626  struct ControllerCommandItem
627  {
628  ControllerState m_controllerState;
629  bool m_controllerStateChanged;
630  bool m_controllerCommandDone;
631  ControllerCommand m_controllerCommand;
632  pfnControllerCallback_t m_controllerCallback;
633  ControllerError m_controllerReturnError;
634  void* m_controllerCallbackContext;
635  bool m_highPower;
636  bool m_controllerAdded;
637  uint8 m_controllerCommandNode;
638  uint8 m_controllerCommandArg;
639  uint8 m_controllerDeviceProtocolInfo[254];
640  uint8 m_controllerDeviceProtocolInfoLength;
641  };
642 
643  ControllerCommandItem* m_currentControllerCommand;
644 
645  void DoControllerCommand();
646  void UpdateControllerState(ControllerState const _state, ControllerError const _error = ControllerError_None);
647 
648  uint8 m_SUCNodeId;
649 
650  void UpdateNodeRoutes(uint8 const_nodeId, bool _doUpdate = false);
651 
652  Internal::Platform::Event* m_controllerResetEvent;
653 
654  //-----------------------------------------------------------------------------
655  // Sending Z-Wave messages
656  //-----------------------------------------------------------------------------
657  public:
658  enum MsgQueue
659  {
660  MsgQueue_Command = 0,
667  MsgQueue_Count // Number of message queues
668  };
669 
670  void SendMsg(Internal::Msg* _msg, MsgQueue const _queue);
671 
676  {
677  return m_transmitOptions;
678  }
679 
680  private:
698  bool WriteNextMsg(MsgQueue const _queue); // Extracts the first message from the queue, and makes it the current one.
699  bool WriteMsg(string const &str); // Sends the current message to the Z-Wave network
700  void RemoveCurrentMsg(); // Deletes the current message and cleans up the callback etc states
701  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.
702  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.
703  bool IsExpectedReply(uint8 const _nodeId); // Determine if reply message is the one we are expecting
704  void SendQueryStageComplete(uint8 const _nodeId, Node::QueryStage const _stage);
705  void RetryQueryStageComplete(uint8 const _nodeId, Node::QueryStage const _stage);
706  void CheckCompletedNodeQueries(); // Send notifications if all awake and/or sleeping nodes have completed their queries
707 
708  // Requests to be sent to nodes are assigned to one of five queues.
709  // From highest to lowest priority, these are
710  //
711  // 0) The security queue, for handling encrypted messages. This is the
712  // highest priority send queue, because the security process inserts
713  // messages to handle the encryption process that must be sent before
714  // a new message can be wrapped.
715  //
716  // 1) The command queue, for controller commands. This is the 2nd highest
717  // priority send queue, because the controller command processes are not
718  // permitted to be interrupted by other requests.
719  //
720  // 2) The controller queue exists to handle multi-step controller commands. These
721  // typically require user interaction or affect the network in some way.
722  //
723  // 3) The No Operation command class queue. This is used for device probing
724  // at startup as well as network diagnostics.
725  //
726  // 4) The wakeup queue. This holds messages that have been held for a
727  // sleeping device that has now woken up. These get a high priority
728  // because such devices do not stay awake for very long.
729  //
730  // 5) The send queue. This is for normal messages, usually triggered by
731  // a user interaction with the application.
732  //
733  // 6) The query queue. For node query messages sent when a new node is
734  // discovered. The query process generates a large number of requests,
735  // so the query queue has a low priority to avoid making the system
736  // unresponsive.
737  //
738  // 7) The poll queue. Requests to devices that need their state polling
739  // at regular intervals. These are of the lowest priority, and are only
740  // sent when nothing else is going on
741  //
742  enum MsgQueueCmd
743  {
744  MsgQueueCmd_SendMsg = 0,
745  MsgQueueCmd_QueryStageComplete,
746  MsgQueueCmd_Controller,
747  MsgQueueCmd_ReloadNode
748  };
749 
750  class MsgQueueItem
751  {
752  public:
753  MsgQueueItem() :
754  m_msg(NULL), m_nodeId(0), m_queryStage(Node::QueryStage_None), m_retry(false), m_cci(NULL)
755  {
756  }
757 
758  bool operator ==(MsgQueueItem const& _other) const
759  {
760  if (_other.m_command == m_command)
761  {
762  if (m_command == MsgQueueCmd_SendMsg)
763  {
764  return ((*_other.m_msg) == (*m_msg));
765  }
766  else if (m_command == MsgQueueCmd_QueryStageComplete)
767  {
768  return ((_other.m_nodeId == m_nodeId) && (_other.m_queryStage == m_queryStage));
769  }
770  else if (m_command == MsgQueueCmd_Controller)
771  {
772  return ((_other.m_cci->m_controllerCommand == m_cci->m_controllerCommand) && (_other.m_cci->m_controllerCallback == m_cci->m_controllerCallback));
773  }
774  else if (m_command == MsgQueueCmd_ReloadNode)
775  {
776  return (_other.m_nodeId == m_nodeId);
777  }
778 
779  }
780 
781  return false;
782  }
783 
784  MsgQueueCmd m_command;
785  Internal::Msg* m_msg;
786  uint8 m_nodeId;
787  Node::QueryStage m_queryStage;
788  bool m_retry;
789  ControllerCommandItem* m_cci;
790  };
791 
793  list<MsgQueueItem> m_msgQueue[MsgQueue_Count];OPENZWAVE_EXPORT_WARNINGS_ON
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 
867  list<Notification*> m_notifications;
869  Internal::Platform::Event* m_notificationsEvent;
870 
871  //-----------------------------------------------------------------------------
872  // Statistics
873  //-----------------------------------------------------------------------------
874  public:
875  struct DriverData
876  {
877  uint32 m_SOFCnt; // Number of SOF bytes received
878  uint32 m_ACKWaiting; // Number of unsolicited messages while waiting for an ACK
879  uint32 m_readAborts; // Number of times read were aborted due to timeouts
880  uint32 m_badChecksum; // Number of bad checksums
881  uint32 m_readCnt; // Number of messages successfully read
882  uint32 m_writeCnt; // Number of messages successfully sent
883  uint32 m_CANCnt; // Number of CAN bytes received
884  uint32 m_NAKCnt; // Number of NAK bytes received
885  uint32 m_ACKCnt; // Number of ACK bytes received
886  uint32 m_OOFCnt; // Number of bytes out of framing
887  uint32 m_dropped; // Number of messages dropped & not delivered
888  uint32 m_retries; // Number of messages retransmitted
889  uint32 m_callbacks; // Number of unexpected callbacks
890  uint32 m_badroutes; // Number of failed messages due to bad route response
891  uint32 m_noack; // Number of no ACK returned errors
892  uint32 m_netbusy; // Number of network busy/failure messages
893  uint32 m_notidle; // Number of RF Network Busy messages
894  uint32 m_txverified; // Number of TX Verified messages
895  uint32 m_nondelivery; // Number of messages not delivered to network
896  uint32 m_routedbusy; // Number of messages received with routed busy status
897  uint32 m_broadcastReadCnt; // Number of broadcasts read
898  uint32 m_broadcastWriteCnt; // Number of broadcasts sent
899  };
900  void LogDriverStatistics();
901 
902  private:
903  void GetDriverStatistics(DriverData* _data);
904  void GetNodeStatistics(uint8 const _nodeId, Node::NodeData* _data);
905 
906  uint32 m_SOFCnt; // Number of SOF bytes received
907  uint32 m_ACKWaiting; // Number of unsolicited messages while waiting for an ACK
908  uint32 m_readAborts; // Number of times read were aborted due to timeouts
909  uint32 m_badChecksum; // Number of bad checksums
910  uint32 m_readCnt; // Number of messages successfully read
911  uint32 m_writeCnt; // Number of messages successfully sent
912  uint32 m_CANCnt; // Number of CAN bytes received
913  uint32 m_NAKCnt; // Number of NAK bytes received
914  uint32 m_ACKCnt; // Number of ACK bytes received
915  uint32 m_OOFCnt; // Number of bytes out of framing
916  uint32 m_dropped; // Number of messages dropped & not delivered
917  uint32 m_retries; // Number of retransmitted messages
918  uint32 m_callbacks; // Number of unexpected callbacks
919  uint32 m_badroutes; // Number of failed messages due to bad route response
920  uint32 m_noack; // Number of no ACK returned errors
921  uint32 m_netbusy; // Number of network busy/failure messages
922  uint32 m_notidle; // Number of not idle messages
923  uint32 m_txverified; // Number of TX Verified messages
924  uint32 m_nondelivery; // Number of messages not delivered to network
925  uint32 m_routedbusy; // Number of messages received with routed busy status
926  uint32 m_broadcastReadCnt; // Number of broadcasts read
927  uint32 m_broadcastWriteCnt; // Number of broadcasts sent
928  //time_t m_commandStart; // Start time of last command
929  //time_t m_timeoutLost; // Cumulative time lost to timeouts
930 
931  //-----------------------------------------------------------------------------
932  // Security Command Class Related (Version 1.1)
933  //-----------------------------------------------------------------------------
934  public:
935  aes_encrypt_ctx *GetAuthKey();
936  aes_encrypt_ctx *GetEncKey();
937  bool isNetworkKeySet();
938 
939  private:
940  bool initNetworkKeys(bool newnode);
941  uint8 *GetNetworkKey();
942  bool SendEncryptedMessage();
943  bool SendNonceRequest(string logmsg);
944  void SendNonceKey(uint8 nodeId, uint8 *nonce);
945  aes_encrypt_ctx *AuthKey;
946  aes_encrypt_ctx *EncryptKey;
947  uint8 m_nonceReportSent;
948  uint8 m_nonceReportSentAttempt;
949  bool m_inclusionkeySet;
950 
951  //-----------------------------------------------------------------------------
952  // Event Signaling for DNS and HTTP Threads
953  //-----------------------------------------------------------------------------
954  private:
955  struct EventMsg
956  {
957  enum EventType
958  {
959  Event_DNS = 1,
960  Event_Http
961  };
962  EventType type;
963  union
964  {
965  Internal::DNSLookup *lookup;
966  Internal::HttpDownload *httpdownload;
967  } event;
968  };
969 
970  void SubmitEventMsg(EventMsg *);
971  void ProcessEventMsg();
972 
974  list<EventMsg *> m_eventQueueMsg;OPENZWAVE_EXPORT_WARNINGS_ON
975  Internal::Platform::Event* m_queueMsgEvent; // Events for each queue, which are signalled when the queue is not empty
976  Internal::Platform::Mutex* m_eventMutex; // Serialize access to the queues
977 
978  //-----------------------------------------------------------------------------
979  // DNS Related
980  //-----------------------------------------------------------------------------
981 
982  public:
983  bool CheckNodeConfigRevision(Node *);
984  bool CheckMFSConfigRevision();
985  void ReloadNode(uint8 const _nodeId);
986 
987  private:
988  void processConfigRevision(Internal::DNSLookup *);
989 
990  //-----------------------------------------------------------------------------
991  // HTTP Client Related
992  //-----------------------------------------------------------------------------
993 
994  public:
995  bool setHttpClient(Internal::i_HttpClient *client);
996  private:
997  bool startConfigDownload(uint16 _manufacturerId, uint16 _productType, uint16 _productId, string configfile, uint8 node = 0);
998  bool startMFSDownload(string configfile);
999  bool refreshNodeConfig(uint8 node);
1000  void processDownload(Internal::HttpDownload *);
1001  Internal::i_HttpClient *m_httpClient;
1002 
1003  //-----------------------------------------------------------------------------
1004  // Metadata Related
1005  //-----------------------------------------------------------------------------
1006 
1007  public:
1008  string const GetMetaData(uint8 const _nodeId, Node::MetaDataFields _metadata);
1009  Node::ChangeLogEntry const GetChangeLog(uint8 const _nodeId, uint32_t revision);
1010 
1011  //-----------------------------------------------------------------------------
1012  // ManufacturerSpecificDB Related
1013  //-----------------------------------------------------------------------------
1014 
1015  public:
1016  Internal::ManufacturerSpecificDB *GetManufacturerSpecificDB();
1017  bool downloadConfigRevision(Node *);
1018  bool downloadMFSRevision();
1019  private:
1020  Internal::ManufacturerSpecificDB *m_mfs;
1021 
1022  };
1023 
1024 } // namespace OpenZWave
1025 
1026 #endif // _Driver_H
uint32 m_CANCnt
Definition: Driver.h:883
Definition: Bitfield.cpp:30
MsgQueue
Definition: Driver.h:658
Implements COMMAND_CLASS_SCENEACTIVATION (0x2B), a Z-Wave device command class.
Definition: SceneActivation.h:44
#define OPENZWAVE_EXPORT
Definition: Defs.h:51
unsigned short uint16
Definition: Defs.h:89
#define OPENZWAVE_EXPORT_WARNINGS_ON
Definition: Defs.h:53
uint32 m_routedbusy
Definition: Driver.h:896
uint32 m_nondelivery
Definition: Driver.h:895
Implements COMMAND_CLASS_CONTROLLER_REPLICATION (0x21), a Z-Wave device command class.
Definition: ControllerReplication.h:43
uint8 GetTransmitOptions() const
Definition: Driver.h:675
Implements a platform-independent thread management class.
Definition: Thread.h:47
uint32 m_readAborts
Definition: Driver.h:879
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:879
uint32 m_ACKWaiting
Definition: Driver.h:878
struct OpenZWave::InstanceAssociation InstanceAssociation
Internal::TimerThread * GetTimer()
Definition: Driver.h:207
QueryStage
Definition: Node.h:125
uint32 m_badChecksum
Definition: Driver.h:880
Definition: Driver.h:661
uint32 m_writeCnt
Definition: Driver.h:882
uint8 GetTargetNodeId() const
Identifies the Node ID of the "target" node (if any) for this function.
Definition: Msg.h:75
#define OPENZWAVE_EXPORT_WARNINGS_OFF
Definition: Defs.h:52
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
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:875
#define NULL
Definition: Defs.h:82
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:552
uint32 m_readCnt
Definition: Driver.h:881
Implements COMMAND_CLASS_WAKE_UP (0x84), a Z-Wave device command class.
Definition: WakeUp.h:51
ControllerError
Definition: Driver.h:597
uint32 m_OOFCnt
Definition: Driver.h:886
ControllerState
Definition: Driver.h:578
uint32 m_notidle
Definition: Driver.h:893
uint32 m_SOFCnt
Definition: Driver.h:877
ControllerInterface
Definition: Driver.h:111
uint32 m_broadcastReadCnt
Definition: Driver.h:897
The Driver class handles communication between OpenZWave and a device attached via a serial port (typ...
Definition: Driver.h:84
Definition: Node.h:786
uint32 m_badroutes
Definition: Driver.h:890
signed int int32
Definition: Defs.h:91
unsigned int uint32
Definition: Defs.h:92
Manages a group of devices (various nodes associated with each other).
Definition: Group.h:59
Implements a platform-independent TimeStamp.
Definition: TimeStamp.h:44
uint32 m_broadcastWriteCnt
Definition: Driver.h:898
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:665
uint32 m_txverified
Definition: Driver.h:894
uint32 m_callbacks
Definition: Driver.h:889
Implements a platform-independent mutex–for serializing access to a shared resource.
Definition: Mutex.h:44
uint32 m_netbusy
Definition: Driver.h:892
Definition: Driver.h:666
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:888
Definition: Driver.h:664
uint32 m_noack
Definition: Driver.h:891
uint8 GetNodeNumber(Internal::Msg const *_msg) const
Definition: Driver.h:466
uint32 m_dropped
Definition: Driver.h:887
Definition: DNSThread.h:58
uint32 m_NAKCnt
Definition: Driver.h:884
uint32 m_ACKCnt
Definition: Driver.h:885
Definition: Driver.h:663
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:237
unsigned char uint8
Definition: Defs.h:86