XcorrUtils.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. static Process p = new Process();
  46. // D:/data/test/r1.dat D:/data/test/r4.dat 1562500 -250000 20 16384 100000 1048576 11
  47. public static async Task<CafResult> Calc(XcorrStruct xs)
  48. {
  49. CafResult res = new CafResult();
  50. await Task.Run(() =>
  51. {
  52. p.StartInfo.FileName = Path.Combine(p.StartInfo.WorkingDirectory, "xcorr\\XcorrCpu.exe");
  53. p.StartInfo.Arguments = $"\"{xs.file1}\" \"{xs.file2}\" {(Int64)(xs.samplingRate)} {xs.dtCenter} {xs.dtRange} {xs.dfRange} {xs.smpStart} {xs.smpCount} {xs.snrThreshold}";
  54. p.StartInfo.CreateNoWindow = true;
  55. p.StartInfo.RedirectStandardError = true;
  56. p.StartInfo.RedirectStandardOutput = true;
  57. p.StartInfo.UseShellExecute = false;
  58. p.Start();
  59. Stopwatch stopWatch = new Stopwatch();
  60. stopWatch.Start();
  61. p.WaitForExit();
  62. stopWatch.Stop();
  63. TimeSpan ts = stopWatch.Elapsed;
  64. var str = p.StandardOutput.ReadToEnd();
  65. res.FromLine(str);
  66. res.file1 = xs.file1;
  67. res.file2 = xs.file2;
  68. res.tm = Math.Round(stopWatch.Elapsed.TotalMilliseconds, 4);
  69. res.smpstart = xs.smpStart;
  70. res.smplen = xs.smpCount;
  71. });
  72. return res;
  73. }
  74. public static async Task<IEnumerable<DmcResult>> DmcCheckAsync(string fileName, double fsHz, DmcType dmcType)
  75. {
  76. string dmcCmd = "all";
  77. string pFileName = Path.Combine(p.StartInfo.WorkingDirectory, "xcorr\\dmc.exe");
  78. string pArguments = string.Empty;
  79. switch (dmcType)
  80. {
  81. case DmcType.DAMA:
  82. dmcCmd = "dm";
  83. pArguments = $"{dmcCmd} \"{fileName}\"";// -f {fs}" -c --dmfirst";
  84. break;
  85. case DmcType.IBS:
  86. dmcCmd = "nd";
  87. pArguments = $"{dmcCmd} \"{fileName}\"";// -f {fs}" -c --dmfirst";
  88. break;
  89. case DmcType.Ky5758:
  90. pFileName = Path.Combine(p.StartInfo.WorkingDirectory, "xcorr\\enc.exe");
  91. //enc.exe enc-test.dat 0.096 5 0全部文件
  92. pArguments = $"{fileName} {fsHz * 1e-6} {5} {0}";
  93. break;
  94. default:
  95. break;
  96. }
  97. return await Task.Run(() =>
  98. {
  99. p.StartInfo.FileName = pFileName;
  100. p.StartInfo.Arguments = pArguments;
  101. p.StartInfo.CreateNoWindow = true;
  102. p.StartInfo.RedirectStandardError = true;
  103. p.StartInfo.RedirectStandardOutput = true;
  104. p.StartInfo.UseShellExecute = false;
  105. p.Start();
  106. Stopwatch stopWatch = new Stopwatch();
  107. stopWatch.Start();
  108. p.WaitForExit();
  109. stopWatch.Stop();
  110. TimeSpan ts = stopWatch.Elapsed;
  111. var str = p.StandardOutput.ReadToEnd();
  112. return ConvertDmcResult(str, ts.TotalMilliseconds);
  113. });
  114. }
  115. public static IEnumerable<DmcResult> ConvertDmcResult(string res, double tm)
  116. {
  117. var lines = res.Split(Environment.NewLine.ToArray(), StringSplitOptions.RemoveEmptyEntries);
  118. foreach (var line in lines)
  119. {
  120. var items = line.Split('\t');
  121. if (items.Length < 2) continue;
  122. int start = int.Parse(items[0]);
  123. int length = int.Parse(items[1]);
  124. string userName = "";
  125. if (items.Length >= 3)
  126. userName = items[2];
  127. yield return new DmcResult(start, length, userName, Math.Round(tm,4));
  128. }
  129. }
  130. public static void Stop()
  131. {
  132. try
  133. {
  134. p.Kill();
  135. }
  136. catch (Exception)
  137. {
  138. }
  139. }
  140. }
  141. }