Example #1
0
        public void HandleNotification(ZWNotification notification)
        {
            var notificationType = notification.GetType();

            switch (notificationType)
            {
            case ZWNotification.Type.ValueAdded:
                var addedValue = notification.GetValueID();
                Log.Debug("Node {0} Value Added: {1} - {2} - {3}", notification.GetNodeId(),
                          _manager.GetValueLabel(addedValue), GetValue(addedValue, _manager),
                          _manager.GetValueUnits(addedValue));
                var vaNode = GetNode(notification.GetHomeId(), notification.GetNodeId());
                if (vaNode != null)
                {
                    vaNode.Values.Add(addedValue);
                }
                break;

            case ZWNotification.Type.NodeAdded:
                var homeId = notification.GetHomeId();
                var nodeId = notification.GetNodeId();
                if (GetNode(homeId, nodeId) == null)
                {
                    var node = AddNode(homeId, nodeId);
                    Log.Debug("Node Added: {0}, Home: {1}", node.NodeId, node.HomeId);
                }
                break;

            default:
                Log.Trace("Unhandled ZWave Notification: {0}", notificationType.ToString());
                break;
            }
        }
Example #2
0
 public NotificationEventArgs(IZWaveManager manager, ZWNotification notification)
 {
     Manager          = manager;
     NodeId           = notification.GetNodeId();
     NotificationType = notification.GetType();
     ValueId          = notification.GetValueID();
     HomeId           = notification.GetHomeId();
 }
        private void CheckAllNodesQueried(ZWNotification notification)
        {
            var type = notification.GetType();

            if (type.Equals(ZWNotification.Type.AllNodesQueriedSomeDead) ||
                type.Equals(ZWNotification.Type.AllNodesQueried))
            {
                _allNodesQueried = true;
            }
        }
 /// <summary>
 /// Handles Notifications.
 /// </summary>
 /// <param name="notification">The notification.</param>
 public static void NotificationHandler(ZWNotification notification)
 {
     switch (notification.GetType())
     {
     case ZWNotification.Type.ControllerCommand:
     {
         MyControllerStateChangedHandler(((ZWControllerState)notification.GetEvent()));
         break;
     }
     }
 }
 private void NotificationHandler()
 {
     // Check whether all the queries on this node have completed
     if (m_notification.GetType() == ZWNotification.Type.NodeQueriesComplete)
     {
         if ((m_notification.GetHomeId() == m_homeId) && (m_notification.GetNodeId() == m_nodeId))
         {
             // Done!
             m_manager.OnNotification -= new ManagedNotificationsHandler(NotificationHandler);
             DialogResult              = DialogResult.OK;
         }
     }
 }
