From 2daf438fd6902138b4229e21a8d67b02da778599 Mon Sep 17 00:00:00 2001 From: Roy Date: Tue, 20 Dec 2022 13:06:58 +0200 Subject: Modified TCP machines discovery method to MultiCast. --- .../Tango.Integration/ExternalBridge/ExternalBridgeService.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs') diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs index 4218f9e9a..6396774ae 100644 --- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs +++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs @@ -40,6 +40,7 @@ namespace Tango.Integration.ExternalBridge private TcpServer _tcpServer; private int _discovery_port = 8888; //Will be overridden by settings in constructor.. private int _external_bridge_port = 1984; //Will be overridden by settings in constructor.. + private String _multicastAddress = "234.55.66.77"; //Will be overridden by settings in constructor.. private HubConnection _connection; private IHubProxy _proxy; private bool _isSignalRConnected; @@ -199,6 +200,7 @@ namespace Tango.Integration.ExternalBridge _discovery_port = settings.ExternalBridgeServiceDiscoveryPort; _external_bridge_port = settings.ExternalBridgeServicePort; + _multicastAddress = settings.ExternalBridgeMulticastGroup; _tcpServer = new TcpServer(_external_bridge_port); _tcpServer.ClientConnected += _tcpServer_ClientConnected; @@ -234,7 +236,8 @@ namespace Tango.Integration.ExternalBridge _discoveryService = new UdpDiscoveryService(_discovery_port, new ExternalBridgeUdpDiscoveryPacket() { SerialNumber = Machine.SerialNumber, - }); + Guid = Machine.Guid, + }) { MulticastGroupAddress = _multicastAddress }; _discoveryService.BeforeBroadcasting -= _discoverySevice_BeforeBroadcasting; _discoveryService.BeforeBroadcasting += _discoverySevice_BeforeBroadcasting; -- cgit v1.3.1 From dbbed260e777d217cc3e897ae31483af183aaabc Mon Sep 17 00:00:00 2001 From: Roy Date: Tue, 20 Dec 2022 13:48:23 +0200 Subject: Implemented FSE/RSM TCP Connection By IP. --- .../Tango.FSE.UI/Panes/MachineConnectionPaneVM.cs | 14 +++++- .../ExternalBridge/ExternalBridgeScanner.cs | 53 ++++++++++++++++++++++ .../ExternalBridge/ExternalBridgeService.cs | 6 ++- .../Tango.Transport/Discovery/TcpValidationInfo.cs | 14 ++++++ .../Discovery/UdpDiscoveryService.cs | 19 +++++++- .../Tango.Transport/Tango.Transport.csproj | 1 + 6 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 Software/Visual_Studio/Tango.Transport/Discovery/TcpValidationInfo.cs (limited to 'Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs') 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(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; @@ -34,6 +36,11 @@ namespace Tango.Transport.Discovery /// public DiscoveryMessage CurrentDiscoveryMessage { get; set; } + /// + /// Gets or sets the TCP validation information. + /// + public TcpValidationInfo TcpValidationInfo { get; set; } + /// /// Gets or sets the multi-cast group address when using multi-cast discovery method. /// @@ -59,6 +66,7 @@ namespace Tango.Transport.Discovery /// private UdpDiscoveryService() { + TcpValidationInfo = new TcpValidationInfo(); Interval = TimeSpan.FromSeconds(5); CurrentDiscoveryMessage = Activator.CreateInstance(); } @@ -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 @@ + -- cgit v1.3.1