Skip to content

Commit 3cb2bca

Browse files
committed
added: tcp tunneling
1 parent dde4419 commit 3cb2bca

File tree

5 files changed

+54
-21
lines changed

5 files changed

+54
-21
lines changed

Arguments.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ internal class Arguments{
2525
new("config", "Konfigurationsname", Argument.ArgumentType.String, "default"),
2626
new("interactive", "Alle Argumente müssen vom Benutzer eingegeben werden", Argument.ArgumentType.Bool, false),
2727
new("no-resume", "Vorhandene Dateien werden immer komplett neu übertragen", Argument.ArgumentType.Bool, false),
28-
new("device-timeout", "Timeout in dem das Gerät eine Antwort schicken muss", Argument.ArgumentType.Int, 4000)
28+
new("device-timeout", "Timeout in dem das Gerät eine Antwort schicken muss", Argument.ArgumentType.Int, 4000),
29+
new("tcp", "Verwende TCP als Transportprotokoll", Argument.ArgumentType.Bool, false)
2930
};
3031

3132
public UnicastAddress? PhysicalAddress { get; private set; } = null;
@@ -130,6 +131,7 @@ public async Task Init(string[] args, bool isOpen = false)
130131
Console.ForegroundColor = ConsoleColor.DarkGray;
131132
Console.WriteLine($"Verwende als source address {Get<string>("gs")}");
132133
Console.ResetColor();
134+
Set("tcp", "false");
133135
}
134136

135137
SaveArgs(configName);
@@ -181,7 +183,7 @@ private async Task<bool> SearchGateways(bool isAuto = false)
181183
if (svcFamilies.GetServiceFamilyVersion(Kaenx.Konnect.Enums.ServiceFamilies.Tunneling) > 0)
182184
{
183185
int tunnelingVersion = svcFamilies.GetServiceFamilyVersion(Kaenx.Konnect.Enums.ServiceFamilies.Tunneling);
184-
Console.WriteLine($"{counter,2} Tunneling v{tunnelingVersion} -> {hpai.Endpoint,-20} ({deviceInfo.UnicastAddress,-9}) [{deviceInfo.FriendlyName}]");
186+
Console.WriteLine($"{counter,2} Tunneling v{tunnelingVersion} [UDP] -> {hpai.Endpoint,-20} ({deviceInfo.UnicastAddress,-9}) [{deviceInfo.FriendlyName}]");
185187
Connection conn = new(hpai.Endpoint)
186188
{
187189
FriendlyName = deviceInfo.FriendlyName,
@@ -190,12 +192,26 @@ private async Task<bool> SearchGateways(bool isAuto = false)
190192
};
191193
gateways.Add(conn);
192194
counter++;
195+
196+
if(tunnelingVersion >= 2)
197+
{
198+
Console.WriteLine($"{counter,2} Tunneling v{tunnelingVersion} [TCP] -> {hpai.Endpoint,-20} ({deviceInfo.UnicastAddress,-9}) [{deviceInfo.FriendlyName}]");
199+
Connection tcpConn = new(hpai.Endpoint)
200+
{
201+
IsTCP = true,
202+
FriendlyName = deviceInfo.FriendlyName,
203+
PhysicalAddress = deviceInfo.UnicastAddress,
204+
Version = tunnelingVersion
205+
};
206+
gateways.Add(tcpConn);
207+
counter++;
208+
}
193209
}
194210