Example #6
0
        public static void Execute(ZWave zWave, ZWNotification notification, Action<ZWManager, ZWaveEventArgs> zWaveEvent)
        {
            var nodeId = notification.GetNodeId();
            var homeId = notification.GetHomeId();
            var node = zWave.Nodes.SingleOrDefault(x => x.ID == nodeId);

            if (zWave.HomeId == null)
                zWave.HomeId = homeId;

            var notificationType = notification.GetType();

            switch (notificationType)
            {
                case ZWNotification.Type.ValueChanged:
                    {
                        bool errorWhileLoading = false;
                        if (node.Failed)
                        {
                            zWave.Manager.RequestAllConfigParams(homeId, nodeId);
                            var sum = 0;
                            while (!node.Loaded)
                            {
                                Thread.Sleep(ZWGlobal.Constants.IterationWaitingInterval);
                                sum += ZWGlobal.Constants.IterationWaitingInterval;
                                if (sum >= ZWGlobal.Constants.MaxWaitingInterval)
                                {
                                    errorWhileLoading = true;
                                    break;
                                }
                            }
                            node.Failed = false;
                        }
                        if (!errorWhileLoading)
                        {
                            var valueId = notification.GetValueID();
                            zWaveEvent(zWave.Manager, new ZWaveEventArgs(
                                zWave,
                                zWave.Nodes.Single(x => x.ID == nodeId),
                                valueId,
                                valueId.GetValue<object>(zWave.Manager)
                                ));
                        }
                        break;
                    }

                case ZWNotification.Type.NodeAdded:
                    {
                        if (!zWave.Nodes.Any(x => x.HomeID == homeId && x.ID == notification.GetNodeId()))
                        {
                            node = new Node();
                            node.ID = notification.GetNodeId();
                            node.HomeID = homeId;
                            zWave.Manager.RequestAllConfigParams(homeId, node.ID);
                            node.RequestingValuesBegan = true;
                            zWave.Nodes.Add(node);
                        }
                        break;
                    }

                case ZWNotification.Type.NodeNew:
                    {
                        node = new Node();
                        node.ID = notification.GetNodeId();
                        node.HomeID = homeId;
                        zWave.Nodes.Add(node);
                        zWave.Manager.RequestAllConfigParams(homeId, node.ID);
                        node.RequestingValuesBegan = true;
                        break;
                    }

                case ZWNotification.Type.NodeRemoved:
                    {
                        zWave.Nodes
                        .Remove(
                             zWave.Nodes.SingleOrDefault(x => x.ID == notification.GetNodeId())
                        );
                        break;
                    }

                case ZWNotification.Type.ValueAdded:
                    {
                        node.AddValue(notification.GetValueID());
                        break;
                    }

                case ZWNotification.Type.ValueRemoved:
                    {
                        node.RemoveValue(notification.GetValueID());
                        break;
                    }

                case ZWNotification.Type.NodeProtocolInfo:
                    {
                        node.Label = zWave.Manager.GetNodeType(homeId, node.ID);
                        break;
                    }

                case ZWNotification.Type.NodeQueriesComplete:
                    {
                        node.Loaded = true;
                        if (!zWave.Nodes.Where(x => !x.Loaded).Any() || !zWave.Nodes.Any())
                        {
                            zWave.NodesLoaded = true;
                            if (!ZWGlobal.GetAllZWaveControllersNames().Where(x => !x.NodesLoaded).Any())
                                ZWGlobal.ControllersLoaded = true;
                        }
                        break;
                    }

                case ZWNotification.Type.AllNodesQueried:
                    {
                        zWave.NodesLoaded = true;
                        zWave.Failed = false;
                        if (!ZWGlobal.GetAllZWaveControllersNames().Where(x => !x.NodesLoaded || x.Failed == null).Any())
                            ZWGlobal.ControllersLoaded = true;
                        break;
                    }

                case ZWNotification.Type.DriverFailed:
                    {
                        zWave.Failed = true;
                        break;
                    }
                    //case ZWNotification.Type.NodeNaming:
                    //    {
                    //        break;
                    //    }

                    //case ZWNotification.Type.Group:
                    //    {
                    //        break;
                    //    }

                    //case ZWNotification.Type.NodeEvent:
                    //    {
                    //        break;
                    //    }

                    //case ZWNotification.Type.PollingDisabled:
                    //    {
                    //        break;
                    //    }

                    //case ZWNotification.Type.PollingEnabled:
                    //    {
                    //        break;
                    //    }

                    //case ZWNotification.Type.DriverReady:
                    //    {
                    //        break;
                    //    }

                    //case ZWNotification.Type.EssentialNodeQueriesComplete:
                    //    {
                    //        break;
                    //    }
            }

            if (notificationType == ZWNotification.Type.AllNodesQueriedSomeDead ||
                notificationType == ZWNotification.Type.AwakeNodesQueried)
            {
                zWave.NodesLoaded = true;
                zWave.Nodes.Where(x => !x.Loaded).Select(x => x.Failed = true);
                if (!ZWGlobal.GetAllZWaveControllersNames().Where(x => !x.NodesLoaded).Any())
                    ZWGlobal.ControllersLoaded = true;
            }

            //normal naming event not works
            if (node != null) //crutch
            {
                node.Manufacturer = zWave.Manager.GetNodeManufacturerName(homeId, node.ID);
                node.Product = zWave.Manager.GetNodeProductName(homeId, node.ID);
                node.Location = zWave.Manager.GetNodeLocation(homeId, node.ID);
                node.Name = zWave.Manager.GetNodeName(homeId, node.ID);
            }
        }
