using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
namespace XdCxRhDW.App.Api
{
public class DrawDfoLineHelper
{
private const string exeName = "locow.exe";
private static double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
///
/// 高轨双星频差线
///
///
///
///
public static IEnumerable<(double lon, double lat)> DfoLineTwoStart(DfoLineTwoStartOption opt)
{
List list = new List();
string exePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "API\\频差线");
if (string.IsNullOrWhiteSpace(exePath))
throw new Exception($"请先调用SetExePath指定{exeName}进程所在路径,支持相对路径");
if (!Directory.Exists(exePath))
throw new Exception($"路径[{exePath}]不存在");
var exeFile = Path.Combine(exePath, exeName);
if (!File.Exists(exeFile))
throw new Exception($"文件[{exeFile}]不存在");
List arguments = new List();
arguments.Add("dfoline");
arguments.Add($"{opt.TargetDfo}");
arguments.Add($"{opt.Freq * 1e6}");
arguments.Add($"{opt.Turn1 * 1e6}");
arguments.Add($"{opt.Turn2 * 1e6}");
arguments.Add($"--rec1 {opt.MsAnt[0]} {opt.MsAnt[1]} 0");
arguments.Add($"--rec1 {opt.NsAnt[0]} {opt.NsAnt[1]} 0");
arguments.Add($"--eph1 {opt.MsEph[0]} {opt.MsEph[1]} {opt.MsEph[2]} {opt.MsEph[3]} {opt.MsEph[4]} {opt.MsEph[5]}");
arguments.Add($"--eph1 {opt.NsEph[0]} {opt.NsEph[1]} {opt.NsEph[2]} {opt.NsEph[3]} {opt.NsEph[4]} {opt.NsEph[5]}");
arguments.Add($"--refdf {opt.RefDfo}");
arguments.Add($"--reffreq {opt.RefFreq * 1e6}");
arguments.Add($"--reflla {opt.RefGeod[0]} {opt.RefGeod[0]} 0");
Process p = new Process();
p.StartInfo.WorkingDirectory = exePath;
p.StartInfo.FileName = exeFile;
p.StartInfo.Arguments = string.Join(" ", arguments);
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
var succeed = p.WaitForExit(10000);
if (!succeed)
{
throw new Exception($"进程[{exeName}]超时未完成!");
}
string result = p.StandardOutput.ReadToEnd();
if (string.IsNullOrWhiteSpace(result))
{
throw new Exception("计算频差线出现未知错误!");
}
var array = result.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (array[0] == "1")
{
throw new Exception(array[1]);
}
//if (File.Exists(file))
//{
// var dtostr = File.ReadAllText(file);
// list = Newtonsoft.Json.JsonConvert.DeserializeObject>(dtostr);
//}
var Lines = list.Select(s => (s.Lon, s.Lat));
return Lines;
}
}
}