コード例 #1
0
        public void GetDevice(ushort nwkAddr, ulong ieeeAddr, Action <Device> callback)
        {
            Device device = new Device()
            {
                NwkAdress   = nwkAddr,
                IeeeAddress = ieeeAddr
            };

            NodeDescRequest nodeDesc = new NodeDescRequest()
            {
                DestinationAddress        = nwkAddr,
                NetworkAddressOfInteresst = nwkAddr
            };

            nodeDesc.OnResponse += (object sender, ZpiObject e) =>
            {
                NodeDescResponse rsp = e.ToSpecificObject <NodeDescResponse>();
                device.Type           = (Devices)(rsp.LogicaltypeCmplxdescavaiUserdescavai & 0x07);
                device.ManufacturerId = rsp.ManufacturerCode;

                ActiveEndpointsRequest activeEp = new ActiveEndpointsRequest()
                {
                    DestinationAddress        = nwkAddr,
                    NetworkAddressOfInteresst = nwkAddr
                };
                activeEp.OnResponse += (object s, ZpiObject ep) =>
                {
                    ActiveEndpointResponse eprsp = ep.ToSpecificObject <ActiveEndpointResponse>();

                    foreach (byte epByte in eprsp.Endpoints)
                    {
                        int count = 0;
                        GetEndpoint(device, epByte, nwkAddr, (endpoint) =>
                        {
                            device.Endpoints.Add(endpoint);
                            count++;

                            if (count == eprsp.Endpoints.Count())
                            {
                                callback?.Invoke(device);
                            }
                        });
                    }
                };
                activeEp.RequestAsync(_znp);
            };

            nodeDesc.RequestAsync(_znp);
        }
コード例 #2
0
        /// <summary>
        /// Get the active endpoints for a node
        ///
        /// <returns>true if the message was processed ok</returns>
        /// </summary>
        private async Task <bool> RequestActiveEndpoints()
        {
            ActiveEndpointsRequest activeEndpointsRequest = new ActiveEndpointsRequest();

            activeEndpointsRequest.DestinationAddress = new ZigBeeEndpointAddress((ushort)Node.NetworkAddress);
            activeEndpointsRequest.NwkAddrOfInterest  = Node.NetworkAddress;

            CommandResult response = await NetworkManager.SendTransaction(activeEndpointsRequest, activeEndpointsRequest);

            ActiveEndpointsResponse activeEndpointsResponse = (ActiveEndpointsResponse)response.Response;

            Log.Debug("{IeeeAddress}: Node SVC Discovery: ActiveEndpointsResponse returned {Response}", Node.IeeeAddress, response);

            if (activeEndpointsResponse == null)
            {
                return(false);
            }

            // Get the simple descriptors for all endpoints
            List <ZigBeeEndpoint> endpoints = new List <ZigBeeEndpoint>();

            foreach (byte endpointId in activeEndpointsResponse.ActiveEpList)
            {
                ZigBeeEndpoint endpoint = await GetSimpleDescriptor(endpointId);

                if (endpoint == null)
                {
                    return(false);
                }

                endpoints.Add(endpoint);
            }

            // All endpoints have been received, so add them to the node
            foreach (ZigBeeEndpoint endpoint in endpoints)
            {
                _updatedNode.AddEndpoint(endpoint);
            }

            return(true);
        }