Example #7
0
        /// <summary>
        /// The notification handler.
        /// </summary>
        private void NotificationHandler()
        {
            switch (m_notification.GetType())
            {
            case ZWNotification.Type.ValueAdded:
            {
                Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                if (node != null)
                {
                    node.AddValue(m_notification.GetValueID());
                }
                break;
            }

            case ZWNotification.Type.ValueRemoved:
            {
                Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                if (node != null)
                {
                    node.RemoveValue(m_notification.GetValueID());
                }
                break;
            }

            case ZWNotification.Type.ValueChanged:
            {
/*						Console.WriteLine("Value Changed");
 *                                              ZWValueID v = m_notification.GetValueID();
 *                                              Console.WriteLine("  Node : " + v.GetNodeId().ToString());
 *                                              Console.WriteLine("  CC   : " + v.GetCommandClassId().ToString());
 *                                              Console.WriteLine("  Type : " + v.GetType().ToString());
 *                                              Console.WriteLine("  Index: " + v.GetIndex().ToString());
 *                                              Console.WriteLine("  Inst : " + v.GetInstance().ToString());
 *                                              Console.WriteLine("  Value: " + GetValue(v).ToString());
 *                                              Console.WriteLine("  Label: " + m_manager.GetValueLabel(v));
 *                                              Console.WriteLine("  Help : " + m_manager.GetValueHelp(v));
 *                                              Console.WriteLine("  Units: " + m_manager.GetValueUnits(v));
 */
                break;
            }

            case ZWNotification.Type.Group:
            {
                break;
            }

            case ZWNotification.Type.NodeAdded:
            {
                // if this node was in zwcfg*.xml, this is the first node notification
                // if not, the NodeNew notification should already have been received
                if (GetNode(m_notification.GetHomeId(), m_notification.GetNodeId()) == null)
                {
                    Node node = new Node();
                    node.ID     = m_notification.GetNodeId();
                    node.HomeID = m_notification.GetHomeId();
                    m_nodeList.Add(node);
                }
                break;
            }

            case ZWNotification.Type.NodeNew:
            {
                // Add the new node to our list (and flag as uninitialized)
                Node node = new Node();
                node.ID     = m_notification.GetNodeId();
                node.HomeID = m_notification.GetHomeId();
                m_nodeList.Add(node);
                break;
            }

            case ZWNotification.Type.NodeRemoved:
            {
                foreach (Node node in m_nodeList)
                {
                    if (node.ID == m_notification.GetNodeId())
                    {
                        m_nodeList.Remove(node);
                        break;
                    }
                }
                break;
            }

            case ZWNotification.Type.NodeProtocolInfo:
            {
                Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                if (node != null)
                {
                    node.Label = m_manager.GetNodeType(m_homeId, node.ID);
                }
                break;
            }

            case ZWNotification.Type.NodeNaming:
            {
                Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                if (node != null)
                {
                    node.Manufacturer = m_manager.GetNodeManufacturerName(m_homeId, node.ID);
                    node.Product      = m_manager.GetNodeProductName(m_homeId, node.ID);
                    node.Location     = m_manager.GetNodeLocation(m_homeId, node.ID);
                    node.Name         = m_manager.GetNodeName(m_homeId, node.ID);
                }
                break;
            }

            case ZWNotification.Type.NodeEvent:
            {
                break;
            }

            case ZWNotification.Type.PollingDisabled:
            {
                Console.WriteLine("Polling disabled notification");
                break;
            }

            case ZWNotification.Type.PollingEnabled:
            {
                Console.WriteLine("Polling enabled notification");
                break;
            }

            case ZWNotification.Type.DriverReady:
            {
                m_homeId = m_notification.GetHomeId();
                toolStripStatusLabel1.Text = "Initializing...driver with Home ID 0x" + m_homeId.ToString("X8") +
                                             " is ready.";
                break;
            }

            case ZWNotification.Type.NodeQueriesComplete:
            {
                // as an example, enable query of BASIC info (CommandClass = 0x20)
                Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                //if (node != null)
                //{
                //    foreach (ZWValueID vid in node.Values)
                //    {
                //        if (vid.GetCommandClassId() == 0x84)	// remove this "if" to poll all values
                //            m_manager.EnablePoll(vid);
                //    }
                //}
                toolStripStatusLabel1.Text = "Initializing...node " + node.ID + " query complete.";
                break;
            }

            case ZWNotification.Type.EssentialNodeQueriesComplete:
            {
                Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                toolStripStatusLabel1.Text = "Initializing...node " + node.ID + " essential queries complete.";
                break;
            }

            case ZWNotification.Type.AllNodesQueried:
            {
                toolStripStatusLabel1.Text = "Ready:  All nodes queried.";
                m_manager.WriteConfig(m_notification.GetHomeId());
                break;
            }

            case ZWNotification.Type.AllNodesQueriedSomeDead:
            {
                toolStripStatusLabel1.Text = "Ready:  All nodes queried but some are dead.";
                m_manager.WriteConfig(m_notification.GetHomeId());
                break;
            }

            case ZWNotification.Type.AwakeNodesQueried:
            {
                toolStripStatusLabel1.Text = "Ready:  Awake nodes queried (but not some sleeping nodes).";
                m_manager.WriteConfig(m_notification.GetHomeId());
                break;
            }
            }

            //NodeGridView.Refresh();
            NodeGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
            NodeGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
        }
        public void Publish(ZWNotification zwNotification)
        {
            Contract.Requires<ArgumentNullException>(zwNotification != null);

            var type = zwNotification.GetType();

            switch (type)
            {
                case ZWNotification.Type.DriverReady:
                    _eventPublisher.Publish(new ZWaveDriverReady(zwNotification));
                    break;

                case ZWNotification.Type.AllNodesQueried:
                    _eventPublisher.Publish(new ZWaveAllNodesQueried(zwNotification));
                    break;

                case ZWNotification.Type.AllNodesQueriedSomeDead:
                    _eventPublisher.Publish(new ZWaveAllNodesQueriedSomeDead(zwNotification));
                    break;

                case ZWNotification.Type.ValueAdded:
                    _eventPublisher.Publish(new ZWaveValueAdded(zwNotification));
                    break;

                case ZWNotification.Type.ValueRemoved:
                    _eventPublisher.Publish(new ZWaveValueRemoved(zwNotification));
                    break;

                case ZWNotification.Type.ValueChanged:
                    _eventPublisher.Publish(new ZWaveValueChanged(zwNotification));
                    break;

                case ZWNotification.Type.ValueRefreshed:
                    _eventPublisher.Publish(new ZWaveValueRefreshed(zwNotification));
                    break;

                case ZWNotification.Type.Group:
                    _eventPublisher.Publish(new ZWaveGroup(zwNotification));
                    break;

                case ZWNotification.Type.NodeNew:
                    _eventPublisher.Publish(new ZWaveNodeNew(zwNotification));
                    break;

                case ZWNotification.Type.NodeAdded:
                    _eventPublisher.Publish(new ZWaveNodeAdded(zwNotification));
                    break;

                case ZWNotification.Type.NodeRemoved:
                    _eventPublisher.Publish(new ZWaveNodeRemoved(zwNotification));
                    break;

                case ZWNotification.Type.NodeProtocolInfo:
                    _eventPublisher.Publish(new ZWaveNodeProtocolInfo(zwNotification));
                    break;

                case ZWNotification.Type.NodeNaming:
                    _eventPublisher.Publish(new ZWaveNodeNaming(zwNotification));
                    break;

                case ZWNotification.Type.NodeEvent:
                    _eventPublisher.Publish(new ZWaveNodeEvent(zwNotification));
                    break;

                case ZWNotification.Type.PollingDisabled:
                    _eventPublisher.Publish(new ZWavePollingDisabled(zwNotification));
                    break;

                case ZWNotification.Type.PollingEnabled:
                    _eventPublisher.Publish(new ZWavePollingEnabled(zwNotification));
                    break;

                case ZWNotification.Type.SceneEvent:
                    _eventPublisher.Publish(new ZWaveSceneEvent(zwNotification));
                    break;

                case ZWNotification.Type.CreateButton:
                    _eventPublisher.Publish(new ZWaveCreateButton(zwNotification));
                    break;

                case ZWNotification.Type.DeleteButton:
                    _eventPublisher.Publish(new ZWaveDeleteButton(zwNotification));
                    break;

                case ZWNotification.Type.ButtonOn:
                    _eventPublisher.Publish(new ZWaveButtonOn(zwNotification));
                    break;

                case ZWNotification.Type.ButtonOff:
                    _eventPublisher.Publish(new ZWaveButtonOff(zwNotification));
                    break;

                case ZWNotification.Type.DriverFailed:
                    _eventPublisher.Publish(new ZWaveDriverFailed(zwNotification));
                    break;

                case ZWNotification.Type.DriverReset:
                    _eventPublisher.Publish(new ZWaveDriverReset(zwNotification));
                    break;

                case ZWNotification.Type.EssentialNodeQueriesComplete:
                    _eventPublisher.Publish(new ZWaveEssentialNodeQueriesComplete(zwNotification));
                    break;

                case ZWNotification.Type.NodeQueriesComplete:
                    _eventPublisher.Publish(new ZWaveNodeQueriesComplete(zwNotification));
                    break;

                case ZWNotification.Type.AwakeNodesQueried:
                    _eventPublisher.Publish(new ZWaveAwakeNodesQueried(zwNotification));
                    break;

                case ZWNotification.Type.Notification:
                    _eventPublisher.Publish(new ZWaveNotification(zwNotification));
                    break;

                case ZWNotification.Type.DriverRemoved:
                    _eventPublisher.Publish(new ZWaveDriverRemoved(zwNotification));
                    break;

                case ZWNotification.Type.ControllerCommand:
                    _eventPublisher.Publish(new ZWaveControllerCommand(zwNotification));
                    break;

                default:
                    throw new InvalidOperationException($"Unknown notification: {zwNotification}");
            }
        }
