aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio
diff options
context:
space:
mode:
authorRoy <Roy.mail.net@gmail.com>2023-01-31 09:51:01 +0200
committerRoy <Roy.mail.net@gmail.com>2023-01-31 09:51:01 +0200
commit2b9a91ba032dcbbeedaefb1d7b06cb93285b99df (patch)
treeb3895a89b3f3b73009b260ad2b062e8547878f09 /Software/Visual_Studio
parent180ba6c91451ace9f20bbad8ab4a64c9f25ab83c (diff)
parent1c913a54575b885cb63acd4b6362e7b5669f856c (diff)
downloadTango-2b9a91ba032dcbbeedaefb1d7b06cb93285b99df.tar.gz
Tango-2b9a91ba032dcbbeedaefb1d7b06cb93285b99df.zip
Merged I4.0
Diffstat (limited to 'Software/Visual_Studio')
-rw-r--r--Software/Visual_Studio/Advanced Installer Projects/PPC Installer-cache/cacheIndex.txtbin52 -> 52 bytes
-rw-r--r--Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures.Documentation/Help/proc-doc.chmbin335565 -> 335559 bytes
-rw-r--r--Software/Visual_Studio/FSE/Tango.FSE.UI/Panes/MachineConnectionPaneVM.cs14
-rw-r--r--Software/Visual_Studio/FSE/Tango.FSE.UI/Properties/AssemblyInfo.cs2
-rw-r--r--Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs122
-rw-r--r--Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeService.cs9
-rw-r--r--Software/Visual_Studio/Tango.Integration/IntegrationSettings.cs13
-rw-r--r--Software/Visual_Studio/Tango.PMR/Integration/ExternalBridgeUdpDiscoveryPacket.cs35
-rw-r--r--Software/Visual_Studio/Tango.Transport/Discovery/DiscoveryMethod.cs14
-rw-r--r--Software/Visual_Studio/Tango.Transport/Discovery/TcpValidationInfo.cs14
-rw-r--r--Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs52
-rw-r--r--Software/Visual_Studio/Tango.Transport/Helpers/IPAddressHelper.cs31
-rw-r--r--Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj3
13 files changed, 283 insertions, 26 deletions
diff --git a/Software/Visual_Studio/Advanced Installer Projects/PPC Installer-cache/cacheIndex.txt b/Software/Visual_Studio/Advanced Installer Projects/PPC Installer-cache/cacheIndex.txt
index 993ced97e..5fe5afe5a 100644
--- a/Software/Visual_Studio/Advanced Installer Projects/PPC Installer-cache/cacheIndex.txt
+++ b/Software/Visual_Studio/Advanced Installer Projects/PPC Installer-cache/cacheIndex.txt
Binary files differ
diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures.Documentation/Help/proc-doc.chm b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures.Documentation/Help/proc-doc.chm
index d570e1f2e..2d9611889 100644
--- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures.Documentation/Help/proc-doc.chm
+++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.Procedures.Documentation/Help/proc-doc.chm
Binary files differ
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/FSE/Tango.FSE.UI/Properties/AssemblyInfo.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/Properties/AssemblyInfo.cs
index b3f45c5a3..942c667ae 100644
--- a/Software/Visual_Studio/FSE/Tango.FSE.UI/Properties/AssemblyInfo.cs
+++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/Properties/AssemblyInfo.cs
@@ -8,4 +8,4 @@ using System.Windows;
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Tango FSE")]
-[assembly: AssemblyVersion("1.4.4.0")]
+[assembly: AssemblyVersion("1.4.5.0")]
diff --git a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs
index 694502d2e..da55a13d3 100644
--- a/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs
+++ b/Software/Visual_Studio/Tango.Integration/ExternalBridge/ExternalBridgeScanner.cs
@@ -22,7 +22,10 @@ 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;
namespace Tango.Integration.ExternalBridge
{
@@ -35,7 +38,6 @@ namespace Tango.Integration.ExternalBridge
private Thread _tcpDiscoveryThread;
private Thread _usbDiscoveryThread;
private Thread _signalRDiscoveryThread;
- private UdpClient _server;
private IntegrationSettings _settings;
private HubConnection _connection;
private IHubProxy _proxy;
@@ -99,13 +101,6 @@ namespace Tango.Integration.ExternalBridge
{
LogManager.Log("External bridge scanner started...");
- if (_server == null)
- {
- _server = new UdpClient();
- _server.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
- _server.Client.Bind(new IPEndPoint(IPAddress.Any, _settings.ExternalBridgeServiceDiscoveryPort));
- }
-
IsStarted = true;
foreach (var machine in AvailableMachines.OfType<ExternalBridgeTcpClient>().ToList())
@@ -167,6 +162,19 @@ namespace Tango.Integration.ExternalBridge
if (IsStarted)
{
IsStarted = false;
+
+ try
+ {
+ _usbDiscoveryThread.Abort();
+ _tcpDiscoveryThread.Abort();
+ _signalRDiscoveryThread.Abort();
+ AvailableMachines.Clear();
+ }
+ catch (Exception ex)
+ {
+ Debug.WriteLine(ex);
+ }
+
LogManager.Log("External bridge scanner stopped.");
}
}
@@ -209,13 +217,39 @@ namespace Tango.Integration.ExternalBridge
{
try
{
- var ClientEp = new IPEndPoint(IPAddress.Any, _settings.ExternalBridgeServiceDiscoveryPort);
- _server.EnableBroadcast = true;
- var ClientRequestData = _server.Receive(ref ClientEp);
+ ExternalBridgeUdpDiscoveryPacket discoveryPacket = null;
+ String address = null;
- ExternalBridgeUdpDiscoveryPacket packet = ExternalBridgeUdpDiscoveryPacket.Parser.ParseFrom(ClientRequestData);
+ if (_settings.ExternalBridgeDiscoveryMethod == DiscoveryMethod.Multicast)
+ {
+ using (UdpClient udpClient = new UdpClient())
+ {
+ udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
+ udpClient.Client.Bind(new IPEndPoint(IPAddress.Any, _settings.ExternalBridgeServiceDiscoveryPort));
+ udpClient.JoinMulticastGroup(IPAddress.Parse(_settings.ExternalBridgeMulticastGroup), IPAddress.Parse(IPAddressHelper.GetLocalIpAddress()));
- String address = ClientEp.Address.ToString();
+ var endPoint = new IPEndPoint(IPAddress.Any, 0);
+ var discoveryData = udpClient.Receive(ref endPoint);
+
+ discoveryPacket = ExternalBridgeUdpDiscoveryPacket.Parser.ParseFrom(discoveryData);
+ address = endPoint.Address.ToString();
+ }
+ }
+ else
+ {
+ using (UdpClient udpClient = new UdpClient())
+ {
+ udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
+ udpClient.Client.Bind(new IPEndPoint(IPAddress.Any, _settings.ExternalBridgeServiceDiscoveryPort));
+ var endPoint = new IPEndPoint(IPAddress.Any, _settings.ExternalBridgeServiceDiscoveryPort);
+
+ udpClient.EnableBroadcast = true;
+ var discoveryData = udpClient.Receive(ref endPoint);
+
+ discoveryPacket = ExternalBridgeUdpDiscoveryPacket.Parser.ParseFrom(discoveryData);
+ address = endPoint.Address.ToString();
+ }
+ }
//validate service existence using TCP connection.
try
@@ -226,7 +260,7 @@ namespace Tango.Integration.ExternalBridge
}
catch
{
- var disconnected_machine = AvailableMachines.OfType<ExternalBridgeTcpClient>().ToList().FirstOrDefault(x => x.SerialNumber == packet.SerialNumber && x.IPAddress == address);
+ var disconnected_machine = AvailableMachines.OfType<ExternalBridgeTcpClient>().ToList().FirstOrDefault(x => x.SerialNumber == discoveryPacket.SerialNumber && x.IPAddress == address);
if (disconnected_machine != null)
{
@@ -238,14 +272,14 @@ namespace Tango.Integration.ExternalBridge
continue;
}
- if (!AvailableMachines.OfType<ExternalBridgeTcpClient>().ToList().Exists(x => x.SerialNumber == packet.SerialNumber && x.IPAddress == address))
+ if (!AvailableMachines.OfType<ExternalBridgeTcpClient>().ToList().Exists(x => x.SerialNumber == discoveryPacket.SerialNumber && x.IPAddress == address))
{
ExternalBridgeTcpClient newMachine = null;
- var knownMachine = KnownMachines.FirstOrDefault(x => x.SerialNumber == packet.SerialNumber);
+ var knownMachine = KnownMachines.FirstOrDefault(x => x.SerialNumber == discoveryPacket.SerialNumber);
if (knownMachine == null && KnownMachines.Count == 0)
{
- newMachine = new ExternalBridgeTcpClient(packet.SerialNumber, address);
+ newMachine = new ExternalBridgeTcpClient(discoveryPacket.SerialNumber, address);
}
else if (knownMachine != null)
{
@@ -275,6 +309,8 @@ namespace Tango.Integration.ExternalBridge
{
LogManager.Log(ex);
}
+
+ Thread.Sleep(100);
}
}
@@ -363,5 +399,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 4218f9e9a..ae7cace31 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,12 @@ namespace Tango.Integration.ExternalBridge
_discoveryService = new UdpDiscoveryService<ExternalBridgeUdpDiscoveryPacket>(_discovery_port, new ExternalBridgeUdpDiscoveryPacket()
{
SerialNumber = Machine.SerialNumber,
- });
+ Guid = Machine.Guid,
+ })
+ {
+ 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.Integration/IntegrationSettings.cs b/Software/Visual_Studio/Tango.Integration/IntegrationSettings.cs
index ce6ace32a..20d0b76e4 100644
--- a/Software/Visual_Studio/Tango.Integration/IntegrationSettings.cs
+++ b/Software/Visual_Studio/Tango.Integration/IntegrationSettings.cs
@@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using Tango.Settings;
using Tango.Transport.Adapters;
+using Tango.Transport.Discovery;
namespace Tango.Integration
{
@@ -21,6 +22,16 @@ namespace Tango.Integration
public int ExternalBridgeServiceDiscoveryPort { get; set; }
/// <summary>
+ /// Gets or sets the external bridge multi-cast group address.
+ /// </summary>
+ public String ExternalBridgeMulticastGroup { get; set; }
+
+ /// <summary>
+ /// Gets or sets the discovery method.
+ /// </summary>
+ public DiscoveryMethod ExternalBridgeDiscoveryMethod { get; set; }
+
+ /// <summary>
/// Gets or sets the name of the embedded device.
/// </summary>
public String EmbeddedDeviceName { get; set; }
@@ -42,6 +53,8 @@ namespace Tango.Integration
{
ExternalBridgeServicePort = 1984;
ExternalBridgeServiceDiscoveryPort = 8888;
+ ExternalBridgeMulticastGroup = "234.55.66.77";
+ ExternalBridgeDiscoveryMethod = DiscoveryMethod.Multicast;
EmbeddedDeviceName = "Tango USB Serial Port";
FilterExternalBridgeUsbMachines = false;
EmbeddedSerialBaudRate = UsbSerialBaudRates.BR_115200;
diff --git a/Software/Visual_Studio/Tango.PMR/Integration/ExternalBridgeUdpDiscoveryPacket.cs b/Software/Visual_Studio/Tango.PMR/Integration/ExternalBridgeUdpDiscoveryPacket.cs
index df584d5c6..309f95be3 100644
--- a/Software/Visual_Studio/Tango.PMR/Integration/ExternalBridgeUdpDiscoveryPacket.cs
+++ b/Software/Visual_Studio/Tango.PMR/Integration/ExternalBridgeUdpDiscoveryPacket.cs
@@ -23,13 +23,14 @@ namespace Tango.PMR.Integration {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"CiZFeHRlcm5hbEJyaWRnZVVkcERpc2NvdmVyeVBhY2tldC5wcm90bxIVVGFu",
- "Z28uUE1SLkludGVncmF0aW9uIkYKIEV4dGVybmFsQnJpZGdlVWRwRGlzY292",
+ "Z28uUE1SLkludGVncmF0aW9uIlQKIEV4dGVybmFsQnJpZGdlVWRwRGlzY292",
"ZXJ5UGFja2V0EgwKBFRpbWUYASABKAkSFAoMU2VyaWFsTnVtYmVyGAIgASgJ",
- "QiEKH2NvbS50d2luZS50YW5nby5wbXIuaW50ZWdyYXRpb25iBnByb3RvMw=="));
+ "EgwKBEd1aWQYAyABKAlCIQofY29tLnR3aW5lLnRhbmdvLnBtci5pbnRlZ3Jh",
+ "dGlvbmIGcHJvdG8z"));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
- new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Integration.ExternalBridgeUdpDiscoveryPacket), global::Tango.PMR.Integration.ExternalBridgeUdpDiscoveryPacket.Parser, new[]{ "Time", "SerialNumber" }, null, null, null)
+ new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.Integration.ExternalBridgeUdpDiscoveryPacket), global::Tango.PMR.Integration.ExternalBridgeUdpDiscoveryPacket.Parser, new[]{ "Time", "SerialNumber", "Guid" }, null, null, null)
}));
}
#endregion
@@ -62,6 +63,7 @@ namespace Tango.PMR.Integration {
public ExternalBridgeUdpDiscoveryPacket(ExternalBridgeUdpDiscoveryPacket other) : this() {
time_ = other.time_;
serialNumber_ = other.serialNumber_;
+ guid_ = other.guid_;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -91,6 +93,17 @@ namespace Tango.PMR.Integration {
}
}
+ /// <summary>Field number for the "Guid" field.</summary>
+ public const int GuidFieldNumber = 3;
+ private string guid_ = "";
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
+ public string Guid {
+ get { return guid_; }
+ set {
+ guid_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as ExternalBridgeUdpDiscoveryPacket);
@@ -106,6 +119,7 @@ namespace Tango.PMR.Integration {
}
if (Time != other.Time) return false;
if (SerialNumber != other.SerialNumber) return false;
+ if (Guid != other.Guid) return false;
return true;
}
@@ -114,6 +128,7 @@ namespace Tango.PMR.Integration {
int hash = 1;
if (Time.Length != 0) hash ^= Time.GetHashCode();
if (SerialNumber.Length != 0) hash ^= SerialNumber.GetHashCode();
+ if (Guid.Length != 0) hash ^= Guid.GetHashCode();
return hash;
}
@@ -132,6 +147,10 @@ namespace Tango.PMR.Integration {
output.WriteRawTag(18);
output.WriteString(SerialNumber);
}
+ if (Guid.Length != 0) {
+ output.WriteRawTag(26);
+ output.WriteString(Guid);
+ }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -143,6 +162,9 @@ namespace Tango.PMR.Integration {
if (SerialNumber.Length != 0) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(SerialNumber);
}
+ if (Guid.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Guid);
+ }
return size;
}
@@ -157,6 +179,9 @@ namespace Tango.PMR.Integration {
if (other.SerialNumber.Length != 0) {
SerialNumber = other.SerialNumber;
}
+ if (other.Guid.Length != 0) {
+ Guid = other.Guid;
+ }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@@ -175,6 +200,10 @@ namespace Tango.PMR.Integration {
SerialNumber = input.ReadString();
break;
}
+ case 26: {
+ Guid = input.ReadString();
+ break;
+ }
}
}
}
diff --git a/Software/Visual_Studio/Tango.Transport/Discovery/DiscoveryMethod.cs b/Software/Visual_Studio/Tango.Transport/Discovery/DiscoveryMethod.cs
new file mode 100644
index 000000000..b1616644b
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Transport/Discovery/DiscoveryMethod.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 enum DiscoveryMethod
+ {
+ Multicast,
+ Broadcast
+ }
+}
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 c37ab7f51..3e714325b 100644
--- a/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs
+++ b/Software/Visual_Studio/Tango.Transport/Discovery/UdpDiscoveryService.cs
@@ -3,12 +3,16 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
+using System.Net.NetworkInformation;
using System.Net.Sockets;
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;
namespace Tango.Transport.Discovery
@@ -33,6 +37,16 @@ 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; }
+
+ /// <summary>
/// Gets or sets the interval in which the discovery message will be sent.
/// </summary>
public TimeSpan Interval { get; set; }
@@ -52,6 +66,7 @@ namespace Tango.Transport.Discovery
/// </summary>
private UdpDiscoveryService()
{
+ TcpValidationInfo = new TcpValidationInfo();
Interval = TimeSpan.FromSeconds(5);
CurrentDiscoveryMessage = Activator.CreateInstance<DiscoveryMessage>();
}
@@ -66,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.");
+ }
};
}
@@ -127,14 +151,15 @@ namespace Tango.Transport.Discovery
private void BroadcastDiscoveryPacket()
{
+ //Broadcast
try
{
+ BeforeBroadcasting?.Invoke(this, CurrentDiscoveryMessage);
+
UdpClient client = new UdpClient();
IPEndPoint endPoint = new IPEndPoint(IPAddress.Broadcast, Port);
- BeforeBroadcasting?.Invoke(this, CurrentDiscoveryMessage);
-
byte[] bytes = CurrentDiscoveryMessage.ToByteArray();
client.EnableBroadcast = true;
@@ -146,6 +171,27 @@ namespace Tango.Transport.Discovery
{
LogManager.Log(ex, "Error broadcasting discovery packet.");
}
+
+ //Multicast
+ try
+ {
+ UdpClient client = new UdpClient(AddressFamily.InterNetwork);
+
+ IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(MulticastGroupAddress), Port);
+
+ client.JoinMulticastGroup(IPAddress.Parse(MulticastGroupAddress), IPAddress.Parse(IPAddressHelper.GetLocalIpAddress()));
+
+ byte[] bytes = CurrentDiscoveryMessage.ToByteArray();
+
+ client.Client.Ttl = 10;
+ client.Send(bytes, bytes.Length, endPoint);
+
+ client.Close();
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error multicasting discovery packet.");
+ }
}
}
}
diff --git a/Software/Visual_Studio/Tango.Transport/Helpers/IPAddressHelper.cs b/Software/Visual_Studio/Tango.Transport/Helpers/IPAddressHelper.cs
new file mode 100644
index 000000000..04a15caa3
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Transport/Helpers/IPAddressHelper.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.NetworkInformation;
+using System.Net.Sockets;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.Transport.Helpers
+{
+ public static class IPAddressHelper
+ {
+ public static string GetLocalIpAddress()
+ {
+ foreach (var netI in NetworkInterface.GetAllNetworkInterfaces())
+ {
+ if (netI.NetworkInterfaceType != NetworkInterfaceType.Wireless80211 &&
+ (netI.NetworkInterfaceType != NetworkInterfaceType.Ethernet ||
+ netI.OperationalStatus != OperationalStatus.Up)) continue;
+ foreach (var uniIpAddrInfo in netI.GetIPProperties().UnicastAddresses.Where(x => netI.GetIPProperties().GatewayAddresses.Count > 0))
+ {
+
+ if (uniIpAddrInfo.Address.AddressFamily == AddressFamily.InterNetwork &&
+ uniIpAddrInfo.AddressPreferredLifetime != uint.MaxValue)
+ return uniIpAddrInfo.Address.ToString();
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj
index bbe0b3780..b45138dff 100644
--- a/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj
+++ b/Software/Visual_Studio/Tango.Transport/Tango.Transport.csproj
@@ -107,16 +107,19 @@
<Compile Include="Compression\SevenZipHelper.cs" />
<Compile Include="ContinuousResponseAbortedException.cs" />
<Compile Include="Discovery\CommunicationScannerResult.cs" />
+ <Compile Include="Discovery\DiscoveryMethod.cs" />
<Compile Include="Discovery\ICommunicationScanner.cs" />
<Compile Include="Discovery\DiscoveredService.cs" />
<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" />
<Compile Include="Encoders\ProtoEncoder.cs" />
<Compile Include="ExtensionMethods\TcpClientExtensions.cs" />
+ <Compile Include="Helpers\IPAddressHelper.cs" />
<Compile Include="ITransportComponent.cs" />
<Compile Include="ITransportAdapter.cs" />
<Compile Include="Adapters\TcpTransportAdapter.cs" />