OpenZWave Library  1.6.936
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  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  uint8 GetNodeGeneric(uint8 const _nodeId);
495  uint8 GetNodeSpecific(uint8 const _nodeId);
496  string GetNodeType(uint8 const _nodeId);
497  uint32 GetNodeNeighbors(uint8 const _nodeId, uint8** o_neighbors);
498 
499  string GetNodeManufacturerName(uint8 const _nodeId);
500  string GetNodeProductName(uint8 const _nodeId);
501  string GetNodeName(uint8 const _nodeId);
502  string GetNodeLocation(uint8 const _nodeId);
503  uint16 GetNodeDeviceType(uint8 const _nodeId);
504  string GetNodeDeviceTypeString(uint8 const _nodeId);
505  uint8 GetNodeRole(uint8 const _nodeId);
506  string GetNodeRoleString(uint8 const _nodeId);
507  uint8 GetNodePlusType(uint8 const _nodeId);
508  string GetNodePlusTypeString(uint8 const _nodeId);
509  bool IsNodeZWavePlus(uint8 const _nodeId);
510 
511  uint16 GetNodeManufacturerId(uint8 const _nodeId);
512  uint16 GetNodeProductType(uint8 const _nodeId);
513  uint16 GetNodeProductId(uint8 const _nodeId);
514  void SetNodeManufacturerName(uint8 const _nodeId, string const& _manufacturerName);
515  void SetNodeProductName(uint8 const _nodeId, string const& _productName);
516  void SetNodeName(uint8 const _nodeId, string const& _nodeName);
517  void SetNodeLocation(uint8 const _nodeId, string const& _location);
518  void SetNodeLevel(uint8 const _nodeId, uint8 const _level);
519  void SetNodeOn(uint8 const _nodeId);
520  void SetNodeOff(uint8 const _nodeId);
521 
522  Internal::VC::Value* GetValue(ValueID const& _id);
523 
524  bool IsAPICallSupported(uint8 const _apinum) const
525  {
526  return ((m_apiMask[(_apinum - 1) >> 3] & (1 << ((_apinum - 1) & 0x07))) != 0);
527  }
528  void SetAPICall(uint8 const _apinum, bool _toSet)
529  {
530  if (_toSet)
531  {
532  m_apiMask[(_apinum - 1) >> 3] |= (1 << ((_apinum - 1) & 0x07));
533  }
534  else
535  {
536  m_apiMask[(_apinum - 1) >> 3] &= ~(1 << ((_apinum - 1) & 0x07));
537  }
538  }
539  uint8 NodeFromMessage(uint8 const* buffer);
540 
541  //-----------------------------------------------------------------------------
542  // Controller commands
543  //-----------------------------------------------------------------------------
544  public:
551  {
552  ControllerCommand_None = 0,
568  ControllerCommand_DeleteButton
569  };
570 
577  {
578  ControllerState_Normal = 0,
588  ControllerState_NodeFailed
589  };
590 
596  {
597  ControllerError_None = 0,
609  ControllerError_Overflow
610  };
611 
612  typedef void (*pfnControllerCallback_t)(ControllerState _state, ControllerError _err, void* _context);
613 
614  private:
615  // The public interface is provided via the wrappers in the Manager class
616  void ResetController(Internal::Platform::Event* _evt);
617  void SoftReset();
618  void RequestNodeNeighbors(uint8 const _nodeId, uint32 const _requestFlags);
619 
620  bool BeginControllerCommand(ControllerCommand _command, pfnControllerCallback_t _callback, void* _context, bool _highPower, uint8 _nodeId, uint8 _arg);
621  bool CancelControllerCommand();
622  void AddNodeStop(uint8 const _funcId); // Handle different controller behaviors
623 
624  struct ControllerCommandItem
625  {
626  ControllerState m_controllerState;
627  bool m_controllerStateChanged;
628  bool m_controllerCommandDone;
629  ControllerCommand m_controllerCommand;
630  pfnControllerCallback_t m_controllerCallback;
631  ControllerError m_controllerReturnError;
632  void* m_controllerCallbackContext;
633  bool m_highPower;
634  bool m_controllerAdded;
635  uint8 m_controllerCommandNode;
636  uint8 m_controllerCommandArg;
637  uint8 m_controllerDeviceProtocolInfo[254];
638  uint8 m_controllerDeviceProtocolInfoLength;
639  };
640 
641  ControllerCommandItem* m_currentControllerCommand;
642 
643  void DoControllerCommand();
644  void UpdateControllerState(ControllerState const _state, ControllerError const _error = ControllerError_None);
645 
646  uint8 m_SUCNodeId;
647 
648  void UpdateNodeRoutes(uint8 const_nodeId, bool _doUpdate = false);
649 
650  Internal::Platform::Event* m_controllerResetEvent;
651 
652  //-----------------------------------------------------------------------------
653  // Sending Z-Wave messages
654  //-----------------------------------------------------------------------------
655  public:
656  enum MsgQueue
657  {
658  MsgQueue_Command = 0,
665  MsgQueue_Count // Number of message queues
666  };
667 
668  void SendMsg(Internal::Msg* _msg, MsgQueue const _queue);
669 
674  {
675  return m_transmitOptions;
676  }
677 
678  private:
696  bool WriteNextMsg(MsgQueue const _queue); // Extracts the first message from the queue, and makes it the current one.
697  bool WriteMsg(string const &str); // Sends the current message to the Z-Wave network
698  void RemoveCurrentMsg(); // Deletes the current message and cleans up the callback etc states
699  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.
700  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.
701  bool IsExpectedReply(uint8 const _nodeId); // Determine if reply message is the one we are expecting
702  void SendQueryStageComplete(uint8 const _nodeId, Node::QueryStage const _stage);
703  void RetryQueryStageComplete(uint8 const _nodeId, Node::QueryStage const _stage);
704  void CheckCompletedNodeQueries(); // Send notifications if all awake and/or sleeping nodes have completed their queries
705 
706  // Requests to be sent to nodes are assigned to one of five queues.
707  // From highest to lowest priority, these are
708  //
709  // 0) The security queue, for handling encrypted messages. This is the
710  // highest priority send queue, because the security process inserts
711  // messages to handle the encryption process that must be sent before
712  // a new message can be wrapped.
713  //
714  // 1) The command queue, for controller commands. This is the 2nd highest
715  // priority send queue, because the controller command processes are not
716  // permitted to be interrupted by other requests.
717  //
718  // 2) The controller queue exists to handle multi-step controller commands. These
719  // typically require user interaction or affect the network in some way.
720  //
721  // 3) The No Operation command class queue. This is used for device probing
722  // at startup as well as network diagnostics.
723  //
724  // 4) The wakeup queue. This holds messages that have been held for a
725  // sleeping device that has now woken up. These get a high priority
726  // because such devices do not stay awake for very long.
727  //
728  // 5) The send queue. This is for normal messages, usually triggered by
729  // a user interaction with the application.
730  //
731  // 6) The query queue. For node query messages sent when a new node is
732  // discovered. The query process generates a large number of requests,
733  // so the query queue has a low priority to avoid making the system
734  // unresponsive.
735  //
736  // 7) The poll queue. Requests to devices that need their state polling
737  // at regular intervals. These are of the lowest priority, and are only
738  // sent when nothing else is going on
739  //
740  enum MsgQueueCmd
741  {
742  MsgQueueCmd_SendMsg = 0,
743  MsgQueueCmd_QueryStageComplete,
744  MsgQueueCmd_Controller,
745  MsgQueueCmd_ReloadNode
746  };
747 
748  class MsgQueueItem
749  {
750  public:
751  MsgQueueItem() :
752  m_msg(NULL), m_nodeId(0), m_queryStage(Node::QueryStage_None), m_retry(false), m_cci(NULL)
753  {
754  }
755 
756  bool operator ==(MsgQueueItem const& _other) const
757  {
758  if (_other.m_command == m_command)
759  {
760  if (m_command == MsgQueueCmd_SendMsg)
761  {
762  return ((*_other.m_msg) == (*m_msg));
763  }
764  else if (m_command == MsgQueueCmd_QueryStageComplete)
765  {
766  return ((_other.m_nodeId == m_nodeId) && (_other.m_queryStage == m_queryStage));
767  }
768  else if (m_command == MsgQueueCmd_Controller)
769  {
770  return ((_other.m_cci->m_controllerCommand == m_cci->m_controllerCommand) && (_other.m_cci->m_controllerCallback == m_cci->m_controllerCallback));
771  }
772  else if (m_command == MsgQueueCmd_ReloadNode)
773  {
774  return (_other.m_nodeId == m_nodeId);
775  }
776 
777  }
778 
779  return false;
780  }
781 
782  MsgQueueCmd m_command;
783  Internal::Msg* m_msg;
784  uint8 m_nodeId;
785  Node::QueryStage m_queryStage;
786  bool m_retry;
787  ControllerCommandItem* m_cci;
788  };
789 
790  list<MsgQueueItem> m_msgQueue[MsgQueue_Count];
791  Internal::Platform::Event* m_queueEvent[MsgQueue_Count]; // Events for each queue, which are signaled when the queue is not empty
792  Internal::Platform::Mutex* m_sendMutex; // Serialize access to the queues
793  Internal::Msg* m_currentMsg;
794  MsgQueue m_currentMsgQueueSource; // identifies which queue held m_currentMsg
795  Internal::Platform::TimeStamp m_resendTimeStamp;
796 
797  //-----------------------------------------------------------------------------
798  // Network functions
799  //-----------------------------------------------------------------------------
800  private:
801  void TestNetwork(uint8 const _nodeId, uint32 const _count);
802 
803  //-----------------------------------------------------------------------------
804  // Virtual Node commands
805  //-----------------------------------------------------------------------------
806  public:
811  private:
812  uint32 GetVirtualNeighbors(uint8** o_neighbors);
813  void RequestVirtualNeighbors(MsgQueue const _queue);
814  bool IsVirtualNode(uint8 const _nodeId) const
815  {
816  return ((m_virtualNeighbors[(_nodeId - 1) >> 3] & 1 << ((_nodeId - 1) & 0x07)) != 0);
817  }
818  void SendVirtualNodeInfo(uint8 const _fromNodeId, uint8 const _ToNodeId);
819  void SendSlaveLearnModeOff();
820  void SaveButtons();
821  void ReadButtons(uint8 const _nodeId);
822 
823  bool m_virtualNeighborsReceived;
824  uint8 m_virtualNeighbors[NUM_NODE_BITFIELD_BYTES]; // Bitmask containing virtual neighbors
825 
826  //-----------------------------------------------------------------------------
827  // SwitchAll
828  //-----------------------------------------------------------------------------
829  private:
830  // The public interface is provided via the wrappers in the Manager class
831  void SwitchAllOn();
832  void SwitchAllOff();
833 
834  //-----------------------------------------------------------------------------
835  // Configuration Parameters (wrappers for the Node methods)
836  //-----------------------------------------------------------------------------
837  private:
838  // The public interface is provided via the wrappers in the Manager class
839  bool SetConfigParam(uint8 const _nodeId, uint8 const _param, int32 _value, uint8 const _size);
840  void RequestConfigParam(uint8 const _nodeId, uint8 const _param);
841 
842  //-----------------------------------------------------------------------------
843  // Groups (wrappers for the Node methods)
844  //-----------------------------------------------------------------------------
845  private:
846  // The public interface is provided via the wrappers in the Manager class
847  uint8 GetNumGroups(uint8 const _nodeId);
848  uint32 GetAssociations(uint8 const _nodeId, uint8 const _groupIdx, uint8** o_associations);
849  uint32 GetAssociations(uint8 const _nodeId, uint8 const _groupIdx, InstanceAssociation** o_associations);
850  uint8 GetMaxAssociations(uint8 const _nodeId, uint8 const _groupIdx);
851  bool IsMultiInstance(uint8 const _nodeId, uint8 const _groupIdx);
852  string GetGroupLabel(uint8 const _nodeId, uint8 const _groupIdx);
853  void AddAssociation(uint8 const _nodeId, uint8 const _groupIdx, uint8 const _targetNodeId, uint8 const _instance = 0x00);
854  void RemoveAssociation(uint8 const _nodeId, uint8 const _groupIdx, uint8 const _targetNodeId, uint8 const _instance = 0x00);
855 
856  //-----------------------------------------------------------------------------
857  // Notifications
858  //-----------------------------------------------------------------------------
859  private:
860  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.
861  void NotifyWatchers(); // Passes the notifications to all the registered watcher callbacks in turn.
862  list<Notification*> m_notifications;
863  Internal::Platform::Event* m_notificationsEvent;
864 
865  //-----------------------------------------------------------------------------
866  // Statistics
867  //-----------------------------------------------------------------------------
868  public:
869  struct DriverData
870  {
871  uint32 m_SOFCnt; // Number of SOF bytes received
872  uint32 m_ACKWaiting; // Number of unsolicited messages while waiting for an ACK
873  uint32 m_readAborts; // Number of times read were aborted due to timeouts
874  uint32 m_badChecksum; // Number of bad checksums
875  uint32 m_readCnt; // Number of messages successfully read
876  uint32 m_writeCnt; // Number of messages successfully sent
877  uint32 m_CANCnt; // Number of CAN bytes received
878  uint32 m_NAKCnt; // Number of NAK bytes received
879  uint32 m_ACKCnt; // Number of ACK bytes received
880  uint32 m_OOFCnt; // Number of bytes out of framing
881  uint32 m_dropped; // Number of messages dropped & not delivered
882  uint32 m_retries; // Number of messages retransmitted
883  uint32 m_callbacks; // Number of unexpected callbacks
884  uint32 m_badroutes; // Number of failed messages due to bad route response
885  uint32 m_noack; // Number of no ACK returned errors
886  uint32 m_netbusy; // Number of network busy/failure messages
887  uint32 m_notidle; // Number of RF Network Busy messages
888  uint32 m_txverified; // Number of TX Verified messages
889  uint32 m_nondelivery; // Number of messages not delivered to network
890  uint32 m_routedbusy; // Number of messages received with routed busy status
891  uint32 m_broadcastReadCnt; // Number of broadcasts read
892  uint32 m_broadcastWriteCnt; // Number of broadcasts sent
893  };
894  void LogDriverStatistics();
895 
896  private:
897  void GetDriverStatistics(DriverData* _data);
898  void GetNodeStatistics(uint8 const _nodeId, Node::NodeData* _data);
899 
900  uint32 m_SOFCnt; // Number of SOF bytes received
901  uint32 m_ACKWaiting; // Number of unsolicited messages while waiting for an ACK
902  uint32 m_readAborts; // Number of times read were aborted due to timeouts
903  uint32 m_badChecksum; // Number of bad checksums
904  uint32 m_readCnt; // Number of messages successfully read
905  uint32 m_writeCnt; // Number of messages successfully sent
906  uint32 m_CANCnt; // Number of CAN bytes received
907  uint32 m_NAKCnt; // Number of NAK bytes received
908  uint32 m_ACKCnt; // Number of ACK bytes received
909  uint32 m_OOFCnt; // Number of bytes out of framing
910  uint32 m_dropped; // Number of messages dropped & not delivered
911  uint32 m_retries; // Number of retransmitted messages
912  uint32 m_callbacks; // Number of unexpected callbacks
913  uint32 m_badroutes; // Number of failed messages due to bad route response
914  uint32 m_noack; // Number of no ACK returned errors
915  uint32 m_netbusy; // Number of network busy/failure messages
916  uint32 m_notidle; // Number of not idle messages
917  uint32 m_txverified; // Number of TX Verified messages
918  uint32 m_nondelivery; // Number of messages not delivered to network
919  uint32 m_routedbusy; // Number of messages received with routed busy status
920  uint32 m_broadcastReadCnt; // Number of broadcasts read
921  uint32 m_broadcastWriteCnt; // Number of broadcasts sent
922  //time_t m_commandStart; // Start time of last command
923  //time_t m_timeoutLost; // Cumulative time lost to timeouts
924 
925  //-----------------------------------------------------------------------------
926  // Security Command Class Related (Version 1.1)
927  //-----------------------------------------------------------------------------
928  public:
929  aes_encrypt_ctx *GetAuthKey();
930  aes_encrypt_ctx *GetEncKey();
931  bool isNetworkKeySet();
932 
933  private:
934  bool initNetworkKeys(bool newnode);
935  uint8 *GetNetworkKey();
936  bool SendEncryptedMessage();
937  bool SendNonceRequest(string logmsg);
938  void SendNonceKey(uint8 nodeId, uint8 *nonce);
939  aes_encrypt_ctx *AuthKey;
940  aes_encrypt_ctx *EncryptKey;
941  uint8 m_nonceReportSent;
942  uint8 m_nonceReportSentAttempt;
943  bool m_inclusionkeySet;
944 
945  //-----------------------------------------------------------------------------
946  // Event Signaling for DNS and HTTP Threads
947  //-----------------------------------------------------------------------------
948  private:
949  struct EventMsg
950  {
951  enum EventType
952  {
953  Event_DNS = 1,
954  Event_Http
955  };
956  EventType type;
957  union
958  {
959  Internal::DNSLookup *lookup;
960  Internal::HttpDownload *httpdownload;
961  } event;
962  };
963 
964  void SubmitEventMsg(EventMsg *);
965  void ProcessEventMsg();
966  list<EventMsg *> m_eventQueueMsg;
967  Internal::Platform::Event* m_queueMsgEvent; // Events for each queue, which are signalled when the queue is not empty
968  Internal::Platform::Mutex* m_eventMutex; // Serialize access to the queues
969 
970  //-----------------------------------------------------------------------------
971  // DNS Related
972  //-----------------------------------------------------------------------------
973 
974  public:
975  bool CheckNodeConfigRevision(Node *);
976  bool CheckMFSConfigRevision();
977  void ReloadNode(uint8 const _nodeId);
978 
979  private:
980  void processConfigRevision(Internal::DNSLookup *);
981 
982  //-----------------------------------------------------------------------------
983  // HTTP Client Related
984  //-----------------------------------------------------------------------------
985 
986  public:
987  bool setHttpClient(Internal::i_HttpClient *client);
988  private:
989  bool startConfigDownload(uint16 _manufacturerId, uint16 _productType, uint16 _productId, string configfile, uint8 node = 0);
990  bool startMFSDownload(string configfile);
991  bool refreshNodeConfig(uint8 node);
992  void processDownload(Internal::HttpDownload *);
993  Internal::i_HttpClient *m_httpClient;
994 
995  //-----------------------------------------------------------------------------
996  // Metadata Related
997  //-----------------------------------------------------------------------------
998 
999  public:
1000  string const GetMetaData(uint8 const _nodeId, Node::MetaDataFields _metadata);
1001  Node::ChangeLogEntry const GetChangeLog(uint8 const _nodeId, uint32_t revision);
1002 
1003  //-----------------------------------------------------------------------------
1004  // ManufacturerSpecificDB Related
1005  //-----------------------------------------------------------------------------
1006 
1007  public:
1008  Internal::ManufacturerSpecificDB *GetManufacturerSpecificDB();
1009  bool downloadConfigRevision(Node *);
1010  bool downloadMFSRevision();
1011  private:
1012  Internal::ManufacturerSpecificDB *m_mfs;
1013 
1014  };
1015 
1016 } // namespace OpenZWave
1017 
1018 #endif // _Driver_H
uint32 m_CANCnt
Definition: Driver.h:877
Definition: Bitfield.cpp:30
MsgQueue
Definition: Driver.h:656
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:890
uint32 m_nondelivery
Definition: Driver.h:889
Implements COMMAND_CLASS_CONTROLLER_REPLICATION (0x21), a Z-Wave device command class.
Definition: ControllerReplication.h:43
uint8 GetTransmitOptions() const
Definition: Driver.h:673
Implements a platform-independent thread management class.
Definition: Thread.h:47
uint32 m_readAborts
Definition: Driver.h:873
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:872
struct OpenZWave::InstanceAssociation InstanceAssociation
Internal::TimerThread * GetTimer()
Definition: Driver.h:207
QueryStage
Definition: Node.h:125
uint32 m_badChecksum
Definition: Driver.h:874
Definition: Driver.h:659
uint32 m_writeCnt
Definition: Driver.h:876
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
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:869
#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:550
uint32 m_readCnt
Definition: Driver.h:875
Implements COMMAND_CLASS_WAKE_UP (0x84), a Z-Wave device command class.
Definition: WakeUp.h:51
ControllerError
Definition: Driver.h:595
uint32 m_OOFCnt
Definition: Driver.h:880
ControllerState
Definition: Driver.h:576
uint32 m_notidle
Definition: Driver.h:887
uint32 m_SOFCnt
Definition: Driver.h:871
ControllerInterface
Definition: Driver.h:111
uint32 m_broadcastReadCnt
Definition: Driver.h:891
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:884
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:59
Implements a platform-independent TimeStamp.
Definition: TimeStamp.h:44
uint32 m_broadcastWriteCnt
Definition: Driver.h:892
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:663
uint32 m_txverified
Definition: Driver.h:888
uint32 m_callbacks
Definition: Driver.h:883
Implements a platform-independent mutex–for serializing access to a shared resource.
Definition: Mutex.h:44
uint32 m_netbusy
Definition: Driver.h:886
Definition: Driver.h:664
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:882
Definition: Driver.h:662
uint32 m_noack
Definition: Driver.h:885
uint8 GetNodeNumber(Internal::Msg const *_msg) const
Definition: Driver.h:464
uint32 m_dropped
Definition: Driver.h:881
Definition: DNSThread.h:58
uint32 m_NAKCnt
Definition: Driver.h:878
uint32 m_ACKCnt
Definition: Driver.h:879
Definition: Driver.h:661
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