using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using DevExpress.XtraBars.Docking2010.Views.Widget; using Extensions; using XzXdDw.App.Model; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox; using static DevExpress.XtraPrinting.Native.ExportOptionsPropertiesNames; namespace XzXdDw.App.Api { public static class PosApi { #region cpp dll Interop //两星一地定位 private const string X2D1 = @"AddIns\DLL_SC_2X1D_DW.dll"; [DllImport(X2D1, EntryPoint = "SC_2X1D_DW", CallingConvention = CallingConvention.Cdecl)]//两星一地 private extern static void X2D1_POS_Core(double[] mainSat, double[] adjaSat, double[] cdbStation, double[] satStation1, double[] satStation2, double[] satStation3, double[] satStation4, double[] satStation5, double[] refStation, double[] zone, double tarSxDto, double tarXdDto, double samp_main_dto, double samp_neigh_dto, double[] res); private const string gzdw = @"Api\低轨时频差线及定位\DLL_XDXZ.dll"; /// /// 地轨双星dw /// /// /// /// /// /// /// /// /// /// /// /// [DllImport(gzdw, EntryPoint = "TwoStar_DTFO_DW", CallingConvention = CallingConvention.Cdecl)] public extern static void TwoStar_DTFO_DW(double[] main_sat, double[] neigh_sat, double[] Ref_Station_LLH , double[] Zone, double target_dto, double target_dfo, double ref_dto, double ref_dfo, double fu1, double fu2, double[] target_llh); /// /// 单星dw /// /// 第一时刻星历 长度6 /// 第二时刻星历 长度6 /// 第三时刻星历 长度6 /// /// 频差1(Hz) /// 频差2(Hz) /// 上行频点(Hz) /// [DllImport(gzdw, EntryPoint = "SingleStar_DFO_DW", CallingConvention = CallingConvention.Cdecl)]//两星一地 public extern static void SingleStar_DFO_DW(double[] main_sat, double[] neigh_sat1, double[] neigh_sat2 , double[] Zone, double target_dfo1, double target_dfo2, double fu, double[] target_llh); /// /// 底轨双星时差线 /// /// 主星星历 长度6 /// 邻星星历 长度6 /// 参考站位置 /// -85, 85, -180, 180 /// 目标时差(s) /// 参考时差(s) /// /// [DllImport(gzdw, EntryPoint = "TwoStar_SCX", CallingConvention = CallingConvention.Cdecl)]//两星一地 public extern static void TwoStar_SCX(double[] main_sat_pos, double[] neigh_sat_pos, double[] ref_pos, double[] Zone, double target_dto, double ref_dto, out IntPtr LOP_Value, ref int LOP_Len); /// /// 地轨双星频差线 /// /// /// /// /// /// 目标频差(Hz) /// 参考频差(Hz) /// 上行频点1(Hz) /// 上行频点2(Hz) /// /// [DllImport(gzdw, EntryPoint = "TwoStar_PCX", CallingConvention = CallingConvention.Cdecl)]//两星一地 public extern static void TwoStar_PCX(double[] main_sat, double[] neigh_sat, double[] ref_pos, double[] Zone, double target_dfo, double ref_dfo, double fu1, double fu2, out IntPtr LOP_Value, ref int LOP_Len); /// /// 单星频差线 /// /// /// /// /// /// /// /// [DllImport(gzdw, EntryPoint = "SingleStar_PCX", CallingConvention = CallingConvention.Cdecl)]//两星一地 public extern static void SingleStar_PCX(double[] main_sat, double[] neigh_sat , double[] Zone, double target_dfo, double fu, out IntPtr LOP_Value, ref int LOP_Len); private const string XdtsDll = @"Api\时差线\Positioning.dll"; /// /// /// /// /// /// /// /// /// /// 目标时差 (s) /// 参考时差 (s) /// /// [DllImport(XdtsDll, EntryPoint = "CurveByTwoTDOA", CallingConvention = CallingConvention.Cdecl)]//两星一地 public extern static void CurveByTwoTDOA(double[] main_sat_pos, double[] neigh_sat_pos, double[] rec1_pos, double[] rec2_pos, double[] ref_pos, double[] Zone, double target_dto, double ref_dto, out IntPtr LOP_Value, ref int LOP_Len); #endregion /// /// 两星一地,返回经度纬度高度及镜像点,数组长度为6 /// /// /// public static double[] X2D1_POS(CgRes cgRes, List listTx) { var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat); var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb); var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref); double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ }; double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ }; double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 }; double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 }; double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 }; double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域 double[] res = new double[6]; X2D1_POS_Core(mainSat, adjaSat, cdbStation, satStation, satStation, satStation, satStation, satStation, refStation, zone, cgRes.DtoSx / 1e6, cgRes.DtoCdb / 1e6, cgRes.YbMain / 1e6, cgRes.YbAdja / 1e6, res); return res; } public static double[] X2D1_POS(CgRes cgRes, TxInfo satTx, TxInfo cdbTx, TxInfo refTx) { double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ }; double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ }; double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 }; double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 }; double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 }; double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域 double[] res = new double[6]; X2D1_POS_Core(mainSat, adjaSat, cdbStation, satStation, satStation, satStation, satStation, satStation, refStation, zone, cgRes.DtoSx / 1e6, cgRes.DtoCdb / 1e6, cgRes.YbMain / 1e6, cgRes.YbAdja / 1e6, res); return res; } public static double[] X1_POS(CgRes cg, CgRes cg1, double upfreqHz) { double[] mainSat = new double[6] { cg.MainX, cg.MainY, cg.MainZ, cg.MainVX, cg.MainVY, cg.MainVZ }; double[] adjaSat1 = new double[6] { cg.AdjaX, cg.AdjaY, cg.AdjaZ, cg.AdjaVX, cg.AdjaVY, cg.AdjaVZ }; double[] adjaSat2 = new double[6] { cg1.AdjaX, cg1.AdjaY, cg1.AdjaZ, cg1.AdjaVX, cg1.AdjaVY, cg1.AdjaVZ }; double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域 double[] res = new double[6]; SingleStar_DFO_DW(mainSat, adjaSat1, adjaSat2, zone, cg.DfoSx, cg1.DfoSx, upfreqHz, res); IsRange(res); return res; } public static double[] X2_POS(CgRes cg, TxInfo refTx, double upfreqHz1, double upfreqHz2) { double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 }; double[] mainSat = new double[6] { cg.MainX, cg.MainY, cg.MainZ, cg.MainVX, cg.MainVY, cg.MainVZ }; double[] adjaSat1 = new double[6] { cg.AdjaX, cg.AdjaY, cg.AdjaZ, cg.AdjaVX, cg.AdjaVY, cg.AdjaVZ }; double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域 double[] res = new double[6]; TwoStar_DTFO_DW(mainSat, adjaSat1, refStation, zone, cg.DtoSx / 1e6, cg.DfoSx, cg.DtoCdb / 1e6, cg.DfoCdb, upfreqHz1, upfreqHz2, res); IsRange(res); return res; } public static bool IsGeoPoint(double[] res) { return res[0] >= -180 && res[0] <= 180 && res[1] >= -90 && res[1] <= 90; } private static void IsRange(double[] PosRes) { var centerLon = ConfigurationManager.AppSettings["CenterLon"].To(144); var centerLat = ConfigurationManager.AppSettings["CenterLat"].To(13); var lonRange = ConfigurationManager.AppSettings["LonRange"].To(10); var LatRange = ConfigurationManager.AppSettings["LatRange"].To(10); var startLon = centerLon - lonRange / 2f; var endLon = centerLon + lonRange / 2f; var startLat = centerLat - LatRange / 2f; var endLat = centerLat + LatRange / 2f; double posLon = PosRes[0]; double posLat = PosRes[1]; double posHigth = PosRes[2]; if (posLon == 0 || posLon == 999) { return; } if (startLon > posLon || endLon < posLon || startLat > posLat || endLat < posLat) { PosRes[0] = PosRes[3]; PosRes[1] = PosRes[4]; PosRes[2] = PosRes[5]; PosRes[3] = posLon; PosRes[4] = posLat; PosRes[5] = posHigth; } } } }