Beispiel #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 if (Endpoints.TryGetValue(endpointAddress.Endpoint, out ZigBeeEndpoint endpoint))
            {
                endpoint.CommandReceived(zclCommand);
            }
        }
Beispiel #2
0
        public void Send(ZclCommand zclCommand, Endpoint srcEndpoint, Endpoint dstEndpoint, Cluster cluster, byte[] payload)
        {
            //DataRequest dataRequest = new DataRequest()
            //{
            //    DestinationAddress = dstEndpoint.Device.NwkAdress,
            //    SourceEndpoint = 0, //TODO: senderEp = srcEp.isLocal() ? srcEp : controller.getCoord().getDelegator(profId);
            //    DestinationEndpoint = dstEndpoint.Id,
            //    Cluster = (ushort)cluster,
            //    TransactionSeqNumber = Controller.NextTransId(),
            //    Options = (byte)(AFOptions.ACK_REQUEST | AFOptions.DISCV_ROUTE),
            //    Radius = 0x1e,
            //    Length = (byte)payload.Length,
            //    Data = payload
            //};

            //dataRequest.OnResponse += (object sender, ZpiObject zpiObject) =>
            //{
            //    //TODO: parse zpiObject payload to ZclPacket and it's payload to ZclCommand
            //    // AF:IncommingMsg --> AREQ Id: 129
            //    // 1. AF_DataConfirm 2. AF_IncommingMsg ???
            //    // Call ZclCommand Response() with parsed object as value

            //    throw new NotImplementedException();
            //    zclCommand.Response(null);
            //};

            //dataRequest.RequestAsync(Controller.Znp);
        }
Beispiel #3
0
        private void SendOnOffCommand(ZclCommand command)
        {
            Debug.WriteLine("Command {0}", command.Name);
            command.Send();
            DisplayOnOffStatus();

            // wait some time after command has been sent so man can see something happening on LED band
            System.Threading.Tasks.Task.Delay(1000).Wait();
        }
Beispiel #4
0
        /// <summary>
        /// Incoming command handler. The endpoint will process any commands addressed to this endpoint ID and pass o
        /// clusters and applications
        ///
        /// <param name="command">the <see cref="ZclCommand"> received</param>
        /// </summary>
        public void CommandReceived(ZclCommand command)
        {
            if (!command.SourceAddress.Equals(GetEndpointAddress()))
            {
                return;
            }

            // Pass all commands received from this endpoint to any registered applications
            lock (_applications)
            {
                foreach (IZigBeeApplication application in _applications.Values)
                {
                    application.CommandReceived(command);
                }
            }

            // Get the cluster
            ZclCluster cluster = GetReceiveCluster(command.ClusterId, command.CommandDirection);

            if (cluster == null)
            {
                Log.Debug("{EndpointAdress}: Cluster {Cluster} not found for attribute response", GetEndpointAddress(), command.ClusterId);
                return;
            }

            if (command is ReportAttributesCommand reportAttributesCommand)
            {
                // Pass the reports to the cluster
                cluster.HandleAttributeReport(reportAttributesCommand.Reports);
                return;
            }

            if (command is ReadAttributesResponse readAttributesResponse)
            {
                // Pass the reports to the cluster
                cluster.HandleAttributeStatus(readAttributesResponse.Records);
                return;
            }

            // If this is a specific cluster command, pass the command to the cluster command handler
            if (!command.GenericCommand)
            {
                cluster.HandleCommand(command);
            }
        }
Beispiel #5
0
        public void TestDresdenElektronik()
        {
            ZclCommand commandToggle = null;
            ZclCommand commandOn     = null;

            // look for OnOff cluster in the In cluster list of this end point
            var onOffcluster = m_testedEndPoint.GetCluster(OnOffCluster.CLUSTER_ID);

            if (onOffcluster != null)
            {
                onOffcluster.CommandList.TryGetValue(OnOffCluster.COMMAND_ON, out commandOn);
                onOffcluster.CommandList.TryGetValue(OnOffCluster.COMMAND_TOGGLE, out commandToggle);
            }

            // set light on
            SendOnOffCommand(commandOn);
            for (int index = 0; index < 9; index++)
            {
                // toggle light
                SendOnOffCommand(commandToggle);
            }
            // set light on
            SendOnOffCommand(commandOn);
        }
Beispiel #6
0
        public void ZclGlobal(Endpoint srcEndpoint, Endpoint dstEndpoint, Cluster cluster, ZclCommand zclCommand)
        {
            ZclPacket packet = new ZclPacket(zclCommand.Id);

            packet.Header.TransactionSequenceNumber = nextZclSeqNum();
            packet.Payload = zclCommand.Frame;

            if (packet.Header.FrameControl.Direction == Direction.ClientToServer) // client-to-server, thus require getting the feedback response
            {
                //TODO: Register event for response
            }

            BinarySerializer serializer = new BinarySerializer();

            using (MemoryStream stream = new MemoryStream())
            {
                serializer.Serialize(stream, packet);

                Send(zclCommand, srcEndpoint, dstEndpoint, cluster, stream.ToArray());
            }
        }