| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using CliWrap;
- using CliWrap.Buffered;
- using Ips.Library.Basic;
- using Ips.Library.Entity;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ips.CorAlgorithm
- {
- public static class CocUtil
- {
- static readonly string CliFile = Path.Combine(IpsPath.CliRootDir, "coc", "coc.exe");
- public static async Task<ExeResult<CorResult[]>> Calc(string file1, string file2, CorOptions options, int timeout = 0, CancellationToken token = default)
- {
- if (options == null)
- {
- throw new ArgumentNullException(nameof(options));
- }
- if (options.Timeslots != null && options.Timeslots.Length == 0)
- {
- throw new Exception("没有需要计算的时隙!");
- }
- //时隙扩展样点,扩展规则为:[start-expSamples,length+expSamples],如果start-expSamples<0,扩展为:[0,length+expSamples+Math.Abs(start-expSamples)]
- //var expSamples = (int)((options.DtoRange / 2) * 1e-6 * options.Fs);
- //var expSamples = 0;
- var cli = Cli.Wrap(CliFile)
- .WithArguments(args =>
- {
- args.Add(file1);
- args.Add(file2);
- args.Add(options.DtoCenter, false);
- args.Add(options.DtoRange, false);
- args.Add(options.Snr, false);
- args.Add(options.DfoCenter, false);
- args.Add(options.DfoRange, false);
- args.Add(options.DtoCorr, false);
- args.Add(options.DfoCorr, false);
- args.Add(options.Fs, false);
- args.Add(options.BandWidth, false);
- args.Add("-l").Add(options.DataLen, false);
- args.Add("-z").Add(options.AddZero, false);
- args.Add("-o").Add(options.TimeOffset, false);
- args.Add("-f").Add((int)options.OffsetType, false);
- args.Add("-t").Add(options.ThreadNum, false);
- if (options.Timeslots != null)
- {
- args.Add("-d").Add(options.Timeslots.JoinAsString(" "), false);
- args.Add("-m").Add(options.MergeType.ToString("d"), false);
- }
- }).WithValidation(CommandResultValidation.None);
- var res = await cli.ExecuteBufferedAsync(timeout == 0 ? token : token.LinkTimeout(timeout));
- var result = CorResult.FromLines(res.StandardOutput, options.Snr);
- return ExeResult.Create(result, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode, res.StandardError);
- }
- }
- }
|