XcorrUtils.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Threading.Tasks;
  6. using XdCxRhDW.Dto;
  7. namespace CpuCgServer
  8. {
  9. public class XcorrStruct
  10. {
  11. public String file1 { get; set; }
  12. public String file2 { get; set; }
  13. public long smpStart { get; set; } //开始样点
  14. public double smpCount { get; set; } //样点数
  15. public double samplingRate { get; set; } //采样率
  16. public double dtCenter { get; set; } //时差中心
  17. public double dtRange { get; set; } //时差范围
  18. public double dfRange { get; set; } //频差范围
  19. public double snrThreshold { get; set; } //信噪比门限
  20. public XcorrStruct Copy()
  21. {
  22. XcorrStruct xItem = new XcorrStruct();
  23. xItem.file1 = file1;
  24. xItem.file2 = file2;
  25. xItem.smpCount = smpCount;
  26. xItem.samplingRate = samplingRate;
  27. xItem.dtCenter = dtCenter;
  28. xItem.dtRange = dtRange;
  29. xItem.dfRange = dfRange;
  30. xItem.smpStart = smpStart;
  31. xItem.snrThreshold = snrThreshold;
  32. return xItem;
  33. }
  34. }
  35. public class MultiXcorrStruct
  36. {
  37. public String file1 { get; set; }
  38. public String file2 { get; set; }
  39. public List<XcorrSmp> xcorrSmps { get; set; }
  40. public double samplingRate { get; set; } //采样率
  41. public double dtCenter { get; set; } //时差中心
  42. public double dtRange { get; set; } //时差范围
  43. public double dfRange { get; set; } //频差范围
  44. public double snrThreshold { get; set; } //信噪比门限
  45. }
  46. /// <summary>
  47. /// 时隙样点信息
  48. /// </summary>
  49. public class XcorrSmp
  50. {
  51. /// <summary>
  52. ///
  53. /// </summary>
  54. /// <param name="smpStart"></param>
  55. /// <param name="smpCount"></param>
  56. public XcorrSmp(long smpStart, long smpCount)
  57. {
  58. this.smpStart = smpStart;
  59. this.smpCount = smpCount;
  60. }
  61. public long smpStart { get; set; }
  62. public long smpCount { get; set; }
  63. }
  64. public class XcorrUtils
  65. {
  66. Process cafp;
  67. Process mucafp;
  68. // D:/data/test/r1.dat D:/data/test/r4.dat 1562500 -250000 20 16384 100000 1048576 11
  69. public async Task<CafResultDto> Calc(XcorrStruct xs)
  70. {
  71. CafResultDto res = new CafResultDto();
  72. cafp = new Process();
  73. await Task.Run(() =>
  74. {
  75. int flag = 0;
  76. if (xs.smpStart == 0)
  77. {
  78. flag = 2;//文件参估,避免滑动时溢出
  79. cafp.StartInfo.Arguments = $"{flag} \"{xs.file1}\" \"{xs.file2}\" {(Int64)(xs.samplingRate)} {xs.dtCenter} {xs.dtRange} {xs.dfRange} {xs.smpCount} {xs.snrThreshold}";
  80. }
  81. else
  82. {
  83. var minStart = xs.dtRange / 2 / 1e6 * xs.samplingRate;
  84. if (xs.smpStart < minStart)//滑动计算起时值必须要大于等于此数
  85. {
  86. xs.smpStart = (long)minStart;
  87. }
  88. cafp.StartInfo.Arguments = $"{flag} \"{xs.file1}\" \"{xs.file2}\" {(Int64)(xs.samplingRate)} {xs.dtCenter} {xs.dtRange} {xs.dfRange} {xs.smpStart} {xs.smpCount} {xs.snrThreshold}";
  89. }
  90. var exePath = Path.Combine(cafp.StartInfo.WorkingDirectory, "AddIns");
  91. cafp.StartInfo.WorkingDirectory = exePath;
  92. cafp.StartInfo.FileName = Path.Combine(exePath, "XcorrCpu.exe");
  93. cafp.StartInfo.CreateNoWindow = true;
  94. cafp.StartInfo.RedirectStandardError = true;
  95. cafp.StartInfo.RedirectStandardOutput = true;
  96. cafp.StartInfo.UseShellExecute = false;
  97. cafp.Start();
  98. Stopwatch stopWatch = new Stopwatch();
  99. stopWatch.Start();
  100. cafp.WaitForExit();
  101. stopWatch.Stop();
  102. TimeSpan ts = stopWatch.Elapsed;
  103. var str = cafp.StandardOutput.ReadToEnd();
  104. res.FromLine(str);
  105. res.file1 = xs.file1;
  106. res.file2 = xs.file2;
  107. res.tm = (int)stopWatch.Elapsed.TotalMilliseconds;
  108. res.smpstart = xs.smpStart;
  109. res.smplen = (long)xs.smpCount;
  110. });
  111. return res;
  112. }
  113. public async Task<List<CafResultDto>> MultiCalc(MultiXcorrStruct xs)
  114. {
  115. List<CafResultDto> res = new List<CafResultDto>();
  116. mucafp = new Process();
  117. await Task.Run(() =>
  118. {
  119. int flag = 4;
  120. string smparg = $"{xs.xcorrSmps.Count}";
  121. xs.xcorrSmps.ForEach(n => smparg += $" {n.smpStart} {n.smpCount}");
  122. mucafp.StartInfo.Arguments = $"{flag} \"{xs.file1}\" \"{xs.file2}\" {(Int64)(xs.samplingRate)} {xs.dtCenter} {xs.dtRange} {xs.dfRange} {xs.snrThreshold} {smparg}";
  123. var exePath = Path.Combine(mucafp.StartInfo.WorkingDirectory, "AddIns");
  124. mucafp.StartInfo.WorkingDirectory = exePath;
  125. mucafp.StartInfo.FileName = Path.Combine(exePath, "XcorrCpu.exe");
  126. mucafp.StartInfo.CreateNoWindow = true;
  127. mucafp.StartInfo.RedirectStandardError = true;
  128. mucafp.StartInfo.RedirectStandardOutput = true;
  129. mucafp.StartInfo.UseShellExecute = false;
  130. mucafp.Start();
  131. Stopwatch stopWatch = new Stopwatch();
  132. stopWatch.Start();
  133. mucafp.WaitForExit();
  134. stopWatch.Stop();
  135. TimeSpan ts = stopWatch.Elapsed;
  136. var str = mucafp.StandardOutput.ReadToEnd();
  137. var items = str.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  138. for (int i = 0; i < items.Length; i++)
  139. {
  140. var item = items[i];
  141. var cafres = item.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  142. if (cafres.Length != 3)
  143. {
  144. continue;
  145. }
  146. CafResultDto caf = new CafResultDto();
  147. caf.file1 = xs.file1;
  148. caf.file2 = xs.file2;
  149. caf.tm = (int)stopWatch.Elapsed.TotalMilliseconds;
  150. caf.smpstart = xs.xcorrSmps[i].smpStart;
  151. caf.smplen = xs.xcorrSmps[i].smpCount;
  152. double snr = Math.Round(double.Parse(cafres[2]), 1);
  153. if (snr == 0)
  154. {
  155. caf.dt = 0;
  156. caf.df = 0;
  157. }
  158. else
  159. {
  160. caf.dt = Math.Round(double.Parse(cafres[0]), 3);
  161. caf.df = Math.Round(double.Parse(cafres[1]), 3);
  162. caf.snr = snr;
  163. }
  164. res.Add(caf);
  165. }
  166. });
  167. return res;
  168. }
  169. }
  170. }