PosApi.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. private 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. #endregion
  29. /// <summary>
  30. /// 一星一地,返返回经度纬度高度及镜像点,数组长度为6
  31. /// </summary>
  32. /// <param name="cgRes"></param>
  33. /// <param name="cxRes"></param>
  34. /// <returns></returns>
  35. public static double[] X1D1_POS(CgRes cgRes, List<TxInfo> listTx, CxRes cxRes)
  36. {
  37. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  38. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  39. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  40. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  41. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  42. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  43. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  44. double[] cxStation = new double[3] { cxTx.Lon, cxTx.Lat, 0 };
  45. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  46. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  47. double theta = cxRes.Fx;//单位°
  48. double[] res = new double[6];
  49. X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb / 1e6, cgRes.YbMain / 1e6, res);
  50. return res.Select(p => Math.Round(p, 4)).ToArray();
  51. }
  52. /// <summary>
  53. /// 两星一地,返回经度纬度高度及镜像点,数组长度为6
  54. /// </summary>
  55. /// <param name="cgRes"></param>
  56. /// <returns></returns>
  57. public static double[] X2D1_POS(CgRes cgRes, List<TxInfo> listTx)
  58. {
  59. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  60. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  61. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  62. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  63. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  64. double[] adjaSat = new double[3] { cgRes.AdjaX, cgRes.AdjaY, cgRes.AdjaZ };
  65. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  66. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  67. double[] cxStation = new double[3] { cxTx.Lon, cxTx.Lat, 0 };
  68. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  69. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  70. double[] res = new double[6];
  71. 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);
  72. return res;
  73. }
  74. /// <summary>
  75. /// 融合定位,返回经度纬度高度及镜像点,数组长度为6
  76. /// </summary>
  77. /// <returns></returns>
  78. public static double[] RH_POS(CgRes cgRes, List<TxInfo> listTx, CxRes cxRes)
  79. {
  80. var res1 = X1D1_POS(cgRes, listTx, cxRes);
  81. var res2 = X2D1_POS(cgRes, listTx);
  82. double[] res = new double[] { 999, 999, 0, 999, 999, 0 };
  83. if (IsGeoPoint(res1) && IsGeoPoint(res2))
  84. {
  85. res = new double[6] {
  86. (res1[0] + res2[0]) / 2 + 0.003,
  87. (res1[1] + res2[1]) / 2 - 0.002,
  88. (res1[2] + res2[2]) / 2,
  89. (res1[3] + res2[3]) / 2 + 0.003,
  90. (res1[4] + res2[4]) / 2 - 0.002,
  91. (res1[5] + res2[5]) / 2,
  92. };
  93. }
  94. else if (IsGeoPoint(res1))
  95. {
  96. res = new double[6]
  97. {
  98. res1[0] + 0.003,
  99. res1[1] - 0.002,
  100. res1[2],
  101. res1[3] + 0.003,
  102. res1[4] - 0.002,
  103. res1[5],
  104. };
  105. }
  106. else if (IsGeoPoint(res2))
  107. {
  108. res = new double[6]
  109. {
  110. res2[0] + 0.003,
  111. res2[1] - 0.002,
  112. res2[2],
  113. res2[3] + 0.003,
  114. res2[4] - 0.002,
  115. res2[5],
  116. };
  117. }
  118. return res;
  119. }
  120. public static bool IsGeoPoint(double[] res)
  121. {
  122. return res[0] >= -180 && res[0] <= 180 && res[1] >= -90 && res[1] <= 90;
  123. }
  124. }
  125. }