195211
if (svcFamilies.GetServiceFamilyVersion(Kaenx.Konnect.Enums.ServiceFamilies.Routing) > 0)
196212
{
197213
int routingVersion = svcFamilies.GetServiceFamilyVersion(Kaenx.Konnect.Enums.ServiceFamilies.Routing);
198-
Console.WriteLine($"{counter,2} Routing v{routingVersion} -> {hpai.Endpoint,-20} ({deviceInfo.UnicastAddress,-9}) [{deviceInfo.FriendlyName}]");
214+
Console.WriteLine($"{counter,2} Routing v{routingVersion} [UDP] -> {hpai.Endpoint,-20} ({deviceInfo.UnicastAddress,-9}) [{deviceInfo.FriendlyName}]");
199215
Connection conn = new(hpai.Endpoint)
200216
{
201217
IsRouting = true,
@@ -235,6 +251,7 @@ private async Task<bool> SearchGateways(bool isAuto = false)
235251
Set("gw", conn.IPAddress.Address.ToString());
236252
Set("ga", conn.PhysicalAddress.ToString());
237253
Set("port", conn.IPAddress.Port.ToString());
254+
Set("tcp", conn.IsTCP.ToString());
238255
IsRouting = conn.IsRouting;
239256
}
240257
}
@@ -259,6 +276,7 @@ private async Task<bool> SearchGateways(bool isAuto = false)
259276
Set("gw", conn.IPAddress.Address.ToString());
260277
Set("ga", conn.PhysicalAddress.ToString());
261278
Set("port", conn.IPAddress.Port.ToString());
279+
Set("tcp", conn.IsTCP.ToString());
262280
IsRouting = conn.IsRouting;
263281
}
264282
return true;

Connection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class Connection
99
public IPEndPoint IPAddress { get; set; }
1010
public UnicastAddress PhysicalAddress { get; set; } = UnicastAddress.FromString("0.0.0");
1111
public int Version { get; set; } = 1;
12+
public bool IsTCP { get; set; } = false;
1213