Example #9
0
 public static void NotificationHandler(ZWNotification notification)
 {
     switch (notification.GetType())
     {
         case ZWNotification.Type.ControllerCommand:
             {
                 MyControllerStateChangedHandler(((ZWControllerState)notification.GetEvent()));
                 break;
             }
     }
 }
        /// <summary>
        /// Method which handles the events raised by the ZWave network
        /// </summary>
        /// <param name="m_notification"></param>
        private static void NotificationHandler(ZWNotification m_notification)
        {
            if (m_notification == null) { return; }

            switch (m_notification.GetType())
            {
                case ZWNotification.Type.ValueAdded:
                    {
                        Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                        if (node != null)
                            node.AddValue(m_notification.GetValueID());
                        break;
                    }
                case ZWNotification.Type.ValueRemoved:
                    {
                        Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                        if (node != null)
                            node.RemoveValue(m_notification.GetValueID());
                        break;
                    }
                case ZWNotification.Type.ValueChanged:
                    {
                        Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                        if (node != null)
                            node.SetValue(m_notification.GetValueID());
                        break;
                    }
                case ZWNotification.Type.NodeAdded:
                    {
                        Node node = new Node();
                        node.ID = m_notification.GetNodeId();
                        node.HomeID = m_notification.GetHomeId();
                        m_nodeList.Add(node);
                        break;
                    }
                case ZWNotification.Type.NodeRemoved:
                    {
                        foreach (Node node in m_nodeList)
                        {
                            if (node.ID == m_notification.GetNodeId())
                            {
                                m_nodeList.Remove(node);
                                break;
                            }
                        }
                        break;
                    }
                case ZWNotification.Type.NodeProtocolInfo:
                    {
                        Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                        if (node != null)
                            node.Label = m_manager.GetNodeType(m_homeId, node.ID);
                        break;
                    }
                case ZWNotification.Type.NodeNaming:
                    {
                        Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                        if (node != null)
                        {
                            node.Manufacturer = m_manager.GetNodeManufacturerName(m_homeId, node.ID);
                            node.Product = m_manager.GetNodeProductName(m_homeId, node.ID);
                            node.Location = m_manager.GetNodeLocation(m_homeId, node.ID);
                            node.Name = m_manager.GetNodeName(m_homeId, node.ID);
                        }
                        break;
                    }
                case ZWNotification.Type.DriverReady:
                    {
                        m_homeId = m_notification.GetHomeId();
                        break;
                    }
                case ZWNotification.Type.AllNodesQueried:
                    {
                        m_nodesReady = true;
                        break;
                    }
                default:
                    break;
            }
        }
