GdopHelper.cs 12 KB

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