コード例 #1
0
        public void CommandReceived(ZigBeeCommand command)
        {
            // This gets called for all received commands
            // Check if it's our address
            if (command.SourceAddress.Address != NetworkAddress)
            {
                return;
            }

            if (!(command is ZclCommand))
            {
                return;
            }

            ZclCommand            zclCommand      = (ZclCommand)command;
            ZigBeeEndpointAddress endpointAddress = (ZigBeeEndpointAddress)zclCommand.SourceAddress;

            if (endpointAddress.Endpoint == BROADCAST_ENDPOINT)
            {
                foreach (ZigBeeEndpoint endpoint in Endpoints.Values)
                {
                    endpoint.CommandReceived(zclCommand);
                }
            }
            else
            {
                ZigBeeEndpoint endpoint = Endpoints[endpointAddress.Endpoint];
                if (endpoint != null)
                {
                    endpoint.CommandReceived(zclCommand);
                }
            }
        }
コード例 #2
0
ファイル: ZigBeeNode.cs プロジェクト: lulzzz/ZigbeeNet
        public void SetDao(ZigBeeNodeDao dao)
        {
            IeeeAddress     = new IeeeAddress(dao.IeeeAddress);
            NetworkAddress  = dao.NetworkAddress;
            NodeDescriptor  = dao.NodeDescriptor;
            PowerDescriptor = dao.PowerDescriptor;
            if (dao.BindingTable != null)
            {
                BindingTable.AddRange(dao.BindingTable);
            }

            foreach (ZigBeeEndpointDao endpointDao in dao.Endpoints)
            {
                ZigBeeEndpoint endpoint = new ZigBeeEndpoint(this, endpointDao.EndpointId);
                endpoint.SetDao(endpointDao);
                Endpoints[endpoint.EndpointId] = endpoint;
            }
        }
コード例 #3
0
        /// <summary>
        /// Updates an endpoint information in the node
        ///
        /// <param name="endpoint">the <see cref="ZigBeeEndpoint"> to update</param>
        /// </summary>
        public void UpdateEndpoint(ZigBeeEndpoint endpoint)
        {
            _endpoints[endpoint.EndpointId] = endpoint;

            lock (_endpointListeners)
            {
                foreach (IZigBeeNetworkEndpointListener listener in _endpointListeners)
                {
                    Task.Run(() =>
                    {
                        listener.DeviceUpdated(endpoint);
                    }).ContinueWith((t) =>
                    {
                        Log.Error(t.Exception, "Error: {Exception}");
                    }, TaskContinuationOptions.OnlyOnFaulted);
                }
            }
        }
コード例 #4
0
ファイル: ZigBeeNode.cs プロジェクト: lulzzz/ZigbeeNet
        /// <summary>
        /// Adds an endpoint to the node
        ///
        /// @param endpoint the {@link ZigBeeEndpoint} to add
        /// </summary>
        public void AddEndpoint(ZigBeeEndpoint endpoint)
        {
            //lock (Endpoints)
            //{
            Endpoints.AddOrUpdate(endpoint.EndpointId, endpoint, (_, __) => endpoint);
            //}

            lock (_endpointListeners)
            {
                foreach (IZigBeeNetworkEndpointListener listener in _endpointListeners)
                {
                    Task.Run(() =>
                    {
                        listener.DeviceAdded(endpoint);
                    }).ContinueWith((t) =>
                    {
                        _logger.Error(t.Exception, "Error");
                    }, TaskContinuationOptions.OnlyOnFaulted);
                }
            }
        }