Make_WirelessThroughput.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. using DevExpress.Utils.Drawing.Helpers;
  2. using DevExpress.XtraReports;
  3. using NPOI.SS.Formula.Functions;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Diagnostics;
  9. using System.Drawing;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Net;
  13. using System.Net.Sockets;
  14. using System.Text;
  15. using System.Text.RegularExpressions;
  16. using System.Threading;
  17. using System.Web.Services.Description;
  18. using System.Web.UI.WebControls.WebParts;
  19. using System.Windows.Forms;
  20. using UAS_MES_NEW.DataOperate;
  21. using UAS_MES_NEW.Entity;
  22. using UAS_MES_NEW.PublicMethod;
  23. namespace UAS_MES_NEW.Make
  24. {
  25. public partial class Make_WirelessThroughput : Form
  26. {
  27. public Make_WirelessThroughput()
  28. {
  29. InitializeComponent();
  30. }
  31. StringBuilder SQL = new StringBuilder();
  32. DataTable dt;
  33. DataHelper dh;
  34. string telnetPort;
  35. private void Make_WirelessThroughput_Load(object sender, EventArgs e)
  36. {
  37. dh = SystemInf.dh;
  38. try
  39. {
  40. string hostName = Dns.GetHostName();
  41. IPHostEntry hostEntry = Dns.GetHostEntry(hostName);
  42. foreach (IPAddress ip in hostEntry.AddressList)
  43. {
  44. if (ip.AddressFamily == AddressFamily.InterNetwork)
  45. {
  46. IPList.Text = ip.ToString();
  47. }
  48. }
  49. }
  50. catch (Exception ex)
  51. {
  52. ShowMsg(0, $"获取iperf服务器地址失败,{ex.Message}");
  53. }
  54. if (!IPList.Text.Contains(":"))
  55. {
  56. IPList.Text = IPList.Text + ":5021";
  57. }
  58. telnetPort = "23";
  59. //if (!ProductList.Text.Contains(":"))
  60. //{
  61. // ProductList.Text = ProductList.Text + ":23";
  62. //}
  63. Locat1.Visible = false;
  64. Locat2.Visible = false;
  65. Locat3.Visible = false;
  66. Radio1.Visible = false;
  67. Radio2.Visible = false;
  68. }
  69. private void SN_KeyDown(object sender, KeyEventArgs e)
  70. {
  71. if (e.KeyCode != Keys.Enter) return;
  72. if (IPList.Text.IndexOf(':') > 0) IPList.Text = IPList.Text.Replace(":", ":");
  73. else IPList.Text = IPList.Text.Trim();
  74. SN.Text = SN.Text.Trim().Replace(";", ";");
  75. string sn = SN.Text.Trim();
  76. SQL.Clear();
  77. //SQL.Append($"SELECT pr_test_account,pr_test_password FROM makeserial,product WHERE ms_sncode = '{sn}' AND ms_prodcode = pr_code");
  78. SQL.Append($"SELECT * FROM (SELECT pr_test_account,pr_test_password FROM makeserial,product WHERE ms_sncode = '{sn}' AND ms_prodcode = pr_code ORDER BY ms_indate DESC) WHERE ROWNUM = 1");
  79. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  80. if (dt.Rows.Count == 0)
  81. {
  82. ShowMsg(0, $"序列号:{sn}未维护吞吐量测试账户密码");
  83. }
  84. else
  85. {
  86. Account.Text = dt.Rows[0]["pr_test_account"].ToString();
  87. Password.Text = dt.Rows[0]["pr_test_password"].ToString();
  88. }
  89. if (IsCheckSet()) return;
  90. UpdateSN("L", SN.Text.Trim());
  91. ShowMsg(1, $"开始测试");
  92. int iSPort = Convert.ToInt32(IPList.Text.Trim().Split(':')[1]);
  93. var tester = new CameraIperfTester(
  94. timeOut: TestTime.Text.Trim(),
  95. cameraIp: ProductList.Text.Trim().Split(':')[0],
  96. cameraPort: Convert.ToInt32(telnetPort),
  97. username: Account.Text.Trim(),
  98. password: Password.Text.Trim(),
  99. iperfServerIp: IPList.Text.Trim().Split(':')[0],
  100. iperfServerPort: iSPort
  101. );
  102. string parentPath = Path.GetDirectoryName(ExePath.Text.Trim());
  103. string logsPath = Path.Combine(parentPath, "iperf_logs");
  104. if (!Directory.Exists(logsPath))
  105. {
  106. Directory.CreateDirectory(logsPath);
  107. }
  108. string Msg = tester.TestStart(SN.Text.Trim(), ExePath.Text.Trim(), logsPath, comboBox1.SelectedIndex.ToString());
  109. if (Msg.StartsWith("NG"))
  110. {
  111. ShowMsg(0, Msg);
  112. return;
  113. }
  114. string upRate = Msg.Split('|')[0].Split(',')[1];
  115. string downRate = Msg.Split('|')[1];
  116. ShowMsg(1, $"OK,上行速率: {upRate},下行速率: {downRate}");
  117. ResMax.Text = upRate;
  118. ResMin.Text = downRate;
  119. string tDetail = $"upRate/{upRate};downRate/{downRate}";
  120. CheckPassStation(SN.Text, "PASS", tDetail);
  121. }
  122. private void CheckPassStation(string sn, string testRes, string testDetail)
  123. {
  124. List<string> param = new List<string>() { };
  125. string outMsg = "";
  126. param.Add(workOrder.Text);
  127. param.Add(sn);
  128. param.Add(User.UserSourceCode);
  129. param.Add(testRes);
  130. param.Add("");
  131. param.Add("");
  132. param.Add("Thruput");
  133. param.Add(testDetail);
  134. param.Add(outMsg);
  135. string[] paramList = param.ToArray();
  136. dh.CallProcedure("cs_insert_testrejects", ref paramList);
  137. if (paramList[8].Substring(0, 2) == "OK")
  138. {
  139. ShowMsg(1, $"序列号{sn}采集成功:测试结果为{testRes}");
  140. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, workOrder.Text, User.UserLineCode, User.UserSourceCode, "无线吞吐量", "无线吞吐量过站成功", sn, "");
  141. }
  142. dt = (DataTable)dh.ExecuteSql($"SELECT mp_id FROM makeprocess WHERE mp_sncode = '{sn}' AND instr(mp_stepname, '吞吐量') > 0", "select");
  143. if (dt.Rows.Count > 0)
  144. {
  145. ShowMsg(1, $"序列号:{sn}已经过站记录");
  146. return;
  147. }
  148. string oWO, oWOId, oErrMsg = "";
  149. if (LogicHandler.CheckStepSNAndMacode(workOrder.Text, User.UserSourceCode, sn, User.UserCode, out oWO, out oWOId, out oErrMsg))
  150. {
  151. if (LogicHandler.SetStepResult(oWO, User.UserSourceCode, sn, "无线吞吐量", "OK", User.UserCode, out oErrMsg))
  152. {
  153. ShowMsg(0, $"序列号{sn},过站记录成功");
  154. }
  155. else
  156. {
  157. ShowMsg(0, $"序列号{sn},处理过站NG:{oErrMsg}");
  158. }
  159. }
  160. else
  161. {
  162. ShowMsg(0, $"序列号{sn},过站核对NG:{oErrMsg}");
  163. }
  164. }
  165. private bool IsCheckSet()
  166. {
  167. if (string.IsNullOrEmpty(IPList.Text))
  168. {
  169. ShowMsg(0, "请选择本地iperf 服务IP地址");
  170. return true;
  171. }
  172. if (string.IsNullOrEmpty(ProductList.Text))
  173. {
  174. ShowMsg(0, "请选择产品固定IP地址");
  175. return true;
  176. }
  177. if (string.IsNullOrEmpty(Account.Text))
  178. {
  179. ShowMsg(0, "请输入Telnet登录账号");
  180. return true;
  181. }
  182. if (string.IsNullOrEmpty(Password.Text))
  183. {
  184. ShowMsg(0, "请输入Telnet登录密码");
  185. return true;
  186. }
  187. if (string.IsNullOrEmpty(ExePath.Text))
  188. {
  189. ShowMsg(0, "请输入启动iperf3文件");
  190. return true;
  191. }
  192. if (!File.Exists(ExePath.Text))
  193. {
  194. Console.WriteLine("iperf3启动文件不存在");
  195. }
  196. if (string.IsNullOrEmpty(TestTime.Text))
  197. {
  198. ShowMsg(0, "请输入测试时长");
  199. return true;
  200. }
  201. if (comboBox1.SelectedIndex == -1)
  202. {
  203. ShowMsg(0, "请选择指令模式");
  204. return true;
  205. }
  206. //if (Locat1.Checked == false || Locat2.Checked == false || Locat3.Checked == false)
  207. //{
  208. // ShowMsg(0, "请选择固件位置");
  209. // return true;
  210. //}
  211. //if (Radio1.Checked == false || Radio1.Checked == false )
  212. //{
  213. // ShowMsg(0, "请选择测试类型");
  214. // return true;
  215. //}
  216. return false;
  217. }
  218. private void UpdateSN(string type, string sn)
  219. {
  220. if (type == "C")
  221. {
  222. serialNumber.Text = "";
  223. workOrder.Text = "";
  224. productCode.Text = "";
  225. productName.Text = "";
  226. }
  227. else if (type == "L")
  228. {
  229. SQL.Clear();
  230. SQL.Append($@"SELECT ms_sncode,ma_code,pr_code,pr_spec FROM makeserial,make,product
  231. WHERE ms_sncode = '{sn}' AND ms_makecode = ma_code AND ms_prodcode = pr_code");
  232. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  233. if (dt.Rows.Count > 0)
  234. {
  235. serialNumber.Text = dt.Rows[0]["ms_sncode"].ToString();
  236. workOrder.Text = dt.Rows[0]["ma_code"].ToString();
  237. productCode.Text = dt.Rows[0]["pr_code"].ToString();
  238. productName.Text = dt.Rows[0]["pr_spec"].ToString();
  239. }
  240. else
  241. {
  242. UpdateSN("C", sn);
  243. }
  244. }
  245. }
  246. public class CameraIperfTester
  247. {
  248. int timeOut;
  249. string cameraIp, iperfServerIp, username, password;
  250. int cameraPort, iperfServerPort;
  251. string SN, iperfPath, logDirectory;
  252. private TcpClient _telnetClient;
  253. private NetworkStream _telnetStream;
  254. string sVal1, sVal2, rVal1, rVal2;
  255. public CameraIperfTester(string timeOut, string cameraIp, int cameraPort, string username, string password, string iperfServerIp, int iperfServerPort)
  256. {
  257. this.timeOut = Convert.ToInt32(timeOut) * 1000;
  258. this.cameraIp = cameraIp;
  259. this.cameraPort = cameraPort;
  260. this.username = username;
  261. this.password = password;
  262. this.iperfServerIp = iperfServerIp;
  263. this.iperfServerPort = iperfServerPort;
  264. }
  265. public string TestStart(string sn, string iP, string lD,string cmdType)
  266. {
  267. StringBuilder Msg = new StringBuilder();
  268. Msg.Append(TelnetConnect());
  269. if (Msg.ToString().StartsWith("NG")) return Msg.ToString();
  270. SN = sn;
  271. iperfPath = iP;
  272. logDirectory = lD;
  273. Msg.Clear();
  274. Msg.Append(StartIperfTest(cmdType));
  275. if (Msg.ToString().StartsWith("NG")) return Msg.ToString();
  276. return Msg.ToString();
  277. }
  278. public string TelnetConnect()
  279. {
  280. try
  281. {
  282. _telnetClient = new TcpClient();
  283. IAsyncResult connectResult = _telnetClient.BeginConnect(cameraIp, cameraPort, null, null);
  284. bool connected = connectResult.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(timeOut));
  285. if (!connected)
  286. {
  287. _telnetClient.Close();
  288. return "NG,连接超时";
  289. }
  290. try
  291. {
  292. _telnetClient.EndConnect(connectResult);
  293. }
  294. catch (SocketException ex)
  295. {
  296. return $"NG,连接失败: {ex.Message}";
  297. }
  298. _telnetStream = _telnetClient.GetStream();
  299. _telnetStream.ReadTimeout = timeOut;
  300. StringBuilder fullResponse = new StringBuilder();
  301. string welcomeResponse = ReadStream(_telnetStream);
  302. if (welcomeResponse.StartsWith("NG")) return welcomeResponse;
  303. fullResponse.Append(welcomeResponse);
  304. WriteStream(_telnetStream, username);
  305. string usernameResponse = ReadStream(_telnetStream);
  306. if (usernameResponse.StartsWith("NG")) return usernameResponse;
  307. fullResponse.Append(usernameResponse);
  308. WriteStream(_telnetStream, password);
  309. string loginResponse = ReadStream(_telnetStream);
  310. if (loginResponse.StartsWith("NG")) return loginResponse;
  311. fullResponse.Append(loginResponse);
  312. return $"OK,{fullResponse.ToString()}";
  313. }
  314. catch (Exception ex)
  315. {
  316. Close();
  317. return $"NG,{ex.Message}";
  318. }
  319. }
  320. public string StartIperfTest(string cmdType)
  321. {
  322. try
  323. {
  324. StringBuilder streamTxt = new StringBuilder();
  325. string upRate, downRate, cmdLog, upLog, downLog;
  326. if (cmdType == "0")
  327. {
  328. WriteStream(_telnetStream, "killall iperf3");
  329. streamTxt.Append(ReadStream(_telnetStream));
  330. Thread.Sleep(500);
  331. WriteStream(_telnetStream, $"iperf3 -s -p {iperfServerPort} -i 1&");
  332. streamTxt.Append(ReadStream(_telnetStream));
  333. Thread.Sleep(500);
  334. cmdLog = Path.Combine(logDirectory, $"{SN}_CMD.log");
  335. File.WriteAllText(cmdLog, streamTxt.ToString());
  336. upLog = Path.Combine(logDirectory, $"{SN}_up.log");
  337. downLog = Path.Combine(logDirectory, $"{SN}_down.log");
  338. RunIperfClient($"-c {cameraIp} -p {iperfServerPort} -t 10 -w 1M -i 1 -P 8 -R", iperfPath, upLog);
  339. RunIperfClient($"-c {cameraIp} -p {iperfServerPort} -t 10 -w 1M -i 1 -P 8", iperfPath, downLog);
  340. upRate = ParseIperfBitrate(upLog);
  341. downRate = ParseIperfBitrate(downLog);
  342. Close();
  343. return $"OK,{upRate}|{downRate}";
  344. }
  345. else
  346. {
  347. WriteStream(_telnetStream, "killall iperf3_mstar");
  348. streamTxt.Append(ReadStream(_telnetStream));
  349. Thread.Sleep(500);
  350. WriteStream(_telnetStream, "cp /mnt/tf/usb1_1/iperf3_mstar /var/tmp/ -f");
  351. streamTxt.Append(ReadStream(_telnetStream));
  352. Thread.Sleep(500);
  353. WriteStream(_telnetStream, "chmod a+x /var/tmp/iperf3_mstar");
  354. streamTxt.Append(ReadStream(_telnetStream));
  355. Thread.Sleep(500);
  356. WriteStream(_telnetStream, $"/var/tmp/iperf3_mstar -s -p {iperfServerPort} -i 1 &");
  357. streamTxt.Append(ReadStream(_telnetStream));
  358. cmdLog = Path.Combine(logDirectory, $"{SN}_CMD.log");
  359. File.WriteAllText(cmdLog, streamTxt.ToString());
  360. upLog = Path.Combine(logDirectory, $"{SN}_up.log");
  361. downLog = Path.Combine(logDirectory, $"{SN}_down.log");
  362. RunIperfClient($"/var/tmp/iperf3 -c {cameraIp} -p {iperfServerPort} -t 6 -w 1M -i 1 -l 1518 -P 8 -R", iperfPath, upLog);
  363. RunIperfClient($"/var/tmp/iperf3 -c {cameraIp} -p {iperfServerPort} -t 6 -w 1M -i 1 -l 1518 -P 8", iperfPath, downLog);
  364. upRate = ParseIperfBitrate(upLog);
  365. downRate = ParseIperfBitrate(downLog);
  366. Close();
  367. return $"OK,{upRate}|{downRate}";
  368. }
  369. }
  370. catch (Exception ex)
  371. {
  372. return $"NG,{ex.Message}";
  373. }
  374. }
  375. private void RunIperfClient(string args, string path, string logPath)
  376. {
  377. var psi = new ProcessStartInfo
  378. {
  379. FileName = path,
  380. Arguments = args,
  381. RedirectStandardOutput = true,
  382. RedirectStandardError = true,
  383. UseShellExecute = false,
  384. CreateNoWindow = true,
  385. WorkingDirectory = Path.GetDirectoryName(path)
  386. };
  387. using (var process = Process.Start(psi))
  388. {
  389. StringBuilder outputBuilder = new StringBuilder();
  390. StringBuilder errorBuilder = new StringBuilder();
  391. process.OutputDataReceived += (sender, e) =>
  392. {
  393. if (!string.IsNullOrEmpty(e.Data))
  394. {
  395. outputBuilder.AppendLine(e.Data);
  396. }
  397. };
  398. process.ErrorDataReceived += (sender, e) =>
  399. {
  400. if (!string.IsNullOrEmpty(e.Data))
  401. {
  402. errorBuilder.AppendLine(e.Data);
  403. }
  404. };
  405. process.BeginOutputReadLine();
  406. process.BeginErrorReadLine();
  407. process.WaitForExit();
  408. File.WriteAllText(logPath, outputBuilder.ToString() + errorBuilder.ToString());
  409. }
  410. }
  411. public string ParseIperfBitrate(string logPath)
  412. {
  413. if (!File.Exists(logPath)) return "0.0";
  414. var lines = File.ReadAllLines(logPath);
  415. List<string> logItem = new List<string> { };
  416. foreach (var line in lines)
  417. {
  418. if (line.Trim().StartsWith("[SUM]"))
  419. {
  420. logItem.Add(line);
  421. }
  422. }
  423. if (logItem.Count > 0 && logItem[logItem.Count - 2].Contains("sender"))
  424. {
  425. var match = Regex.Match(logItem[logItem.Count - 2], @"(\d+\.\d+\s+MBytes).*?(\d+\.\d+\s+Mbits/sec)");
  426. if (match.Success)
  427. {
  428. sVal1 = match.Groups[1].Value;
  429. sVal2 = match.Groups[2].Value;
  430. }
  431. }
  432. if (logItem.Count > 0 && logItem[logItem.Count - 1].Contains("receiver"))
  433. {
  434. var match = Regex.Match(logItem[logItem.Count - 1], @"(\d+\.\d+\s+MBytes).*?(\d+\.\d+\s+Mbits/sec)");
  435. if (match.Success)
  436. {
  437. rVal1 = match.Groups[1].Value;
  438. rVal2 = match.Groups[2].Value;
  439. }
  440. }
  441. //double num1 = (double.Parse(sVal1.Split(' ')[0]) + double.Parse(rVal1.Split(' ')[0])) / 2;
  442. //double num2 = (double.Parse(sVal2.Split(' ')[0]) + double.Parse(rVal2.Split(' ')[0])) / 2;
  443. return rVal2;
  444. }
  445. private string WriteStream(NetworkStream stream, string data)
  446. {
  447. try
  448. {
  449. byte[] dataBytes = Encoding.UTF8.GetBytes(data + "\r\n");
  450. stream.Write(dataBytes, 0, dataBytes.Length);
  451. stream.Flush();
  452. return $"OK";
  453. }
  454. catch (Exception ex)
  455. {
  456. Close();
  457. return $"NG,写入数据时发生错误: {ex.Message}";
  458. }
  459. }
  460. private string ReadStream(NetworkStream stream)
  461. {
  462. try
  463. {
  464. StringBuilder response = new StringBuilder();
  465. byte[] buffer = new byte[1024];
  466. int bytesRead;
  467. while (stream.DataAvailable || response.Length == 0)
  468. {
  469. bytesRead = stream.Read(buffer, 0, buffer.Length);
  470. if (bytesRead > 0)
  471. {
  472. response.Append(Encoding.UTF8.GetString(buffer, 0, bytesRead));
  473. }
  474. else
  475. {
  476. break;
  477. }
  478. Thread.Sleep(100);
  479. }
  480. return response.ToString();
  481. }
  482. catch (IOException ioEx) when (ioEx.InnerException is SocketException socketEx && socketEx.SocketErrorCode == SocketError.TimedOut)
  483. {
  484. Close();
  485. return "NG,读取数据超时";
  486. }
  487. catch (Exception ex)
  488. {
  489. Close();
  490. return $"NG,读取数据时发生错误: {ex.Message}";
  491. }
  492. }
  493. private void Close()
  494. {
  495. _telnetClient?.Close();
  496. _telnetStream?.Close();
  497. }
  498. }
  499. private void ShowMsg(int type, string msg)
  500. {
  501. msg = msg.Replace("\r", "").Replace("\n", "");
  502. string msgTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  503. string showMsg = $"{msgTime}: {msg}\n";
  504. if (type == 0)
  505. {
  506. OperatResult.AppendText(showMsg, Color.Red);
  507. }
  508. else if (type == 1)
  509. {
  510. OperatResult.AppendText(showMsg, Color.Green);
  511. }
  512. }
  513. private void Radio1_Click(object sender, EventArgs e)
  514. {
  515. if (Radio1.Checked)
  516. {
  517. Radio2.Checked = false;
  518. }
  519. }
  520. private void Radio2_Click(object sender, EventArgs e)
  521. {
  522. if (Radio2.Checked)
  523. {
  524. Radio1.Checked = false;
  525. }
  526. }
  527. private void Locat1_Click(object sender, EventArgs e)
  528. {
  529. if (Locat1.Checked)
  530. {
  531. Locat2.Checked = false;
  532. Locat3.Checked = false;
  533. }
  534. }
  535. private void Locat2_Click(object sender, EventArgs e)
  536. {
  537. if (Locat2.Checked)
  538. {
  539. Locat1.Checked = false;
  540. Locat3.Checked = false;
  541. }
  542. }
  543. private void Locat3_Click(object sender, EventArgs e)
  544. {
  545. if (Locat3.Checked)
  546. {
  547. Locat1.Checked = false;
  548. Locat2.Checked = false;
  549. }
  550. }
  551. private void Account_KeyDown(object sender, KeyEventArgs e)
  552. {
  553. if (e.KeyCode != Keys.Enter) return;
  554. Password.Focus();
  555. Password.SelectAll();
  556. }
  557. private void Password_KeyDown(object sender, KeyEventArgs e)
  558. {
  559. if (e.KeyCode != Keys.Enter) return;
  560. TestTime.Focus();
  561. TestTime.SelectAll();
  562. }
  563. private void ExePath_Click(object sender, EventArgs e)
  564. {
  565. using (OpenFileDialog openFileDialog = new OpenFileDialog())
  566. {
  567. openFileDialog.Title = "选择iperf3启动文件";
  568. openFileDialog.Filter = "可执行文件 (*.exe)|*.exe|所有文件 (*.*)|*.*";
  569. openFileDialog.FilterIndex = 1;
  570. openFileDialog.RestoreDirectory = true;
  571. // 设置初始目录(可选)
  572. if (!string.IsNullOrEmpty(ExePath.Text) && System.IO.File.Exists(ExePath.Text))
  573. {
  574. openFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(ExePath.Text);
  575. }
  576. else
  577. {
  578. openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
  579. }
  580. if (openFileDialog.ShowDialog() == DialogResult.OK)
  581. {
  582. ExePath.Text = openFileDialog.FileName;
  583. ShowMsg(1, $"已成功选择iperf3启动文件");
  584. }
  585. }
  586. }
  587. private void Clear_Click(object sender, EventArgs e)
  588. {
  589. OperatResult.Clear();
  590. }
  591. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  592. {
  593. if (comboBox1.SelectedIndex == -1) return;
  594. if (string.IsNullOrEmpty(IPList.Text))
  595. {
  596. ShowMsg(0, $"请先选择iperf服务地址");
  597. comboBox1.SelectedIndex = -1;
  598. return;
  599. }
  600. if (string.IsNullOrEmpty(ProductList.Text))
  601. {
  602. ShowMsg(0, $"请先选择产品IP地址");
  603. comboBox1.SelectedIndex = -1;
  604. return;
  605. }
  606. string iperfServerPort = IPList.Text.Trim().Split(':')[1];
  607. string cameraIp = ProductList.Text.Trim().Split(':')[0];
  608. if (comboBox1.SelectedIndex == 0)
  609. {
  610. ShowMsg(1, $"指令一:");
  611. ShowMsg(1, $" killall iperf3");
  612. ShowMsg(1, $" iperf3 -s -p {iperfServerPort} -i 1&");
  613. ShowMsg(1, $" -c {cameraIp} -p {iperfServerPort} -t 10 -w 1M -i 1 -P 8 -R");
  614. ShowMsg(1, $" -c {cameraIp} -p {iperfServerPort} -t 10 -w 1M -i 1 -P 8");
  615. }
  616. else if (comboBox1.SelectedIndex == 1)
  617. {
  618. ShowMsg(1, $"指令二:");
  619. ShowMsg(1, $" killall iperf3_mstar");
  620. ShowMsg(1, $" cp /mnt/tf/usb1_1/iperf3_mstar /var/tmp/ -f");
  621. ShowMsg(1, $" chmod a+x /var/tmp/iperf3_mstar");
  622. ShowMsg(1, $" /var/tmp/iperf3_mstar -s -p {iperfServerPort} -i 1 &");
  623. ShowMsg(1, $" /var/tmp/iperf3 -c {cameraIp} -p {iperfServerPort} -t 6 -w 1M -i 1 -l 1518 -P 8 -R");
  624. ShowMsg(1, $" /var/tmp/iperf3 -c {cameraIp} -p {iperfServerPort} -t 6 -w 1M -i 1 -l 1518 -P 8");
  625. }
  626. }
  627. }
  628. }