XcorrUtils.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 = stopWatch.Elapsed.TotalSeconds;
  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, DmcType dmcType)
  75. {
  76. string dmcCmd = "all";
  77. switch (dmcType)
  78. {
  79. case DmcType.DAMA:
  80. dmcCmd = "dm";
  81. break;
  82. case DmcType.IBS:
  83. dmcCmd = "nd";
  84. break;
  85. case DmcType.Ky5758:
  86. throw new Exception("ky未实现!");
  87. break;
  88. default:
  89. break;
  90. }
  91. return await Task.Run(() =>
  92. {
  93. p.StartInfo.FileName = Path.Combine(p.StartInfo.WorkingDirectory, "xcorr\\dmc.exe");
  94. p.StartInfo.Arguments = $"{dmcCmd} \"{fileName}\"";// -f {fs}" -c --dmfirst";
  95. p.StartInfo.CreateNoWindow = true;
  96. p.StartInfo.RedirectStandardError = true;
  97. p.StartInfo.RedirectStandardOutput = true;
  98. p.StartInfo.UseShellExecute = false;
  99. p.Start();
  100. Stopwatch stopWatch = new Stopwatch();
  101. stopWatch.Start();
  102. p.WaitForExit();
  103. stopWatch.Stop();
  104. TimeSpan ts = stopWatch.Elapsed;
  105. var str = p.StandardOutput.ReadToEnd();
  106. return ConvertDmcResult(str);
  107. });
  108. }
  109. public static IEnumerable<DmcResult> ConvertDmcResult(string res)
  110. {
  111. var lines = res.Split(Environment.NewLine.ToArray(), StringSplitOptions.RemoveEmptyEntries);
  112. foreach (var line in lines)
  113. {
  114. var items = line.Split('\t');
  115. if (items.Length < 2) continue;
  116. int start = int.Parse(items[0]);
  117. int length = int.Parse(items[1]);
  118. string userName = "";
  119. if (items.Length >= 3)
  120. userName = items[2];
  121. yield return new DmcResult(start, length, userName);
  122. }
  123. }
  124. public static void Stop()
  125. {
  126. try
  127. {
  128. p.Kill();
  129. }
  130. catch (Exception)
  131. {
  132. }
  133. }
  134. }
  135. }