CogUtil.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 CogUtil
  13. {
  14. static readonly string CliFile = Path.Combine(IpsPath.CliRootDir, "cog", "cog.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. var cli = Cli.Wrap(CliFile)
  26. .WithArguments(args =>
  27. {
  28. args.Add(file1);
  29. args.Add(file2);
  30. args.Add(options.DtoCenter, false);
  31. args.Add(options.DtoRange, false);
  32. args.Add(options.Snr, false);
  33. args.Add(options.DfoRange, false);
  34. args.Add(options.DtoCorr, false);
  35. args.Add(options.DfoCorr, false);
  36. args.Add(options.Fs, false);
  37. args.Add("-l").Add(options.DataLen, false);
  38. args.Add("-z").Add(options.AddZero, false);
  39. args.Add("-o").Add(options.TimeOffset, false);
  40. args.Add("-f").Add((int)options.OffsetType, false);
  41. if (options.Timeslots != null)
  42. {
  43. args.Add("-d").Add(options.Timeslots.JoinAsString(" "), false);
  44. args.Add("-m").Add(options.MergeType.ToString("d"), false);
  45. }
  46. }).WithValidation(CommandResultValidation.None);
  47. var res = await cli.ExecuteBufferedAsync(timeout == 0 ? token : token.LinkTimeout(timeout));
  48. var result = CorResult.FromLines(res.StandardOutput, options.Snr);
  49. return ExeResult.Create(result, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode, res.StandardError);
  50. }
  51. }
  52. }