/// <summary>
        /// Initializes a new instance of the <see cref="ControllerCommandDlg"/> class.
        /// </summary>
        /// <param name="_mainDlg">The main form.</param>
        /// <param name="_manager">The manager.</param>
        /// <param name="homeId">The home identifier.</param>
        /// <param name="_op">The Controller Command.</param>
        /// <param name="nodeId">The node identifier.</param>
        public ControllerCommandDlg(MainForm _mainDlg, ZWManager _manager, UInt32 homeId, Func <bool> _op,
                                    Byte nodeId, ZWControllerCommand cmd)
        {
            m_mainDlg = _mainDlg;
            m_manager = _manager;
            m_homeId  = homeId;
            m_op      = cmd;
            m_nodeId  = nodeId;
            m_dlg     = this;

            InitializeComponent();

            m_manager.NotificationReceived += new NotificationReceivedEventHandler(NotificationHandler);
            switch (m_op)
            {
            case ZWControllerCommand.RequestNodeNeighborUpdate:
            {
                this.Text        = "Node Neighbor Update";
                this.label1.Text = "Request that a node update its list of neighbors.";

                if (!m_manager.RequestNodeNeighborUpdate(m_homeId, m_nodeId))
                {
                    MyControllerStateChangedHandler(ZWControllerState.Failed);
                }
                break;
            }

            case ZWControllerCommand.AddDevice:
            {
                this.Text        = "Add Device";
                this.label1.Text =
                    "Press the program button on the Z-Wave device to add it to the network.\nFor security reasons, the PC Z-Wave Controller must be close to the device being added.";

                if (!m_manager.AddNode(m_homeId, m_mainDlg.SecurityEnabled))
                {
                    MyControllerStateChangedHandler(ZWControllerState.Failed);
                }
                break;
            }

            case ZWControllerCommand.CreateNewPrimary:
            {
                this.Text        = "Create New Primary Controller";
                this.label1.Text =
                    "Put the target controller into receive configuration mode.\nThe PC Z-Wave Controller must be within 2m of the controller that is being made the primary.";

                if (!m_manager.CreateNewPrimary(m_homeId))
                {
                    MyControllerStateChangedHandler(ZWControllerState.Failed);
                }
                break;
            }

            case ZWControllerCommand.ReceiveConfiguration:
            {
                this.Text        = "Receive Configuration";
                this.label1.Text =
                    "Transfering the network configuration\nfrom another controller.\n\nPlease bring the other controller within 2m of the PC controller and set it to send its network configuration.";

                if (!m_manager.ReceiveConfiguration(m_homeId))
                {
                    MyControllerStateChangedHandler(ZWControllerState.Failed);
                }
                break;
            }

            case ZWControllerCommand.RemoveDevice:
            {
                this.Text        = "Remove Device";
                this.label1.Text =
                    "Press the program button on the Z-Wave device to remove it from the network.\nFor security reasons, the PC Z-Wave Controller must be close to the device being removed.";

                if (!m_manager.RemoveNode(m_homeId))
                {
                    MyControllerStateChangedHandler(ZWControllerState.Failed);
                }
                break;
            }

            case ZWControllerCommand.TransferPrimaryRole:
            {
                this.Text        = "Transfer Primary Role";
                this.label1.Text =
                    "Transfering the primary role\nto another controller.\n\nPlease bring the new controller within 2m of the PC controller and set it to receive the network configuration.";

                if (!m_manager.TransferPrimaryRole(m_homeId))
                {
                    MyControllerStateChangedHandler(ZWControllerState.Failed);
                }
                break;
            }

            case ZWControllerCommand.HasNodeFailed:
            {
                this.ButtonCancel.Enabled = false;
                this.Text        = "Has Node Failed";
                this.label1.Text = "Testing whether the node has failed.\nThis command cannot be cancelled.";

                if (!m_manager.HasNodeFailed(m_homeId, m_nodeId))
                {
                    MyControllerStateChangedHandler(ZWControllerState.Failed);
                }
                break;
            }

            case ZWControllerCommand.RemoveFailedNode:
            {
                this.ButtonCancel.Enabled = false;
                this.Text        = "Remove Failed Node";
                this.label1.Text =
                    "Removing the failed node from the controller's list.\nThis command cannot be cancelled.";

                if (!m_manager.RemoveFailedNode(m_homeId, m_nodeId))
                {
                    MyControllerStateChangedHandler(ZWControllerState.Failed);
                }
                break;
            }

            case ZWControllerCommand.ReplaceFailedNode:
            {
                this.ButtonCancel.Enabled = false;
                this.Text        = "Replacing Failed Node";
                this.label1.Text = "Testing the failed node.\nThis command cannot be cancelled.";

                if (!m_manager.ReplaceFailedNode(m_homeId, m_nodeId))
                {
                    MyControllerStateChangedHandler(ZWControllerState.Failed);
                }
                break;
            }

            case ZWControllerCommand.RefreshNodeInfo:
            {
                this.ButtonCancel.Enabled = false;
                this.Text        = "Refreshing Node Info";
                this.label1.Text = "Refreshing the node info\nThis command cannot be cancelled.";

                if (!m_manager.RefreshNodeInfo(m_homeId, m_nodeId))
                {
                    MyControllerStateChangedHandler(ZWControllerState.Failed);
                }
                break;
            }

            case ZWControllerCommand.RequestNetworkUpdate:
            {
                this.ButtonCancel.Enabled = false;
                this.Text        = "Requesting Network Update";
                this.label1.Text = "Requesting the Network Update.";

                if (!m_manager.RequestNetworkUpdate(m_homeId, m_nodeId))
                {
                    MyControllerStateChangedHandler(ZWControllerState.Failed);
                }
                break;
            }

            default:
            {
                m_manager.NotificationReceived -= NotificationHandler;
                break;
            }
            }
        }
