Exemple #1
0
        public async Task ExecuteAsync(byte portId)
        {
            Console.WriteLine($"Discover Port {portId}. Receiving Messages ...");

            await protocol.ConnectAsync(); // registering to bluetooth notification

            await Task.Delay(2000);        // await ports to be announced initially by device.

            using var disposable = protocol.UpstreamMessages.Subscribe(x => Console.Write("."));

            await discoverPorts.ExecuteAsync(portId);

            await protocol.SendMessageReceiveResultAsync <HubActionMessage>(new HubActionMessage()
            {
                HubId = 0, Action = HubAction.SwitchOffHub
            }, result => result.Action == HubAction.HubWillSwitchOff);

            Console.WriteLine(string.Empty);

            Console.WriteLine($"Discover Ports Function: {discoverPorts.ReceivedMessages} / {discoverPorts.SentMessages}");

            Console.WriteLine("##################################################");
            foreach (var data in discoverPorts.ReceivedMessagesData.OrderBy(x => x[2]).ThenBy(x => x[4]).ThenBy(x => (x.Length <= 5) ? -1 : x[5]))
            {
                Console.WriteLine(BytesStringUtil.DataToString(data));
            }
            Console.WriteLine("##################################################");
        }
Exemple #2
0
    public async Task DiscoverAsync()
    {
        var discoverPortsFunction = new DiscoverPorts(_protocol);

        await discoverPortsFunction.ExecuteAsync(_portId);

        BuildModes();
    }
Exemple #3
0
        public async Task ExecuteAsync(SystemType knownSystemType, byte portId, bool headerEnabled)
        {
            Console.WriteLine($"Discover Port {portId}. Receiving Messages ...");

            await protocol.ConnectAsync(knownSystemType); // registering to bluetooth notification

            await Task.Delay(2000);                       // await ports to be announced initially by device.

            using var disposable = protocol.UpstreamMessages.Subscribe(x => Console.Write("."));

            await discoverPorts.ExecuteAsync(portId);

            await protocol.SendMessageReceiveResultAsync <HubActionMessage>(new HubActionMessage(HubAction.SwitchOffHub) { HubId = 0 }, result => result.Action == HubAction.HubWillSwitchOff);

            Console.WriteLine(string.Empty);

            Console.WriteLine($"Discover Ports Function: {discoverPorts.ReceivedMessages} / {discoverPorts.SentMessages}");

            Console.WriteLine(knownSystemType);
            Console.WriteLine("##################################################");
            //Exception was thrown if no device was attached to the port
            if (discoverPorts.ReceivedMessages > 0)
            {
                var systemTypeMessage = CreateSystemTypeHeader(knownSystemType);
                var attachedIOMessage = CreateAttachedIOHeader(portId);


                if (headerEnabled)
                {
                    Console.WriteLine(BytesStringUtil.DataToString(systemTypeMessage));
                    Console.WriteLine(BytesStringUtil.DataToString(attachedIOMessage));
                }

                foreach (var data in discoverPorts.ReceivedMessagesData.OrderBy(x => x[2]).ThenBy(x => x[4]).ThenBy(x => (x.Length <= 5) ? -1 : x[5]))
                {
                    Console.WriteLine(BytesStringUtil.DataToString(data));
                }
            }
            else
            {
                Console.WriteLine($":-( It seems there is no device attached to port {portId} on this hub...");
            }

            Console.WriteLine("##################################################");
        }
Exemple #4
0
        public async Task ExecuteAsync(SystemType knownSystemType)
        {
            Console.WriteLine("Discover Ports. Receiving Messages ...");

            await protocol.ConnectAsync(knownSystemType); // registering to bluetooth notification

            await Task.Delay(2000);                       // await ports to be announced initially by device.

            using var disposable = protocol.UpstreamMessages.Subscribe(x => Console.Write("."));

            await discoverPorts.ExecuteAsync();

            await protocol.SendMessageReceiveResultAsync <HubActionMessage>(new HubActionMessage(HubAction.SwitchOffHub) { HubId = 0 }, result => result.Action == HubAction.HubWillSwitchOff);

            Console.WriteLine(string.Empty);

            Console.WriteLine($"Discover Ports Function: {discoverPorts.ReceivedMessages} / {discoverPorts.SentMessages}");

            PrettyPrintKnowledge(System.Console.Out, protocol.Knowledge, false);
        }