123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- namespace XdCxRhDW.Core.Api
- {
- public static class GdopHelper
- {
- static readonly DateTime dtZero = new DateTime(1970, 1, 1, 8, 0, 0, 0);
- /// <summary>
- /// 两星一地GDOP 无参时参考位置不赋值
- /// </summary>
- /// <param name="mainLines">主星星历</param>
- /// <param name="adajLines">邻星星历</param>
- /// <param name="captime">信号时间</param>
- /// <param name="cdbPos">超短波位置 3</param>
- /// <param name="refPos">参考站位置 3</param>
- /// <param name="dtousErr">时差误差</param>
- /// <param name="ephLocErr">星历误差</param>
- /// <returns></returns>
- public static (List<MapSatInfo>, List<ErrDistanceMapPoints>) Gdop2Sat1D(string mainLines, string adajLines, DateTime captime, double[] cdbPos, double dtousErr, double ephLocErr, double[] refPos = null)
- {
- int satCount = 2;
- //该值和points 一一对应
- double[] level = GdopParam.误差配置.误差距离m;
- double[] satllh = new double[satCount * 3];
- var timeSpan = (long)(captime - dtZero).TotalSeconds;
- IntPtr res = IntPtr.Zero;
- int[] resCount = new int[level.Length];
- if (refPos == null || refPos.Length == 0)
- {
- GDOPApi.Gdop2Sat1DNoRef(mainLines, adajLines, timeSpan, cdbPos, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
- }
- else
- {
- GDOPApi.Gdop2Sat1DRef(mainLines, adajLines, timeSpan, cdbPos, refPos, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
- }
- IntPtr tmp = res;
- //用于绘制的数据
- List<double[]> points = new List<double[]>();
- for (int idx = 0; idx < level.Length; ++idx)
- {
- double[] levelval = new double[resCount[idx]];
- Marshal.Copy(tmp, levelval, 0, resCount[idx]);
- tmp += (resCount[idx] * sizeof(double));
- points.Add(levelval);
- }
- GDOPApi.FreeGDOPBuf(res);
- List<MapSatInfo> satInfos = ParseResult(satCount, satllh, mainLines, adajLines);
- List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
- for (int i = 0; i < points.Count; i++)
- {
- if (!points[i].Any()) continue;
- ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
- errDistanceMap.ErrDistance = level[i];
- errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
- errs.Add(errDistanceMap);
- }
- return (satInfos, errs);
- }
- /// <summary>
- /// 一星一地GDOP
- /// </summary>
- /// <param name="mainLines">主星星历</param>
- /// <param name="captime">信号时间</param>
- /// <param name="cdbPos">超短波位置 3</param>
- /// <param name="cxPos">测向站位置 3</param>
- /// <param name="dtousErr">时差误差</param>
- /// <param name="doaErr">测向误差</param>
- /// <param name="ephLocErr">星历误差</param>
- /// <param name="refPos">参考站位置 3</param>
- /// <returns></returns>
- public static (List<MapSatInfo>, List<ErrDistanceMapPoints>) Gdop1Sat1D(string mainLines, DateTime captime, double[] cdbPos, double[] cxPos, double dtousErr, double doaErr, double ephLocErr, double[] refPos = null)
- {
- int satCount = 1;
- //该值和points 一一对应
- double[] level = GdopParam.误差配置.误差距离m;
- double[] satllh = new double[satCount * 3];
- var timeSpan = (long)(captime - dtZero).TotalSeconds;
- IntPtr res = IntPtr.Zero;
- int[] resCount = new int[level.Length];
- if (refPos == null || refPos.Length == 0)
- {
- GDOPApi.GdopXDCXNoRef(mainLines, timeSpan, cdbPos, cxPos, dtousErr, doaErr, ephLocErr, level, level.Length, resCount, out res, satllh);
- }
- else
- {
- GDOPApi.GdopXDCXRef(mainLines, timeSpan, cdbPos, cxPos, refPos, dtousErr, doaErr, ephLocErr, level, level.Length, resCount, out res, satllh);
- }
- IntPtr tmp = res;
- //用于绘制的数据
- List<double[]> points = new List<double[]>();
- for (int idx = 0; idx < level.Length; ++idx)
- {
- double[] levelval = new double[resCount[idx]];
- Marshal.Copy(tmp, levelval, 0, resCount[idx]);
- tmp += (resCount[idx] * sizeof(double));
- points.Add(levelval);
- }
- GDOPApi.FreeGDOPBuf(res);
- List<MapSatInfo> satInfos = ParseResult(satCount, satllh, mainLines);
- List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
- for (int i = 0; i < points.Count; i++)
- {
- if (!points[i].Any()) continue;
- ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
- errDistanceMap.ErrDistance = level[i];
- errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
- errs.Add(errDistanceMap);
- }
- return (satInfos, errs);
- }
- public static (List<MapSatInfo>, List<ErrDistanceMapPoints>) Gdop3Sat(string mainLines, string adajLines, string adajLines2,
- DateTime captime, double dtousErr, double ephLocErr, double[] refPos = null)
- {
- int satCount = 3;
- //该值和points 一一对应
- double[] level = GdopParam.误差配置.误差距离m;
- double[] satllh = new double[satCount * 3];
- var timeSpan = (long)(captime - dtZero).TotalSeconds;
- IntPtr res = IntPtr.Zero;
- int[] resCount = new int[level.Length];
- if (refPos == null || refPos.Length == 0)
- {
- GDOPApi.Gdop3SatNoRef(mainLines, adajLines, adajLines2, timeSpan, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
- }
- else
- {
- GDOPApi.Gdop3SatRef(mainLines, adajLines, adajLines2, timeSpan, refPos, dtousErr, ephLocErr, level, level.Length, resCount, out res, satllh);
- }
- IntPtr tmp = res;
- //用于绘制的数据
- List<double[]> points = new List<double[]>();
- for (int idx = 0; idx < level.Length; ++idx)
- {
- double[] levelval = new double[resCount[idx]];
- Marshal.Copy(tmp, levelval, 0, resCount[idx]);
- tmp += (resCount[idx] * sizeof(double));
- points.Add(levelval);
- }
- GDOPApi.FreeGDOPBuf(res);
- List<MapSatInfo> satInfos = ParseResult(satCount, satllh, mainLines, adajLines, adajLines2);
- List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
- for (int i = 0; i < points.Count; i++)
- {
- if (!points[i].Any()) continue;
- ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
- errDistanceMap.ErrDistance = level[i];
- errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
- errs.Add(errDistanceMap);
- }
- return (satInfos, errs);
- }
- public static (List<MapSatInfo>, List<ErrDistanceMapPoints>) Gdop3SatDF(string mainLines, string adajLines, string adajLines2,
- DateTime captime, double fuHz1, double fuHz2, double dfoErr, double ephLocErr, double ephVErr, double[] refPos)
- {
- int satCount = 3;
- //该值和points 一一对应
- double[] level = GdopParam.误差配置.误差距离m;
- double[] satllh = new double[satCount * 3];
- var timeSpan = (long)(captime - dtZero).TotalSeconds;
- IntPtr res = IntPtr.Zero;
- int[] resCount = new int[level.Length];
- GDOPApi.Gdop3SatDF(mainLines, adajLines, adajLines2, timeSpan, refPos,fuHz1,fuHz2,dfoErr, ephLocErr,ephVErr, level, level.Length, resCount, out res, satllh);
- IntPtr tmp = res;
- //用于绘制的数据
- List<double[]> points = new List<double[]>();
- for (int idx = 0; idx < level.Length; ++idx)
- {
- double[] levelval = new double[resCount[idx]];
- Marshal.Copy(tmp, levelval, 0, resCount[idx]);
- tmp += (resCount[idx] * sizeof(double));
- points.Add(levelval);
- }
- GDOPApi.FreeGDOPBuf(res);
- List<MapSatInfo> satInfos = ParseResult(satCount, satllh, mainLines, adajLines, adajLines2);
- List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
- for (int i = 0; i < points.Count; i++)
- {
- if (!points[i].Any()) continue;
- ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
- errDistanceMap.ErrDistance = level[i];
- errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
- errs.Add(errDistanceMap);
- }
- return (satInfos, errs);
- }
- public static (List<MapSatInfo>, List<ErrDistanceMapPoints>) Gdop2SatDRef(string mainLines, string adajLines,
- DateTime captime, double fuHz1, double fuHz2, double dtousErr, double dfoErr, double ephLocErr, double ephVErr, double[] refPos)
- {
- int satCount = 2;
- //该值和points 一一对应
- double[] level = GdopParam.误差配置.误差距离m;
- double[] satllh = new double[satCount * 3];
- var timeSpan = (long)(captime - dtZero).TotalSeconds;
- IntPtr res = IntPtr.Zero;
- int[] resCount = new int[level.Length];
- GDOPApi.Gdop2SatDRef(mainLines, adajLines, timeSpan, refPos, fuHz1, fuHz2, dtousErr, dfoErr, ephLocErr, ephVErr, level, level.Length, resCount, out res, satllh);
- IntPtr tmp = res;
- //用于绘制的数据
- List<double[]> points = new List<double[]>();
- for (int idx = 0; idx < level.Length; ++idx)
- {
- double[] levelval = new double[resCount[idx]];
- Marshal.Copy(tmp, levelval, 0, resCount[idx]);
- tmp += (resCount[idx] * sizeof(double));
- points.Add(levelval);
- }
- GDOPApi.FreeGDOPBuf(res);
- List<MapSatInfo> satInfos = ParseResult(satCount, satllh, mainLines, adajLines);
- List<ErrDistanceMapPoints> errs = new List<ErrDistanceMapPoints>();
- for (int i = 0; i < points.Count; i++)
- {
- if (!points[i].Any()) continue;
- ErrDistanceMapPoints errDistanceMap = new ErrDistanceMapPoints();
- errDistanceMap.ErrDistance = level[i];
- errDistanceMap.MapDots.AddRange(ParseResult(points[i]));
- errs.Add(errDistanceMap);
- }
- return (satInfos, errs);
- }
- private static List<MapDot> ParseResult(double[] ponits)
- {
- List<MapDot> mapDots = new List<MapDot>();
- int count = 2;
- for (int i = 0; i < ponits.Length / count; i++)
- {
- MapDot mapDot = new MapDot();
- mapDot.Lat = ponits[count * i + 1];
- mapDot.Lon = ponits[count * i];
- mapDots.Add(mapDot);
- }
- return mapDots;
- }
- private static List<MapSatInfo> ParseResult(int satCount, double[] satllh, params string[] ephLine)
- {
- List<MapSatInfo> list = new List<MapSatInfo>();
- int len = 3;
- for (int i = 0; i < satCount; i++)
- {
- MapSatInfo satInfo = new MapSatInfo();
- var ephstrs = ephLine[i].Split(new string[] { " ", "U" }, StringSplitOptions.RemoveEmptyEntries);
- if (ephstrs.Length == 16)
- {
- satInfo.SatCode = Convert.ToInt32(ephstrs[1]);
- }
- satInfo.SatLon = Convert.ToDouble(satllh[len * i]);
- satInfo.SatLat = Convert.ToDouble(satllh[len * i + 1]);
- list.Add(satInfo);
- }
- return list;
- }
- }
- }
|