|
|
@@ -1,4 +1,5 @@
|
|
|
using DevExpress.Utils.Drawing.Helpers;
|
|
|
+using DevExpress.XtraReports;
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
@@ -56,7 +57,7 @@ namespace UAS_MES_NEW.Make
|
|
|
|
|
|
if (!IPList.Text.Contains(":"))
|
|
|
{
|
|
|
- IPList.Text = IPList.Text + ":5001";
|
|
|
+ IPList.Text = IPList.Text + ":5021";
|
|
|
}
|
|
|
|
|
|
if (!ProductList.Text.Contains(":"))
|
|
|
@@ -69,15 +70,13 @@ namespace UAS_MES_NEW.Make
|
|
|
{
|
|
|
if (e.KeyCode != Keys.Enter) return;
|
|
|
|
|
|
- if (IsCheckSet()) return;
|
|
|
-
|
|
|
- string sn = SN.Text.Trim();
|
|
|
-
|
|
|
if (IPList.Text.IndexOf(':') > 0) IPList.Text = IPList.Text.Replace(":", ":");
|
|
|
else IPList.Text = IPList.Text.Trim();
|
|
|
|
|
|
- if (SN.Text.IndexOf(';') > 0) SN.Text = sn.Replace(";", ";");
|
|
|
- else SN.Text = sn;
|
|
|
+ if (IsCheckSet()) return;
|
|
|
+
|
|
|
+ SN.Text = SN.Text.Trim().Replace(";", ";");
|
|
|
+ string sn = SN.Text.Trim();
|
|
|
|
|
|
UpdateSN("L", SN.Text.Trim());
|
|
|
|
|
|
@@ -90,19 +89,11 @@ namespace UAS_MES_NEW.Make
|
|
|
cameraIp: ProductList.Text.Trim().Split(':')[0],
|
|
|
cameraPort: cSPort,
|
|
|
username: Account.Text.Trim(),
|
|
|
- password: ProductList.Text.Trim(),
|
|
|
+ password: Password.Text.Trim(),
|
|
|
iperfServerIp: IPList.Text.Trim().Split(':')[0],
|
|
|
iperfServerPort: iSPort
|
|
|
);
|
|
|
|
|
|
- string Msg = tester.TelnetConnect();
|
|
|
- if (Msg.Substring(0, 2) != "OK")
|
|
|
- {
|
|
|
- ShowMsg(0, $"Telnet登录失败,{Msg}");
|
|
|
- return;
|
|
|
- }
|
|
|
- ShowMsg(1, $"Telnet登录成功");
|
|
|
-
|
|
|
string parentPath = Path.GetDirectoryName(ExePath.Text.Trim());
|
|
|
string logsPath = Path.Combine(parentPath, "iperf_logs");
|
|
|
if (!Directory.Exists(logsPath))
|
|
|
@@ -110,21 +101,10 @@ namespace UAS_MES_NEW.Make
|
|
|
Directory.CreateDirectory(logsPath);
|
|
|
}
|
|
|
|
|
|
- //string[] comList = new string[] {
|
|
|
- // "killall iperf3",
|
|
|
- // $"iperf3 -s -p {iSPort} -i 1&"
|
|
|
- //};
|
|
|
-
|
|
|
- string[] comList = new string[] {
|
|
|
- "cd /tmp/",
|
|
|
- "ls iperf3_mstar",
|
|
|
- "chmod a+x iperf3_mstar"
|
|
|
- };
|
|
|
-
|
|
|
- Msg = tester.StartIperfTest(SN.Text.Trim(), ExePath.Text.Trim(), logsPath, comList);
|
|
|
- if (Msg.Substring(0, 2) != "OK")
|
|
|
+ string Msg = tester.TestStart(SN.Text.Trim(), ExePath.Text.Trim(), logsPath);
|
|
|
+ if (Msg.StartsWith("NG"))
|
|
|
{
|
|
|
- ShowMsg(0, $"iperf3启动失败,{Msg}");
|
|
|
+ ShowMsg(0, Msg);
|
|
|
return;
|
|
|
}
|
|
|
string upRate = Msg.Split('|')[0].Split(',')[1];
|
|
|
@@ -135,31 +115,41 @@ namespace UAS_MES_NEW.Make
|
|
|
string tDetail = $"upRate/{upRate};downRate/{downRate}";
|
|
|
CheckPassStation(SN.Text, upRate, downRate, "PASS", tDetail);
|
|
|
}
|
|
|
+
|
|
|
private void CheckPassStation(string sn, string upRate, string downRate, string testRes,string testDetail)
|
|
|
{
|
|
|
+ List<string> param = new List<string>() { };
|
|
|
+ string outMsg = "";
|
|
|
+ param.Add(workOrder.Text);
|
|
|
+ param.Add(sn);
|
|
|
+ param.Add(User.UserSourceCode);
|
|
|
+ param.Add(testRes);
|
|
|
+ param.Add("");
|
|
|
+ param.Add("");
|
|
|
+ param.Add("WirelessThroughput");
|
|
|
+ param.Add(testDetail);
|
|
|
+ param.Add(outMsg);
|
|
|
+ string[] paramList = param.ToArray();
|
|
|
+ dh.CallProcedure("cs_insert_testrejects", ref paramList);
|
|
|
+ if (paramList[8].Substring(0, 2) == "OK")
|
|
|
+ {
|
|
|
+ ShowMsg(1, $"序列号{sn}采集成功:测试结果为{testRes}");
|
|
|
+ LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, workOrder.Text, User.UserLineCode, User.UserSourceCode, "无线吞吐量", "无线吞吐量过站成功", sn, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ dt = (DataTable)dh.ExecuteSql($"SELECT mp_id FROM makeprocess WHERE mp_sncode = '{sn}' AND mp_sourcecode = 'AOI'", "select");
|
|
|
+ if (dt.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ ShowMsg(1, $"序列号:{sn}已经过站记录");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
string oWO, oWOId, oErrMsg = "";
|
|
|
if (LogicHandler.CheckStepSNAndMacode(workOrder.Text, User.UserSourceCode, sn, User.UserCode, out oWO, out oWOId, out oErrMsg))
|
|
|
{
|
|
|
if (LogicHandler.SetStepResult(oWO, User.UserSourceCode, sn, "无线吞吐量", "OK", User.UserCode, out oErrMsg))
|
|
|
{
|
|
|
- List<string> param = new List<string>() { };
|
|
|
- string outMsg = "";
|
|
|
- param.Add(oWO);
|
|
|
- param.Add(sn);
|
|
|
- param.Add(User.UserSourceCode);
|
|
|
- param.Add(testRes);
|
|
|
- param.Add("");
|
|
|
- param.Add("");
|
|
|
- param.Add("WirelessThroughput");
|
|
|
- param.Add(testDetail);
|
|
|
- param.Add(outMsg);
|
|
|
- string[] paramList = param.ToArray();
|
|
|
- dh.CallProcedure("cs_insert_testrejects", ref paramList);
|
|
|
- if (paramList[8].Substring(0, 2) == "OK")
|
|
|
- {
|
|
|
- ShowMsg(1, $"序列号{sn}采集成功:测试结果为{testRes}");
|
|
|
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oWO, User.UserLineCode, User.UserSourceCode, "无线吞吐量", "无线吞吐量过站成功", sn, "");
|
|
|
- }
|
|
|
+ ShowMsg(0, $"序列号{sn},过站记录成功");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -260,12 +250,10 @@ namespace UAS_MES_NEW.Make
|
|
|
public class CameraIperfTester
|
|
|
{
|
|
|
int timeOut;
|
|
|
- string cameraIp;
|
|
|
- int cameraPort;
|
|
|
- string username;
|
|
|
- string password;
|
|
|
- string iperfServerIp;
|
|
|
- int iperfServerPort;
|
|
|
+ string cameraIp, iperfServerIp, username, password;
|
|
|
+ int cameraPort, iperfServerPort;
|
|
|
+
|
|
|
+ string SN, iperfPath, logDirectory;
|
|
|
|
|
|
private TcpClient _telnetClient;
|
|
|
private NetworkStream _telnetStream;
|
|
|
@@ -283,41 +271,22 @@ namespace UAS_MES_NEW.Make
|
|
|
this.iperfServerPort = iperfServerPort;
|
|
|
}
|
|
|
|
|
|
- public string StartIperfTest(string SN, string iperfPath,string logDirectory, string[] CList)
|
|
|
+ public string TestStart(string sn, string iP, string lD)
|
|
|
{
|
|
|
- if (_telnetStream == null)
|
|
|
- return "NG,未建立连接";
|
|
|
- try
|
|
|
- {
|
|
|
- foreach (var comItem in CList)
|
|
|
- {
|
|
|
- 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);
|
|
|
+ StringBuilder Msg = new StringBuilder();
|
|
|
|
|
|
- RunIperfClient($"./iperf3_mstar -c {cameraIp} -p {iperfServerPort} -i l -b 100M -t 10 -R", iperfPath, upLog);
|
|
|
- RunIperfClient($"./iperf3_mstar -c {cameraIp} -p {iperfServerPort} -i l -b 100M -t 10", iperfPath, downLog);
|
|
|
+ Msg.Append(TelnetConnect());
|
|
|
+ if (Msg.ToString().StartsWith("NG")) return Msg.ToString();
|
|
|
|
|
|
- string upRate = ParseIperfBitrate(upLog);
|
|
|
- string downRate = ParseIperfBitrate(downLog);
|
|
|
+ SN = sn;
|
|
|
+ iperfPath = iP;
|
|
|
+ logDirectory = lD;
|
|
|
+ Msg.Clear();
|
|
|
+ Msg.Append(StartIperfTest());
|
|
|
+ if (Msg.ToString().StartsWith("NG")) return Msg.ToString();
|
|
|
|
|
|
- return $"OK,{upRate}|{downRate}";
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- return $"NG,{ex.Message}";
|
|
|
- }
|
|
|
+ return Msg.ToString();
|
|
|
}
|
|
|
-
|
|
|
public string TelnetConnect()
|
|
|
{
|
|
|
try
|
|
|
@@ -341,28 +310,78 @@ namespace UAS_MES_NEW.Make
|
|
|
}
|
|
|
|
|
|
_telnetStream = _telnetClient.GetStream();
|
|
|
- _telnetStream.ReadTimeout = 3000; // 3S读取超时
|
|
|
+ _telnetStream.ReadTimeout = timeOut;
|
|
|
|
|
|
StringBuilder fullResponse = new StringBuilder();
|
|
|
|
|
|
string welcomeResponse = ReadStream(_telnetStream);
|
|
|
+ if (welcomeResponse.StartsWith("NG")) return welcomeResponse;
|
|
|
fullResponse.Append(welcomeResponse);
|
|
|
|
|
|
WriteStream(_telnetStream, username);
|
|
|
string usernameResponse = ReadStream(_telnetStream);
|
|
|
+ if (usernameResponse.StartsWith("NG")) return usernameResponse;
|
|
|
fullResponse.Append(usernameResponse);
|
|
|
|
|
|
WriteStream(_telnetStream, password);
|
|
|
string loginResponse = ReadStream(_telnetStream);
|
|
|
+ if (loginResponse.StartsWith("NG")) return loginResponse;
|
|
|
fullResponse.Append(loginResponse);
|
|
|
|
|
|
return $"OK,{fullResponse.ToString()}";
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
+ Close();
|
|
|
return $"NG,{ex.Message}";
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public string StartIperfTest()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ StringBuilder streamTxt = new StringBuilder();
|
|
|
+
|
|
|
+ //string[] comList = new string[] {
|
|
|
+ // "killall iperf3",
|
|
|
+ // $"iperf3 -s -p {iSPort} -i 1&"
|
|
|
+ //};
|
|
|
+
|
|
|
+ WriteStream(_telnetStream, "killall iperf3_mstar");
|
|
|
+ streamTxt.Append(ReadStream(_telnetStream));
|
|
|
+ Thread.Sleep(1000);
|
|
|
+
|
|
|
+ WriteStream(_telnetStream, "cp /mnt/tf/usb1_1/iperf3_mstar /var/tmp/ -f");
|
|
|
+ streamTxt.Append(ReadStream(_telnetStream));
|
|
|
+ Thread.Sleep(1000);
|
|
|
+
|
|
|
+ WriteStream(_telnetStream, "chmod a+x /var/tmp/iperf3_mstar");
|
|
|
+ streamTxt.Append(ReadStream(_telnetStream));
|
|
|
+ Thread.Sleep(1000);
|
|
|
+
|
|
|
+ WriteStream(_telnetStream, $"/var/tmp/iperf3_mstar -s -p {iperfServerPort} -i 1 &");
|
|
|
+ streamTxt.Append(ReadStream(_telnetStream));
|
|
|
+
|
|
|
+ string cmdLog = Path.Combine(logDirectory, $"{SN}_CMD.log");
|
|
|
+ File.WriteAllText(cmdLog, streamTxt.ToString());
|
|
|
+
|
|
|
+ string upLog = Path.Combine(logDirectory, $"{SN}_up.log");
|
|
|
+ string downLog = Path.Combine(logDirectory, $"{SN}_down.log");
|
|
|
+
|
|
|
+ RunIperfClient($"/var/tmp/iperf3 -c {cameraIp} -p {iperfServerPort} -t 6 -w 1M -i 1 -l 1518 -P 8 -R", iperfPath, upLog);
|
|
|
+ RunIperfClient($"/var/tmp/iperf3 -c {cameraIp} -p {iperfServerPort} -t 6 -w 1M -i 1 -l 1518 -P 8", iperfPath, downLog);
|
|
|
+
|
|
|
+ string upRate = ParseIperfBitrate(upLog);
|
|
|
+ string downRate = ParseIperfBitrate(downLog);
|
|
|
+ return $"OK,{upRate}|{downRate}";
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ return $"NG,{ex.Message}";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void RunIperfClient(string args, string path, string logPath)
|
|
|
{
|
|
|
var psi = new ProcessStartInfo
|
|
|
@@ -404,6 +423,7 @@ namespace UAS_MES_NEW.Make
|
|
|
File.WriteAllText(logPath, outputBuilder.ToString() + errorBuilder.ToString());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
public string ParseIperfBitrate(string logPath)
|
|
|
{
|
|
|
if (!File.Exists(logPath)) return "0.0";
|
|
|
@@ -442,50 +462,62 @@ namespace UAS_MES_NEW.Make
|
|
|
return rVal2;
|
|
|
}
|
|
|
|
|
|
- private void WriteStream(NetworkStream stream, string text)
|
|
|
+ private string WriteStream(NetworkStream stream, string data)
|
|
|
{
|
|
|
- byte[] data = Encoding.ASCII.GetBytes(text + "\r\n");
|
|
|
- stream.Write(data, 0, data.Length);
|
|
|
- stream.Flush();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ byte[] dataBytes = Encoding.UTF8.GetBytes(data + "\r\n");
|
|
|
+ stream.Write(dataBytes, 0, dataBytes.Length);
|
|
|
+ stream.Flush();
|
|
|
+ return $"OK";
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Close();
|
|
|
+ return $"NG,写入数据时发生错误: {ex.Message}";
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private string ReadStream(NetworkStream stream)
|
|
|
{
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- byte[] buffer = new byte[1024];
|
|
|
- int totalBytesRead = 0;
|
|
|
- int currentBytesRead = 0;
|
|
|
- DateTime lastReadTime = DateTime.UtcNow;
|
|
|
- TimeSpan idleTimeout = TimeSpan.FromMilliseconds(800); // 空闲超时
|
|
|
-
|
|
|
try
|
|
|
{
|
|
|
- do
|
|
|
+ StringBuilder response = new StringBuilder();
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int bytesRead;
|
|
|
+
|
|
|
+ while (stream.DataAvailable || response.Length == 0)
|
|
|
{
|
|
|
- currentBytesRead = stream.Read(buffer, 0, buffer.Length);
|
|
|
- if (currentBytesRead > 0)
|
|
|
+ bytesRead = stream.Read(buffer, 0, buffer.Length);
|
|
|
+ if (bytesRead > 0)
|
|
|
{
|
|
|
- sb.Append(Encoding.ASCII.GetString(buffer, 0, currentBytesRead));
|
|
|
- totalBytesRead += currentBytesRead;
|
|
|
- lastReadTime = DateTime.UtcNow;
|
|
|
+ response.Append(Encoding.UTF8.GetString(buffer, 0, bytesRead));
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ Thread.Sleep(100);
|
|
|
+ }
|
|
|
|
|
|
- } while ((DateTime.UtcNow - lastReadTime) < idleTimeout);
|
|
|
-
|
|
|
- }
|
|
|
- catch (IOException ioEx)
|
|
|
- {
|
|
|
-
|
|
|
+ return response.ToString();
|
|
|
}
|
|
|
- catch (ObjectDisposedException)
|
|
|
+ catch (IOException ioEx) when (ioEx.InnerException is SocketException socketEx && socketEx.SocketErrorCode == SocketError.TimedOut)
|
|
|
{
|
|
|
- throw;
|
|
|
+ Close();
|
|
|
+ return "NG,读取数据超时";
|
|
|
}
|
|
|
- catch (SocketException sockEx)
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- throw new IOException($"NG,网络错误: {sockEx.Message}", sockEx);
|
|
|
+ Close();
|
|
|
+ return $"NG,读取数据时发生错误: {ex.Message}";
|
|
|
}
|
|
|
- return sb.ToString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Close()
|
|
|
+ {
|
|
|
+ _telnetClient?.Close();
|
|
|
+ _telnetStream?.Close();
|
|
|
}
|
|
|
}
|
|
|
|