GdopHelper.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. 
  2. using DevExpress.XtraBars.Docking.Helpers;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Runtime.InteropServices;
  7. namespace XdCxRhDW.App.Api.GDOP误差椭圆
  8. {
  9. public static class GdopHelper
  10. {
  11. static readonly DateTime dtZero = new DateTime(1970, 1, 1, 8, 0, 0, 0);
  12. /// <summary>
  13. /// 两星一地GDOP 无参时参考位置不赋值
  14. /// </summary>
  15. /// <param name="mainLines">主星星历</param>
  16. /// <param name="adajLines">邻星星历</param>
  17. /// <param name="captime">信号时间</param>
  18. /// <param name="cdbPos">超短波位置 3</param>
  19. /// <param name="refPos">参考站位置 3</param>
  20. /// <param name="dtousErr">时差误差</param>
  21. /// <param name="ephLocErr">星历误差</param>
  22. /// <returns></returns>
  23. public static (List<SatInfo>, List<ErrDistanceMapPoints>) Gdop2Sat1D(string mainLines, string adajLines, DateTime captime, double[] cdbPos, double dtousErr, double ephLocErr, double[] refPos = null)
  24. {
  25. int satCount = 2;
  26. //该值和points 一一对应
  27. double[] level = GdopParam.误差配置.误差距离m;
  28. double[] satllh = new double[satCount * 3];
  29. var timeSpan = (long)(captime - dtZero).TotalSeconds;
  30. IntPtr res = IntPtr.Zero;
  31. int[] resCount = new int[level.Length];
  32. if (refPos == null || refPos.Length == 0)
  33. {
  34. GDOPApi.Gdop2Sat1DNoRef(mainLines, adajLines, timeSpan, cdbPos, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  35. }
  36. else
  37. {
  38. GDOPApi.Gdop2Sat1DRef(mainLines, adajLines, timeSpan, cdbPos, refPos, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  39. }
  40. IntPtr tmp = res;
  41. //用于绘制的数据
  42. List<double[]> points = new List<double[]>();
  43. for (int idx = 0; idx < level.Length; ++idx)
  44. {
  45. double[] levelval = new double[resCount[idx]];
  46. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  47. tmp += (resCount[idx] * sizeof(double));
  48. points.Add(levelval);
  49. }
  50. GDOPApi.FreeGDOPBuf(res);
  51. List<SatInfo> satInfos = ParseResult(satCount, satllh, mainLines, adajLines);
  52. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  53. for (int i = 0; i < points.Count; i++)
  54. {
  55. if (!points[i].Any()) continue;
  56. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  57. errDistanceMap.ErrDistance = level[i];
  58. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  59. errs.Add(errDistanceMap);
  60. }
  61. return (satInfos, errs);
  62. }
  63. /// <summary>
  64. /// 一星一地GDOP
  65. /// </summary>
  66. /// <param name="mainLines">主星星历</param>
  67. /// <param name="captime">信号时间</param>
  68. /// <param name="cdbPos">超短波位置 3</param>
  69. /// <param name="cxPos">测向站位置 3</param>
  70. /// <param name="dtousErr">时差误差</param>
  71. /// <param name="doaErr">测向误差</param>
  72. /// <param name="ephLocErr">星历误差</param>
  73. /// <param name="refPos">参考站位置 3</param>
  74. /// <returns></returns>
  75. public static (List<SatInfo>, List<ErrDistanceMapPoints>) Gdop1Sat1D(string mainLines, DateTime captime, double[] cdbPos, double[] cxPos, double dtousErr, double doaErr, double ephLocErr, double[] refPos = null)
  76. {
  77. int satCount = 2;
  78. //该值和points 一一对应
  79. double[] level = GdopParam.误差配置.误差距离m;
  80. double[] satllh = new double[satCount * 3];
  81. var timeSpan = (long)(captime - dtZero).TotalSeconds;
  82. IntPtr res = IntPtr.Zero;
  83. int[] resCount = new int[level.Length];
  84. if (refPos == null || refPos.Length == 0)
  85. {
  86. GDOPApi.GdopXDCXNoRef(mainLines, timeSpan, cdbPos, cxPos, dtousErr, doaErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  87. }
  88. else
  89. {
  90. GDOPApi.GdopXDCXRef(mainLines, timeSpan, cdbPos, cxPos, refPos, dtousErr, doaErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  91. }
  92. IntPtr tmp = res;
  93. //用于绘制的数据
  94. List<double[]> points = new List<double[]>();
  95. for (int idx = 0; idx < level.Length; ++idx)
  96. {
  97. double[] levelval = new double[resCount[idx]];
  98. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  99. tmp += (resCount[idx] * sizeof(double));
  100. points.Add(levelval);
  101. }
  102. GDOPApi.FreeGDOPBuf(res);
  103. List<SatInfo> satInfos = ParseResult(satCount, satllh, mainLines);
  104. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  105. for (int i = 0; i < points.Count; i++)
  106. {
  107. if (!points[i].Any()) continue;
  108. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  109. errDistanceMap.ErrDistance = level[i];
  110. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  111. errs.Add(errDistanceMap);
  112. }
  113. return (satInfos, errs);
  114. }
  115. private static (List<SatInfo>, List<ErrDistanceMapPoints>) Gdop3Sat(string mainLines, string adajLines, string adajLines2,
  116. DateTime captime, double dtousErr, double ephLocErr, double[] refPos = null)
  117. {
  118. int satCount = 2;
  119. //该值和points 一一对应
  120. double[] level = GdopParam.误差配置.误差距离m;
  121. double[] satllh = new double[satCount * 3];
  122. var timeSpan = (long)(captime - dtZero).TotalSeconds;
  123. IntPtr res = IntPtr.Zero;
  124. int[] resCount = new int[level.Length];
  125. if (refPos == null || refPos.Length == 0)
  126. {
  127. GDOPApi.Gdop3SatNoRef(mainLines, adajLines, adajLines2, timeSpan, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  128. }
  129. else
  130. {
  131. GDOPApi.Gdop3SatRef(mainLines, adajLines, adajLines2, timeSpan, refPos, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  132. }
  133. IntPtr tmp = res;
  134. //用于绘制的数据
  135. List<double[]> points = new List<double[]>();
  136. for (int idx = 0; idx < level.Length; ++idx)
  137. {
  138. double[] levelval = new double[resCount[idx]];
  139. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  140. tmp += (resCount[idx] * sizeof(double));
  141. points.Add(levelval);
  142. }
  143. GDOPApi.FreeGDOPBuf(res);
  144. List<SatInfo> satInfos = ParseResult(satCount, satllh, mainLines, adajLines, adajLines2);
  145. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  146. for (int i = 0; i < points.Count; i++)
  147. {
  148. if (!points[i].Any()) continue;
  149. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  150. errDistanceMap.ErrDistance = level[i];
  151. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  152. errs.Add(errDistanceMap);
  153. }
  154. return (satInfos, errs);
  155. }
  156. private static (List<SatInfo>, List<ErrDistanceMapPoints>) Gdop3SatDF(string mainLines, string adajLines, string adajLines2,
  157. DateTime captime, double fuHz1, double fuHz2, double dfoErr, double ephLocErr, double ephVErr, double[] refPos)
  158. {
  159. int satCount = 2;
  160. //该值和points 一一对应
  161. double[] level = GdopParam.误差配置.误差距离m;
  162. double[] satllh = new double[satCount * 3];
  163. var timeSpan = (long)(captime - dtZero).TotalSeconds;
  164. IntPtr res = IntPtr.Zero;
  165. int[] resCount = new int[level.Length];
  166. GDOPApi.Gdop3SatDF(mainLines, adajLines, adajLines2, timeSpan, refPos,fuHz1,fuHz2,dfoErr, ephLocErr,ephVErr, level, level.Length, resCount, out res, satllh);
  167. IntPtr tmp = res;
  168. //用于绘制的数据
  169. List<double[]> points = new List<double[]>();
  170. for (int idx = 0; idx < level.Length; ++idx)
  171. {
  172. double[] levelval = new double[resCount[idx]];
  173. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  174. tmp += (resCount[idx] * sizeof(double));
  175. points.Add(levelval);
  176. }
  177. GDOPApi.FreeGDOPBuf(res);
  178. List<SatInfo> satInfos = ParseResult(satCount, satllh, mainLines, adajLines, adajLines2);
  179. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  180. for (int i = 0; i < points.Count; i++)
  181. {
  182. if (!points[i].Any()) continue;
  183. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  184. errDistanceMap.ErrDistance = level[i];
  185. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  186. errs.Add(errDistanceMap);
  187. }
  188. return (satInfos, errs);
  189. }
  190. private static List<MapDot> ParseResult(double[] ponits)
  191. {
  192. List<MapDot> mapDots = new List<MapDot>();
  193. int count = 2;
  194. for (int i = 0; i < ponits.Length / count; i++)
  195. {
  196. MapDot mapDot = new MapDot();
  197. mapDot.Lat = ponits[count * i + 1];
  198. mapDot.Lon = ponits[count * i];
  199. mapDots.Add(mapDot);
  200. }
  201. return mapDots;
  202. }
  203. private static List<SatInfo> ParseResult(int satCount, double[] satllh, params string[] ephLine)
  204. {
  205. List<SatInfo> list = new List<SatInfo>();
  206. int len = 3;
  207. for (int i = 0; i < satCount; i++)
  208. {
  209. SatInfo satInfo = new SatInfo();
  210. var ephstrs = ephLine[i].Split(new string[] { " ", "U" }, StringSplitOptions.RemoveEmptyEntries);
  211. if (ephstrs.Length == 16)
  212. {
  213. satInfo.SatCode = Convert.ToInt32(ephstrs[1]);
  214. }
  215. satInfo.SatLon = Convert.ToDouble(satllh[len * i]);
  216. satInfo.SatLat = Convert.ToDouble(satllh[len * i + 1]);
  217. list.Add(satInfo);
  218. }
  219. return list;
  220. }
  221. }
  222. }