123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374 |
- using DevExpress.Charts.Native;
- using DevExpress.Internal.WinApi.Windows.UI.Notifications;
- using DevExpress.XtraPrinting;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XdCxRhDW.App.DTO;
- using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
- namespace XzXdDw.App.Api.低轨GDOP误差椭圆
- {
- /// <summary>
- /// 误差椭圆计算帮助类.该类调用了GdopCore.exe进程
- /// 每种误差椭圆算法提供了两个接口,这两种接口是完全等价的,一种传入双行根,一种直接传入卫星状态x、y、z等
- /// </summary>
- public static class ErrEllipseHelper
- {
- private static string exePath = "Api\\低轨GDOP误差椭圆\\GDOP";
- private const string exeName = "GdopCore.exe";
- /// <summary>
- /// 三星双时差误差椭圆带参
- /// </summary>
- /// <param name="mainSatTle">主星双行根数</param>
- /// <param name="adja1SatTle">邻1星双行根数</param>
- /// <param name="adja2SatTle">邻2星双行根数</param>
- /// <param name="time">采集时刻</param>
- /// <param name="posLonLat">定位点经纬度,数组长度=2</param>
- /// <param name="refLonLat">参考站经纬度,数组长度=2</param>
- /// <param name="R1">输出参数:椭圆长轴(km)</param>
- /// <param name="R2">输出参数:椭圆短轴(km)</param>
- /// <param name="dtousErr">时差误差(单位us)</param>
- /// <param name="satLocErr">星历位置误差(单位米)</param>
- /// <param name="errProb">误差概率百分比(0-100,默认50)</param>
- /// <returns></returns>
- public static (List<SatInfo>, List<ErrDistanceMapLines>) ErrEllipse3Sat2DtoRef(string mainSatTle, string adja1SatTle, string adja2SatTle, DateTime time, double[] posLonLat, double[] refLonLat, out double R1, out double R2, double dtousErr = 1, double satLocErr = 10000, double errProb = 50)
- {
- 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}]不存在");
- Process p = new Process();
- p.StartInfo.WorkingDirectory = exePath;
- p.StartInfo.FileName = exeFile;
- p.StartInfo.Arguments = $"50 \"{mainSatTle}\" \"{adja1SatTle}\" \"{adja2SatTle}\" \"{time:yyyy-MM-dd HH:mm:ss.000000}\" {string.Join(" ", posLonLat)} {string.Join(" ", refLonLat)} {dtousErr} {satLocErr} {errProb}";
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.UseShellExecute = false;
- StringBuilder sb = new StringBuilder();
- p.OutputDataReceived += (sender, e) => sb.Append(e.Data);
- p.Start();
- p.BeginOutputReadLine();
- p.WaitForExit();//WaitForExit加了超时时间的话进程退出后不能保证异步流已经读取完成,这是.NET框架的BUG
- return ParseResult(3, sb.ToString(), out R1, out R2);
- }
- /// <summary>
- /// 三星双时差误差椭圆带参
- /// </summary>
- /// <param name="mainSatEph">主星xyz星历,数组长度=3</param>
- /// <param name="adja1SatEph">邻1星xyz星历,数组长度=3</param>
- /// <param name="adja2SatEph">邻2星xyz星历,数组长度=3</param>
- /// <param name="posLonLat">定位点经纬度,数组长度=2</param>
- /// <param name="refLonLat">参考站经纬度,数组长度=2</param>
- /// <param name="R1">输出参数:椭圆长轴(km)</param>
- /// <param name="R2">输出参数:椭圆短轴(km)</param>
- /// <param name="dtousErr">时差误差(单位us)</param>
- /// <param name="satLocErr">星历位置误差(单位米)</param>
- /// <param name="errProb">误差概率百分比(0-100,默认50)</param>
- /// <returns></returns>
- public static (List<SatInfo>, List<ErrDistanceMapLines>) ErrEllipse3Sat2DtoRef(double[] mainSatEph, double[] adja1SatEph, double[] adja2SatEph, double[] posLonLat, double[] refLonLat, out double R1, out double R2, double dtousErr = 1, double satLocErr = 10000, double errProb = 50)
- {
- 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}]不存在");
- Process p = new Process();
- p.StartInfo.WorkingDirectory = exePath;
- p.StartInfo.FileName = exeFile;
- p.StartInfo.Arguments = $"51 {string.Join(" ", mainSatEph)} {string.Join(" ", adja1SatEph)} {string.Join(" ", adja2SatEph)} {string.Join(" ", posLonLat)} {string.Join(" ", refLonLat)} {dtousErr} {satLocErr} {errProb}";
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.UseShellExecute = false;
- StringBuilder sb = new StringBuilder();
- p.OutputDataReceived += (sender, e) => sb.Append(e.Data);
- p.Start();
- p.BeginOutputReadLine();
- p.WaitForExit();//WaitForExit加了超时时间的话进程退出后不能保证异步流已经读取完成,这是.NET框架的BUG
- return ParseResult(3, sb.ToString(), out R1, out R2);
- }
- /// <summary>
- /// 三星双时差误差椭圆无参
- /// </summary>
- /// <param name="mainSatTle">主星双行根数</param>
- /// <param name="adja1SatTle">邻1星双行根数</param>
- /// <param name="adja2SatTle">邻2星双行根数</param>
- /// <param name="time">采集时刻</param>
- /// <param name="posLonLat">定位点经纬度,数组长度=2</param>
- /// <param name="recLonLat">接收站经纬度,数组长度=2</param>
- /// <param name="R1">输出参数:椭圆长轴(km)</param>
- /// <param name="R2">输出参数:椭圆短轴(km)</param>
- /// <param name="dtousErr">时差误差(单位us)</param>
- /// <param name="satLocErr">星历位置误差(单位米)</param>
- /// <param name="errProb">误差概率百分比(0-100,默认50)</param>
- /// <returns></returns>
- public static (List<SatInfo>, List<ErrDistanceMapLines>) ErrEllipse3Sat2Dto(string mainSatTle, string adja1SatTle, string adja2SatTle, DateTime time, double[] posLonLat, double[] recLonLat, out double R1, out double R2, double dtousErr = 1, double satLocErr = 10000, double errProb = 50)
- {
- 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}]不存在");
- Process p = new Process();
- p.StartInfo.WorkingDirectory = exePath;
- p.StartInfo.FileName = exeFile;
- p.StartInfo.Arguments = $"52 \"{mainSatTle}\" \"{adja1SatTle}\" \"{adja2SatTle}\" \"{time:yyyy-MM-dd HH:mm:ss.000000}\" {string.Join(" ", posLonLat)} {string.Join(" ", recLonLat)} {dtousErr} {satLocErr} {errProb}";
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.UseShellExecute = false;
- StringBuilder sb = new StringBuilder();
- p.OutputDataReceived += (sender, e) => sb.Append(e.Data);
- p.Start();
- p.BeginOutputReadLine();
- p.WaitForExit();//WaitForExit加了超时时间的话进程退出后不能保证异步流已经读取完成,这是.NET框架的BUG
- return ParseResult(3, sb.ToString(), out R1, out R2);
- }
- /// <summary>
- /// 三星双时差误差椭圆无参
- /// </summary>
- /// <param name="mainSatEph">主星xyz星历,数组长度=3</param>
- /// <param name="adja1SatEph">邻1星xyz星历,数组长度=3</param>
- /// <param name="adja2SatEph">邻2星xyz星历,数组长度=3</param>
- /// <param name="posLonLat">定位点经纬度,数组长度=2</param>
- /// <param name="recLonLat">接收站经纬度,数组长度=2</param>
- /// <param name="R1">输出参数:椭圆长轴(km)</param>
- /// <param name="R2">输出参数:椭圆短轴(km)</param>
- /// <param name="dtousErr">时差误差(单位us)</param>
- /// <param name="satLocErr">星历位置误差(单位米)</param>
- /// <param name="errProb">误差概率百分比(0-100,默认50)</param>
- /// <returns></returns>
- public static (List<SatInfo>, List<ErrDistanceMapLines>) ErrEllipse3Sat2Dto(double[] mainSatEph, double[] adja1SatEph, double[] adja2SatEph, double[] posLonLat, double[] recLonLat, out double R1, out double R2, double dtousErr = 1, double satLocErr = 10000, double errProb = 50)
- {
- 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}]不存在");
- Process p = new Process();
- p.StartInfo.WorkingDirectory = exePath;
- p.StartInfo.FileName = exeFile;
- p.StartInfo.Arguments = $"51 {string.Join(" ", mainSatEph)} {string.Join(" ", adja1SatEph)} {string.Join(" ", adja2SatEph)} {string.Join(" ", posLonLat)} {string.Join(" ", recLonLat)} {dtousErr} {satLocErr} {errProb}";
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.UseShellExecute = false;
- StringBuilder sb = new StringBuilder();
- p.OutputDataReceived += (sender, e) => sb.Append(e.Data);
- p.Start();
- p.BeginOutputReadLine();
- p.WaitForExit();//WaitForExit加了超时时间的话进程退出后不能保证异步流已经读取完成,这是.NET框架的BUG
- return ParseResult(3, sb.ToString(), out R1, out R2);
- }
- /// <summary>
- /// 双星时频差误差椭圆带参
- /// </summary>
- /// <param name="mainTle">主星双行根数</param>
- /// <param name="adjaTle">邻星双行根数</param>
- /// <param name="time">采集时刻</param>
- /// <param name="tarFreqUpMHz">目标上行频点MHz</param>
- /// <param name="refFreqUpMHz">参考上行频点MHz</param>
- /// <param name="mainSatTransMHz">主星转发器本振MHz</param>
- /// <param name="adjaSatTransMHz">邻星转发器本振MHz</param>
- /// <param name="posLonLat">定位点经纬度,数组长度=2</param>
- /// <param name="refLonLat">参考站经纬度,数组长度=2</param>
- /// <param name="R1">输出参数:椭圆长轴(km)</param>
- /// <param name="R2">输出参数:椭圆短轴(km)</param>
- /// <returns></returns>
- public static (List<SatInfo>, List<ErrDistanceMapLines>) ErrEllipse2SatDtoDfoRef(string mainTle, string adjaTle, DateTime time, double tarFreqUpMHz, double refFreqUpMHz, double mainSatTransMHz, double adjaSatTransMHz, double[] posLonLat, double[] refLonLat, out double R1, out double R2)
- {
- 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}]不存在");
- Process p = new Process();
- p.StartInfo.WorkingDirectory = exePath;
- p.StartInfo.FileName = exeFile;
- p.StartInfo.Arguments = $"54 \"{mainTle}\" \"{adjaTle}\" \"{time:yyyy-MM-dd HH:mm:ss.000000}\" {tarFreqUpMHz} {refFreqUpMHz} {mainSatTransMHz} {adjaSatTransMHz} {string.Join(" ", posLonLat)} {string.Join(" ", refLonLat)} ";
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.UseShellExecute = false;
- StringBuilder sb = new StringBuilder();
- p.OutputDataReceived += (sender, e) => sb.Append(e.Data);
- p.Start();
- p.BeginOutputReadLine();
- p.WaitForExit();//WaitForExit加了超时时间的话进程退出后不能保证异步流已经读取完成,这是.NET框架的BUG
- return ParseResult(2, sb.ToString(), out R1, out R2);
- }
- /// <summary>
- /// 双星时频差误差椭圆带参
- /// </summary>
- /// <param name="mainSatEph">主星星历xyz vx vy vz,数组长度=6</param>
- /// <param name="adjaSatEph">邻星星历xyz vx vy vz,数组长度=6</param>
- /// <param name="tarFreqUpMHz">目标上行频点MHz</param>
- /// <param name="refFreqUpMHz">参考上行频点MHz</param>
- /// <param name="mainSatTransMHz">主星转发器本振MHz</param>
- /// <param name="adjaSatTransMHz">邻星转发器本振MHz</param>
- /// <param name="posLonLat">定位点经纬度,数组长度=2</param>
- /// <param name="refLonLat">参考站经纬度,数组长度=2</param>
- /// <param name="R1">输出参数:椭圆长轴(km)</param>
- /// <param name="R2">输出参数:椭圆短轴(km)</param>
- /// <returns></returns>
- public static (List<SatInfo>, List<ErrDistanceMapLines>) ErrEllipse2SatDtoDfoRef(double[] mainSatEph, double[] adjaSatEph, double tarFreqUpMHz, double refFreqUpMHz, double mainSatTransMHz, double adjaSatTransMHz, double[] posLonLat, double[] refLonLat, out double R1, out double R2)
- {
- 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}]不存在");
- Process p = new Process();
- p.StartInfo.WorkingDirectory = exePath;
- p.StartInfo.FileName = exeFile;
- p.StartInfo.Arguments = $"55 {string.Join(" ", mainSatEph)} {string.Join(" ", adjaSatEph)} {tarFreqUpMHz} {refFreqUpMHz} {mainSatTransMHz} {adjaSatTransMHz} {string.Join(" ", posLonLat)} {string.Join(" ", refLonLat)}";
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.UseShellExecute = false;
- StringBuilder sb = new StringBuilder();
- p.OutputDataReceived += (sender, e) => sb.Append(e.Data);
- p.Start();
- p.BeginOutputReadLine();
- p.WaitForExit();//WaitForExit加了超时时间的话进程退出后不能保证异步流已经读取完成,这是.NET框架的BUG
- return ParseResult(2, sb.ToString(), out R1, out R2);
- }
- /// <summary>
- /// 双星时频差误差椭圆无参
- /// </summary>
- /// <param name="mainTle">主星双行根数</param>
- /// <param name="adjaTle">邻星双行根数</param>
- /// <param name="time">采集时刻</param>
- /// <param name="tarFreqUpMHz">目标上行频点MHz</param>
- /// <param name="mainSatTransMHz">主星转发器本振MHz</param>
- /// <param name="adjaSatTransMHz">邻星转发器本振MHz</param>
- /// <param name="posLonLat">定位点经纬度,数组长度=2</param>
- /// <param name="recLonLat">接收站经纬度,数组长度=2</param>
- /// <param name="R1">输出参数:椭圆长轴(km)</param>
- /// <param name="R2">输出参数:椭圆短轴(km)</param>
- /// <returns></returns>
- public static (List<SatInfo>, List<ErrDistanceMapLines>) ErrEllipse2SatDtoDfo(string mainTle, string adjaTle, DateTime time, double tarFreqUpMHz, double mainSatTransMHz, double adjaSatTransMHz, double[] posLonLat, double[] recLonLat, out double R1, out double R2)
- {
- 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}]不存在");
- Process p = new Process();
- p.StartInfo.WorkingDirectory = exePath;
- p.StartInfo.FileName = exeFile;
- p.StartInfo.Arguments = $"56 \"{mainTle}\" \"{adjaTle}\" \"{time:yyyy-MM-dd HH:mm:ss.000000}\" {tarFreqUpMHz} {mainSatTransMHz} {adjaSatTransMHz} {string.Join(" ", posLonLat)} {string.Join(" ", recLonLat)}";
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.UseShellExecute = false;
- StringBuilder sb = new StringBuilder();
- p.OutputDataReceived += (sender, e) => sb.Append(e.Data);
- p.Start();
- p.BeginOutputReadLine();
- p.WaitForExit();//WaitForExit加了超时时间的话进程退出后不能保证异步流已经读取完成,这是.NET框架的BUG
- return ParseResult(2, sb.ToString(), out R1, out R2);
- }
- /// <summary>
- /// 双星时频差误差椭圆无参
- /// </summary>
- /// <param name="mainSatEph">主星星历xyz vx vy vz,数组长度=6</param>
- /// <param name="adjaSatEph">邻星星历xyz vx vy vz,数组长度=6</param>
- /// <param name="tarFreqUpMHz">目标上行频点MHz</param>
- /// <param name="mainSatTransMHz">主星转发器本振MHz</param>
- /// <param name="adjaSatTransMHz">邻星转发器本振MHz</param>
- /// <param name="posLonLat">定位点经纬度,数组长度=2</param>
- /// <param name="recLonLat">接收站经纬度,数组长度=2</param>
- /// <param name="R1">输出参数:椭圆长轴(km)</param>
- /// <param name="R2">输出参数:椭圆短轴(km)</param>
- /// <returns></returns>
- public static (List<SatInfo>, List<ErrDistanceMapLines>) ErrEllipse2SatDtoDfo(double[] mainSatEph, double[] adjaSatEph, double tarFreqUpMHz, double mainSatTransMHz, double adjaSatTransMHz, double[] posLonLat, double[] recLonLat, out double R1, out double R2)
- {
- 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}]不存在");
- Process p = new Process();
- p.StartInfo.WorkingDirectory = exePath;
- p.StartInfo.FileName = exeFile;
- p.StartInfo.Arguments = $"57 {string.Join(" ", mainSatEph)} {string.Join(" ", adjaSatEph)} {tarFreqUpMHz} {mainSatTransMHz} {adjaSatTransMHz} {string.Join(" ", posLonLat)} {string.Join(" ", recLonLat)}";
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.UseShellExecute = false;
- StringBuilder sb = new StringBuilder();
- p.OutputDataReceived += (sender, e) => sb.Append(e.Data);
- p.Start();
- p.BeginOutputReadLine();
- p.WaitForExit();//WaitForExit加了超时时间的话进程退出后不能保证异步流已经读取完成,这是.NET框架的BUG
- return ParseResult(2, sb.ToString(), out R1, out R2);
- }
- private static (List<SatInfo>, List<ErrDistanceMapLines>) ParseResult(int satCount, string txt, out double errR1, out double errR2)
- {
- if (string.IsNullOrWhiteSpace(txt))
- {
- throw new Exception("误差椭圆计算出现未知错误!");
- }
- if (txt.StartsWith("1 "))
- {
- throw new Exception(txt.Remove(0, 2));
- }
- var arr = txt.Split(' ');
- List<SatInfo> list = new List<SatInfo>();
- for (int i = 0; i < satCount; i++)
- {
- SatInfo satInfo = new SatInfo();
- var satCode = Convert.ToInt32(arr[3 * i + 1]);
- if (satCode > 0)
- satInfo.SatCode = satCode;
- satInfo.SatLon = Convert.ToDouble(arr[3 * i + 2]);
- satInfo.SatLat = Convert.ToDouble(arr[3 * i + 3]);
- list.Add(satInfo);
- }
- errR1 = Convert.ToDouble(arr[1 + satCount * 3]);//椭圆长轴
- errR2 = Convert.ToDouble(arr[2 + satCount * 3]);//椭圆短轴
- var jsonStr = arr[3 + satCount * 3];
- var res = JsonConvert.DeserializeObject<List<ErrDistanceMapLines>>(jsonStr);
- return (list, res);
- }
- }
- }
|