Skip to content

Commit 3eb6901

Browse files
committed
fix: useMaxAPDU
1 parent 67dfbc3 commit 3eb6901

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"preLaunchTask": "build",
2828
// If you have changed target frameworks, make sure to update the program path.
2929
"program": "${workspaceFolder}/bin/Debug/net9.0/KnxFileTransferClient.dll",
30-
"args": ["open", "--pkg", "52"],
30+
"args": ["open", "--pkg", "50"],
3131
"cwd": "${workspaceFolder}",
3232
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
3333
"console": "integratedTerminal",

Program.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static async Task<int> Main(string[] args)
122122
throw new Exception($"Das Zielgerät {arguments.PhysicalAddress} ist nicht erreichbar.", ex);
123123
}
124124
Console.WriteLine($"Info: Verbindung zum KNX-Gerät {arguments.Get<string>("pa")} hergestellt");
125+
useMaxAPDU = 255;
125126
// TODO get real MaxFrameLength from connection
126127
// if(conn.MaxFrameLength < useMaxAPDU)
127128
// useMaxAPDU = conn.MaxFrameLength;
@@ -130,14 +131,14 @@ static async Task<int> Main(string[] args)
130131
device.SetMaxFrameLength(useMaxAPDU);
131132
Console.WriteLine($"Info: Gerät MaxAPDU: {device.MaxFrameLength}");
132133
Console.WriteLine($"Info: Verwende MaxAPDU: {useMaxAPDU}");
133-
Console.WriteLine($"Info: Verwende Package: {arguments.Get<int>("pkg")}");
134134
if(arguments.Get<int>("pkg") > (useMaxAPDU - 3)) {
135135
Console.ForegroundColor = ConsoleColor.DarkYellow;
136136
Console.WriteLine("WARN: Package ist größer als MaxAPDU");
137137
Console.WriteLine($"WARN: Package wird geändert auf {useMaxAPDU-3}");
138138
Console.ResetColor();
139139
arguments.Set("pkg", useMaxAPDU-3);
140140
}
141+
Console.WriteLine($"Info: Verwende Package: {arguments.Get<int>("pkg")}");
141142
// Set the MaxAPDU that we calculated
142143
device.MaxFrameLength = useMaxAPDU;
143144

@@ -165,10 +166,20 @@ static async Task<int> Main(string[] args)
165166
string args3 = Console.ReadLine() ?? "";
166167
string[] args2 = args3.Split(" ");
167168
arguments = new Arguments();
168-
await arguments.Init(args2, true);
169-
await device.Connect(true);
170-
// Set the MaxAPDU that we calculated
171-
device.MaxFrameLength = useMaxAPDU;
169+
try
170+
{
171+
await arguments.Init(args2, true);
172+
await device.Connect(true);
173+
// Set the MaxAPDU that we calculated
174+
device.MaxFrameLength = useMaxAPDU;
175+
} catch(Exception ex)
176+
{
177+
Console.ForegroundColor = ConsoleColor.Red;
178+
Console.WriteLine("Error: " + ex.Message);
179+
Console.ResetColor();
180+
isOpen = false;
181+
continue;
182+
}
172183
}
173184

174185
try
@@ -735,6 +746,20 @@ private static async Task update(Arguments args, FileTransferClient client)
735746
return;
736747
}
737748

749+
Console.WriteLine("Info: Dateiübertragung abgeschlossen ");
750+
Console.WriteLine("Info: Übertragene Firmware wird geprüft... ");
751+
752+
Lib.FileInfo fileInfo = await client.FileInfo("/fw.bin", args.Get<bool>("force"));
753+
Console.WriteLine($"Info: CRC der übertragene Firmware: {fileInfo.GetCrc()}");
754+
byte[] file = FileHandler.GetBytes(args.Source);
755+
756+
CRCTool crc = new();
757+
crc.Init(CRCTool.CRCCode.CRC32);
758+
ulong crc32 = crc.CalculateCRC(file);
759+
byte[] x = BitConverter.GetBytes(crc32).Take(4).Reverse().ToArray();
760+
string crc32str = BitConverter.ToString(x).Replace("-", "");
761+
Console.WriteLine($"Info: CRC der lokalen Firmware: {crc32str}");
762+
738763
Console.WriteLine("Info: Gerät wird neu gestartet ");
739764

740765
await device.InvokeFunctionProperty(159, 101, System.Text.UTF8Encoding.UTF8.GetBytes("/fw.bin" + char.MinValue));

0 commit comments

Comments
 (0)