Make_WirelessThroughput.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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(1, $"序列号{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. return Msg.ToString();
  276. }
  277. public string TelnetConnect()
  278. {
  279. try
  280. {
  281. _telnetClient = new TcpClient();
  282. IAsyncResult connectResult = _telnetClient.BeginConnect(cameraIp, cameraPort, null, null);
  283. bool connected = connectResult.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(timeOut));
  284. if (!connected)
  285. {
  286. _telnetClient.Close();
  287. return "NG,连接超时";
  288. }
  289. try
  290. {
  291. _telnetClient.EndConnect(connectResult);
  292. }
  293. catch (SocketException ex)
  294. {
  295. return $"NG,连接失败: {ex.Message}";
  296. }
  297. _telnetStream = _telnetClient.GetStream();
  298. _telnetStream.ReadTimeout = timeOut;
  299. StringBuilder fullResponse = new StringBuilder();
  300. string welcomeResponse = ReadStream(_telnetStream);
  301. if (welcomeResponse.StartsWith("NG")) return welcomeResponse;
  302. fullResponse.Append(welcomeResponse);
  303. WriteStream(_telnetStream, username);
  304. string usernameResponse = ReadStream(_telnetStream);
  305. if (usernameResponse.StartsWith("NG")) return usernameResponse;
  306. fullResponse.Append(usernameResponse);
  307. WriteStream(_telnetStream, password);
  308. string loginResponse = ReadStream(_telnetStream);
  309. if (loginResponse.StartsWith("NG")) return loginResponse;
  310. fullResponse.Append(loginResponse);
  311. return $"OK,{fullResponse.ToString()}";
  312. }
  313. catch (Exception ex)
  314. {
  315. Close();
  316. return $"NG,{ex.Message}";
  317. }
  318. }
  319. public string StartIperfTest(string cmdType)
  320. {
  321. try
  322. {
  323. StringBuilder streamTxt = new StringBuilder();
  324. string upRate, downRate, cmdLog, upLog, downLog;
  325. if (cmdType == "0")
  326. {
  327. WriteStream(_telnetStream, "killall iperf3");
  328. streamTxt.Append(ReadStream(_telnetStream));
  329. Thread.Sleep(500);
  330. WriteStream(_telnetStream, $"iperf3 -s -p {iperfServerPort} -i 1&");
  331. streamTxt.Append(ReadStream(_telnetStream));
  332. Thread.Sleep(500);
  333. cmdLog = Path.Combine(logDirectory, $"{SN}_CMD.log");
  334. File.WriteAllText(cmdLog, streamTxt.ToString());
  335. upLog = Path.Combine(logDirectory, $"{SN}_up.log");
  336. downLog = Path.Combine(logDirectory, $"{SN}_down.log");
  337. RunIperfClient($"-c {cameraIp} -p {iperfServerPort} -t 10 -w 1M -i 1 -P 8 -R", iperfPath, upLog);
  338. RunIperfClient($"-c {cameraIp} -p {iperfServerPort} -t 10 -w 1M -i 1 -P 8", iperfPath, downLog);
  339. upRate = ParseIperfBitrate(upLog);
  340. downRate = ParseIperfBitrate(downLog);
  341. Close();
  342. if(string.IsNullOrEmpty(upRate) || string.IsNullOrEmpty(downRate))
  343. {
  344. return $"NG,指令一无法获测试结果,请核对指令或使用吞吐量日志解析";
  345. }
  346. return $"OK,{upRate}|{downRate}";
  347. }
  348. else
  349. {
  350. WriteStream(_telnetStream, "killall iperf3_mstar");
  351. streamTxt.Append(ReadStream(_telnetStream));
  352. Thread.Sleep(500);
  353. WriteStream(_telnetStream, "cp /mnt/tf/usb1_1/iperf3_mstar /var/tmp/ -f");
  354. streamTxt.Append(ReadStream(_telnetStream));
  355. Thread.Sleep(500);
  356. WriteStream(_telnetStream, "chmod a+x /var/tmp/iperf3_mstar");
  357. streamTxt.Append(ReadStream(_telnetStream));
  358. Thread.Sleep(500);
  359. WriteStream(_telnetStream, $"/var/tmp/iperf3_mstar -s -p {iperfServerPort} -i 1 &");
  360. streamTxt.Append(ReadStream(_telnetStream));
  361. cmdLog = Path.Combine(logDirectory, $"{SN}_CMD.log");
  362. File.WriteAllText(cmdLog, streamTxt.ToString());
  363. upLog = Path.Combine(logDirectory, $"{SN}_up.log");
  364. downLog = Path.Combine(logDirectory, $"{SN}_down.log");
  365. RunIperfClient($"/var/tmp/iperf3 -c {cameraIp} -p {iperfServerPort} -t 6 -w 1M -i 1 -l 1518 -P 8 -R", iperfPath, upLog);
  366. RunIperfClient($"/var/tmp/iperf3 -c {cameraIp} -p {iperfServerPort} -t 6 -w 1M -i 1 -l 1518 -P 8", iperfPath, downLog);
  367. upRate = ParseIperfBitrate(upLog);
  368. downRate = ParseIperfBitrate(downLog);
  369. Close();
  370. if (string.IsNullOrEmpty(upRate) || string.IsNullOrEmpty(downRate))
  371. {
  372. return $"NG,指令二获取测试结果,请核对指令或使用吞吐量日志解析";
  373. }
  374. return $"OK,{upRate}|{downRate}";
  375. }
  376. }
  377. catch (Exception ex)
  378. {
  379. return $"NG,{ex.Message}";
  380. }
  381. }
  382. private void RunIperfClient(string args, string path, string logPath)
  383. {
  384. var psi = new ProcessStartInfo
  385. {
  386. FileName = path,
  387. Arguments = args,
  388. RedirectStandardOutput = true,
  389. RedirectStandardError = true,
  390. UseShellExecute = false,
  391. CreateNoWindow = true,
  392. WorkingDirectory = Path.GetDirectoryName(path)
  393. };
  394. using (var process = Process.Start(psi))
  395. {
  396. StringBuilder outputBuilder = new StringBuilder();
  397. StringBuilder errorBuilder = new StringBuilder();
  398. process.OutputDataReceived += (sender, e) =>
  399. {
  400. if (!string.IsNullOrEmpty(e.Data))
  401. {
  402. outputBuilder.AppendLine(e.Data);
  403. }
  404. };
  405. process.ErrorDataReceived += (sender, e) =>
  406. {
  407. if (!string.IsNullOrEmpty(e.Data))
  408. {
  409. errorBuilder.AppendLine(e.Data);
  410. }
  411. };
  412. process.BeginOutputReadLine();
  413. process.BeginErrorReadLine();
  414. process.WaitForExit();
  415. File.WriteAllText(logPath, outputBuilder.ToString() + errorBuilder.ToString());
  416. }
  417. }
  418. public string ParseIperfBitrate(string logPath)
  419. {
  420. if (!File.Exists(logPath)) return "0.0";
  421. var lines = File.ReadAllLines(logPath);
  422. List<string> logItem = new List<string> { };
  423. foreach (var line in lines)
  424. {
  425. if (line.Trim().StartsWith("[SUM]"))
  426. {
  427. logItem.Add(line);
  428. }
  429. }
  430. if (logItem.Count > 0 && logItem[logItem.Count - 2].Contains("sender"))
  431. {
  432. var match = Regex.Match(logItem[logItem.Count - 2], @"(\d+\.\d+\s+MBytes).*?(\d+\.\d+\s+Mbits/sec)");
  433. if (match.Success)
  434. {
  435. sVal1 = match.Groups[1].Value;
  436. sVal2 = match.Groups[2].Value;
  437. }
  438. }
  439. if (logItem.Count > 0 && logItem[logItem.Count - 1].Contains("receiver"))
  440. {
  441. var match = Regex.Match(logItem[logItem.Count - 1], @"(\d+\.\d+\s+MBytes).*?(\d+\.\d+\s+Mbits/sec)");
  442. if (match.Success)
  443. {
  444. rVal1 = match.Groups[1].Value;
  445. rVal2 = match.Groups[2].Value;
  446. }
  447. }
  448. //double num1 = (double.Parse(sVal1.Split(' ')[0]) + double.Parse(rVal1.Split(' ')[0])) / 2;
  449. //double num2 = (double.Parse(sVal2.Split(' ')[0]) + double.Parse(rVal2.Split(' ')[0])) / 2;
  450. return rVal2;
  451. }
  452. private string WriteStream(NetworkStream stream, string data)
  453. {
  454. try
  455. {
  456. byte[] dataBytes = Encoding.UTF8.GetBytes(data + "\r\n");
  457. stream.Write(dataBytes, 0, dataBytes.Length);
  458. stream.Flush();
  459. return $"OK";
  460. }
  461. catch (Exception ex)
  462. {
  463. Close();
  464. return $"NG,写入数据时发生错误: {ex.Message}";
  465. }
  466. }
  467. private string ReadStream(NetworkStream stream)
  468. {
  469. try
  470. {
  471. StringBuilder response = new StringBuilder();
  472. byte[] buffer = new byte[1024];
  473. int bytesRead;
  474. while (stream.DataAvailable || response.Length == 0)
  475. {
  476. bytesRead = stream.Read(buffer, 0, buffer.Length);
  477. if (bytesRead > 0)
  478. {
  479. response.Append(Encoding.UTF8.GetString(buffer, 0, bytesRead));
  480. }
  481. else
  482. {
  483. break;
  484. }
  485. Thread.Sleep(100);
  486. }
  487. return response.ToString();
  488. }
  489. catch (IOException ioEx) when (ioEx.InnerException is SocketException socketEx && socketEx.SocketErrorCode == SocketError.TimedOut)
  490. {
  491. Close();
  492. return "NG,读取数据超时";
  493. }
  494. catch (Exception ex)
  495. {
  496. Close();
  497. return $"NG,读取数据时发生错误: {ex.Message}";
  498. }
  499. }
  500. private void Close()
  501. {
  502. _telnetClient?.Close();
  503. _telnetStream?.Close();
  504. }
  505. }
  506. private void ShowMsg(int type, string msg)
  507. {
  508. msg = msg.Replace("\r", "").Replace("\n", "");
  509. string msgTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  510. string showMsg = $"{msgTime}: {msg}\n";
  511. if (type == 0)
  512. {
  513. OperatResult.AppendText(showMsg, Color.Red);
  514. }
  515. else if (type == 1)
  516. {
  517. OperatResult.AppendText(showMsg, Color.Green);
  518. }
  519. }
  520. private void Radio1_Click(object sender, EventArgs e)
  521. {
  522. if (Radio1.Checked)
  523. {
  524. Radio2.Checked = false;
  525. }
  526. }
  527. private void Radio2_Click(object sender, EventArgs e)
  528. {
  529. if (Radio2.Checked)
  530. {
  531. Radio1.Checked = false;
  532. }
  533. }
  534. private void Locat1_Click(object sender, EventArgs e)
  535. {
  536. if (Locat1.Checked)
  537. {
  538. Locat2.Checked = false;
  539. Locat3.Checked = false;
  540. }
  541. }
  542. private void Locat2_Click(object sender, EventArgs e)
  543. {
  544. if (Locat2.Checked)
  545. {
  546. Locat1.Checked = false;
  547. Locat3.Checked = false;
  548. }
  549. }
  550. private void Locat3_Click(object sender, EventArgs e)
  551. {
  552. if (Locat3.Checked)
  553. {
  554. Locat1.Checked = false;
  555. Locat2.Checked = false;
  556. }
  557. }
  558. private void Account_KeyDown(object sender, KeyEventArgs e)
  559. {
  560. if (e.KeyCode != Keys.Enter) return;
  561. Password.Focus();
  562. Password.SelectAll();
  563. }
  564. private void Password_KeyDown(object sender, KeyEventArgs e)
  565. {
  566. if (e.KeyCode != Keys.Enter) return;
  567. TestTime.Focus();
  568. TestTime.SelectAll();
  569. }
  570. private void ExePath_Click(object sender, EventArgs e)
  571. {
  572. using (OpenFileDialog openFileDialog = new OpenFileDialog())
  573. {
  574. openFileDialog.Title = "选择iperf3启动文件";
  575. openFileDialog.Filter = "可执行文件 (*.exe)|*.exe|所有文件 (*.*)|*.*";
  576. openFileDialog.FilterIndex = 1;
  577. openFileDialog.RestoreDirectory = true;
  578. // 设置初始目录(可选)
  579. if (!string.IsNullOrEmpty(ExePath.Text) && System.IO.File.Exists(ExePath.Text))
  580. {
  581. openFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(ExePath.Text);
  582. }
  583. else
  584. {
  585. openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
  586. }
  587. if (openFileDialog.ShowDialog() == DialogResult.OK)
  588. {
  589. ExePath.Text = openFileDialog.FileName;
  590. ShowMsg(1, $"已成功选择iperf3启动文件");
  591. }
  592. }
  593. }
  594. private void Clear_Click(object sender, EventArgs e)
  595. {
  596. OperatResult.Clear();
  597. }
  598. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  599. {
  600. if (comboBox1.SelectedIndex == -1) return;
  601. if (string.IsNullOrEmpty(IPList.Text))
  602. {
  603. ShowMsg(0, $"请先选择iperf服务地址");
  604. comboBox1.SelectedIndex = -1;
  605. return;
  606. }
  607. if (string.IsNullOrEmpty(ProductList.Text))
  608. {
  609. ShowMsg(0, $"请先选择产品IP地址");
  610. comboBox1.SelectedIndex = -1;
  611. return;
  612. }
  613. string iperfServerPort = IPList.Text.Trim().Split(':')[1];
  614. string cameraIp = ProductList.Text.Trim().Split(':')[0];
  615. if (comboBox1.SelectedIndex == 0)
  616. {
  617. ShowMsg(1, $"指令一:");
  618. ShowMsg(1, $" killall iperf3");
  619. ShowMsg(1, $" iperf3 -s -p {iperfServerPort} -i 1&");
  620. ShowMsg(1, $" -c {cameraIp} -p {iperfServerPort} -t 10 -w 1M -i 1 -P 8 -R");
  621. ShowMsg(1, $" -c {cameraIp} -p {iperfServerPort} -t 10 -w 1M -i 1 -P 8");
  622. }
  623. else if (comboBox1.SelectedIndex == 1)
  624. {
  625. ShowMsg(1, $"指令二:");
  626. ShowMsg(1, $" killall iperf3_mstar");
  627. ShowMsg(1, $" cp /mnt/tf/usb1_1/iperf3_mstar /var/tmp/ -f");
  628. ShowMsg(1, $" chmod a+x /var/tmp/iperf3_mstar");
  629. ShowMsg(1, $" /var/tmp/iperf3_mstar -s -p {iperfServerPort} -i 1 &");
  630. ShowMsg(1, $" /var/tmp/iperf3 -c {cameraIp} -p {iperfServerPort} -t 6 -w 1M -i 1 -l 1518 -P 8 -R");
  631. ShowMsg(1, $" /var/tmp/iperf3 -c {cameraIp} -p {iperfServerPort} -t 6 -w 1M -i 1 -l 1518 -P 8");
  632. }
  633. }
  634. }
  635. }