FormCpuCg.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.ComponentModel.DataAnnotations;
  5. using System.Data;
  6. using System.Diagnostics;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using DevExpress.Utils.DPI;
  14. using DevExpress.XtraEditors;
  15. using ExtensionsDev;
  16. using XdCxRhDW.Core.Api;
  17. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
  18. namespace XdCxRhDw.CpuCgTools
  19. {
  20. public partial class FormCpuCg : DevExpress.XtraEditors.XtraForm
  21. {
  22. public class CgParam
  23. {
  24. public string F1 { get; set; }
  25. public string F2 { get; set; }
  26. public string snr { get; set; }
  27. public string dfoCenter { get; set; }
  28. public string dfoRange { get; set; }
  29. public string dtoXb { get; set; }
  30. public string dfoXb { get; set; }
  31. public string thread { get; set; }
  32. public string addZero { get; set; }
  33. public string start { get; set; }
  34. public string len { get; set; }
  35. public string dtoCenter { get; set; }
  36. public string dtoRange { get; set; }
  37. public string fs { get; set; }
  38. }
  39. public class CgRes
  40. {
  41. [Display(Name = "文件1")]
  42. public string File1 { get; set; }
  43. [Display(Name = "文件2")]
  44. public string File2 { get; set; }
  45. [Display(Name = "时差(us)")]
  46. public double Dto { get; set; }
  47. [Display(Name = "频差(us)")]
  48. public double Dfo { get; set; }
  49. [Display(Name = "信噪比(dB)")]
  50. public double Snr { get; set; }
  51. [Display(Name = "耗时(ms)")]
  52. public double CostTimeMs { get; set; }
  53. }
  54. List<CgRes> list = new List<CgRes>();
  55. public FormCpuCg()
  56. {
  57. InitializeComponent();
  58. }
  59. private void XtraForm1_Load(object sender, EventArgs e)
  60. {
  61. gridControl1.Init().UseExportCsv().UseExportXlsx();
  62. gridControl1.DataSource = list;
  63. txtF1.UseChooseFile();
  64. txtF2.UseChooseFile();
  65. if (File.Exists("tmp.txt"))
  66. {
  67. var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<CgParam>(File.ReadAllText("tmp.txt"));
  68. txtAddZero.Text = obj.addZero;
  69. txtDfoCenter.Text = obj.dfoCenter;
  70. txtDfoRange.Text = obj.dfoRange;
  71. txtDfoXb.Text = obj.dfoXb;
  72. txtDtoCenter.Text = obj.dtoCenter;
  73. txtDtoRange.Text = obj.dtoRange;
  74. txtDtoXb.Text = obj.dtoXb;
  75. txtF1.Text = obj.F1;
  76. txtF2.Text = obj.F2;
  77. txtFs.Text = obj.fs;
  78. txtLen.Text = obj.len;
  79. txtSnr.Text = obj.snr;
  80. txtStart.Text = obj.start;
  81. txtThread.Text = obj.thread;
  82. }
  83. }
  84. private (bool, string) checkParam()
  85. {
  86. //{txtF1.Text}\" \"{txtF2.Text}\" {dtocenterus} {txtDtoRange.Text}
  87. if (string.IsNullOrWhiteSpace(txtF1.Text))
  88. {
  89. return (false, "文件1不能为空!");
  90. }
  91. if (string.IsNullOrWhiteSpace(txtF2.Text))
  92. {
  93. return (false, "文件2不能为空!");
  94. }
  95. if (string.IsNullOrWhiteSpace(txtFs.Text))
  96. {
  97. return (false, "采样率不能为空!");
  98. }
  99. if (string.IsNullOrWhiteSpace(txtDtoCenter.Text))
  100. {
  101. return (false, "时差中心不能为空!");
  102. }
  103. if (string.IsNullOrWhiteSpace(txtDtoRange.Text))
  104. {
  105. return (false, "时差范围不能为空!");
  106. }
  107. if (string.IsNullOrWhiteSpace(txtSnr.Text))
  108. {
  109. return (false, "信噪比不能为空!");
  110. }
  111. return (true, string.Empty);
  112. }
  113. private async void btnCalc_Click(object sender, EventArgs e)
  114. {
  115. var ckres = checkParam();
  116. if (!ckres.Item1)
  117. {
  118. DxHelper.MsgBoxHelper.ShowError($"{ckres.Item2}");
  119. return;
  120. }
  121. this.tablePanel1.Enabled = false;
  122. await Task.Run(() =>
  123. {
  124. try
  125. {
  126. Stopwatch sw = new Stopwatch();
  127. sw.Start();
  128. Process p = new Process();
  129. p.StartInfo.WorkingDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Core");
  130. p.StartInfo.FileName = Path.Combine(p.StartInfo.WorkingDirectory, "coc.exe");
  131. string snr = "";
  132. if (!string.IsNullOrWhiteSpace(txtSnr.Text))
  133. snr = $"{txtSnr.Text} ";
  134. string dfoCenter = "";
  135. if (!string.IsNullOrWhiteSpace(txtDfoCenter.Text))
  136. dfoCenter = $"{txtDfoCenter.Text} ";
  137. string dfoRange = "";
  138. if (!string.IsNullOrWhiteSpace(txtDfoRange.Text))
  139. dfoRange = $"{txtDfoRange.Text} ";
  140. string dtoXb = "";
  141. if (!string.IsNullOrWhiteSpace(txtDtoXb.Text))
  142. dtoXb = $"{txtDtoXb.Text} ";
  143. string dfoXb = "";
  144. if (!string.IsNullOrWhiteSpace(txtDfoXb.Text))
  145. dfoXb = $"{txtDfoXb.Text} ";
  146. string fs = $"{Convert.ToDouble(txtFs.Text) * 1000000} ";
  147. string bandWidth = "25000 ";
  148. string thread = "";
  149. if (!string.IsNullOrWhiteSpace(txtThread.Text))
  150. thread = $"-t {txtThread.Text} ";
  151. else
  152. thread = $"-t {Environment.ProcessorCount} ";
  153. string defalut = "-l 0 -f 0";//-l样点数 -f信号偏移类型
  154. string addZero = $"-z 0 ";
  155. if (!string.IsNullOrWhiteSpace(txtAddZero.Text))
  156. addZero = $"-z {txtAddZero.Text} ";
  157. string slot = "";
  158. if (!string.IsNullOrWhiteSpace(txtStart.Text) && !string.IsNullOrWhiteSpace(txtLen.Text))
  159. slot = $" -m 0 -d {txtStart.Text} {txtLen.Text} ";// -m时隙合并方式
  160. if (!string.IsNullOrWhiteSpace(txtStart.Text) && (string.IsNullOrWhiteSpace(txtLen.Text) || Convert.ToInt32(txtLen.Text) <= 0))
  161. {
  162. FileInfo f1 = new FileInfo(txtF1.Text);
  163. FileInfo f2 = new FileInfo(txtF2.Text);
  164. long size = f1.Length;
  165. if (f1.Length > f2.Length)
  166. size = f2.Length;
  167. size /= 4;//IQ文件一个样点4个字节
  168. var len = size - Convert.ToInt32(txtStart.Text);
  169. slot = $" -m 0 -d {txtStart.Text} {len} ";// -m时隙合并方式
  170. }
  171. long dtocenterus = Convert.ToInt64(txtDtoCenter.Text);
  172. string timeoffset = "-o 0 ";
  173. if (dtocenterus > 200000)
  174. {
  175. timeoffset = $"-o {dtocenterus * 1e-6} ";
  176. dtocenterus = 0;
  177. }
  178. CgParam cp = new CgParam()
  179. {
  180. addZero = txtAddZero.Text,
  181. dfoCenter = txtDfoCenter.Text,
  182. dfoRange = txtDfoRange.Text,
  183. dfoXb = txtDfoXb.Text,
  184. dtoCenter = txtDtoCenter.Text,
  185. dtoRange = txtDtoRange.Text,
  186. dtoXb = txtDtoXb.Text,
  187. F1 = txtF1.Text,
  188. F2 = txtF2.Text,
  189. fs = txtFs.Text,
  190. len = txtLen.Text,
  191. snr = txtSnr.Text,
  192. start = txtStart.Text,
  193. thread = txtThread.Text,
  194. };
  195. var jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(cp);
  196. File.WriteAllText("tmp.txt", jsonStr);
  197. //p.StartInfo.Arguments = $"\"{txtF1.Text}\" \"{txtF2.Text}\" {txtFs.Text} {txtDtoCenter.Text} {txtDtoRange.Text} {snr}{dfoCenter}{dfoRange}{dtoXb}{dfoXb}{thread}{addZero}{slot}";
  198. p.StartInfo.Arguments = $"\"{txtF1.Text}\" \"{txtF2.Text}\" {dtocenterus} {txtDtoRange.Text} {snr}{dfoCenter}{dfoRange}{dtoXb}{dfoXb}{fs}{bandWidth}{thread}{addZero}{timeoffset}{slot}{defalut}";
  199. p.StartInfo.CreateNoWindow = true;
  200. p.StartInfo.RedirectStandardError = false;
  201. p.StartInfo.RedirectStandardOutput = true;
  202. p.StartInfo.UseShellExecute = false;
  203. p.Start();
  204. p.WaitForExit();
  205. var str = p.StandardOutput.ReadToEnd();
  206. sw.Stop();
  207. var res = CorResult.FromLines(str, Convert.ToDouble(txtSnr.Text));
  208. if (res.Length > 0)
  209. {
  210. var costTimeMs = res[0].UseTime;
  211. var dt = Math.Round(Convert.ToDouble(res[0].Dto), 3);
  212. var df = Math.Round(Convert.ToDouble(res[0].Dfo), 1);
  213. var snrRes = Math.Round(Convert.ToDouble(res[0].Snr), 1);
  214. list.Add(new CgRes() { File1 = txtF1.Text, File2 = txtF2.Text, CostTimeMs = costTimeMs, Dto = dt, Dfo = df, Snr = snrRes });
  215. }
  216. else
  217. {
  218. this.Invoke(new Action(() => DxHelper.MsgBoxHelper.ShowInfo("无参估计算结果")));
  219. }
  220. }
  221. catch (Exception ex)
  222. {
  223. Serilog.Log.Error(ex,"参估计算出错");
  224. this.Invoke(new Action(() => DxHelper.MsgBoxHelper.ShowError("参估计算出错")));
  225. }
  226. });
  227. this.gridView1.RefreshData();
  228. this.tablePanel1.Enabled = true;
  229. }
  230. }
  231. }