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.Data.Entity.Core.Common.EntitySql;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using XdCxRhDW.App.DTO;
namespace XzXdDw.App.Api.星地GDOP误差椭圆
{
public static class GdopHelper
{
private const string GDOPDll = @"Api\星地GDOP误差椭圆\GDOP\GDOP_Draw.dll";
static readonly DateTime dtZero = new DateTime(1970, 1, 1, 8, 0, 0, 0);
///
[DllImport(GDOPDll, CallingConvention = CallingConvention.Cdecl)]
public static extern int GdopLeoTowSatDRef(string mainLines, string adajLines, Int64 captime, double[] refPos
, double fuHz1, double fuHz2, double dtousErr, double dfoHzErr, double ephLocErr, double ephVLocErr
, double[] level, int levlen, int[] resCount, out IntPtr res, double[] satllh);
[DllImport(GDOPDll, CallingConvention = CallingConvention.Cdecl)]
public static extern int GdopSingleSatD(string mainLines, Int64 captime1, Int64 captime2, Int64 captime3
, double fuHz, double dfoHzErr, double ephLocErr, double ephVLocErr
, double[] level, int levlen, int[] resCount,out IntPtr res, double[] satllh);
[DllImport(GDOPDll, CallingConvention = CallingConvention.Cdecl)]
public static extern void FreeGDOPBuf(IntPtr val);
///
/// 低轨双星GDOP
///
/// 主星星历
/// 邻星星历
/// 采集时间
/// 参考站位置 长度3
/// 目标上行频点 Hz
/// 参考上行频点 Hz
/// 时差误差
/// 频差误差
/// 星历位置误差
/// 星历速度误差
public static (List, List) GdopLeoTowSatDRef(string mainLines, string adajLines, DateTime captime, double[] refPos
, double fuHz1, double fuHz2, double dtousErr, double dfoHzErr, double ephLocErr, double ephVLocErr)
{
int satCount = 2;
//该值和points 一一对应
double[] level = GdopParam.误差配置.小误差距离m;
double[] satllh = new double[satCount*3];
var timeSpan = (long)(captime - dtZero).TotalSeconds;
IntPtr res = IntPtr.Zero;
int[] resCount = new int[level.Length];
GdopLeoTowSatDRef(mainLines, adajLines, timeSpan, refPos
, fuHz1, fuHz2, dtousErr, dfoHzErr, ephLocErr, ephVLocErr, level, level.Length, resCount, out res, satllh);
IntPtr tmp = res;
//用于绘制的数据
List points = new List();
for (int idx = 0; idx < level.Length; ++idx)
{
double[] levelval = new double[resCount[idx]];
Marshal.Copy(tmp, levelval, 0, resCount[idx]);
tmp += (resCount[idx] * sizeof(double));
points.Add(levelval);
}
FreeGDOPBuf(res);
List satInfos = ParseResult(satCount, satllh, mainLines, adajLines);
List errs = new List();
for (int i = 0; i < points.Count; i++)
{
if (!points[i].Any()) continue;
ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
errDistanceMap.ErrDistance = level[i];
errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
errs.Add(errDistanceMap);
}
return (satInfos, errs);
}
///
/// 单星GDOP
///
/// 主星星历
/// 第一采集时刻
/// 第二采集时刻
/// 第三采集时刻
/// 频差误差
/// 星历位置误差
/// 星历速度误差
/// 目标上行频点
///
public static (List, List) GdopSingleSat(string mainLines, DateTime captime1, DateTime captime2, DateTime captime3, double dfoHzErr, double ephLocErr, double ephVLocErr, double fuHz)
{
int satCount = 1;
//该值和points 一一对应
double[] level = GdopParam.误差配置.小误差距离m;
double[] satllh = new double[satCount * 3];
var timeSpan1 = (long)(captime1 - dtZero).TotalSeconds;
var timeSpan2 = (long)(captime2 - dtZero).TotalSeconds;
var timeSpan3 = (long)(captime3 - dtZero).TotalSeconds;
IntPtr res = IntPtr.Zero;
int[] resCount = new int[level.Length];
GdopSingleSatD(mainLines, timeSpan1, timeSpan2, timeSpan3,fuHz, dfoHzErr,ephLocErr,ephVLocErr,level,level.Length,resCount,out res,satllh);
IntPtr tmp = res;
//用于绘制的数据
List points = new List();
for (int idx = 0; idx < level.Length; ++idx)
{
double[] levelval = new double[resCount[idx]];
Marshal.Copy(tmp, levelval, 0, resCount[idx]);
tmp += (resCount[idx] * sizeof(double));
points.Add(levelval);
}
FreeGDOPBuf(res);
List satInfos = ParseResult(satCount, satllh, mainLines);
List errs = new List();
for (int i = 0; i < points.Count; i++)
{
if (!points[i].Any()) continue;
ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
errDistanceMap.ErrDistance = level[i];
errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
errs.Add(errDistanceMap);
}
return (satInfos, errs);
}
private static List ParseResult(double[] ponits)
{
List mapDots = new List();
int count = 2;
for (int i = 0; i < ponits.Length / count; i++)
{
MapDot mapDot = new MapDot();
mapDot.Lat = ponits[count * i + 1];
mapDot.Lon = ponits[count * i];
mapDots.Add(mapDot);
}
return mapDots;
}
private static List ParseResult(int satCount, double[] satllh, params string[] ephLine)
{
List list = new List();
int len = 3;
for (int i = 0; i < satCount; i++)
{
SatInfo satInfo = new SatInfo();
var ephstrs = ephLine[i].Split(new string[] { " ", "U" }, StringSplitOptions.RemoveEmptyEntries);
if (ephstrs.Length == 16)
{
satInfo.SatCode = Convert.ToInt32(ephstrs[1]);
}
satInfo.SatLon = Convert.ToDouble(satllh[len * i]);
satInfo.SatLat = Convert.ToDouble(satllh[len * i + 1]);
list.Add(satInfo);
}
return list;
}
}
}