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 async Task ExecuteAsync(TextReader reader, byte systemType, ushort deviceType, byte hubId, byte portId, Version hw, Version sw) { var knowledge = _protocol.Knowledge; // override cached data using var disposable = _protocol.UpstreamRawMessages .Subscribe(tuple => KnowledgeManager.ApplyStaticProtocolKnowledge(tuple.message, knowledge)); await _protocol.ConnectAsync((SystemType)systemType); // registering to bluetooth notification if (systemType != 0) { Console.Error.WriteLine("Command Line provided Device Type, hubId, portId and versions hw/sw"); await _mock.MockCharacteristic.AttachIO((DeviceType)deviceType, hubId, portId, hw, sw); } var foundSystemType = false; var foundAttachedIO = false; var line = await reader.ReadLineAsync(); while (line is not null) { if (line.Substring(6, 8) == "01-0B-06") // property msg - systemtype - update { foundSystemType = true; } if (line.Substring(6, 2) == "04" && line.Substring(12, 2) == "01") // attached io msg (04) - port - attach event { foundAttachedIO = true; } await _mock.MockCharacteristic.WriteUpstreamAsync(line); line = await reader.ReadLineAsync(); } if (systemType == 0 && (foundSystemType == false || foundAttachedIO == false)) { Console.Error.WriteLine("#############################"); Console.Error.WriteLine("SystemType and/or attached IO message not found in data or command line arguments"); Console.Error.WriteLine("#############################"); } DevicesList.PrettyPrintKnowledge(System.Console.Out, _protocol.Knowledge); }
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); }