yhluo 1 ヶ月 前
コミット
da4ce097d5
1 ファイル変更31 行追加11 行削除
  1. 31 11
      UAS_MES_HYSX/FunctionCode/Make/Make_WirelessThroughput.cs

+ 31 - 11
UAS_MES_HYSX/FunctionCode/Make/Make_WirelessThroughput.cs

@@ -118,9 +118,8 @@ namespace UAS_MES_NEW.Make
             string[] comList = new string[] {
                 "cd /tmp/",
                 "ls iperf3_mstar",
-                "chmod a+x iperf3_mstar",
-                $"iperf3_mstar -s -p {iSPort} -i 1 &"
-        };
+                "chmod a+x iperf3_mstar"
+            };
 
             Msg = tester.StartIperfTest(SN.Text.Trim(), ExePath.Text.Trim(), logsPath, comList);
             if (Msg.Substring(0, 2) != "OK")
@@ -295,12 +294,13 @@ namespace UAS_MES_NEW.Make
                         WriteStream(_telnetStream, comItem);
                         ReadStream(_telnetStream);
                     }
-
                     Thread.Sleep(1000); // 等服务端启动
 
+                    string serverStartLog = Path.Combine(logDirectory, $"{SN}_start.log");
+                    RunIperfClient($"./iperf3_mstar -s -p {iperfServerPort} -i l&", iperfPath, serverStartLog);
+
                     string upLog = Path.Combine(logDirectory, $"{SN}_up.log");
                     string downLog = Path.Combine(logDirectory, $"{SN}_down.log");
-
                     //RunIperfClient($"-c {cameraIp} -p {iperfServerPort} -t 10 -w 1M -i 1 -P 8 -R", iperfPath, upLog);
                     //RunIperfClient($"-c {cameraIp} -p {iperfServerPort} -t 10 -w 1M -i 1 -P 8", iperfPath, downLog);
 
@@ -372,16 +372,36 @@ namespace UAS_MES_NEW.Make
                     RedirectStandardOutput = true,
                     RedirectStandardError = true,
                     UseShellExecute = false,
-                    CreateNoWindow = true
+                    CreateNoWindow = true,
+                    WorkingDirectory = Path.GetDirectoryName(path)
                 };
-
                 using (var process = Process.Start(psi))
                 {
-                    string output = process.StandardOutput.ReadToEnd();
-                    string error = process.StandardError.ReadToEnd();
-                    process.WaitForExit(5000); // 最多等 15 秒
+                    StringBuilder outputBuilder = new StringBuilder();
+                    StringBuilder errorBuilder = new StringBuilder();
+
+                    process.OutputDataReceived += (sender, e) =>
+                    {
+                        if (!string.IsNullOrEmpty(e.Data))
+                        {
+                            outputBuilder.AppendLine(e.Data);
+                        }
+                    };
+
+                    process.ErrorDataReceived += (sender, e) =>
+                    {
+                        if (!string.IsNullOrEmpty(e.Data))
+                        {
+                            errorBuilder.AppendLine(e.Data);
+                        }
+                    };
+
+                    process.BeginOutputReadLine();
+                    process.BeginErrorReadLine();
+
+                    process.WaitForExit();
 
-                    File.WriteAllText(logPath, output + Environment.NewLine + error);
+                    File.WriteAllText(logPath, outputBuilder.ToString() + errorBuilder.ToString());
                 }
             }
             public string ParseIperfBitrate(string logPath)