CocUtil.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using CliWrap;
  2. using CliWrap.Buffered;
  3. using Ips.Library.Basic;
  4. using Ips.Library.Entity;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace Ips.CorAlgorithm
  11. {
  12. public static class CocUtil
  13. {
  14. static readonly string CliFile = Path.Combine(IpsPath.CliRootDir, "coc", "coc.exe");
  15. public static async Task<ExeResult<CorResult[]>> Calc(string file1, string file2, CorOptions options, int timeout = 0, CancellationToken token = default)
  16. {
  17. if (options == null)
  18. {
  19. throw new ArgumentNullException(nameof(options));
  20. }
  21. if (options.Timeslots != null && options.Timeslots.Length == 0)
  22. {
  23. throw new Exception("没有需要计算的时隙!");
  24. }
  25. //时隙扩展样点,扩展规则为:[start-expSamples,length+expSamples],如果start-expSamples<0,扩展为:[0,length+expSamples+Math.Abs(start-expSamples)]
  26. //var expSamples = (int)((options.DtoRange / 2) * 1e-6 * options.Fs);
  27. //var expSamples = 0;
  28. var cli = Cli.Wrap(CliFile)
  29. .WithArguments(args =>
  30. {
  31. args.Add(file1);
  32. args.Add(file2);
  33. args.Add(options.DtoCenter, false);
  34. args.Add(options.DtoRange, false);
  35. args.Add(options.Snr, false);
  36. args.Add(options.DfoCenter, false);
  37. args.Add(options.DfoRange, false);
  38. args.Add(options.DtoCorr, false);
  39. args.Add(options.DfoCorr, false);
  40. args.Add(options.Fs, false);
  41. args.Add(options.BandWidth, false);
  42. args.Add("-l").Add(options.DataLen, false);
  43. args.Add("-z").Add(options.AddZero, false);
  44. args.Add("-o").Add(options.TimeOffset, false);
  45. args.Add("-f").Add((int)options.OffsetType, false);
  46. args.Add("-t").Add(options.ThreadNum, false);
  47. if (options.Timeslots != null)
  48. {
  49. args.Add("-d").Add(options.Timeslots.JoinAsString(" "), false);
  50. args.Add("-m").Add(options.MergeType.ToString("d"), false);
  51. }
  52. }).WithValidation(CommandResultValidation.None);
  53. var res = await cli.ExecuteBufferedAsync(timeout == 0 ? token : token.LinkTimeout(timeout));
  54. var result = CorResult.FromLines(res.StandardOutput, options.Snr);
  55. return ExeResult.Create(result, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode, res.StandardError);
  56. }
  57. }
  58. }