Example #11
0
        public static void NotificationHandler(ZWNotification notification)
        {
            // Console.WriteLine("Notification! " + notification.GetType() + ": NodeID:" + notification.GetNodeId() + ", HomeId:" + notification.GetHomeId());
            var node = FindNode(notification.GetHomeId(), notification.GetNodeId());

            switch (notification.GetType())
            {
                case ZWNotification.Type.AllNodesQueried:
                    {
                        Console.WriteLine("***** AllNodesQueried");
                        _manager.WriteConfig(notification.GetHomeId());
                        _mre.Set();
                        break;
                    }
                case ZWNotification.Type.AllNodesQueriedSomeDead:
                    {
                        Console.WriteLine("Ready:  All nodes queried but some are dead.");
                        _manager.WriteConfig(notification.GetHomeId());
                        break;
                    }
                case ZWNotification.Type.AwakeNodesQueried:
                    {
                        Console.WriteLine("Ready:  Awake nodes queried (but not some sleeping nodes).");
                        _manager.WriteConfig(notification.GetHomeId());
                        _mre.Set();
                        break;
                    }
                case (ZWNotification.Type.NodeAdded):
                    {
                        node.Id = notification.GetNodeId();
                        node.HomeId = notification.GetHomeId();
                        //FillInfo(node);
                        break;
                    }

                case (ZWNotification.Type.NodeNaming):
                    {
                        Console.WriteLine("Node naming event!");
                        node.ManufacturerName = _manager.GetNodeManufacturerName(node.HomeId, node.Id);
                        node.Product = _manager.GetNodeProductName(node.HomeId, node.Id);
                        node.Location = _manager.GetNodeLocation(node.HomeId, node.Id);
                        node.Name = _manager.GetNodeName(node.HomeId, node.Id);
                        Console.WriteLine("Product: " + node.Product + ", Location:" + node.Location + ", Name:" + node.Name);
                        break;
                    }

                case ZWNotification.Type.NodeProtocolInfo:
                    {
                        node.Label = _manager.GetNodeType(node.HomeId, node.Id);
                        Console.WriteLine("***********************");
                        Console.WriteLine("NodeProtocolInfo: label is " + node.Label);
                        Console.WriteLine("***********************");
                        break;
                    }

                case ZWNotification.Type.PollingDisabled:
                    {
                        Console.WriteLine("Polling disabled notification");
                        break;
                    }

                case ZWNotification.Type.PollingEnabled:
                    {
                        Console.WriteLine("Polling enabled notification");
                        break;
                    }

                case ZWNotification.Type.DriverReady:
                    {
                        _homeId = notification.GetHomeId();
                        // Console.WriteLine("Home Id is :" + _homeId);
                        break;
                    }
                case ZWNotification.Type.NodeQueriesComplete:
                    {
                        Console.WriteLine(node.Label + ": node queries complete");
                        break;
                    }
                case ZWNotification.Type.EssentialNodeQueriesComplete:
                    {
                        Console.WriteLine(node.Label + ": essential node queries complete");
                        break;
                    }

                case ZWNotification.Type.ValueAdded:
                    {
                        node.ValueIds.Add(notification.GetValueID());
                        break;
                    }

                case ZWNotification.Type.ValueChanged:
                    {
                        Console.WriteLine("");
                        string s;
                        bool b;

                        Console.WriteLine(node.Name + ": " + node.Location);
                        Console.WriteLine("Notification type is " + notification.GetType());
                        var valueId = notification.GetValueID();
                        var valueType = notification.GetValueID().GetType();
                        _manager.GetValueAsString(valueId, out s);
                        _manager.GetValueAsBool(valueId, out b);
                        byte bt;
                        _manager.GetValueAsByte(valueId, out bt);
                        Console.WriteLine("Value Type: " + valueType);
                        Console.WriteLine(System.DateTime.Now +     "** VALUE CHANGED ** <<" + node.Label + ">> <<" + notification.GetValueID().GetId().ToString() + ">> string:" + s + ",bool:" + b + ",byte=" + bt);
                        Console.WriteLine("Genre: " + valueId.GetGenre().ToString());
                        Console.WriteLine("");
                        break;
                    }

            }
        }
