XcorrUtils.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8. using XdCxRhDW.App.CpuCgTools;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using DevExpress.Drawing.Internal.Fonts.Interop;
  12. using System.Windows.Documents;
  13. using XdCxRhDW.App.WebAPI.DTO;
  14. using XdCxRhDw.Dto;
  15. namespace XdCxRhDW.App.CorTools
  16. {
  17. class XcorrStruct
  18. {
  19. public String file1 { get; set; }
  20. public String file2 { get; set; }
  21. public int smpStart { get; set; } //开始样点
  22. public int smpCount { get; set; } //样点数
  23. public double samplingRate { get; set; } //采样率
  24. public double dtCenter { get; set; } //时差中心
  25. public double dtRange { get; set; } //时差范围
  26. public double dfRange { get; set; } //频差范围
  27. public double snrThreshold { get; set; } //信噪比门限
  28. public XcorrStruct Copy()
  29. {
  30. XcorrStruct xItem = new XcorrStruct();
  31. xItem.file1 = file1;
  32. xItem.file2 = file2;
  33. xItem.smpCount = smpCount;
  34. xItem.samplingRate = samplingRate;
  35. xItem.dtCenter = dtCenter;
  36. xItem.dtRange = dtRange;
  37. xItem.dfRange = dfRange;
  38. xItem.smpStart = smpStart;
  39. xItem.snrThreshold = snrThreshold;
  40. return xItem;
  41. }
  42. }
  43. class XcorrUtils
  44. {
  45. Process cafp;
  46. Process dmp;
  47. // D:/data/test/r1.dat D:/data/test/r4.dat 1562500 -250000 20 16384 100000 1048576 11
  48. public async Task<CafResult> Calc(XcorrStruct xs)
  49. {
  50. CafResult res = new CafResult();
  51. cafp = new Process();
  52. await Task.Run(() =>
  53. {
  54. cafp.StartInfo.FileName = Path.Combine(cafp.StartInfo.WorkingDirectory, "xcorr\\XcorrCpu.exe");
  55. cafp.StartInfo.Arguments = $"\"{xs.file1}\" \"{xs.file2}\" {(Int64)(xs.samplingRate)} {xs.dtCenter} {xs.dtRange} {xs.dfRange} {xs.smpStart} {xs.smpCount} {xs.snrThreshold}";
  56. cafp.StartInfo.CreateNoWindow = true;
  57. cafp.StartInfo.RedirectStandardError = true;
  58. cafp.StartInfo.RedirectStandardOutput = true;
  59. cafp.StartInfo.UseShellExecute = false;
  60. cafp.Start();
  61. Stopwatch stopWatch = new Stopwatch();
  62. stopWatch.Start();
  63. cafp.WaitForExit();
  64. stopWatch.Stop();
  65. TimeSpan ts = stopWatch.Elapsed;
  66. var str = cafp.StandardOutput.ReadToEnd();
  67. res.FromLine(str);
  68. res.file1 = xs.file1;
  69. res.file2 = xs.file2;
  70. res.tm = Math.Round(stopWatch.Elapsed.TotalMilliseconds, 4);
  71. res.smpstart = xs.smpStart;
  72. res.smplen = xs.smpCount;
  73. });
  74. return res;
  75. }
  76. public async Task<IEnumerable<DmcResult>> DmcCheckAsync(string fileName, double fsHz, DmcType dmcType)
  77. {
  78. string dmcCmd = "all";
  79. dmp = new Process();
  80. string pFileName = Path.Combine(dmp.StartInfo.WorkingDirectory, "xcorr\\dmc.exe");
  81. string pArguments = string.Empty;
  82. switch (dmcType)
  83. {
  84. case DmcType.DAMA:
  85. dmcCmd = "dm";
  86. pArguments = $"{dmcCmd} \"{fileName}\"";// -f {fs}" -c --dmfirst";
  87. break;
  88. case DmcType.IBS:
  89. dmcCmd = "nd";
  90. pArguments = $"{dmcCmd} \"{fileName}\"";// -f {fs}" -c --dmfirst";
  91. break;
  92. case DmcType.Ky5758:
  93. pFileName = Path.Combine(dmp.StartInfo.WorkingDirectory, "xcorr\\enc.exe");
  94. //enc.exe enc-test.dat 0.096 5 0全部文件
  95. pArguments = $"{fileName} {fsHz * 1e-6} {5} {0}";
  96. break;
  97. default:
  98. break;
  99. }
  100. return await Task.Run(() =>
  101. {
  102. dmp.StartInfo.FileName = pFileName;
  103. dmp.StartInfo.Arguments = pArguments;
  104. dmp.StartInfo.CreateNoWindow = true;
  105. dmp.StartInfo.RedirectStandardError = true;
  106. dmp.StartInfo.RedirectStandardOutput = true;
  107. dmp.StartInfo.UseShellExecute = false;
  108. dmp.Start();
  109. Stopwatch stopWatch = new Stopwatch();
  110. stopWatch.Start();
  111. dmp.WaitForExit();
  112. stopWatch.Stop();
  113. TimeSpan ts = stopWatch.Elapsed;
  114. var str = dmp.StandardOutput.ReadToEnd();
  115. return ConvertDmcResult(str, ts.TotalMilliseconds);
  116. });
  117. }
  118. public static IEnumerable<DmcResult> ConvertDmcResult(string res, double tm)
  119. {
  120. var lines = res.Split(Environment.NewLine.ToArray(), StringSplitOptions.RemoveEmptyEntries);
  121. foreach (var line in lines)
  122. {
  123. var items = line.Split('\t');
  124. if (items.Length < 2) continue;
  125. int start = int.Parse(items[0]);
  126. int length = int.Parse(items[1]);
  127. string userName = "";
  128. if (items.Length >= 3)
  129. userName = items[2];
  130. yield return new DmcResult(start, length, userName, Math.Round(tm, 4));
  131. }
  132. }
  133. public void StopDm()
  134. {
  135. try
  136. {
  137. if (dmp != null)
  138. {
  139. dmp.Kill();
  140. }
  141. }
  142. catch (Exception)
  143. {
  144. }
  145. }
  146. public void StopCalc()
  147. {
  148. try
  149. {
  150. if (cafp != null)
  151. {
  152. cafp.Kill();
  153. }
  154. }
  155. catch (Exception)
  156. {
  157. }
  158. }
  159. }
  160. }