示例#2
0
 /// <summary>
 /// Handles the Click event of the addDeviceToolStripMenuItem control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void addDeviceToolStripMenuItem_Click(object sender, EventArgs e)
 {
     DoCommand(() =>
               m_manager.AddNode(m_homeId, m_securityEnabled),
               ControllerCommandDlg.ZWControllerCommand.AddDevice);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ControllerCommandDlg"/> class.
        /// </summary>
        /// <param name="_mainDlg">The main form.</param>
        /// <param name="_manager">The manager.</param>
        /// <param name="homeId">The home identifier.</param>
        /// <param name="_op">The Controller Command.</param>
        /// <param name="nodeId">The node identifier.</param>
        public ControllerCommandDlg(MainForm _mainDlg, ZWManager _manager, UInt32 homeId, ZWControllerCommand _op,
            Byte nodeId)
        {
            m_mainDlg = _mainDlg;
            m_manager = _manager;
            m_homeId = homeId;
            m_op = _op;
            m_nodeId = nodeId;
            m_dlg = this;

            InitializeComponent();

            m_manager.OnNotification += new ManagedNotificationsHandler(NotificationHandler);
            switch (m_op)
            {
                case ZWControllerCommand.RequestNodeNeighborUpdate:
                {
                    this.Text = "Node Neighbor Update";
                    this.label1.Text = "Request that a node update its list of neighbors.";

                    if (!m_manager.RequestNodeNeighborUpdate(m_homeId, m_nodeId))
                    {
                        MyControllerStateChangedHandler(ZWControllerState.Failed);
                    }
                    break;
                }
                case ZWControllerCommand.AddDevice:
                {
                    this.Text = "Add Device";
                    this.label1.Text =
                        "Press the program button on the Z-Wave device to add it to the network.\nFor security reasons, the PC Z-Wave Controller must be close to the device being added.";

                    if (!m_manager.AddNode(m_homeId, m_mainDlg.SecurityEnabled))
                    {
                        MyControllerStateChangedHandler(ZWControllerState.Failed);
                    }
                    break;
                }
                case ZWControllerCommand.CreateNewPrimary:
                {
                    this.Text = "Create New Primary Controller";
                    this.label1.Text =
                        "Put the target controller into receive configuration mode.\nThe PC Z-Wave Controller must be within 2m of the controller that is being made the primary.";

                    if (!m_manager.CreateNewPrimary(m_homeId))
                    {
                        MyControllerStateChangedHandler(ZWControllerState.Failed);
                    }
                    break;
                }
                case ZWControllerCommand.ReceiveConfiguration:
                {
                    this.Text = "Receive Configuration";
                    this.label1.Text =
                        "Transfering the network configuration\nfrom another controller.\n\nPlease bring the other controller within 2m of the PC controller and set it to send its network configuration.";

                    if (!m_manager.ReceiveConfiguration(m_homeId))
                    {
                        MyControllerStateChangedHandler(ZWControllerState.Failed);
                    }
                    break;
                }
                case ZWControllerCommand.RemoveDevice:
                {
                    this.Text = "Remove Device";
                    this.label1.Text =
                        "Press the program button on the Z-Wave device to remove it from the network.\nFor security reasons, the PC Z-Wave Controller must be close to the device being removed.";

                    if (!m_manager.RemoveNode(m_homeId))
                    {
                        MyControllerStateChangedHandler(ZWControllerState.Failed);
                    }
                    break;
                }
                case ZWControllerCommand.TransferPrimaryRole:
                {
                    this.Text = "Transfer Primary Role";
                    this.label1.Text =
                        "Transfering the primary role\nto another controller.\n\nPlease bring the new controller within 2m of the PC controller and set it to receive the network configuration.";

                    if (!m_manager.TransferPrimaryRole(m_homeId))
                    {
                        MyControllerStateChangedHandler(ZWControllerState.Failed);
                    }
                    break;
                }
                case ZWControllerCommand.HasNodeFailed:
                {
                    this.ButtonCancel.Enabled = false;
                    this.Text = "Has Node Failed";
                    this.label1.Text = "Testing whether the node has failed.\nThis command cannot be cancelled.";

                    if (!m_manager.HasNodeFailed(m_homeId, m_nodeId))
                    {
                        MyControllerStateChangedHandler(ZWControllerState.Failed);
                    }
                    break;
                }
                case ZWControllerCommand.RemoveFailedNode:
                {
                    this.ButtonCancel.Enabled = false;
                    this.Text = "Remove Failed Node";
                    this.label1.Text =
                        "Removing the failed node from the controller's list.\nThis command cannot be cancelled.";

                    if (!m_manager.RemoveFailedNode(m_homeId, m_nodeId))
                    {
                        MyControllerStateChangedHandler(ZWControllerState.Failed);
                    }
                    break;
                }
                case ZWControllerCommand.ReplaceFailedNode:
                {
                    this.ButtonCancel.Enabled = false;
                    this.Text = "Replacing Failed Node";
                    this.label1.Text = "Testing the failed node.\nThis command cannot be cancelled.";

                    if (!m_manager.ReplaceFailedNode(m_homeId, m_nodeId))
                    {
                        MyControllerStateChangedHandler(ZWControllerState.Failed);
                    }
                    break;
                }
                case ZWControllerCommand.RequestNetworkUpdate:
                {
                    this.ButtonCancel.Enabled = false;
                    this.Text = "Requesting Network Update";
                    this.label1.Text = "Requesting the Network Update.";

                    if (!m_manager.RequestNetworkUpdate(m_homeId, m_nodeId))
                    {
                        MyControllerStateChangedHandler(ZWControllerState.Failed);
                    }
                    break;
                }
                default:
                {
                    m_manager.OnNotification -= NotificationHandler;
                    break;
                }
            }
        }
示例#4
0
        public ControllerCommandDlg(ZWManager _manager, uint _homeId, ZWControllerCommand _op, byte? nodeId, bool securityEnabled)
        {
            m_manager = _manager;
            homeId = _homeId;
            m_op = _op;
            m_nodeId = nodeId != null ? nodeId.Value : (byte)0;
            m_dlg = this;

            InitializeComponent();

            m_manager.OnNotification += new ManagedNotificationsHandler(NotificationHandler);
            switch (m_op)
            {
                case ZWControllerCommand.RequestNodeNeighborUpdate:
                    {
                        this.Text = "Обновление списка соседних узлов";
                        this.label1.Text = "Узел обновляет список соседних узлов";

                        if (!m_manager.RequestNodeNeighborUpdate(homeId, m_nodeId))
                        {
                            MyControllerStateChangedHandler(ZWControllerState.Failed);
                        }
                        break;
                    }
                case ZWControllerCommand.AddDevice:
                    {
                        this.Text = "Добавить устройство в ZWave сеть";
                        this.label1.Text =
                            "Нажмите программную кнопку на Z-Wave устройстве для добавления его в сеть.\nДля безопасности, контроллер должен быть рядом с устройством ZWave (не более 2 метров).";

                        if (!m_manager.AddNode(homeId, securityEnabled))
                        {
                            MyControllerStateChangedHandler(ZWControllerState.Failed);
                        }
                        break;
                    }
                case ZWControllerCommand.CreateNewPrimary:
                    {
                        this.Text = "Создать новый основной контроллер";
                        this.label1.Text =
                            "Введите новый контроллер в режим передачи данных.\nТекущий контроллер должен быть рядом с целевым контроллером (не более 2 метров).";

                        if (!m_manager.CreateNewPrimary(homeId))
                        {
                            MyControllerStateChangedHandler(ZWControllerState.Failed);
                        }
                        break;
                    }
                case ZWControllerCommand.ReceiveConfiguration:
                    {
                        this.Text = "Передача конфигурации";
                        this.label1.Text =
                            "Передача сетевой конфигурации от другого устройства.\nПоместите другой контроллер в пределах 2 метров от текущего контроллера.";

                        if (!m_manager.ReceiveConfiguration(homeId))
                        {
                            MyControllerStateChangedHandler(ZWControllerState.Failed);
                        }
                        break;
                    }
                case ZWControllerCommand.RemoveDevice:
                    {
                        this.Text = "Удалит устройство из сети";
                        this.label1.Text =
                            "Нажмите программную кнопку на устройстве ZWave для удаления его из сети.\nПо причинам безопасности, контроллер должен быть в радиусе 2-х метров от устройства.";

                        if (!m_manager.RemoveNode(homeId))
                        {
                            MyControllerStateChangedHandler(ZWControllerState.Failed);
                        }
                        break;
                    }
                case ZWControllerCommand.TransferPrimaryRole:
                    {
                        this.Text = "Передача роли основного контроллера другому контроллеру";
                        this.label1.Text =
                            "Передача роли основного контроллера другому контроллеру.\n\nПо причинам безопасности, контроллер должен быть в радиусе 2-х метров от устройства.";

                        if (!m_manager.TransferPrimaryRole(homeId))
                        {
                            MyControllerStateChangedHandler(ZWControllerState.Failed);
                        }
                        break;
                    }
                case ZWControllerCommand.HasNodeFailed:
                    {
                        this.ButtonCancel.Enabled = false;
                        this.Text = "Проверка узла на неисправность";
                        this.label1.Text = "Проверка узла.\nЭта команда не может быть отменена";

                        if (!m_manager.HasNodeFailed(homeId, m_nodeId))
                        {
                            MyControllerStateChangedHandler(ZWControllerState.Failed);
                        }
                        break;
                    }
                case ZWControllerCommand.RemoveFailedNode:
                    {
                        this.ButtonCancel.Enabled = false;
                        this.Text = "Удаление неисправного узла";
                        this.label1.Text =
                            "Удаление неисправного узла.\nКоманда не может быть отменена.";

                        if (!m_manager.RemoveFailedNode(homeId, m_nodeId))
                        {
                            MyControllerStateChangedHandler(ZWControllerState.Failed);
                        }
                        break;
                    }
                case ZWControllerCommand.ReplaceFailedNode:
                    {
                        this.ButtonCancel.Enabled = false;
                        this.Text = "Замена неисправного узла";
                        this.label1.Text = "Тестирование неисправного узла.\nКоманда не может быть отменена.";

                        if (!m_manager.ReplaceFailedNode(homeId, m_nodeId))
                        {
                            MyControllerStateChangedHandler(ZWControllerState.Failed);
                        }
                        break;
                    }
                case ZWControllerCommand.RequestNetworkUpdate:
                    {
                        this.ButtonCancel.Enabled = false;
                        this.Text = "Запрос обновления сети устройств";
                        this.label1.Text = "Запрос обновления сети устройств.";

                        if (!m_manager.RequestNetworkUpdate(homeId, m_nodeId))
                        {
                            MyControllerStateChangedHandler(ZWControllerState.Failed);
                        }
                        break;
                    }
                default:
                    {
                        m_manager.OnNotification -= NotificationHandler;
                        break;
                    }
            }
        }
示例#5
0
 public void AddNewDevice(Controller controller, Action <bool> callback)
 {
     _callbacksPool.ExecuteBool(() => _manager.AddNode(controller.HomeID, false), callback, 5 * 60);
 }