示例#1
0
        private async Task EnumerateRouterAdaptor(UInt16 routerAddress)
        {
            var address = GetFreeAddress();

            var responseTask = Manager.WaitForResponseAsync((UInt16)NodeCommand.RouterDetect, 500);

            var(success, response) = await SendRequestAsync(routerAddress, OutgoingTransaction.Create((UInt16)NodeCommand.RouterEnumerateAdaptor, CreateTransactionId()).Write(address));

            if (response != null && response.ResponseCode == IdpResponseCode.OK)
            {
                var enumerated = response.Transaction.Read <bool>();

                if (enumerated)
                {
                    var routerDetectResponse = await responseTask;

                    if (routerDetectResponse != null && routerDetectResponse.ResponseCode == IdpResponseCode.OK)
                    {
                        var routerEnumerated = routerDetectResponse.Transaction.Read <bool>();

                        if (routerEnumerated)
                        {
                            await OnNodeAdded(routerAddress, address);

                            return;
                        }
                    }
                }
            }

            _freeAddresses.Push(address);

            _currentEnumerationNode.EnumerationState = NodeEnumerationState.Idle;
        }
示例#2
0
        private async Task OnNodeAdded(UInt16 parentAddress, UInt16 address)
        {
            _nodeInfo[address] = new NodeInfo(_nodeInfo[parentAddress], address);

            _nodeInfo[parentAddress].Children.Add(_nodeInfo[address]);

            var(success, response) = await SendRequestAsync(address, OutgoingTransaction.Create((UInt16)NodeCommand.GetNodeInfo, CreateTransactionId()));

            if (response != null && response.ResponseCode == IdpResponseCode.OK)
            {
                _nodeInfo[address].Guid = response.Transaction.Read <Guid>();

                _nodeInfo[address].Name = response.Transaction.ReadUtf8String();

                // TODO read string.

                if (_nodeInfo[address].IsRouter)
                {
                    _nodeInfo[address].EnumerationState = NodeEnumerationState.Pending;
                }
                else
                {
                    _nodeInfo[address].EnumerationState = NodeEnumerationState.Idle;
                }

                // normally on enumerate called here...
            }
        }
示例#3
0
        public async Task <bool> DisconnectAsync()
        {
            var(success, response) = await SendRequestAsync(OutgoingTransaction.Create((UInt16)ClientCommand.Disconnect, CreateTransactionId()));

            if (success && response != null && response.ResponseCode == IdpResponseCode.OK)
            {
                return(true);
            }

            return(false);
        }
        public async Task <UInt16> QueryInterfaceAsync(Guid guid)
        {
            UInt16 result = 0;

            var(success, response) = await SendRequestAsync(0,
                                                            OutgoingTransaction.Create((UInt16)NodeCommand.QueryInterface, CreateTransactionId(), IdpCommandFlags.None)
                                                            .Write(guid));

            if (success && response != null && response.ResponseCode == IdpResponseCode.OK)
            {
                result = response.Transaction.Source;
            }

            return(result);
        }
示例#5
0
        private async Task StartEnumeratingAdaptors(UInt16 routerAddress)
        {
            var(success, response) = await SendRequestAsync(routerAddress,
                                                            OutgoingTransaction.Create((UInt16)NodeCommand.RouterPrepareToEnumerateAdaptors, CreateTransactionId()));

            if (response != null && response.ResponseCode == IdpResponseCode.OK)
            {
                if (_currentEnumerationNode != null)
                {
                    _currentEnumerationNode.EnumerationState = NodeEnumerationState.EnumeratingAdaptors;
                }
            }
            else
            {
                if (_currentEnumerationNode != null)
                {
                    _currentEnumerationNode.EnumerationState = NodeEnumerationState.Idle;
                }
            }
        }
示例#6
0
        private async Task EnumerateRouterNode(UInt16 routerAddress)
        {
            var address = GetFreeAddress();

            var(success, response) = await SendRequestAsync(routerAddress, OutgoingTransaction.Create((UInt16)NodeCommand.RouterEnumerateNode, CreateTransactionId()).Write(address));

            if (response != null && response.ResponseCode == IdpResponseCode.OK)
            {
                var enumerated = response.Transaction.Read <bool>();

                if (enumerated)
                {
                    await OnNodeAdded(routerAddress, address);

                    return;
                }
            }

            _freeAddresses.Push(address);

            _currentEnumerationNode.EnumerationState = NodeEnumerationState.StartEnumeratingAdaptors;
        }
示例#7
0
        private async Task DetectRouter()
        {
            var address = GetFreeAddress();

            var(success, response) = await SendRequestAsync(0xFFFF, OutgoingTransaction.Create((UInt16)NodeCommand.RouterDetect, CreateTransactionId()).Write(address));

            if (success && response != null && response.ResponseCode == IdpResponseCode.OK)
            {
                var enumerated = response.Transaction.Read <bool>();

                if (enumerated)
                {
                    _currentEnumerationNode.EnumerationState = NodeEnumerationState.Idle;

                    await OnNodeAdded(Address, address);

                    return;
                }
            }

            _freeAddresses.Push(address);

            // normally on enumerate called.
        }
示例#8
0
 public void ResetNetwork()
 {
     SendRequest(0x0000, OutgoingTransaction.Create((UInt16)NodeCommand.Reset, CreateTransactionId(), IdpCommandFlags.None));
 }
示例#9
0
        public void PollNetwork()
        {
            //InvalidateNodes();

            SendRequest(0x0000, OutgoingTransaction.Create(0xA002, CreateTransactionId()));
        }
        public void QueryInterface(UInt16 vid, UInt16 pid)
        {
            Manager.RegisterResponseHandler((UInt16)NodeCommand.QueryInterface, response => OnQueryInterfaceResponse(response));

            SendRequest(0, OutgoingTransaction.Create((UInt16)NodeCommand.QueryInterface, CreateTransactionId()).Write(vid).Write(pid));
        }