GdopHelper.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. using DevExpress.Charts.Native;
  2. using DevExpress.Internal.WinApi.Windows.UI.Notifications;
  3. using DevExpress.XtraPrinting;
  4. using Newtonsoft.Json;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data.Entity.Core.Common.EntitySql;
  8. using System.Diagnostics;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Runtime.InteropServices;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using XdCxRhDW.App.DTO;
  15. namespace XzXdDw.App.Api.星地GDOP误差椭圆
  16. {
  17. public static class GdopHelper
  18. {
  19. private const string GDOPDll = @"Api\星地GDOP误差椭圆\GDOP\GDOP_Draw.dll";
  20. static readonly DateTime dtZero = new DateTime(1970, 1, 1, 8, 0, 0, 0);
  21. /// <returns></returns>
  22. [DllImport(GDOPDll, CallingConvention = CallingConvention.Cdecl)]
  23. public static extern int GdopLeoTowSatDRef(string mainLines, string adajLines, Int64 captime, double[] refPos
  24. , double fuHz1, double fuHz2, double dtousErr, double dfoHzErr, double ephLocErr, double ephVLocErr
  25. , double[] level, int levlen, int[] resCount, out IntPtr res, double[] satllh);
  26. [DllImport(GDOPDll, CallingConvention = CallingConvention.Cdecl)]
  27. public static extern int GdopSingleSatD(string mainLines, Int64 captime1, Int64 captime2, Int64 captime3
  28. , double fuHz, double dfoHzErr, double ephLocErr, double ephVLocErr
  29. , double[] level, int levlen, int[] resCount,out IntPtr res, double[] satllh);
  30. [DllImport(GDOPDll, CallingConvention = CallingConvention.Cdecl)]
  31. public static extern void FreeGDOPBuf(IntPtr val);
  32. /// <summary>
  33. /// 低轨双星GDOP
  34. /// </summary>
  35. /// <param name="mainLines">主星星历</param>
  36. /// <param name="adajLines">邻星星历</param>
  37. /// <param name="captime">采集时间</param>
  38. /// <param name="refPos">参考站位置 长度3</param>
  39. /// <param name="fuHz1">目标上行频点 Hz</param>
  40. /// <param name="fuHz2">参考上行频点 Hz</param>
  41. /// <param name="dtousErr">时差误差</param>
  42. /// <param name="dfoHzErr">频差误差</param>
  43. /// <param name="ephLocErr">星历位置误差</param>
  44. /// <param name="ephVLocErr">星历速度误差</param>
  45. public static (List<SatInfo>, List<ErrDistanceMapPoints>) GdopLeoTowSatDRef(string mainLines, string adajLines, DateTime captime, double[] refPos
  46. , double fuHz1, double fuHz2, double dtousErr, double dfoHzErr, double ephLocErr, double ephVLocErr)
  47. {
  48. int satCount = 2;
  49. //该值和points 一一对应
  50. double[] level = GdopParam.误差配置.小误差距离m;
  51. double[] satllh = new double[satCount*3];
  52. var timeSpan = (long)(captime - dtZero).TotalSeconds;
  53. IntPtr res = IntPtr.Zero;
  54. int[] resCount = new int[level.Length];
  55. GdopLeoTowSatDRef(mainLines, adajLines, timeSpan, refPos
  56. , fuHz1, fuHz2, dtousErr, dfoHzErr, ephLocErr, ephVLocErr, level, level.Length, resCount, out res, satllh);
  57. IntPtr tmp = res;
  58. //用于绘制的数据
  59. List<double[]> points = new List<double[]>();
  60. for (int idx = 0; idx < level.Length; ++idx)
  61. {
  62. double[] levelval = new double[resCount[idx]];
  63. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  64. tmp += (resCount[idx] * sizeof(double));
  65. points.Add(levelval);
  66. }
  67. FreeGDOPBuf(res);
  68. List<SatInfo> satInfos = ParseResult(satCount, satllh, mainLines, adajLines);
  69. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  70. for (int i = 0; i < points.Count; i++)
  71. {
  72. if (!points[i].Any()) continue;
  73. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  74. errDistanceMap.ErrDistance = level[i];
  75. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  76. errs.Add(errDistanceMap);
  77. }
  78. return (satInfos, errs);
  79. }
  80. /// <summary>
  81. /// 单星GDOP
  82. /// </summary>
  83. /// <param name="mainLines">主星星历</param>
  84. /// <param name="captime1">第一采集时刻</param>
  85. /// <param name="captime2">第二采集时刻</param>
  86. /// <param name="captime3">第三采集时刻</param>
  87. /// <param name="dfoHzErr">频差误差</param>
  88. /// <param name="ephLocErr">星历位置误差</param>
  89. /// <param name="ephVLocErr">星历速度误差</param>
  90. /// <param name="fuHz">目标上行频点</param>
  91. /// <returns></returns>
  92. public static (List<SatInfo>, List<ErrDistanceMapPoints>) GdopSingleSat(string mainLines, DateTime captime1, DateTime captime2, DateTime captime3, double dfoHzErr, double ephLocErr, double ephVLocErr, double fuHz)
  93. {
  94. int satCount = 1;
  95. //该值和points 一一对应
  96. double[] level = GdopParam.误差配置.小误差距离m;
  97. double[] satllh = new double[satCount * 3];
  98. var timeSpan1 = (long)(captime1 - dtZero).TotalSeconds;
  99. var timeSpan2 = (long)(captime2 - dtZero).TotalSeconds;
  100. var timeSpan3 = (long)(captime3 - dtZero).TotalSeconds;
  101. IntPtr res = IntPtr.Zero;
  102. int[] resCount = new int[level.Length];
  103. GdopSingleSatD(mainLines, timeSpan1, timeSpan2, timeSpan3,fuHz, dfoHzErr,ephLocErr,ephVLocErr,level,level.Length,resCount,out res,satllh);
  104. IntPtr tmp = res;
  105. //用于绘制的数据
  106. List<double[]> points = new List<double[]>();
  107. for (int idx = 0; idx < level.Length; ++idx)
  108. {
  109. double[] levelval = new double[resCount[idx]];
  110. Marshal.Copy(tmp, levelval, 0, resCount[idx]);
  111. tmp += (resCount[idx] * sizeof(double));
  112. points.Add(levelval);
  113. }
  114. FreeGDOPBuf(res);
  115. List<SatInfo> satInfos = ParseResult(satCount, satllh, mainLines);
  116. List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
  117. for (int i = 0; i < points.Count; i++)
  118. {
  119. if (!points[i].Any()) continue;
  120. ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
  121. errDistanceMap.ErrDistance = level[i];
  122. errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
  123. errs.Add(errDistanceMap);
  124. }
  125. return (satInfos, errs);
  126. }
  127. private static List<MapDot> ParseResult(double[] ponits)
  128. {
  129. List<MapDot> mapDots = new List<MapDot>();
  130. int count = 2;
  131. for (int i = 0; i < ponits.Length / count; i++)
  132. {
  133. MapDot mapDot = new MapDot();
  134. mapDot.Lat = ponits[count * i + 1];
  135. mapDot.Lon = ponits[count * i];
  136. mapDots.Add(mapDot);
  137. }
  138. return mapDots;
  139. }
  140. private static List<SatInfo> ParseResult(int satCount, double[] satllh, params string[] ephLine)
  141. {
  142. List<SatInfo> list = new List<SatInfo>();
  143. int len = 3;
  144. for (int i = 0; i < satCount; i++)
  145. {
  146. SatInfo satInfo = new SatInfo();
  147. var ephstrs = ephLine[i].Split(new string[] { " ", "U" }, StringSplitOptions.RemoveEmptyEntries);
  148. if (ephstrs.Length == 16)
  149. {
  150. satInfo.SatCode = Convert.ToInt32(ephstrs[1]);
  151. }
  152. satInfo.SatLon = Convert.ToDouble(satllh[len * i]);
  153. satInfo.SatLat = Convert.ToDouble(satllh[len * i + 1]);
  154. list.Add(satInfo);
  155. }
  156. return list;
  157. }
  158. }
  159. }