using CliWrap; using CliWrap.Buffered; using Ips.Library.Basic; using Ips.Library.CliLib; using Ips.Library.Entity; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace Ips.LocAlgorithm { public class Loc32Util { static readonly string CliPath = Path.Combine(IpsPath.CliRootDir, "loc32", "loc32.exe"); public static async Task> X3( double dtotar1, double dtotar2, double[] msant1, double[] nsant1, double[] msant2, double[] nsant2, double[] mseph1, double[] nseph1, double[] mseph2, double[] nseph2, int timeout = 60, CancellationToken token = default ) { const string cmd = "x3"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(dtotar1), dtotar1); args.IpsAdd(nameof(dtotar2), dtotar2); args.IpsAdd(nameof(msant1), msant1); args.IpsAdd(nameof(nsant1), nsant1); args.IpsAdd(nameof(msant2), msant2); args.IpsAdd(nameof(nsant2), nsant2); args.IpsAdd(nameof(mseph1), mseph1); args.IpsAdd(nameof(nseph1), nseph1); args.IpsAdd(nameof(mseph2), mseph2); args.IpsAdd(nameof(nseph2), nseph2); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var dwResult = PosResult.FromString(PosType.X3, false, res.StandardOutput); return ExeResult.Create(dwResult, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode, res.StandardError); } public static async Task> X3Ref( double dtotar1, double dtotar2, double dtoref1, double dtoref2, double[] refgeod1, double[] refgeod2, double[] msant1, double[] nsant1, double[] msant2, double[] nsant2, double[] mseph1, double[] nseph1, double[] mseph2, double[] nseph2, int timeout = 60, CancellationToken token = default ) { const string cmd = "x3ref"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(dtotar1), dtotar1); args.IpsAdd(nameof(dtotar2), dtotar2); args.IpsAdd(nameof(dtoref1), dtoref1); args.IpsAdd(nameof(dtoref2), dtoref2); args.IpsAdd(nameof(refgeod1), refgeod1); args.IpsAdd(nameof(refgeod2), refgeod2); args.IpsAdd(nameof(msant1), msant1); args.IpsAdd(nameof(nsant1), nsant1); args.IpsAdd(nameof(msant2), msant2); args.IpsAdd(nameof(nsant2), nsant2); args.IpsAdd(nameof(mseph1), mseph1); args.IpsAdd(nameof(nseph1), nseph1); args.IpsAdd(nameof(mseph2), mseph2); args.IpsAdd(nameof(nseph2), nseph2); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var dwResult = PosResult.FromString(PosType.X3Ref, true, res.StandardOutput); return ExeResult.Create(dwResult, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode, res.StandardError); } public static Task> X4( double dtotar1, double dtotar2, double dtotar3, double[] nsant1, double[] nsant2, double[] nsant3, double[] nseph1, double[] nseph2, double[] nseph3, int timeout = 60, CancellationToken token = default ) { var dt1 = dtotar2 - dtotar1; var dt2 = dtotar3 - dtotar1; return X3(dt1, dt2, nsant1, nsant2, nsant1, nsant3, nseph1, nseph2, nseph1, nseph3, timeout, token); } public static Task> X4Ref( double dtotar1, double dtotar2, double dtotar3, double dtoref1, double dtoref2, double dtoref3, double[] refgeod, double[] nsant1, double[] nsant2, double[] nsant3, double[] nseph1, double[] nseph2, double[] nseph3, int timeout = 60, CancellationToken token = default ) { var dt1 = dtotar2 - dtotar1; var dt2 = dtotar3 - dtotar1; var refdt1 = dtoref2 - dtoref1; var refdt2 = dtoref3 - dtoref1; return X3Ref(dt1, dt2, refdt1, refdt2, refgeod, refgeod, nsant1, nsant2, nsant1, nsant3, nseph1, nseph2, nseph1, nseph3, timeout, token); } public static async Task>> DtoLineSx(double dtotar, double[] msant, double[] nsant, double[] mseph, double[] nseph, int timeout = 60, CancellationToken token = default) { const string cmd = "dtolinesx"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(dtotar), dtotar); args.IpsAdd(nameof(msant), msant); args.IpsAdd(nameof(nsant), nsant); args.IpsAdd(nameof(mseph), mseph); args.IpsAdd(nameof(nseph), nseph); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var dwResult = GeoLine.FromListString(res.StandardOutput); return ExeResult.Create(dwResult, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode); } public static async Task>> DtoLineSxRef(double dtotar, double dtoref, double[] refgeod, double[] mseph, double[] nseph, double[] msant, double[] nsaant, int timeout = 60, CancellationToken token = default) { const string cmd = "dtolinesxref"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(dtotar), dtotar); args.IpsAdd(nameof(dtoref), dtoref); args.IpsAdd(nameof(refgeod), refgeod); args.IpsAdd(nameof(mseph), mseph); args.IpsAdd(nameof(nseph), nseph); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var dwResult = GeoLine.FromListString(res.StandardOutput); return ExeResult.Create(dwResult, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode); } public static async Task>> DtoLineLoc(double[] pos, double[] msant, double[] nsant, double[] mseph, double[] nseph, int timeout = 60, CancellationToken token = default) { const string cmd = "dtolineloc"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(pos), pos); args.IpsAdd(nameof(msant), msant); args.IpsAdd(nameof(nsant), nsant); args.IpsAdd(nameof(mseph), mseph); args.IpsAdd(nameof(nseph), nseph); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var dwResult = GeoLine.FromListString(res.StandardOutput); return ExeResult.Create(dwResult, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode); } public static async Task> X2Ref( double[] msant, double[] nsant, double[] refgeod, double tarfreq, double reffreq, double msturn, double nsturn, double dtotar, double dtoref, double dfotar, double dforef, double[] mseph, double[] nseph, int timeout = 60, CancellationToken token = default ) { const string cmd = "x2ref"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(msant), msant); args.IpsAdd(nameof(nsant), nsant); args.IpsAdd(nameof(refgeod), refgeod); args.IpsAdd(nameof(tarfreq), tarfreq); args.IpsAdd(nameof(reffreq), reffreq); args.IpsAdd(nameof(msturn), msturn); args.IpsAdd(nameof(nsturn), nsturn); args.IpsAdd(nameof(dtotar), dtotar); args.IpsAdd(nameof(dtoref), dtoref); args.IpsAdd(nameof(dfotar), dfotar); args.IpsAdd(nameof(dforef), dforef); args.IpsAdd(nameof(mseph), mseph); args.IpsAdd(nameof(nseph), nseph); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var dwResult = PosResult.FromString(PosType.X2Ref, true, res.StandardOutput); return ExeResult.Create(dwResult, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode, res.StandardError); } public static async Task> X3Df( double tarfreq, double reffreq, double msturn, double nsturn, double dfotar1, double dfotar2, double dforef1, double dforef2, double[] refgeod1, double[] refgeod2, double[] msant1, double[] nsant1, double[] msant2, double[] nsant2, double[] mseph1, double[] nseph1, double[] mseph2, double[] nseph2, int timeout = 60, CancellationToken token = default) { const string cmd = "x3df"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(tarfreq), tarfreq); args.IpsAdd(nameof(reffreq), reffreq); args.IpsAdd(nameof(msturn), msturn); args.IpsAdd(nameof(nsturn), nsturn); args.IpsAdd(nameof(dfotar1), dfotar1); args.IpsAdd(nameof(dfotar2), dfotar2); args.IpsAdd(nameof(dforef1), dforef1); args.IpsAdd(nameof(dforef2), dforef2); args.IpsAdd(nameof(refgeod1), refgeod1); args.IpsAdd(nameof(refgeod2), refgeod2); args.IpsAdd(nameof(msant1), msant1); args.IpsAdd(nameof(nsant1), nsant1); args.IpsAdd(nameof(msant2), msant2); args.IpsAdd(nameof(nsant2), nsant2); args.IpsAdd(nameof(mseph1), mseph1); args.IpsAdd(nameof(nseph1), nseph1); args.IpsAdd(nameof(mseph2), mseph2); args.IpsAdd(nameof(nseph2), nseph2); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var dwResult = PosResult.FromString(PosType.X3Ref, true, res.StandardOutput); return ExeResult.Create(dwResult, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode, res.StandardError); } public static async Task>> DtoLineLocRef(double[] pos, double[] refgeod, double[] mseph, double[] nseph, int timeout = 60, CancellationToken token = default) { const string cmd = "dtolinelocref"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(pos), pos); args.IpsAdd(nameof(refgeod), refgeod); args.IpsAdd(nameof(mseph), mseph); args.IpsAdd(nameof(nseph), nseph); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var dwResult = GeoLine.FromListString(res.StandardOutput); return ExeResult.Create(dwResult, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode); } public static async Task>> DtoLineYiDi(double dtotar, double[] mseph, double[] nseph, double[] msant, double[] nsant, int timeout = 60, CancellationToken token = default) { const string cmd = "dtolineyidi"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(dtotar), dtotar); args.IpsAdd(nameof(mseph), mseph); args.IpsAdd(nameof(nseph), nseph); args.IpsAdd(nameof(msant), msant); args.IpsAdd(nameof(nsant), nsant); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var dwResult = GeoLine.FromListString(res.StandardOutput); return ExeResult.Create(dwResult, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode); } public static async Task>> DfoLine( double[] msant, double[] nsant, double[] mseph, double[] nseph, double[] dfo, double frequp, double msturn, double nsturn, double? refdfo = null, double? reffrequp = null, double[] refgeod = null, double[] pos = null, int timeout = 60, CancellationToken token = default) { const string cmd = "dfoline"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(msant), msant); args.IpsAdd(nameof(nsant), nsant); args.IpsAdd(nameof(mseph), mseph); args.IpsAdd(nameof(nseph), nseph); args.IpsAdd(nameof(dfo), dfo); args.IpsAdd(nameof(frequp), frequp); args.IpsAdd(nameof(msturn), msturn); args.IpsAdd(nameof(nsturn), nsturn); if (refdfo.HasValue) args.IpsAdd(nameof(refdfo), refdfo); if (reffrequp.HasValue) args.IpsAdd(nameof(reffrequp), reffrequp); if (refgeod != null && refgeod.Length > 1) args.IpsAdd(nameof(refgeod), refgeod); if (pos != null && pos.Length > 1) args.IpsAdd(nameof(pos), pos); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var dwResult = GeoLine.FromListString(res.StandardOutput); return ExeResult.Create(dwResult, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode); } public static async Task> Gdop(double[] recgeod, double[] mseph1, double[] nseph1, double[] mseph2, double[] nseph2, int timeout = 60, CancellationToken token = default) { const string cmd = "gdop"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(recgeod), recgeod); args.IpsAdd(nameof(mseph1), mseph1); args.IpsAdd(nameof(nseph1), nseph1); args.IpsAdd(nameof(mseph2), mseph2); args.IpsAdd(nameof(nseph2), nseph2); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var result = new GdopResult(res.StandardOutput); return ExeResult.Create(result, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode); } public static async Task> GdopRef(double[] refgeod, double[] mseph1, double[] nseph1, double[] mseph2, double[] nseph2, int timeout = 60, CancellationToken token = default) { const string cmd = "gdopref"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(refgeod), refgeod); args.IpsAdd(nameof(mseph1), mseph1); args.IpsAdd(nameof(nseph1), nseph1); args.IpsAdd(nameof(mseph2), mseph2); args.IpsAdd(nameof(nseph2), nseph2); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var result = new GdopResult(res.StandardOutput); return ExeResult.Create(result, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode); } public static async Task> LocErr(double[] pos, double[] recgeod, double[] mseph1, double[] nseph1, double[] mseph2, double[] nseph2, int timeout = 60, CancellationToken token = default) { const string cmd = "locerr"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(pos), pos); args.IpsAdd(nameof(recgeod), recgeod); args.IpsAdd(nameof(mseph1), mseph1); args.IpsAdd(nameof(nseph1), nseph1); args.IpsAdd(nameof(mseph2), mseph2); args.IpsAdd(nameof(nseph2), nseph2); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var result = new LocErrResult(res.StandardOutput); return ExeResult.Create(result, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode); } public static async Task> LocErrRef(double[] pos, double[] refgeod, double[] mseph1, double[] nseph1, double[] mseph2, double[] nseph2, int timeout = 60, CancellationToken token = default) { const string cmd = "locerrref"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(pos), pos); args.IpsAdd(nameof(refgeod), refgeod); args.IpsAdd(nameof(mseph1), mseph1); args.IpsAdd(nameof(nseph1), nseph1); args.IpsAdd(nameof(mseph2), mseph2); args.IpsAdd(nameof(nseph2), nseph2); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var result = new LocErrResult(res.StandardOutput); return ExeResult.Create(result, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode); } public static async Task> RefCalc(DateTime[] intimes, double[] inmsephs, double[] innsephs, double[] indtorefs, double[] refgeod, double[] recgeod, DateTime time, double[] mseph, double[] nseph, int timeout = 60, CancellationToken token = default) { const string cmd = "refcalc"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(intimes), intimes); args.IpsAdd(nameof(inmsephs), inmsephs); args.IpsAdd(nameof(innsephs), innsephs); args.IpsAdd(nameof(indtorefs), indtorefs); args.IpsAdd(nameof(refgeod), refgeod); args.IpsAdd(nameof(recgeod), recgeod); args.IpsAdd(nameof(time), time); args.IpsAdd(nameof(mseph), mseph); args.IpsAdd(nameof(nseph), nseph); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var dtoRefOut = double.Parse(res.StandardOutput); return ExeResult.Create(dtoRefOut, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode); } //[CommandOption("pos", 'p', Description = "定位点位置", IsRequired = true)] //public double[] Pos { get; set; } //[CommandOption("mseph", Description = "主星星历", IsRequired = true)] //public double[] MsEph { get; set; } //[CommandOption("nseph", Description = "邻星星历", IsRequired = true)] //public double[] NsEph { get; set; } //[CommandOption("msant", Description = "主星天线位置", IsRequired = true)] //public double[] MsAnt { get; set; } //[CommandOption("nsant", Description = "邻星天线位置", IsRequired = true)] //public double[] NsAnt { get; set; } //[CommandOption("refgeod", Description = "参考站位置")] //public double[] RefGeod { get; set; } public static async Task> CalcDt( double[] pos, double[] mseph, double[] nseph, double[] msant, double[] nsant, double[] refgeod = null, int timeout = 60, CancellationToken token = default) { const string cmd = "calcdt"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(pos), pos); args.IpsAdd(nameof(mseph), mseph); args.IpsAdd(nameof(nseph), nseph); args.IpsAdd(nameof(msant), msant); args.IpsAdd(nameof(nsant), nsant); if (refgeod != null && refgeod.Length > 1) args.IpsAdd(nameof(refgeod), refgeod); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var dtoRefOut = double.Parse(res.StandardOutput); return ExeResult.Create(dtoRefOut, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode); } public static async Task> CalcDf( double frequp, double msturn, double nsturn, double[] pos, double[] mseph, double[] nseph, double[] msant, double[] nsant, double? reffrequp = null, double[] refgeod = null, int timeout = 60, CancellationToken token = default) { const string cmd = "calcdf"; var cli = Cli.Wrap(CliPath) .WithArguments(args => { args.Add(cmd); args.IpsAdd(nameof(frequp), frequp); args.IpsAdd(nameof(msturn), msturn); args.IpsAdd(nameof(nsturn), nsturn); args.IpsAdd(nameof(pos), pos); args.IpsAdd(nameof(mseph), mseph); args.IpsAdd(nameof(nseph), nseph); args.IpsAdd(nameof(msant), msant); args.IpsAdd(nameof(nsant), nsant); if (reffrequp.HasValue) args.IpsAdd(nameof(reffrequp), reffrequp); if (refgeod != null && refgeod.Length > 1) args.IpsAdd(nameof(refgeod), refgeod); }); var res = await cli.ExecuteBufferedAsync(token.LinkTimeout(timeout)); var dtoRefOut = double.Parse(res.StandardOutput); return ExeResult.Create(dtoRefOut, cli.Arguments, res.StartTime, res.ExitTime, res.ExitCode); } } }