CorGpuUtil.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.Data;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace Ips.CorAlgorithm
  12. {
  13. public static class CorGpuUtil
  14. {
  15. static readonly string CliFile = Path.Combine(IpsPath.CliRootDir, "corg", "corg.exe");
  16. public static async Task<ExeResult<CorResult[]>> Calc(string file1, string file2, CorOptions options, int timeout = 0, CancellationToken token = default)
  17. {
  18. if (options == null)
  19. {
  20. throw new ArgumentNullException(nameof(options));
  21. }
  22. if (options.Timeslots != null && options.Timeslots.Length == 0)
  23. {
  24. throw new Exception("没有需要计算的时隙!");
  25. }
  26. var cli = Cli.Wrap(CliFile)
  27. .WithArguments(args =>
  28. {
  29. args.Add(file1);
  30. args.Add(file2);
  31. args.Add(options.DtoCenter, false);
  32. args.Add(options.DtoRange, false);
  33. args.Add(options.Snr, false);
  34. args.Add(options.DfoRange, false);
  35. args.Add(options.DtoCorr, false);
  36. args.Add(options.DfoCorr, false);
  37. args.Add(options.Fs, false);
  38. args.Add("-l").Add(options.DataLen, false);
  39. args.Add("-z").Add(options.AddZero, false);
  40. args.Add("-o").Add(options.TimeOffset, false);
  41. args.Add("-f").Add((int)options.OffsetType, false);
  42. if (options.Timeslots != null)
  43. {
  44. args.Add("-d").Add(options.Timeslots.JoinAsString(" "), false);
  45. args.Add("-m").Add(options.MergeType.ToString("d"), false);
  46. }
  47. }).WithValidation(CommandResultValidation.None);
  48. var res = await cli.ExecuteBufferedAsync(timeout == 0 ? token : token.LinkTimeout(timeout));
  49. var result = CorResult.FromLines(res.StandardOutput, options.Snr);
  50. return ExeResult.Create(result, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode, res.StandardError);
  51. }
  52. }
  53. }