XcorrUtils.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. namespace XdCxRhDW.App.CorTools
  15. {
  16. class XcorrStruct
  17. {
  18. public String file1 { get; set; }
  19. public String file2 { get; set; }
  20. public int smpStart { get; set; } //开始样点
  21. public int smpCount { get; set; } //样点数
  22. public double samplingRate { get; set; } //采样率
  23. public double dtCenter { get; set; } //时差中心
  24. public double dtRange { get; set; } //时差范围
  25. public double dfRange { get; set; } //频差范围
  26. public double snrThreshold { get; set; } //信噪比门限
  27. public XcorrStruct Copy()
  28. {
  29. XcorrStruct xItem = new XcorrStruct();
  30. xItem.file1 = file1;
  31. xItem.file2 = file2;
  32. xItem.smpCount = smpCount;
  33. xItem.samplingRate = samplingRate;
  34. xItem.dtCenter = dtCenter;
  35. xItem.dtRange = dtRange;
  36. xItem.dfRange = dfRange;
  37. xItem.smpStart = smpStart;
  38. xItem.snrThreshold = snrThreshold;
  39. return xItem;
  40. }
  41. }
  42. class XcorrUtils
  43. {
  44. static Process p = new Process();
  45. // D:/data/test/r1.dat D:/data/test/r4.dat 1562500 -250000 20 16384 100000 1048576 11
  46. public static async Task<CafResult> Calc(XcorrStruct xs)
  47. {
  48. CafResult res = new CafResult();
  49. await Task.Run(() =>
  50. {
  51. p.StartInfo.FileName = Path.Combine(p.StartInfo.WorkingDirectory, "xcorr\\XcorrCpu.exe");
  52. p.StartInfo.Arguments = $"\"{xs.file1}\" \"{xs.file2}\" {(Int64)(xs.samplingRate)} {xs.dtCenter} {xs.dtRange} {xs.dfRange} {xs.smpStart} {xs.smpCount} {xs.snrThreshold}";
  53. p.StartInfo.CreateNoWindow = true;
  54. p.StartInfo.RedirectStandardError = true;
  55. p.StartInfo.RedirectStandardOutput = true;
  56. p.StartInfo.UseShellExecute = false;
  57. p.Start();
  58. Stopwatch stopWatch = new Stopwatch();
  59. stopWatch.Start();
  60. p.WaitForExit();
  61. stopWatch.Stop();
  62. TimeSpan ts = stopWatch.Elapsed;
  63. var str = p.StandardOutput.ReadToEnd();
  64. res.FromLine(str);
  65. res.file1 = xs.file1;
  66. res.file2 = xs.file2;
  67. res.tm = stopWatch.Elapsed.TotalSeconds;
  68. res.smpstart = xs.smpStart;
  69. res.smplen = xs.smpCount;
  70. });
  71. return res;
  72. }
  73. public static async Task<IEnumerable<DmcResult>> DmcCheckAsync(string fileName, double fs)
  74. {
  75. return await Task.Run(() =>
  76. {
  77. p.StartInfo.FileName = Path.Combine(p.StartInfo.WorkingDirectory, "xcorr\\dmc.exe");
  78. p.StartInfo.Arguments = $"all \"{fileName}\" -f {fs} -c --dmfirst";
  79. p.StartInfo.CreateNoWindow = true;
  80. p.StartInfo.RedirectStandardError = true;
  81. p.StartInfo.RedirectStandardOutput = true;
  82. p.StartInfo.UseShellExecute = false;
  83. p.Start();
  84. Stopwatch stopWatch = new Stopwatch();
  85. stopWatch.Start();
  86. p.WaitForExit();
  87. stopWatch.Stop();
  88. TimeSpan ts = stopWatch.Elapsed;
  89. var str = p.StandardOutput.ReadToEnd();
  90. return ConvertDmcResult(str);
  91. });
  92. }
  93. public static IEnumerable<DmcResult> ConvertDmcResult(string res)
  94. {
  95. var lines = res.Split(Environment.NewLine.ToArray(), StringSplitOptions.RemoveEmptyEntries);
  96. foreach (var line in lines)
  97. {
  98. var items = line.Split('\t');
  99. if (items.Length < 2) continue;
  100. int start = int.Parse(items[0]);
  101. int length = int.Parse(items[1]);
  102. string userName = "";
  103. if (items.Length >= 3)
  104. userName = items[2];
  105. yield return new DmcResult(start, length, userName);
  106. }
  107. }
  108. public static void Stop()
  109. {
  110. try
  111. {
  112. p.Kill();
  113. }
  114. catch (Exception)
  115. {
  116. }
  117. }
  118. }
  119. }