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 /Software/Visual_Studio/Tango.Integration | |
| parent | 2daf438fd6902138b4229e21a8d67b02da778599 (diff) | |
| download | Tango-dbbed260e777d217cc3e897ae31483af183aaabc.tar.gz Tango-dbbed260e777d217cc3e897ae31483af183aaabc.zip | |
Implemented FSE/RSM TCP Connection By IP.
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration')
| -rw-r--r-- | Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs | 53 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs | 6 |
2 files changed, 58 insertions, 1 deletions
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; |
