CtrlCgTool.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using DevExpress.XtraCharts;
  2. using DevExpress.XtraEditors;
  3. using DevExpress.XtraExport.Helpers;
  4. using DevExpress.XtraGrid.Views.Grid;
  5. using DxHelper;
  6. using ExtensionsDev;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.ComponentModel.DataAnnotations;
  11. using System.Data;
  12. using System.Data.Entity;
  13. using System.Diagnostics;
  14. using System.Drawing;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using System.Windows.Controls;
  20. using System.Windows.Documents;
  21. using System.Windows.Forms;
  22. using CG.App.EFContext;
  23. using XzXdDw.App.Model;
  24. namespace CG.App.UserControl
  25. {
  26. public partial class CtrlCgTool : DevExpress.XtraEditors.XtraUserControl
  27. {
  28. public List<CgCalcRes> list = new List<CgCalcRes>();
  29. public CtrlCgTool()
  30. {
  31. InitializeComponent();
  32. }
  33. private void CtrlCg_Load(object sender, EventArgs e)
  34. {
  35. if (File.Exists("CgTmp.txt"))
  36. {
  37. var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<CgUIParam>(File.ReadAllText("CgTmp.txt"));
  38. txtDfoRange.Text = obj.dfoRange;
  39. txtDtoCenter.Text = obj.dtoCenter;
  40. txtDtoRange.Text = obj.dtoRange;
  41. txtF1.Text = obj.F1;
  42. txtF2.Text = obj.F2;
  43. txtFs.Text = obj.fs;
  44. txtSnr.Text = obj.snr;
  45. txtSampleCount.Text = obj.sampleCount;
  46. txtMode.Text = obj.pMode;
  47. }
  48. txtF1.UseChooseFile();
  49. txtF2.UseChooseFile();
  50. gridCgCalcRes.Init().UseFilter().UseMultiSelect().UseRowNumber().UseExportCsv().UseExportXlsx()
  51. .AddMenu("清除", SvgHelper.CreateClear(), () =>
  52. {
  53. list.Clear();
  54. this.gridView1.RefreshData();
  55. });
  56. gridCgCalcRes.DataSource = list;
  57. }
  58. private async void btnCalc_Click(object sender, EventArgs e)
  59. {
  60. this.layoutControl1.Enabled = false;
  61. await Task.Run(() =>
  62. {
  63. try
  64. {
  65. CgUIParam cp = new CgUIParam()
  66. {
  67. dfoRange = txtDfoRange.Text,
  68. dtoCenter = txtDtoCenter.Text,
  69. dtoRange = txtDtoRange.Text,
  70. F1 = txtF1.Text,
  71. F2 = txtF2.Text,
  72. fs = txtFs.Text,
  73. sampleCount = txtSampleCount.Text,
  74. snr = txtSnr.Text,
  75. pMode = txtMode.SelectedIndex.ToString()
  76. };
  77. var jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(cp);
  78. File.WriteAllText("CgTmp.txt", jsonStr);
  79. Stopwatch sw = new Stopwatch();
  80. sw.Start();
  81. string sampleCount = txtSampleCount.Text;
  82. if (string.IsNullOrWhiteSpace(txtSampleCount.Text) || Convert.ToInt32(txtSampleCount.Text) <= 0)
  83. {
  84. FileInfo f1 = new FileInfo(txtF1.Text);
  85. FileInfo f2 = new FileInfo(txtF2.Text);
  86. sampleCount = (f1.Length / 4).ToString();
  87. if (f1.Length > f2.Length)
  88. sampleCount = (f2.Length / 4).ToString();
  89. }
  90. double fs = Convert.ToDouble(txtFs.Text);
  91. Process p = new Process();
  92. p.StartInfo.WorkingDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "API\\粗估精估");
  93. p.StartInfo.FileName = Path.Combine(p.StartInfo.WorkingDirectory, "XcorrGpu.exe");
  94. // XcorrGpu.exe - m e:/ 1.dat - a e:/ 2.dat - s 8388608 - f 6250000 - c 1780 - r 500 - j 16384 - t 14 - p 0
  95. p.StartInfo.Arguments = $"-m \"{txtF1.Text}\" -a \"{txtF2.Text}\" -s {sampleCount} -f {(Int64)(fs * 1e6)}" +
  96. $" -c {txtDtoCenter.Text} -r {txtDtoRange.Text} -j {txtDfoRange.Text} -t {txtSnr.Text} -p {txtMode.SelectedIndex}";
  97. p.StartInfo.CreateNoWindow = true;
  98. p.StartInfo.RedirectStandardError = true;
  99. p.StartInfo.RedirectStandardOutput = true;
  100. p.StartInfo.UseShellExecute = false;
  101. p.Start();
  102. p.WaitForExit();
  103. var str = p.StandardOutput.ReadToEnd();
  104. sw.Stop();
  105. if (str != null && str.Contains(":") && str.Length > 3)
  106. {
  107. var arr = str.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1].Split("+".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  108. int count = 0;
  109. foreach (var item in arr)
  110. {
  111. if (count >= 1) break;
  112. var dtDfSnr = item.Split("*".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  113. CgCalcRes calcResOne = new CgCalcRes()
  114. {
  115. Dto = Math.Round(Convert.ToDouble(dtDfSnr[0]), 3),
  116. Dfo = Math.Round(Convert.ToDouble(dtDfSnr[1]), 3),
  117. Snr = Math.Round(Convert.ToDouble(dtDfSnr[2]), 1),
  118. CostTime = sw.ElapsedMilliseconds,
  119. File1 = txtF1.Text,
  120. File2 = txtF2.Text,
  121. };
  122. list.Add(calcResOne);
  123. count++;
  124. }
  125. }
  126. }
  127. catch (Exception ex)
  128. {
  129. Serilog.Log.Error("参估计算出错", ex);
  130. this.Invoke(new Action(() => XtraMessageBox.Show("参估计算出错")));
  131. }
  132. });
  133. this.gridView1.RefreshData();
  134. this.layoutControl1.Enabled = true;
  135. }
  136. }
  137. public class CgUIParam
  138. {
  139. public string F1 { get; set; }
  140. public string F2 { get; set; }
  141. public string fs { get; set; }
  142. public string sampleCount { get; set; }
  143. public string dtoCenter { get; set; }
  144. public string dtoRange { get; set; }
  145. public string dfoRange { get; set; }
  146. public string snr { get; set; }
  147. public string pMode { get; set; }
  148. }
  149. public class CgCalcRes
  150. {
  151. [Display(Name = "文件1")]
  152. public string File1 { get; set; }
  153. [Display(Name = "文件2")]
  154. public string File2 { get; set; }
  155. [Display(Name = "时差(us)")]
  156. public double Dto { get; set; }
  157. [Display(Name = "频差(Hz)")]
  158. public double Dfo { get; set; }
  159. [Display(Name = "信噪比(dB)")]
  160. public double Snr { get; set; }
  161. [Display(Name = "耗时(ms)")]
  162. public double CostTime { get; set; }
  163. }
  164. }