Example #1
0
        public void CommandReceived(ZigBeeCommand command)
        {
            // If we have local servers matching the request, then we need to respond
            if (command is MatchDescriptorRequest matchRequest)
            {
                Log.Debug("{ExtPanId}: ClusterMatcher received request {Match}", _networkManager.ZigBeeExtendedPanId, matchRequest);
                if (matchRequest.ProfileId != 0x104)
                {
                    // TODO: Do we need to restrict the profile? Remove this check?
                    return;
                }

                // We want to match any of our local servers (ie our input clusters) with any
                // requested clusters in the requests cluster list
                if (matchRequest.InClusterList.Intersect(_clusters).Count() == 0 &&
                    matchRequest.OutClusterList.Intersect(_clusters).Count() == 0)
                {
                    Log.Debug("{ExtPanId}: ClusterMatcher no match", _networkManager.ZigBeeExtendedPanId);
                    return;
                }

                MatchDescriptorResponse matchResponse = new MatchDescriptorResponse();
                matchResponse.Status = ZdoStatus.SUCCESS;
                List <ushort> matchList = new List <ushort>();
                matchList.Add(1);
                matchResponse.MatchList = matchList;

                matchResponse.DestinationAddress = command.SourceAddress;
                matchResponse.NwkAddrOfInterest  = matchRequest.NwkAddrOfInterest;
                Log.Debug("{ExtPanId}: ClusterMatcher sending match {Response}", _networkManager.ZigBeeExtendedPanId, matchResponse);
                _networkManager.SendCommand(matchResponse);
            }
        }
Example #2
0
        public void CommandReceived(ZigBeeCommand command)
        {
            // If we have local servers matching the request, then we need to respond
            if (command is MatchDescriptorRequest matchRequest)
            {
                Log.Debug("{ExtPanId}: ClusterMatcher received request {Match}", _networkManager.ZigBeeExtendedPanId, matchRequest);
                if (matchRequest.ProfileId != _profileId)
                {
                    Log.Debug("{ExtPanId}: ClusterMatcher no match to profileId", _networkManager.ZigBeeExtendedPanId);
                    return;
                }

                if (matchRequest.NwkAddrOfInterest != _networkManager.LocalNwkAddress &&
                    !ZigBeeBroadcastDestination.IsBroadcast(matchRequest.NwkAddrOfInterest))
                {
                    Log.Debug("{ExtPanId}: ClusterMatcher no match to local address", _networkManager.ZigBeeExtendedPanId);
                    return;
                }

                // We want to match any of our local servers (ie our input clusters) with any
                // requested clusters in the requests cluster list
                if (matchRequest.InClusterList.Intersect(_serverClusters).Count() == 0 &&
                    matchRequest.OutClusterList.Intersect(_clientClusters).Count() == 0)
                {
                    Log.Debug("{ExtPanId}: ClusterMatcher no match", _networkManager.ZigBeeExtendedPanId);
                    return;
                }

                MatchDescriptorResponse matchResponse = new MatchDescriptorResponse();
                matchResponse.Status = ZdoStatus.SUCCESS;
                List <byte> matchList = new List <byte>();
                matchList.Add(_localEndpointId);
                matchResponse.MatchList          = matchList;
                matchResponse.NwkAddrOfInterest  = _networkManager.LocalNwkAddress;
                matchResponse.TransactionId      = matchRequest.TransactionId;
                matchResponse.DestinationAddress = command.SourceAddress;
                Log.Debug("{ExtPanId}: ClusterMatcher sending match {Response}", _networkManager.ZigBeeExtendedPanId, matchResponse);
                _networkManager.SendCommand(matchResponse);
            }
        }
        public void SendCommand()
        {
            IList <IXBeeCommand>     sentCommands     = new List <IXBeeCommand>();
            Mock <IXBeeFrameHandler> frameHandlerMock = new Mock <IXBeeFrameHandler>();

            frameHandlerMock.Setup(frameHandler => frameHandler.SendRequestAsync(It.IsAny <IXBeeCommand>())).Callback <IXBeeCommand>(item => sentCommands.Add(item)).ReturnsAsync(() => null);

            ZigBeeDongleXBee dongle = new ZigBeeDongleXBee(null);

            try
            {
                Type      fieldType = dongle.GetType();
                FieldInfo fieldInfo = fieldType.GetField("_frameHandler", BindingFlags.NonPublic | BindingFlags.Instance);
                fieldInfo.SetValue(dongle, frameHandlerMock.Object);
            }
            catch (Exception ex)
            {
                _output.WriteLine(ex.StackTrace);
            }

            MatchDescriptorResponse command = new MatchDescriptorResponse
            {
                DestinationAddress = new ZigBeeEndpointAddress(46946),
                NwkAddrOfInterest  = 46946,
                Status             = ZDO.ZdoStatus.SUCCESS,
                TransactionId      = 0x2A
            };
            List <ushort> matchList = new List <ushort>
            {
                1
            };

            command.MatchList = matchList;

            ZigBeeApsFrame apsFrame = new ZigBeeApsFrame
            {
                DestinationAddress     = 46946,
                DestinationEndpoint    = 0,
                DestinationIeeeAddress = new IeeeAddress(BigInteger.Parse("000D6F00057CF7C6", NumberStyles.HexNumber)),
                Cluster     = 32774,
                AddressMode = ZigBeeNwkAddressMode.Device,
                Radius      = 31,
                ApsCounter  = 42,
                Payload     = new byte[] { 0x00, 0x00, 0x2E, 0x5B, 0x01, 0x01 }
            };

            _output.WriteLine(command.ToString());
            _output.WriteLine(apsFrame.ToString());

            dongle.SendCommand(apsFrame);
            Assert.Equal(1, sentCommands.Count);
            XBeeTransmitRequestExplicitCommand sentCommand = (XBeeTransmitRequestExplicitCommand)sentCommands[0];

            sentCommand.SetFrameId(32);
            _output.WriteLine(sentCommand.ToString());

            int[] payload = new int[] { 0, 26, 17, 32, 0, 13, 111, 0, 5, 124, 247, 198, 183, 98, 0, 0, 128, 6, 0, 0, 0, 0,
                                        0, 0, 46, 91, 1, 1, 234 };

            int[] output = sentCommand.Serialize();
            Assert.True(payload.SequenceEqual(output));
        }