DDCHelper.cs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace X3TaskServer54
  9. {
  10. static class DDCHelper
  11. {
  12. private static string exePath = "AddIns\\DDC";
  13. private const string exeName = "DigitaDownConverter.exe";
  14. /// <summary>
  15. /// 设置【DigitaDownConverter.exe】文件所在路径,支持相对路径
  16. /// </summary>
  17. public static void SetExePath(string path)
  18. {
  19. if (string.IsNullOrWhiteSpace(path)) return;
  20. if (path.StartsWith("\\"))//相对路径要么开头不带\,要么是 .\
  21. path = path.Remove(0, 1);
  22. exePath = path;
  23. }
  24. /// <summary>
  25. /// 对多个频点信号的AD文件做DDC
  26. /// </summary>
  27. /// <param name="file">输入文件</param>
  28. /// <param name="adTime">采集时刻</param>
  29. /// <param name="chNo">通道号0-3</param>
  30. /// <param name="fsHz">输入文件采样率Hz</param>
  31. /// <param name="freqCenterHz">中心频率Hz</param>
  32. /// <param name="outDir">输出目录</param>
  33. /// <param name="sigs">DDC信号参数</param>
  34. /// <param name="timeoutSeconds">超时时间(秒)</param>
  35. /// <returns>成功后返回DDC输出的文件</returns>
  36. public static List<string> DDC(string file, DateTime adTime, int chNo, long fsHz, long freqCenterHz,
  37. string outDir, IEnumerable<DDCSig> sigs, int timeoutSeconds = 60)
  38. {
  39. if (string.IsNullOrWhiteSpace(exePath))
  40. throw new Exception($"请先调用SetExePath指定{exeName}进程所在路径,支持相对路径");
  41. if (!Directory.Exists(exePath))
  42. throw new Exception($"路径[{exePath}]不存在");
  43. var exeFile = Path.Combine(exePath, exeName);
  44. if (!File.Exists(exeFile))
  45. throw new Exception($"文件[{exeFile}]不存在");
  46. Process p = new Process();
  47. p.StartInfo.WorkingDirectory = exePath;
  48. p.StartInfo.FileName = exeFile;
  49. StringBuilder sb = new StringBuilder();
  50. sb.Append($"\"{file}\" \"{outDir}\" {adTime:yyyyMMddHHmmss} {chNo} {fsHz} {freqCenterHz} {sigs.Count()}");
  51. List<string> list = new List<string>();
  52. foreach (var sig in sigs)
  53. {
  54. sb.Append(" ").Append(sig.FreqDownHz).Append(" ").Append(sig.Mult);
  55. list.Add(Path.Combine(outDir, $"{adTime:yyyyMMddHHmmss}_{sig.FreqDownHz / 1e6:f3}_C{fsHz / sig.Mult}_CH{chNo}.dat"));
  56. }
  57. p.StartInfo.Arguments = sb.ToString();
  58. p.StartInfo.CreateNoWindow = true;
  59. p.StartInfo.RedirectStandardError = true;
  60. p.StartInfo.RedirectStandardOutput = true;
  61. p.StartInfo.UseShellExecute = false;
  62. p.Start();
  63. var succeed = p.WaitForExit(timeoutSeconds * 1000);
  64. if (!succeed)
  65. {
  66. throw new Exception($"进程[{exeName}]超时未完成!");
  67. }
  68. return list.Where(x => File.Exists(x)).ToList();
  69. }
  70. }
  71. class DDCSig
  72. {
  73. /// <summary>
  74. /// 信号下行频点Hz
  75. /// </summary>
  76. public int FreqDownHz { get; set; }
  77. /// <summary>
  78. /// 抽取倍数
  79. /// </summary>
  80. public int Mult { get; set; }
  81. public SlotsInfo Slots { get; set; }
  82. }
  83. }