PosApi.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using DevExpress.Drawing.Internal.Fonts.Interop;
  8. using DevExpress.XtraBars.Docking2010.Views.Widget;
  9. using XdCxRhDW.App.Model;
  10. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
  11. namespace XdCxRhDW.App.Api
  12. {
  13. /// <summary>
  14. ///TODO 定位算法接口.在这里调用罗博士的算法库
  15. /// </summary>
  16. public static class PosApi
  17. {
  18. #region cpp dll Interop
  19. //一星一地测向定位
  20. private const string XDCX = @"AddIns\DLL_DTO_DOA_DW.dll";
  21. //两星一地定位
  22. private const string X2D1 = @"AddIns\DLL_SC_2X1D_DW.dll";
  23. [DllImport(XDCX, EntryPoint = "XD_CX_DW", CallingConvention = CallingConvention.Cdecl)]//一星一地
  24. 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);
  25. [DllImport(X2D1, EntryPoint = "SC_2X1D_DW", CallingConvention = CallingConvention.Cdecl)]//两星一地
  26. public extern static void X2D1_POS_Core(double[] mainSat, double[] adjaSat, double[] cdbStation, double[] satStation1, double[] satStation2, double[] satStation3, double[] satStation4,
  27. double[] satStation5, double[] refStation, double[] zone, double tarSxDto, double tarXdDto, double samp_main_dto, double samp_neigh_dto, double[] res);
  28. private const string XdtsDll = @"Api\时差线\Positioning.dll";
  29. /// <summary>
  30. ///
  31. /// </summary>
  32. /// <param name="main_sat_pos"></param>
  33. /// <param name="neigh_sat_pos"></param>
  34. /// <param name="rec1_pos"></param>
  35. /// <param name="rec2_pos"></param>
  36. /// <param name="ref_pos"></param>
  37. /// <param name="Zone"></param>
  38. /// <param name="target_dto">目标时差 (s)</param>
  39. /// <param name="ref_dto">参考时差 (s)</param>
  40. /// <param name="LOP_Value"></param>
  41. /// <param name="LOP_Len"></param>
  42. [DllImport(XdtsDll, EntryPoint = "CurveByTwoTDOA", CallingConvention = CallingConvention.Cdecl)]//两星一地
  43. public extern static void CurveByTwoTDOA(double[] main_sat_pos, double[] neigh_sat_pos, double[] rec1_pos, double[] rec2_pos, double[] ref_pos, double[] Zone,
  44. double target_dto, double ref_dto, out IntPtr LOP_Value, ref int LOP_Len);
  45. #endregion
  46. /// <summary>
  47. /// 一星一地,返返回经度纬度高度及镜像点,数组长度为6
  48. /// </summary>
  49. /// <param name="cgRes"></param>
  50. /// <param name="cxRes"></param>
  51. /// <returns></returns>
  52. public static double[] X1D1_POS(CgRes cgRes, List<TxInfo> listTx, CxRes cxRes)
  53. {
  54. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  55. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  56. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  57. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  58. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  59. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  60. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  61. double[] cxStation = new double[3] { cxTx.Lon, cxTx.Lat, 0 };
  62. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  63. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  64. double theta = cxRes.Fx;//单位°
  65. double[] res = new double[6];
  66. X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb.Value / 1e6, cgRes.YbMain.Value / 1e6, res);
  67. return res.Select(p => Math.Round(p, 4)).ToArray();
  68. }
  69. /// <summary>
  70. /// 两星一地,返回经度纬度高度及镜像点,数组长度为6
  71. /// </summary>
  72. /// <param name="cgRes"></param>
  73. /// <returns></returns>
  74. public static double[] X2D1_POS(CgRes cgRes, List<TxInfo> listTx)
  75. {
  76. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  77. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  78. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  79. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  80. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  81. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  82. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  83. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  84. double[] cxStation = new double[3] { cxTx.Lon, cxTx.Lat, 0 };
  85. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  86. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  87. double[] res = new double[6];
  88. 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);
  89. return res;
  90. }
  91. /// <summary>
  92. /// 融合定位,返回经度纬度高度及镜像点,数组长度为6
  93. /// </summary>
  94. /// <returns></returns>
  95. public static double[] RH_POS(CgRes cgRes, List<TxInfo> listTx, CxRes cxRes)
  96. {
  97. var res1 = X1D1_POS(cgRes, listTx, cxRes);
  98. var res2 = X2D1_POS(cgRes, listTx);
  99. double[] res = new double[] { 999, 999, 0, 999, 999, 0 };
  100. if (IsGeoPoint(res1) && IsGeoPoint(res2))
  101. {
  102. res = new double[6] {
  103. (res1[0] + res2[0]) / 2 + 0.003,
  104. (res1[1] + res2[1]) / 2 - 0.002,
  105. (res1[2] + res2[2]) / 2,
  106. (res1[3] + res2[3]) / 2 + 0.003,
  107. (res1[4] + res2[4]) / 2 - 0.002,
  108. (res1[5] + res2[5]) / 2,
  109. };
  110. }
  111. else if (IsGeoPoint(res1))
  112. {
  113. res = new double[6]
  114. {
  115. res1[0] + 0.003,
  116. res1[1] - 0.002,
  117. res1[2],
  118. res1[3] + 0.003,
  119. res1[4] - 0.002,
  120. res1[5],
  121. };
  122. }
  123. else if (IsGeoPoint(res2))
  124. {
  125. res = new double[6]
  126. {
  127. res2[0] + 0.003,
  128. res2[1] - 0.002,
  129. res2[2],
  130. res2[3] + 0.003,
  131. res2[4] - 0.002,
  132. res2[5],
  133. };
  134. }
  135. return res;
  136. }
  137. public static bool IsGeoPoint(double[] res)
  138. {
  139. return res[0] >= -180 && res[0] <= 180 && res[1] >= -90 && res[1] <= 90;
  140. }
  141. }
  142. }