Example #12
0
        /// <summary>
        /// Method which handles the events raised by the ZWave network
        /// </summary>
        /// <param name="m_notification"></param>
        private void NotificationHandler(ZWNotification m_notification)
        {
            if (m_notification == null)
            {
                return;
            }

            switch (m_notification.GetType())
            {
            case ZWNotification.Type.ValueAdded:
            {
                ZWaveNode node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                if (node != null)
                {
                    node.AddValue(m_notification.GetValueID());
                    Log("Event", "Node ValueAdded, " + m_manager.GetValueLabel(m_notification.GetValueID()));
                }
                break;
            }

            case ZWNotification.Type.ValueRemoved:
            {
                ZWaveNode node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                if (node != null)
                {
                    node.RemoveValue(m_notification.GetValueID());
                    Log("Event", "Node ValueRemoved, " + m_manager.GetValueLabel(m_notification.GetValueID()));
                }
                break;
            }

            case ZWNotification.Type.ValueChanged:
            {
                ZWaveNode node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                if (node != null)
                {
                    node.SetValue(m_notification.GetValueID());

                    Log("Event", "Node ValueChanged, " + m_manager.GetValueLabel(m_notification.GetValueID()).ToString());
                }

                break;
            }

            case ZWNotification.Type.Group:
            {
                break;
            }

            case ZWNotification.Type.NodeAdded:
            {
                // Add the new node to our list
                ZWaveNode node = new ZWaveNode();
                node.ID     = m_notification.GetNodeId();
                node.HomeID = m_notification.GetHomeId();
                m_nodeList.Add(node);
                Log("Event", "Node added, " + m_notification.GetNodeId().ToString());
                break;
            }

            case ZWNotification.Type.NodeRemoved:
            {
                foreach (ZWaveNode node in m_nodeList)
                {
                    if (node.ID == m_notification.GetNodeId())
                    {
                        Log("Event", "Node removed, " + m_notification.GetNodeId().ToString());
                        m_nodeList.Remove(node);
                        break;
                    }
                }
                break;
            }

            case ZWNotification.Type.NodeProtocolInfo:
            {
                ZWaveNode node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                if (node != null)
                {
                    node.Label = m_manager.GetNodeType(m_homeId, node.ID);
                    Log("Event", "Node protocol info, " + node.Label.ToString());
                }
                break;
            }

            case ZWNotification.Type.NodeNaming:
            {
                ZWaveNode node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                if (node != null)
                {
                    node.Manufacturer = m_manager.GetNodeManufacturerName(m_homeId, node.ID);
                    node.Product      = m_manager.GetNodeProductName(m_homeId, node.ID);
                    node.Location     = m_manager.GetNodeLocation(m_homeId, node.ID);
                    node.Name         = m_manager.GetNodeName(m_homeId, node.ID);
                }
                break;
            }

            case ZWNotification.Type.NodeEvent:
            {
                Log("Event", "Node event");
                break;
            }

            case ZWNotification.Type.PollingDisabled:
            {
                Log("Event", "Polling disabled notification");
                break;
            }

            case ZWNotification.Type.PollingEnabled:
            {
                Log("Event", "Polling disabled notification");
                break;
            }

            case ZWNotification.Type.DriverReady:
            {
                m_homeId = m_notification.GetHomeId();
                Log("Event", "Driver ready, with homeId " + m_homeId.ToString());
                break;
            }

            case ZWNotification.Type.NodeQueriesComplete:
            {
                break;
            }

            case ZWNotification.Type.AllNodesQueried:
            {
                Log("Event", "All nodes queried");
                m_nodesReady = true;
                break;
            }

            case ZWNotification.Type.AwakeNodesQueried:
            {
                Log("Event", "Awake nodes queried (but some sleeping nodes have not been queried)");
                break;
            }
            }
        }
        /// <summary>
        /// Method which handles the events raised by the ZWave network
        /// </summary>
        /// <param name="m_notification"></param>
        static private void NotificationHandler(ZWNotification m_notification)
        {
            if (m_notification == null)
            {
                return;
            }

            switch (m_notification.GetType())
            {
            case ZWNotification.Type.ValueAdded:
            {
                Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                if (node != null)
                {
                    node.AddValue(m_notification.GetValueID());
                }
                break;
            }

            case ZWNotification.Type.ValueRemoved:
            {
                Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                if (node != null)
                {
                    node.RemoveValue(m_notification.GetValueID());
                }
                break;
            }

            case ZWNotification.Type.ValueChanged:
            {
                Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                if (node != null)
                {
                    node.SetValue(m_notification.GetValueID());
                }
                break;
            }

            case ZWNotification.Type.NodeAdded:
            {
                Node node = new Node();
                node.ID     = m_notification.GetNodeId();
                node.HomeID = m_notification.GetHomeId();
                m_nodeList.Add(node);
                break;
            }

            case ZWNotification.Type.NodeRemoved:
            {
                foreach (Node node in m_nodeList)
                {
                    if (node.ID == m_notification.GetNodeId())
                    {
                        m_nodeList.Remove(node);
                        break;
                    }
                }
                break;
            }

            case ZWNotification.Type.NodeProtocolInfo:
            {
                Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                if (node != null)
                {
                    node.Label = m_manager.GetNodeType(m_homeId, node.ID);
                }
                break;
            }

            case ZWNotification.Type.NodeNaming:
            {
                Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                if (node != null)
                {
                    node.Manufacturer = m_manager.GetNodeManufacturerName(m_homeId, node.ID);
                    node.Product      = m_manager.GetNodeProductName(m_homeId, node.ID);
                    node.Location     = m_manager.GetNodeLocation(m_homeId, node.ID);
                    node.Name         = m_manager.GetNodeName(m_homeId, node.ID);
                }
                break;
            }

            case ZWNotification.Type.DriverReady:
            {
                m_homeId = m_notification.GetHomeId();
                break;
            }

            case ZWNotification.Type.AllNodesQueried:
            {
                m_nodesReady = true;
                break;
            }

            default:
                break;
            }
        }
