CheckHelper.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 CheckServer
  12. {
  13. public static class CheckHelper
  14. {
  15. public static async Task<IEnumerable<DmcResult>> DmcCheckAsync(string fileName, double fsHz, DmcType dmcType, double? bandKHz = null)
  16. {
  17. if (bandKHz == null || bandKHz.Value <= 0) bandKHz = 25;
  18. string dmcCmd = "all";
  19. var dmp = new Process();
  20. string pFileName = Path.Combine(dmp.StartInfo.WorkingDirectory, "AddIns\\dmc.exe");
  21. string pArguments = string.Empty;
  22. switch (dmcType)
  23. {
  24. case DmcType.DAMA:
  25. dmcCmd = "dm";
  26. if (fsHz != 96000)
  27. throw new Exception("DAMA只支持96K采样率");
  28. pArguments = $"{dmcCmd} \"{fileName}\" -c true";//-c包含ccow
  29. break;
  30. case DmcType.IBS:
  31. dmcCmd = "nd";
  32. pArguments = $"{dmcCmd} \"{fileName}\" -w {bandKHz}";// -f {fs}" -c --dmfirst";
  33. break;
  34. case DmcType.Ky5758:
  35. pFileName = Path.Combine(dmp.StartInfo.WorkingDirectory, "AddIns\\enc.exe");
  36. //enc.exe enc-test.dat 0.096 5 0全部文件
  37. pArguments = $"{fileName} {fsHz * 1e-6} {5} {0}";
  38. break;
  39. default:
  40. break;
  41. }
  42. return await Task.Run(() =>
  43. {
  44. dmp.StartInfo.FileName = pFileName;
  45. dmp.StartInfo.Arguments = pArguments;
  46. dmp.StartInfo.CreateNoWindow = true;
  47. dmp.StartInfo.RedirectStandardError = true;
  48. dmp.StartInfo.RedirectStandardOutput = true;
  49. dmp.StartInfo.UseShellExecute = false;
  50. dmp.Start();
  51. Stopwatch stopWatch = new Stopwatch();
  52. stopWatch.Start();
  53. dmp.WaitForExit();
  54. stopWatch.Stop();
  55. TimeSpan ts = stopWatch.Elapsed;
  56. var str = dmp.StandardOutput.ReadToEnd();
  57. return ConvertDmcResult(dmcType, str, ts.TotalMilliseconds);
  58. });
  59. }
  60. private static IEnumerable<DmcResult> ConvertDmcResult(DmcType type, string res, double tm)
  61. {
  62. var lines = res.Split(Environment.NewLine.ToArray(), StringSplitOptions.RemoveEmptyEntries);
  63. foreach (var line in lines)
  64. {
  65. var items = line.Split('\t');
  66. if (items.Length < 2) continue;
  67. int start = int.Parse(items[0]);
  68. int length = int.Parse(items[1]);
  69. string userName = "";
  70. if (items.Length >= 3)
  71. userName = items[2];
  72. var item = new DmcResult(start, length, userName, (int)tm);
  73. if (type == DmcType.DAMA)
  74. item.ModType = "BPSK";
  75. else
  76. item.ModType = string.Empty;
  77. item.DmcType = type.GetEnumDisplayName();
  78. yield return item;
  79. }
  80. }
  81. }
  82. }