GdopHelper.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6. namespace XdCxRhDW.Api
  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<MapSatInfo>, 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<MapSatInfo> 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="mainEph">主星星历 x y z vx vy vz</param>
  66. /// <param name="adajEph">邻星星历x y z vx vy vz</param>
  67. /// <param name="cdbPos">超短波位置 3</param>
  68. /// <param name="refPos">参考站位置 3</param>
  69. /// <param name="dtousErr">时差误差</param>
  70. /// <param name="ephLocErr">星历误差</param>
  71. /// <param name="refPos"></param>
  72. /// <returns></returns>
  73. public static (List<MapSatInfo>, List<ErrDistanceMapPoints>) Gdop2Sat1DByXyz(double[] mainEph, double[] adajEph, double[] cdbPos, double dtousErr, double ephLocErr, double[] refPos = null)
  74. {
  75. int satCount = 2;
  76. //该值和points 一一对应
  77. double[] level = GdopParam.误差配置.误差距离m;
  78. double[] satllh = new double[satCount * 3];
  79. IntPtr res = IntPtr.Zero;
  80. int[] resCount = new int[level.Length];
  81. if (refPos == null || refPos.Length == 0)
  82. {
  83. GDOPApi.Gdop2Sat1DNoRefByXyz(mainEph, adajEph, cdbPos, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  84. }
  85. else
  86. {
  87. GDOPApi.Gdop2Sat1DRefByXyz(mainEph, adajEph, cdbPos, refPos, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  88. }
  89. IntPtr tmp = res;
  90. //用于绘制的数据
  91. List<double[]> points = new List<double[]>();
  92. for (int idx = 0; idx < level.Length; ++idx)
  93. {
  94. double[] levelval = new double[resCount[idx]];
  95. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  96. tmp += (resCount[idx] * sizeof(double));
  97. points.Add(levelval);
  98. }
  99. GDOPApi.FreeGDOPBuf(res);
  100. List<MapSatInfo> satInfos = ParseResult(satCount, satllh);
  101. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  102. for (int i = 0; i < points.Count; i++)
  103. {
  104. if (!points[i].Any()) continue;
  105. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  106. errDistanceMap.ErrDistance = level[i];
  107. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  108. errs.Add(errDistanceMap);
  109. }
  110. return (satInfos, errs);
  111. }
  112. /// <summary>
  113. /// 一星一地GDOP
  114. /// </summary>
  115. /// <param name="mainLines">主星星历</param>
  116. /// <param name="captime">信号时间</param>
  117. /// <param name="cdbPos">超短波位置 3</param>
  118. /// <param name="cxPos">测向站位置 3</param>
  119. /// <param name="dtousErr">时差误差</param>
  120. /// <param name="doaErr">测向误差</param>
  121. /// <param name="ephLocErr">星历误差</param>
  122. /// <param name="refPos">参考站位置 3</param>
  123. /// <returns></returns>
  124. public static (List<MapSatInfo>, List<ErrDistanceMapPoints>) Gdop1Sat1D(string mainLines, DateTime captime, double[] cdbPos, double[] cxPos, double dtousErr, double doaErr, double ephLocErr, double[] refPos = null)
  125. {
  126. int satCount = 1;
  127. //该值和points 一一对应
  128. double[] level = GdopParam.误差配置.误差距离m;
  129. double[] satllh = new double[satCount * 3];
  130. var timeSpan = (long)(captime - dtZero).TotalSeconds;
  131. IntPtr res = IntPtr.Zero;
  132. int[] resCount = new int[level.Length];
  133. if (refPos == null || refPos.Length == 0)
  134. {
  135. GDOPApi.GdopXDCXNoRef(mainLines, timeSpan, cdbPos, cxPos, dtousErr, doaErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  136. }
  137. else
  138. {
  139. GDOPApi.GdopXDCXRef(mainLines, timeSpan, cdbPos, cxPos, refPos, dtousErr, doaErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  140. }
  141. IntPtr tmp = res;
  142. //用于绘制的数据
  143. List<double[]> points = new List<double[]>();
  144. for (int idx = 0; idx < level.Length; ++idx)
  145. {
  146. double[] levelval = new double[resCount[idx]];
  147. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  148. tmp += (resCount[idx] * sizeof(double));
  149. points.Add(levelval);
  150. }
  151. GDOPApi.FreeGDOPBuf(res);
  152. List<MapSatInfo> satInfos = ParseResult(satCount, satllh, mainLines);
  153. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  154. for (int i = 0; i < points.Count; i++)
  155. {
  156. if (!points[i].Any()) continue;
  157. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  158. errDistanceMap.ErrDistance = level[i];
  159. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  160. errs.Add(errDistanceMap);
  161. }
  162. return (satInfos, errs);
  163. }
  164. public static (List<MapSatInfo>, List<ErrDistanceMapPoints>) Gdop3Sat(string mainLines, string adajLines, string adajLines2,
  165. DateTime captime, double dtousErr, double ephLocErr, double[] refPos = null)
  166. {
  167. int satCount = 3;
  168. //该值和points 一一对应
  169. double[] level = GdopParam.误差配置.误差距离m;
  170. double[] satllh = new double[satCount * 3];
  171. var timeSpan = (long)(captime - dtZero).TotalSeconds;
  172. IntPtr res = IntPtr.Zero;
  173. int[] resCount = new int[level.Length];
  174. if (refPos == null || refPos.Length == 0)
  175. {
  176. GDOPApi.Gdop3SatNoRef(mainLines, adajLines, adajLines2, timeSpan, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  177. }
  178. else
  179. {
  180. GDOPApi.Gdop3SatRef(mainLines, adajLines, adajLines2, timeSpan, refPos, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
  181. }
  182. IntPtr tmp = res;
  183. //用于绘制的数据
  184. List<double[]> points = new List<double[]>();
  185. for (int idx = 0; idx < level.Length; ++idx)
  186. {
  187. double[] levelval = new double[resCount[idx]];
  188. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  189. tmp += (resCount[idx] * sizeof(double));
  190. points.Add(levelval);
  191. }
  192. GDOPApi.FreeGDOPBuf(res);
  193. List<MapSatInfo> satInfos = ParseResult(satCount, satllh, mainLines, adajLines, adajLines2);
  194. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  195. for (int i = 0; i < points.Count; i++)
  196. {
  197. if (!points[i].Any()) continue;
  198. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  199. errDistanceMap.ErrDistance = level[i];
  200. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  201. errs.Add(errDistanceMap);
  202. }
  203. return (satInfos, errs);
  204. }
  205. public static (List<MapSatInfo>, List<ErrDistanceMapPoints>) Gdop3SatDF(string mainLines, string adajLines, string adajLines2,
  206. DateTime captime, double fuHz1, double fuHz2, double dfoErr, double ephLocErr, double ephVErr, double[] refPos)
  207. {
  208. int satCount = 3;
  209. //该值和points 一一对应
  210. double[] level = GdopParam.误差配置.误差距离m;
  211. double[] satllh = new double[satCount * 3];
  212. var timeSpan = (long)(captime - dtZero).TotalSeconds;
  213. IntPtr res = IntPtr.Zero;
  214. int[] resCount = new int[level.Length];
  215. GDOPApi.Gdop3SatDF(mainLines, adajLines, adajLines2, timeSpan, refPos, fuHz1, fuHz2, dfoErr, ephLocErr, ephVErr, level, level.Length, resCount, out res, satllh);
  216. IntPtr tmp = res;
  217. //用于绘制的数据
  218. List<double[]> points = new List<double[]>();
  219. for (int idx = 0; idx < level.Length; ++idx)
  220. {
  221. double[] levelval = new double[resCount[idx]];
  222. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  223. tmp += (resCount[idx] * sizeof(double));
  224. points.Add(levelval);
  225. }
  226. GDOPApi.FreeGDOPBuf(res);
  227. List<MapSatInfo> satInfos = ParseResult(satCount, satllh, mainLines, adajLines, adajLines2);
  228. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  229. for (int i = 0; i < points.Count; i++)
  230. {
  231. if (!points[i].Any()) continue;
  232. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  233. errDistanceMap.ErrDistance = level[i];
  234. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  235. errs.Add(errDistanceMap);
  236. }
  237. return (satInfos, errs);
  238. }
  239. public static (List<MapSatInfo>, List<ErrDistanceMapPoints>) Gdop2SatDRef(string mainLines, string adajLines,
  240. DateTime captime, double fuHz1, double fuHz2, double dtousErr, double dfoErr, double ephLocErr, double ephVErr, double[] refPos)
  241. {
  242. int satCount = 2;
  243. //该值和points 一一对应
  244. double[] level = GdopParam.误差配置.误差距离m;
  245. double[] satllh = new double[satCount * 3];
  246. var timeSpan = (long)(captime - dtZero).TotalSeconds;
  247. IntPtr res = IntPtr.Zero;
  248. int[] resCount = new int[level.Length];
  249. GDOPApi.Gdop2SatDRef(mainLines, adajLines, timeSpan, refPos, fuHz1, fuHz2, dtousErr, dfoErr, ephLocErr, ephVErr, level, level.Length, resCount, out res, satllh);
  250. IntPtr tmp = res;
  251. //用于绘制的数据
  252. List<double[]> points = new List<double[]>();
  253. for (int idx = 0; idx < level.Length; ++idx)
  254. {
  255. double[] levelval = new double[resCount[idx]];
  256. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  257. tmp += (resCount[idx] * sizeof(double));
  258. points.Add(levelval);
  259. }
  260. GDOPApi.FreeGDOPBuf(res);
  261. List<MapSatInfo> satInfos = ParseResult(satCount, satllh, mainLines, adajLines);
  262. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  263. for (int i = 0; i < points.Count; i++)
  264. {
  265. if (!points[i].Any()) continue;
  266. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  267. errDistanceMap.ErrDistance = level[i];
  268. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  269. errs.Add(errDistanceMap);
  270. }
  271. return (satInfos, errs);
  272. }
  273. private static List<MapDot> ParseResult(double[] ponits)
  274. {
  275. List<MapDot> mapDots = new List<MapDot>();
  276. int count = 2;
  277. for (int i = 0; i < ponits.Length / count; i++)
  278. {
  279. MapDot mapDot = new MapDot();
  280. mapDot.Lon = ponits[count * i];
  281. mapDot.Lat = ponits[count * i + 1];//0 1 2 3 4 5 6 7
  282. mapDots.Add(mapDot);
  283. }
  284. return mapDots;
  285. }
  286. private static List<MapSatInfo> ParseResult(int satCount, double[] satllh)
  287. {
  288. List<MapSatInfo> list = new List<MapSatInfo>();
  289. int len = 3;
  290. for (int i = 0; i < satCount; i++)
  291. {
  292. MapSatInfo satInfo = new MapSatInfo();
  293. satInfo.SatLon = Convert.ToDouble(satllh[len * i]);
  294. satInfo.SatLat = Convert.ToDouble(satllh[len * i + 1]);
  295. list.Add(satInfo);
  296. }
  297. return list;
  298. }
  299. private static List<MapSatInfo> ParseResult(int satCount, double[] satllh, params string[] ephLine)
  300. {
  301. List<MapSatInfo> list = new List<MapSatInfo>();
  302. int len = 3;
  303. for (int i = 0; i < satCount; i++)
  304. {
  305. MapSatInfo satInfo = new MapSatInfo();
  306. var ephstrs = ephLine[i].Split(new string[] { " ", "U" }, StringSplitOptions.RemoveEmptyEntries);
  307. if (ephstrs.Length == 16)
  308. {
  309. satInfo.SatCode = Convert.ToInt32(ephstrs[1]);
  310. }
  311. satInfo.SatLon = Convert.ToDouble(satllh[len * i]);
  312. satInfo.SatLat = Convert.ToDouble(satllh[len * i + 1]);
  313. list.Add(satInfo);
  314. }
  315. return list;
  316. }
  317. }
  318. }