123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- using DevExpress.Drawing.Internal.Fonts.Interop;
- using DevExpress.XtraBars.Docking2010.Views.Widget;
- using XdCxRhDW.App.Model;
- using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
- namespace XdCxRhDW.App.Api
- {
- /// <summary>
- ///TODO 定位算法接口.在这里调用罗博士的算法库
- /// </summary>
- public static class PosApi
- {
- #region cpp dll Interop
- //一星一地测向定位
- private const string XDCX = @"AddIns\DLL_DTO_DOA_DW.dll";
- //两星一地定位
- private const string X2D1 = @"AddIns\DLL_SC_2X1D_DW.dll";
- [DllImport(XDCX, EntryPoint = "XD_CX_DW", CallingConvention = CallingConvention.Cdecl)]//一星一地
- public extern static void X1D1_POS2023_Core(double[] mainSat, double[] satStation, double[] cdbStation, double[] cxStation, double[] refStation, double[] zone, double theta, double tarDto, double refDto, double[] res);
- [DllImport(X2D1, EntryPoint = "SC_2X1D_DW", CallingConvention = CallingConvention.Cdecl)]//两星一地
- public 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 XdtsDll = @"Api\时差线\Positioning.dll";
- /// <summary>
- ///
- /// </summary>
- /// <param name="main_sat_pos"></param>
- /// <param name="neigh_sat_pos"></param>
- /// <param name="rec1_pos"></param>
- /// <param name="rec2_pos"></param>
- /// <param name="ref_pos"></param>
- /// <param name="Zone"></param>
- /// <param name="target_dto">目标时差 (s)</param>
- /// <param name="ref_dto">参考时差 (s)</param>
- /// <param name="LOP_Value"></param>
- /// <param name="LOP_Len"></param>
- [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
- /// <summary>
- /// 一星一地,返返回经度纬度高度及镜像点,数组长度为6
- /// </summary>
- /// <param name="cgRes"></param>
- /// <param name="cxRes"></param>
- /// <returns></returns>
- public static double[] X1D1_POS(CgRes cgRes, List<TxInfo> listTx, CxRes cxRes)
- {
- var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
- var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
- var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
- var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
- double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
- double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
- double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
- double[] cxStation = new double[3] { cxTx.Lon, cxTx.Lat, 0 };
- double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
- double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
- double theta = cxRes.Fx;//单位°
- double[] res = new double[6];
- X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb.Value / 1e6, cgRes.YbMain.Value / 1e6, res);
- return res.Select(p => Math.Round(p, 4)).ToArray();
- }
- /// <summary>
- /// 两星一地,返回经度纬度高度及镜像点,数组长度为6
- /// </summary>
- /// <param name="cgRes"></param>
- /// <returns></returns>
- public static double[] X2D1_POS(CgRes cgRes, List<TxInfo> listTx)
- {
- var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
- var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
- var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
- 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[] cxStation = new double[3] { cxTx.Lon, cxTx.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.Value / 1e6, cgRes.DtoCdb.Value / 1e6, cgRes.YbMain.Value / 1e6, cgRes.YbAdja.Value / 1e6, res);
- return res;
- }
- /// <summary>
- /// 融合定位,返回经度纬度高度及镜像点,数组长度为6
- /// </summary>
- /// <returns></returns>
- public static double[] RH_POS(CgRes cgRes, List<TxInfo> listTx, CxRes cxRes)
- {
- var res1 = X1D1_POS(cgRes, listTx, cxRes);
- var res2 = X2D1_POS(cgRes, listTx);
- double[] res = new double[] { 999, 999, 0, 999, 999, 0 };
- if (IsGeoPoint(res1) && IsGeoPoint(res2))
- {
- res = new double[6] {
- (res1[0] + res2[0]) / 2 + 0.003,
- (res1[1] + res2[1]) / 2 - 0.002,
- (res1[2] + res2[2]) / 2,
- (res1[3] + res2[3]) / 2 + 0.003,
- (res1[4] + res2[4]) / 2 - 0.002,
- (res1[5] + res2[5]) / 2,
- };
- }
- else if (IsGeoPoint(res1))
- {
- res = new double[6]
- {
- res1[0] + 0.003,
- res1[1] - 0.002,
- res1[2],
- res1[3] + 0.003,
- res1[4] - 0.002,
- res1[5],
- };
- }
- else if (IsGeoPoint(res2))
- {
- res = new double[6]
- {
- res2[0] + 0.003,
- res2[1] - 0.002,
- res2[2],
- res2[3] + 0.003,
- res2[4] - 0.002,
- res2[5],
- };
- }
- return res;
- }
- public static bool IsGeoPoint(double[] res)
- {
- return res[0] >= -180 && res[0] <= 180 && res[1] >= -90 && res[1] <= 90;
- }
- }
- }
|