DDCHelper.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 (!outDir.Contains(":"))
  40. {
  41. outDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, outDir);
  42. }
  43. if (string.IsNullOrWhiteSpace(exePath))
  44. throw new Exception($"请先调用SetExePath指定{exeName}进程所在路径,支持相对路径");
  45. if (!Directory.Exists(exePath))
  46. throw new Exception($"路径[{exePath}]不存在");
  47. var exeFile = Path.Combine(exePath, exeName);
  48. if (!File.Exists(exeFile))
  49. throw new Exception($"文件[{exeFile}]不存在");
  50. Process p = new Process();
  51. p.StartInfo.WorkingDirectory = exePath;
  52. p.StartInfo.FileName = exeFile;
  53. StringBuilder sb = new StringBuilder();
  54. sb.Append($"\"{file}\" \"{outDir}\" {adTime:yyyyMMddHHmmss} {chNo} {fsHz} {freqCenterHz} {sigs.Count()}");
  55. List<string> list = new List<string>();
  56. foreach (var sig in sigs)
  57. {
  58. sb.Append(" ").Append(sig.FreqDownHz).Append(" ").Append(sig.Mult);
  59. list.Add(Path.Combine(outDir, $"{adTime:yyyyMMddHHmmss}_{sig.FreqDownHz / 1e6:f3}_C{fsHz / sig.Mult}_CH{chNo}.dat"));
  60. }
  61. p.StartInfo.Arguments = sb.ToString();
  62. p.StartInfo.CreateNoWindow = true;
  63. p.StartInfo.RedirectStandardError = true;
  64. p.StartInfo.RedirectStandardOutput = true;
  65. p.StartInfo.UseShellExecute = false;
  66. p.Start();
  67. var succeed = p.WaitForExit(timeoutSeconds * 1000);
  68. if (!succeed)
  69. {
  70. throw new Exception($"进程[{exeName}]超时未完成!");
  71. }
  72. return list.Where(x => File.Exists(x)).ToList();
  73. }
  74. }
  75. class DDCSig
  76. {
  77. /// <summary>
  78. /// 信号下行频点Hz
  79. /// </summary>
  80. public int FreqDownHz { get; set; }
  81. /// <summary>
  82. /// 抽取倍数
  83. /// </summary>
  84. public int Mult { get; set; }
  85. public SlotsInfo Slots { get; set; }
  86. }
  87. }