XcorrUtils.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.Collections;
  8. using System.Collections.Generic;
  9. using XdCxRhDW.Dto;
  10. using System.Security.Policy;
  11. namespace CpuCgServer
  12. {
  13. public class XcorrStruct
  14. {
  15. public String file1 { get; set; }
  16. public String file2 { get; set; }
  17. public long smpStart { get; set; } //开始样点
  18. public double smpCount { get; set; } //样点数
  19. public double samplingRate { get; set; } //采样率
  20. public double dtCenter { get; set; } //时差中心
  21. public double dtRange { get; set; } //时差范围
  22. public double dfRange { get; set; } //频差范围
  23. public double snrThreshold { get; set; } //信噪比门限
  24. public XcorrStruct Copy()
  25. {
  26. XcorrStruct xItem = new XcorrStruct();
  27. xItem.file1 = file1;
  28. xItem.file2 = file2;
  29. xItem.smpCount = smpCount;
  30. xItem.samplingRate = samplingRate;
  31. xItem.dtCenter = dtCenter;
  32. xItem.dtRange = dtRange;
  33. xItem.dfRange = dfRange;
  34. xItem.smpStart = smpStart;
  35. xItem.snrThreshold = snrThreshold;
  36. return xItem;
  37. }
  38. }
  39. public class XcorrUtils
  40. {
  41. Process cafp;
  42. // D:/data/test/r1.dat D:/data/test/r4.dat 1562500 -250000 20 16384 100000 1048576 11
  43. public async Task<CafResultDto> Calc(XcorrStruct xs)
  44. {
  45. CafResultDto res = new CafResultDto();
  46. cafp = new Process();
  47. await Task.Run(() =>
  48. {
  49. int flag = 0;
  50. if (xs.smpStart == 0)
  51. {
  52. flag = 2;//文件参估,避免滑动时溢出
  53. cafp.StartInfo.Arguments = $"{flag} \"{xs.file1}\" \"{xs.file2}\" {(Int64)(xs.samplingRate)} {xs.dtCenter} {xs.dtRange} {xs.dfRange} {xs.smpCount} {xs.snrThreshold}";
  54. }
  55. else
  56. {
  57. var minStart = xs.dtRange / 2 / 1e6 * xs.samplingRate;
  58. if (xs.smpStart < minStart)//滑动计算起时值必须要大于等于此数
  59. {
  60. xs.smpStart = (long)minStart;
  61. }
  62. cafp.StartInfo.Arguments = $"{flag} \"{xs.file1}\" \"{xs.file2}\" {(Int64)(xs.samplingRate)} {xs.dtCenter} {xs.dtRange} {xs.dfRange} {xs.smpStart} {xs.smpCount} {xs.snrThreshold}";
  63. }
  64. var exePath= Path.Combine(cafp.StartInfo.WorkingDirectory, "AddIns");
  65. cafp.StartInfo.WorkingDirectory = exePath;
  66. cafp.StartInfo.FileName = Path.Combine(exePath,"XcorrCpu.exe");
  67. cafp.StartInfo.CreateNoWindow = true;
  68. cafp.StartInfo.RedirectStandardError = true;
  69. cafp.StartInfo.RedirectStandardOutput = true;
  70. cafp.StartInfo.UseShellExecute = false;
  71. cafp.Start();
  72. Stopwatch stopWatch = new Stopwatch();
  73. stopWatch.Start();
  74. cafp.WaitForExit();
  75. stopWatch.Stop();
  76. TimeSpan ts = stopWatch.Elapsed;
  77. var str = cafp.StandardOutput.ReadToEnd();
  78. res.FromLine(str);
  79. res.file1 = xs.file1;
  80. res.file2 = xs.file2;
  81. res.tm = (int)stopWatch.Elapsed.TotalMilliseconds;
  82. res.smpstart = xs.smpStart;
  83. res.smplen = (long)xs.smpCount;
  84. });
  85. return res;
  86. }
  87. }
  88. }