using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using XdCxRhDW.Dto;
namespace XdCxRhDW.Api
{
public class ErrorEllipseX1Option
{
///
/// 第一时刻星历
///
public double[] MsEph { get; set; }
///
///第二时刻星历
///
public double[] NsEph1 { get; set; }
///
/// 第三时刻星历
///
public double[] NsEph2 { get; set; }
///
/// 定位点
///
public double[] SelectPoint { get; set; }
///
/// 频差误差(Hz)
///
public double DfoErr { get; set; }
///
/// 星历位置误差
///
public double EphPosErr { get; set; }
///
///星历速度误差
///
public double EphVelErr { get; set; }
///
/// 上行频点(Hz)
///
public double fu { get; set; }
///
/// 概率 默认0.5
///
public double Pe { get; set; } = 0.5;
}
public class ErrorEllipseX2Option
{
///
/// 主星星历
///
public double[] MsEph { get; set; }
///
/// 邻星星历
///
public double[] NsEph { get; set; }
///
/// 参考站位置
///
public double[] RefGeod { get; set; }
///
/// 定位点
///
public double[] SelectPoint { get; set; }
///
/// 时差误差(s)
///
public double DtoErr { get; set; }
///
/// 频差误差(Hz)
///
public double DfoErr { get; set; }
///
/// 星历位置误差
///
public double EphPosErr { get; set; }
///
///星历速度误差
///
public double EphVelErr { get; set; }
///
/// 上行频点1(Hz)
///
public double fu1 { get; set; }
///
/// 上行频点2(Hz)
///
public double fu2 { get; set; }
///
/// 概率 默认0.5
///
public double Pe { get; set; } = 0.5;
}
public class ErrorEllipseX3Option
{
///
/// 主星星历
///
public double[] MsEph { get; set; }
///
/// 邻星星历
///
public double[] NsEph1 { get; set; }
///
/// 邻星星历
///
public double[] NsEph2 { get; set; }
///
/// 参考站位置
///
public double[] RefGeod { get; set; }
///
/// 定位点
///
public double[] SelectPoint { get; set; }
///
/// 时差误差(s)
///
public double DtoErr { get; set; }
///
/// 频差误差(Hz)
///
public double DfoErr { get; set; }
///
/// 星历位置误差
///
public double EphPosErr { get; set; }
///
///星历速度误差
///
public double EphVelErr { get; set; }
///
/// 上行频点1(Hz)
///
public double fu1 { get; set; }
///
/// 上行频点2(Hz)
///
public double fu2 { get; set; }
///
/// 概率 默认0.5
///
public double Pe { get; set; } = 0.5;
}
public class ErrorEllipse2X1DOption
{
///
/// 主星星历
///
public double[] MsEph { get; set; }
///
/// 邻星星历
///
public double[] NsEph { get; set; }
///
/// 超短波位置
///
public double[] CDBAnt { get; set; }
///
/// 参考站位置
///
public double[] RefGeod { get; set; }
///
/// 定位点
///
public double[] SelectPoint { get; set; }
///
/// 时差误差(s)
///
public double DtoErr { get; set; }
///
/// 星历误差
///
public double EphErr { get; set; }
///
/// 概率 默认0.5
///
public double Pe { get; set; } = 0.5;
}
public static class LeoErrorEllipseHelper
{
private const string errorEllipseDll = @"AddIns\低轨\DLL_LHDW_0622.dll";
///
/// 低轨双星误差椭圆
///
/// 主星位置 长度6
/// 邻星位置 长度6
/// 参考位置 长度3
/// 定位点长度3
/// 时差误差(s)
/// 频差误差(Hz)
///
///
///
/// 0.5
///
///
[DllImport(errorEllipseDll, EntryPoint = "Error_Ellipse_DTFO", CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr Error_Ellipse_DTFO(double[] main_eph, double[] neigh_eph, double[] ref_pos, double[] Select_Point, double dto_err, double dfo_err,
double eph_pos_err, double eph_vel_err, double fu1, double fu2, double Pe, ref int LOP_Len);
///
/// 两星一地误差椭圆
///
/// 主星位置 长度6
/// 邻星位置 长度6
/// 超短波 长度3
/// 参考站 长度3
/// 定位点 长度3
/// 时差误差(s)
///
/// 0.5
///
///
[DllImport(errorEllipseDll, EntryPoint = "Error_Ellipse_2X1D", CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr Error_Ellipse_2X1D(double[] main_eph, double[] neigh_eph, double[] cdbAnt, double[] refStation, double[] Select_Point, double dto_err,
double eph_err, double Pe, ref int LOP_Len);
///
/// 单星误差椭圆
///
///
///
///
///
///
///
///
///
///
///
///
[DllImport(errorEllipseDll, EntryPoint = "Error_Ellipse_2DFO", CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr Error_Ellipse_2DFO(double[] main_eph, double[] neigh_eph1, double[] neigh_eph2, double[] Select_Point, double dfo_err, double eph_pos_err, double eph_vel_err, double fu, double Pe,
ref int LOP_Len);
[DllImport(errorEllipseDll, CallingConvention = CallingConvention.Cdecl)]
public static extern void freeBuff(IntPtr buf);
public static ErrEllipseResDto ErrorEllipseLeoX2(ErrorEllipseX2Option opt, bool outputErrPoint)
{
int LOP_Len = 0;
IntPtr LOP_ValuePtr = Error_Ellipse_DTFO(
opt.MsEph,
opt.NsEph,
opt.RefGeod,
opt.SelectPoint,
opt.DtoErr,
opt.DfoErr,
opt.EphPosErr,
opt.EphVelErr,
opt.fu1, opt.fu2, opt.Pe, ref LOP_Len);
return ParseResult(LOP_ValuePtr, LOP_Len, outputErrPoint);
}
public static ErrEllipseResDto ErrorEllipseLeoX3(ErrorEllipseX3Option opt, bool outputErrPoint)
{
#warning 未提供低轨三星误差椭圆算法
int LOP_Len = 0;
IntPtr LOP_ValuePtr = Error_Ellipse_DTFO(
opt.MsEph,
opt.NsEph1,
opt.RefGeod,
opt.SelectPoint,
opt.DtoErr,
opt.DfoErr,
opt.EphPosErr,
opt.EphVelErr,
opt.fu1, opt.fu2, opt.Pe, ref LOP_Len);
return ParseResult(LOP_ValuePtr, LOP_Len, outputErrPoint);
}
public static ErrEllipseResDto ErrorEllipse2X1D(ErrorEllipse2X1DOption opt, bool outputErrPoint)
{
int LOP_Len = 0;
IntPtr LOP_ValuePtr = Error_Ellipse_2X1D(
opt.MsEph,
opt.NsEph,
opt.CDBAnt,
opt.RefGeod,
opt.SelectPoint,
opt.DtoErr,
opt.EphErr,
opt.Pe, ref LOP_Len);
return ParseResult(LOP_ValuePtr, LOP_Len, outputErrPoint);
}
public static ErrEllipseResDto ErrorEllipseLeoX1(ErrorEllipseX1Option opt, bool outputErrPoint)
{
int LOP_Len = 0;
IntPtr LOP_ValuePtr = Error_Ellipse_2DFO(
opt.MsEph,
opt.NsEph1,
opt.NsEph2,
opt.SelectPoint,
opt.DfoErr,
opt.EphPosErr,
opt.EphVelErr,
opt.fu, opt.Pe, ref LOP_Len);
return ParseResult(LOP_ValuePtr, LOP_Len,outputErrPoint);
}
private static ErrEllipseResDto ParseResult(IntPtr LOP_ValuePtr, int LOP_Len, bool outputErrPoint)
{
double[] LOP_Value = new double[LOP_Len];
if (LOP_Len > 0)
{
Marshal.Copy(LOP_ValuePtr, LOP_Value, 0, LOP_Value.Length);
}
#warning 低轨多星误差椭圆是否包含长轴、短轴、倾角
ErrEllipseResDto res = new ErrEllipseResDto();
res.LongRadius = LOP_Value[LOP_Value.Length - 3];
res.ShortRadius = LOP_Value[LOP_Value.Length - 2];
res.DipAngle = LOP_Value[LOP_Value.Length - 1];
if (outputErrPoint)
{
int count = LOP_Value.Length - 3;
for (int i = 0; i < count; i += 2)//13 ---01 23 45 67 89
{
res.GeoPoints.Add(new GeoPoint()
{
Lon = LOP_Value[i],
Lat = LOP_Value[i + 1],
});
}
}
return res;
}
}
}