Container for Nodes
示例#1
0
文件: NodeForm.cs 项目: Yadoms/yadoms
        /// <summary>
        /// Initializes a new instance of the <see cref="NodeForm"/> class.
        /// </summary>
        /// <param name="node">The node.</param>
        public NodeForm( Node node )
        {
            m_node = node;
            InitializeComponent();

            // load all possible configuration parameters
            for (byte i = 0; i <= 10; i++)
            {
                MainForm.Manager.RequestConfigParam(node.HomeID, node.ID, i);
            }

            if (node.Manufacturer != "")
            {
                this.Text = "Node " + node.ID.ToString() + ": " + node.Manufacturer + " " + node.Product;
            }
            else
            {
                this.Text = "Node " + node.ID.ToString() + ": " + node.Label;
            }

            foreach (ZWValueID valueID in node.Values)
            {
                Control control = null;
                switch (valueID.GetType())
                {
                    case ZWValueID.ValueType.Bool:
                    {
                        control = new ValuePanelBool(valueID);
                        break;
                    }
                    case ZWValueID.ValueType.Button:
                    {
                        control = new ValuePanelButton(valueID);
                        break;
                    }
                    case ZWValueID.ValueType.Byte:
                    {
                        control = new ValuePanelByte(valueID);
                        break;
                    }
                    case ZWValueID.ValueType.Decimal:
                    {
                        control = new ValuePanelDecimal(valueID);
                        break;
                    }
                    case ZWValueID.ValueType.Int:
                    {
                        control = new ValuePanelInt(valueID);
                        break;
                    }
                    case ZWValueID.ValueType.List:
                    {
                        control = new ValuePanelList(valueID);
                        break;
                    }
                    case ZWValueID.ValueType.Short:
                    {
                        control = new ValuePanelShort(valueID);
                        break;
                    }
                    case ZWValueID.ValueType.String:
                    {
                        control = new ValuePanelString(valueID);
                        break;
                    }
                }

                if (control != null)
                {
                    NodeLayoutPanel.Controls.Add(control);
                }
            }
        }
示例#2
0
文件: MainForm.cs 项目: Yadoms/yadoms
        /// <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;
        }