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("##################################################"); }
public static async Task <PortFeedback> SendPortOutputCommandAsync(this ILegoWirelessProtocol self, PortOutputCommandMessage message) { var portId = message.PortId; var response = await self.SendMessageReceiveResultAsync <PortOutputCommandFeedbackMessage>(message, msg => msg.Feedbacks.Any(f => f.PortId == portId)); return(response.Feedbacks.FirstOrDefault(f => f.PortId == portId).Feedback); }
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("##################################################"); }
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); }