Example #14
0
        internal static void NotificationHandler(ZWNotification notification)
        {
            Console.WriteLine("NOTIFICATION RECEIVED: " + notification.GetType().ToString());
            ZWValueID v = notification.GetValueID();
            Console.WriteLine("  Node : " + v.GetNodeId().ToString());
            Console.WriteLine("  CC   : " + v.GetCommandClassId().ToString());
            Console.WriteLine("  Type : " + v.GetType().ToString());
            Console.WriteLine("  Index: " + v.GetIndex().ToString());
            Console.WriteLine("  Inst : " + v.GetInstance().ToString());
            Console.WriteLine("  Value: " + GetValue(v).ToString());
            Console.WriteLine("  Byte : " + notification.GetByte().ToString());
            Console.WriteLine("  Label: " + MainForm.Manager.GetValueLabel(v));
            Console.WriteLine("  Help : " + MainForm.Manager.GetValueHelp(v));
            Console.WriteLine("  Units: " + MainForm.Manager.GetValueUnits(v));

            #region Switch Ready
            switch (m_ready)
            {
                #region Ready
                case true:
                    {
                        Console.WriteLine(notification.GetType().ToString());
                        string result;
                        switch (notification.GetType())
                        {
                            case ZWNotification.Type.ValueAdded:
                                {
                                    foreach (Node n in _nodes)
                                    {
                                        if (n.ID == notification.GetNodeId())
                                        {
                                            n.AddValue(notification.GetValueID());
                                        }
                                    }
                                    break;
                                }
                            case ZWNotification.Type.ValueChanged:
                                {
                                    foreach (Node n in _nodes)
                                    {
                                        if (n.ID == notification.GetNodeId())
                                        {
                                            if (MainForm.Manager.GetValueLabel(notification.GetValueID()) == "Basic")
                                            {
                                                try
                                                {
                                                    foreach (ZWValueID vid in n.Values)
                                                    {
                                                        if (MainForm.Manager.GetValueLabel(vid) == "Basic")
                                                        {
                                                            Console.WriteLine("Removing Basic Value");
                                                            n.RemoveValue(vid);
                                                        }
                                                    }
                                                }
                                                catch { }
                                                Console.WriteLine("Adding Basic Value");
                                                n.AddValue(notification.GetValueID());
                                                MainForm.Manager.GetValueAsString(notification.GetValueID(), out result);
                                                Console.WriteLine("  Result: " + result);
                                                Console.WriteLine(Environment.NewLine);

                                                //Thread t = new Thread(new ThreadStart(Program._MainForm.engineeringScreen1.subSystemControls1.SetButtonStatuses));
                                                //t.Start();
                                                Program._MainForm.engineeringScreen1.subSystemControls1.SetButtonStatuses();
                                                break;
                                            }
                                        }
                                    }
                                    Console.WriteLine("ValueID: " + notification.GetValueID().ToString());
                                    break;
                                }
                            case ZWNotification.Type.ValueRemoved:
                                {
                                    foreach (Node n in _nodes)
                                    {
                                        if (n.ID == notification.GetNodeId())
                                        {
                                            n.RemoveValue(notification.GetValueID());
                                        }
                                    }
                                    break;
                                }
                            case ZWNotification.Type.NodeEvent:
                                {
                                    foreach (Node n in _nodes)
                                    {
                                        if (n.ID == notification.GetNodeId())
                                        {
                                            switch (notification.GetByte())
                                            {
                                                case 255:
                                                    {
                                                        n.Triggered = true;
                                                        break;
                                                    }
                                                case 0:
                                                    {
                                                        n.Triggered = false;
                                                        break;
                                                    }
                                            }
                                        }
                                    }

                                    BusinessLogic.SensorStatusChange(notification.GetNodeId(), notification.GetByte());
                                    Program._MainForm.engineeringScreen1.SetButtonStatuses();
                                    Program._MainForm.engineeringScreen1.subSystemControls1.SetButtonStatuses();
                                    break;
                                }
                            default:
                                {
                                    Console.WriteLine(Environment.NewLine);
                                    break;
                                }
                        }
                        break;
                    }
                #endregion
                #region Not Ready
                default:
                    {
                        Console.WriteLine(notification.GetType().ToString() + ":");
                        switch (notification.GetType())
                        {
                            case ZWNotification.Type.AwakeNodesQueried:
                                {
                                    Console.WriteLine(Environment.NewLine + notification.GetType().ToString() + Environment.NewLine);
                                    m_ready = true;
                                    //Thread t = new Thread(new ThreadStart(Program._MainForm.engineeringScreen1.SetButtonStatuses));
                                    //t.Start();
                                    Program._MainForm.engineeringScreen1.SetButtonStatuses();

                                    //Thread t2 = new Thread(new ThreadStart(Program._MainForm.engineeringScreen1.subSystemControls1.SetButtonStatuses));
                                    //t2.Start();
                                    Program._MainForm.engineeringScreen1.subSystemControls1.SetButtonStatuses();

                                    StringBuilder message = new StringBuilder();
                                    message.Append("Awake Nodes Query Complete");
                                    MainForm.Speak(message.ToString());
                                    break;
                                }
                            case ZWNotification.Type.NodeQueriesComplete:
                                {
                                    StringBuilder message = new StringBuilder();
                                    message.Append("Node ");
                                    message.Append(v.GetNodeId().ToString());
                                    message.Append(" Query Complete.");
                                    MainForm.Speak(message.ToString());
                                    break;
                                }
                            case ZWNotification.Type.NodeNew:
                                {
                                    Node n = new Node();
                                    n.HomeID = notification.GetHomeId();
                                    n.ID = notification.GetNodeId();
                                    _nodes.Add(n);
                                    break;
                                }
                            case ZWNotification.Type.ValueAdded:
                                {
                                    Node node = new Node();
                                    node.HomeID = notification.GetHomeId();
                                    node.ID = notification.GetNodeId();

                                    if(!_nodes.Contains(_nodes.Find(item => item.ID == node.ID)))
                                    {
                                        _nodes.Add(node);
                                    }
                                    foreach (Node n in _nodes)
                                    {
                                        if (n.ID == notification.GetNodeId())
                                        {
                                            n.AddValue(notification.GetValueID());
                                        }
                                    }
                                    break;
                                }

                        }
                        break;
                    }
                #endregion
            }
            #endregion
        }