1314
public Connection(IPEndPoint ip)
1415
{

KnxFileTransferClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<ImplicitUsings>enable</ImplicitUsings>
1414
<Nullable>enable</Nullable>
1515

16-
<AssemblyVersion>0.2.7.16</AssemblyVersion>
16+
<AssemblyVersion>0.2.7.17</AssemblyVersion>
1717
</PropertyGroup>
1818

1919
<ItemGroup>

Program.cs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,30 @@ static async Task<int> Main(string[] args)
6060

6161
//Print the client version of the client and the lib
6262
Console.ForegroundColor = ConsoleColor.DarkGray;
63-
System.Version? clientVersion = typeof(Program).Assembly.GetName().Version;
64-
if (clientVersion != null)
63+
System.Version? _version = typeof(Program).Assembly.GetName().Version;
64+
if (_version != null)
6565
{
66-
if(clientVersion.Revision != 0)
67-
Console.WriteLine($"Version Client: {clientVersion.Major}.{clientVersion.Minor}.{clientVersion.Build}.{clientVersion.Revision}");
66+
if(_version.Revision != 0)
67+
Console.WriteLine($"Version Client: {_version.Major}.{_version.Minor}.{_version.Build}.{_version.Revision}");
6868
else
69-
Console.WriteLine($"Version Client: {clientVersion.Major}.{clientVersion.Minor}.{clientVersion.Build}");
69+
Console.WriteLine($"Version Client: {_version.Major}.{_version.Minor}.{_version.Build}");
7070
}
7171
// Get the custom library attributes
72-
System.Version? libVersion = typeof(KnxFileTransferClient.Lib.FileTransferClient).Assembly.GetName().Version;
73-
if (libVersion != null)
72+
_version = typeof(KnxFileTransferClient.Lib.FileTransferClient).Assembly.GetName().Version;
73+
if (_version != null)
7474
{
75-
if(libVersion.Revision != 0)
76-
Console.WriteLine($"Version Client.Lib: {libVersion.Major}.{libVersion.Minor}.{libVersion.Build}.{libVersion.Revision}");
75+
if (_version.Revision != 0)
76+
Console.WriteLine($"Version Client.Lib: {_version.Major}.{_version.Minor}.{_version.Build}.{_version.Revision}");
7777
else
78-
Console.WriteLine($"Version Client.Lib: {libVersion.Major}.{libVersion.Minor}.{libVersion.Build}");
78+
Console.WriteLine($"Version Client.Lib: {_version.Major}.{_version.Minor}.{_version.Build}");
79+
}
80+
_version = typeof(Kaenx.Konnect.KnxFactory).Assembly.GetName().Version;
81+
if (_version != null)
82+
{
83+
if (_version.Revision != 0)
84+
Console.WriteLine($"Version Kaenx.Konnect: {_version.Major}.{_version.Minor}.{_version.Build}.{_version.Revision}");
85+
else
86+
Console.WriteLine($"Version Kaenx.Konnect: {_version.Major}.{_version.Minor}.{_version.Build}");
7987
}
8088
Console.ResetColor();
8189
Arguments arguments = new Arguments();
@@ -96,7 +104,7 @@ static async Task<int> Main(string[] args)
96104
catch { canFancy = false; }
97105

98106
Console.ForegroundColor = ConsoleColor.Cyan;
99-
Console.WriteLine($"IP-Adresse: {arguments.Interface}" + (arguments.IsRouting ? " (Multicast)" : ""));
107+
Console.WriteLine($"IP-Adresse: {arguments.Interface} " + (arguments.Get<bool>("tcp") ? "[TCP]" : "[UDP]") + (arguments.IsRouting ? " (Multicast)" : ""));
100108
Console.WriteLine($"IP-Port: {arguments.Get<int>("port")}");
101109
Console.WriteLine($"PA: {arguments.PhysicalAddress}");
102110
Console.WriteLine();
@@ -108,7 +116,12 @@ static async Task<int> Main(string[] args)
108116
if(arguments.IsRouting)
109117
conn = KnxFactory.CreateRouting(UnicastAddress.FromString(arguments.Get<string>("gs")), arguments.Interface, arguments.Get<int>("port"));
110118
else
111-
conn = KnxFactory.CreateTunnelingUdp(arguments.Interface, arguments.Get<int>("port"));
119+
{
120+
if(arguments.Get<bool>("tcp"))
121+
conn = KnxFactory.CreateTunnelingTcp(arguments.Interface, arguments.Get<int>("port"));
122+
else
123+
conn = KnxFactory.CreateTunnelingUdp(arguments.Interface, arguments.Get<int>("port"));
124+
}
112125

113126
try
114127
{
@@ -151,14 +164,15 @@ static async Task<int> Main(string[] args)
151164
if(device.MaxFrameLength < useMaxAPDU)
152165
useMaxAPDU = device.MaxFrameLength;
153166
device.SetMaxFrameLength(useMaxAPDU);
154-
Console.WriteLine($"Info: Gerät MaxAPDU: {device.MaxFrameLength}");
167+
Console.WriteLine($"Info: Package: {arguments.Get<int>("pkg")}");
168+
Console.WriteLine($"Info: Gerät MaxAPDU: {device.MaxFrameLength}");
155169
Console.WriteLine($"Info: Verwende MaxAPDU: {useMaxAPDU}");
156-
if(arguments.Get<int>("pkg") > (useMaxAPDU - 3)) {
170+
if(arguments.Get<int>("pkg") > (useMaxAPDU)) {
157171
Console.ForegroundColor = ConsoleColor.DarkYellow;
158172
Console.WriteLine("WARN: Package ist größer als MaxAPDU");
159-
Console.WriteLine($"WARN: Package wird geändert auf {useMaxAPDU-3}");
173+
Console.WriteLine($"WARN: Package wird geändert auf {useMaxAPDU}");
160174
Console.ResetColor();
161-
arguments.Set("pkg", useMaxAPDU-3);
175+
arguments.Set("pkg", useMaxAPDU);
162176
}
163177
Console.WriteLine($"Info: Verwende Package: {arguments.Get<int>("pkg")}");
164178
// Set the MaxAPDU that we calculated

Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"KnxFileTransferClient": {
44
"commandName": "Project",
5-
"commandLineArgs": "open"
5+
"commandLineArgs": "open --verbose"
66
}
77
}
88
}

0 commit comments

Comments
 (0)