private void StartRegisteringUnknownDevice(XBeeDeviceNetwork deviceNetwork, IXBeeFrame frame)
        {
            // check if this device is already staging
            if (!HomeAutomationSystem.DeviceRegistry.IsStagingDevice(deviceNetwork, frame.Address))
            {
                HomeAutomationSystem.DeviceRegistry.RegisterStagingDevice(deviceNetwork, frame.Address);

                AskForDeviceType(deviceNetwork, frame);
            }
        }
        private void AskForDeviceType(XBeeDeviceNetwork deviceNetwork, IXBeeFrame remoteFrame)
        {
            frameId++;
            if (frameId == 0) frameId++;

            Log.Debug($"Received a frame from an unknown device, so we are asking type ID from this device. Address: {remoteFrame.Address.ToHexString()}");

            // create the XBee frame to send
            IXBeeFrame frame = XBeeFrameBuilder.CreateRemoteATCommand(ATCommands.DD, frameId, remoteFrame.Address, remoteFrame.NetworkAddress);

            deviceNetwork.XBeeService.SendFrame(frame);
        }
        public void ProcessFrame(XBeeDeviceNetwork deviceNetwork, IXBeeFrame frame)
        {
            // get the device type from device registry. if it's not found
            // then we will ask the device to identify itself.
            IXBeeDevice device = HomeAutomationSystem.DeviceRegistry.GetDeviceById(deviceNetwork, frame.Address) as IXBeeDevice;

            if (device != null)
            {
                device.ProcessFrame(frame);

                deviceNetwork.AnnounceDeviceState(device.DeviceState);
            }
            else
            {
                StartRegisteringUnknownDevice(deviceNetwork, frame);
            }
        }
        public void ProcessFrame(XBeeDeviceNetwork deviceNetwork, IXBeeFrame frame)
        {
            RemoteCommandResponse responseFrame = (RemoteCommandResponse)frame;

            // check if this is a DD command response - used for identifying devices by their type
            if (XBeeFrameUtil.IsSameATCommand(responseFrame.ATCommand, ATCommands.DD))
            {
                // build the ID for the device type based on the frame info
                int deviceIdentification = responseFrame.Parameters[2] * 256 + responseFrame.Parameters[3];

                HomeAutomationSystem.DeviceRegistry.RegisterDeviceWithTypeID(deviceNetwork, deviceIdentification, frame.Address, frame.NetworkAddress);
            }
            else
            {
                // get the device type from device registry, and send the frame for processing it.
                IXBeeDevice device = HomeAutomationSystem.DeviceRegistry.GetDeviceById(deviceNetwork, frame.Address) as IXBeeDevice;

                device?.ProcessFrame(frame);
            }
        }