diff options
| author | Roy <Roy.mail.net@gmail.com> | 2022-12-20 13:48:23 +0200 |
|---|---|---|
| committer | Roy <Roy.mail.net@gmail.com> | 2022-12-20 13:48:23 +0200 |
| commit | dbbed260e777d217cc3e897ae31483af183aaabc (patch) | |
| tree | 40488db6e4a8119054ca78bacf6ad458a00670b5 | |
| parent | 2daf438fd6902138b4229e21a8d67b02da778599 (diff) | |
| download | Tango-dbbed260e777d217cc3e897ae31483af183aaabc.tar.gz Tango-dbbed260e777d217cc3e897ae31483af183aaabc.zip | |
Implemented FSE/RSM TCP Connection By IP.
6 files changed, 104 insertions, 3 deletions
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/MachineConnectionPaneVM.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/MachineConnectionPaneVM.cs index 32553fe0f..c70d38a56 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/MachineConnectionPaneVM.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/MachineConnectionPaneVM.cs @@ -43,6 +43,7 @@ namespace Tango.FSE.UI.Panes _filter = value; RaisePropertyChangedAuto(); _tcpMachinesView?.Refresh(); _signalRMachinesView?.Refresh(); + OnFilterChanged(); } } @@ -326,10 +327,21 @@ namespace Tango.FSE.UI.Panes if (machine != null) { - return machine.SerialNumber.ToLower().Contains(Filter.ToStringOrEmpty().ToLower()); + return machine.SerialNumber.ToLower().Contains(Filter.ToStringOrEmpty().ToLower()) || (machine.GetType() == typeof(ExternalBridgeTcpClient) && machine.IPAddress == Filter); } return true; } + + private void OnFilterChanged() + { + if (Filter.IsNotNullOrEmpty()) + { + Task.Factory.StartNew(() => + { + _scanner.TryGetMachineByIP(Filter); + }); + } + } } } diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs index 5e99dd647..6a20b558e 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs @@ -22,6 +22,7 @@ using Tango.PMR; using Tango.PMR.Common; using Tango.PMR.Integration; using Tango.Settings; +using Tango.Transport; using Tango.Transport.Adapters; using Tango.Transport.Discovery; using Tango.Transport.Helpers; @@ -384,5 +385,57 @@ namespace Tango.Integration.ExternalBridge MachineLost?.Invoke(this, sender as IExternalBridgeClient); } } + + public void TryGetMachineByIP(String ip) + { + IPAddress _IP; + if (IPAddress.TryParse(ip, out _IP)) + { + try + { + TcpClient client = new TcpClient(); + client.Connect(ip, _settings.ExternalBridgeServiceDiscoveryPort); + Thread.Sleep(100); + byte[] data = new byte[client.Available]; + client.GetStream().Read(data, 0, data.Length); + client.Dispose(); + TcpValidationInfo info = GenericMessageSerializer.Deserialize<TcpValidationInfo>(data, GenericMessageProtocol.Bson); + + ExternalBridgeTcpClient newMachine = null; + var knownMachine = KnownMachines.FirstOrDefault(x => x.SerialNumber == info.SerialNumber); + + if (knownMachine == null && KnownMachines.Count == 0) + { + newMachine = new ExternalBridgeTcpClient(info.SerialNumber, ip); + } + else if (knownMachine != null) + { + newMachine = new ExternalBridgeTcpClient(knownMachine, ip); + } + + if (newMachine != null) + { + LogManager.Log("Found a new machine via IP Address" + newMachine.SerialNumber); + + ThreadsHelper.InvokeUINow(() => + { + if (AvailableMachines.Count > 0) + { + AvailableMachines.Insert(1, newMachine); + } + else + { + AvailableMachines.Add(newMachine); + } + MachineDiscovered?.Invoke(this, newMachine); + }); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error occurred when trying to find a machine by IP."); + } + } + } } } diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs index 6396774ae..ae7cace31 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs @@ -237,7 +237,11 @@ namespace Tango.Integration.ExternalBridge { SerialNumber = Machine.SerialNumber, Guid = Machine.Guid, - }) { MulticastGroupAddress = _multicastAddress }; + }) + { + MulticastGroupAddress = _multicastAddress, + TcpValidationInfo = new TcpValidationInfo() { Guid = Machine.Guid, SerialNumber = Machine.SerialNumber } + }; _discoveryService.BeforeBroadcasting -= _discoverySevice_BeforeBroadcasting; _discoveryService.BeforeBroadcasting += _discoverySevice_BeforeBroadcasting; diff --git a/Software/Visual_Studio/Tango.Transport/Discovery/TcpValidationInfo.cs b/Software/Visual_Studio/Tango.Transport/Discovery/TcpValidationInfo.cs new file mode 100644 index 000000000..8dd3aedf0 --- /dev/null +++ b/Software/Visual_Studio/Tango.Transport/Discovery/TcpValidationInfo.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Transport.Discovery +{ + public class TcpValidationInfo + { + public String SerialNumber { get; set; } + public String Guid { get; set; } + } +} diff --git a/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs b/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs index e4ccbe4e9..476537559 100644 --- a/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs +++ b/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs @@ -9,7 +9,9 @@ using System.Text; using System.Threading.Tasks; using System.Timers; using Tango.Core; +using Tango.Core.ExtensionMethods; using Tango.PMR.Discovery; +using Tango.PMR.Integration; using Tango.Transport.Helpers; using Tango.Transport.Servers; @@ -35,6 +37,11 @@ namespace Tango.Transport.Discovery public DiscoveryMessage CurrentDiscoveryMessage { get; set; } /// <summary> + /// Gets or sets the TCP validation information. + /// </summary> + public TcpValidationInfo TcpValidationInfo { get; set; } + + /// <summary> /// Gets or sets the multi-cast group address when using multi-cast discovery method. /// </summary> public String MulticastGroupAddress { get; set; } @@ -59,6 +66,7 @@ namespace Tango.Transport.Discovery /// </summary> private UdpDiscoveryService() { + TcpValidationInfo = new TcpValidationInfo(); Interval = TimeSpan.FromSeconds(5); CurrentDiscoveryMessage = Activator.CreateInstance<DiscoveryMessage>(); } @@ -73,7 +81,16 @@ namespace Tango.Transport.Discovery _tcpValidationServer = new TcpServer(Port); _tcpValidationServer.ClientConnected += (x, e) => { - e.Socket.Dispose(); + try + { + var data = GenericMessageSerializer.Serialize(TcpValidationInfo, GenericMessageProtocol.Bson); + e.Socket.GetStream().Write(data, 0, data.Length); + e.Socket.Dispose(); + } + catch (Exception ex) + { + LogManager.Log(ex, "TCP Validation Server Response Error."); + } }; } diff --git a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj index c0fac9344..b45138dff 100644 --- a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj +++ b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj @@ -113,6 +113,7 @@ <Compile Include="Discovery\IDiscoveryClient.cs" /> <Compile Include="Discovery\IDiscoveryComponent.cs" /> <Compile Include="Discovery\IDiscoveryService.cs" /> + <Compile Include="Discovery\TcpValidationInfo.cs" /> <Compile Include="Discovery\UdpDiscoveryClient.cs" /> <Compile Include="Discovery\UdpDiscoveryService.cs" /> <Compile Include="Discovery\UsbCommunicationScanner.cs" /> |
