123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace XdCxRhDW.Core.Api
- {
- /// <summary>
- /// 星历推算帮助类.该类调用了Tle2XYZ.exe进程
- /// </summary>
- public static class EphHelper2
- {
- private static readonly DateTime dtZero = new DateTime(1970, 1, 1, 0, 0, 0, 0);
- private const string dll = @"AddIns\Tle2XYZ.dll";//此dll已加密
- #region cpp dll Interop
- [DllImport(dll, EntryPoint = "GenerateXYZByPeriod", CallingConvention = CallingConvention.Cdecl)]
- private extern static void GenerateXYZByPeriod();
- [DllImport(dll, EntryPoint = "GenerateXYZByPeriodWithOrbit", CallingConvention = CallingConvention.Cdecl)]
- private extern static void GenerateXYZByPeriodWithOrbit();
- [DllImport(dll, EntryPoint = "GenerateXYZByTimes", CallingConvention = CallingConvention.Cdecl)]
- private extern static void GenerateXYZByTimes();
- #endregion
- /// <summary>
- /// 推算双行星历
- /// </summary>
- /// <param name="tleStr">双行根数</param>
- /// <param name="dt">指定时刻(北京时间)</param>
- /// <returns></returns>
- public static SatEphDto2 Calc(string tleStr, DateTime dt)
- {
- if (string.IsNullOrWhiteSpace(dll))
- throw new Exception($"找不到{dll}");
- return null;
- }
- /// <summary>
- /// 批量推算双行星历
- /// </summary>
- /// <param name="tleStr">双行根数</param>
- /// <param name="start">起始时刻(北京)</param>
- /// <param name="end">结束(北京)</param>
- /// <param name="spanSeconds">推算间隔(秒)</param>
- /// <returns></returns>
- public static List<SatEphDto2> CalcMult(string tleStr, DateTime start, DateTime end, int spanSeconds)
- {
- if (string.IsNullOrWhiteSpace(dll))
- throw new Exception($"找不到{dll}");
- return null;
- }
- static List<SatEphDto2> ParseResult(string result)
- {
- if (string.IsNullOrWhiteSpace(result))
- {
- throw new Exception("星历推算出现未知错误!");
- }
- var array = result.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- List<SatEphDto2> list = new List<SatEphDto2>();
- foreach (var item in array)
- {
- var arrayItem = item.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < arrayItem.Length; i++)
- {
- var dto = new SatEphDto2
- {
- SatId = Convert.ToInt32(arrayItem[i++]),
- TleTime = dtZero.AddSeconds(Convert.ToInt64(arrayItem[i++])).AddHours(16),//内部有BUG需要多加8h
- SatTime = dtZero.AddSeconds(Convert.ToInt64(arrayItem[i++])).AddHours(8),//utc to beijing
- X = Math.Round(Convert.ToDouble(arrayItem[i++]), 3),
- Y = Math.Round(Convert.ToDouble(arrayItem[i++]), 3),
- Z = Math.Round(Convert.ToDouble(arrayItem[i++]), 3),
- VX = Math.Round(Convert.ToDouble(arrayItem[i++]), 3),
- VY = Math.Round(Convert.ToDouble(arrayItem[i++]), 3),
- VZ = Math.Round(Convert.ToDouble(arrayItem[i]), 3)
- };
- list.Add(dto);
- }
- }
- return list;
- }
- static SatEphDto2 ParseOneResult(string result)
- {
- if (string.IsNullOrWhiteSpace(result))
- {
- throw new Exception("星历推算出现未知错误!");
- }
- result = result.Replace(";", "");
- var array = result.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- int i = 0;
- var dto = new SatEphDto2
- {
- SatId = Convert.ToInt32(array[i++]),
- TleTime = dtZero.AddSeconds(Convert.ToInt64(array[i++])).AddHours(16),//内部有BUG需要多加8h
- SatTime = dtZero.AddSeconds(Convert.ToInt64(array[i++])).AddHours(8),//utc to beijing
- X = Math.Round(Convert.ToDouble(array[i++]), 3),
- Y = Math.Round(Convert.ToDouble(array[i++]), 3),
- Z = Math.Round(Convert.ToDouble(array[i++]), 3),
- VX = Math.Round(Convert.ToDouble(array[i++]), 3),
- VY = Math.Round(Convert.ToDouble(array[i++]), 3),
- VZ = Math.Round(Convert.ToDouble(array[i++]), 3)
- };
- return dto;
- }
- }
- public class SatEphDto2
- {
- /// <summary>
- /// 卫星编号
- /// </summary>
- [Display(Name = "卫星编号")]
- public int SatId { get; set; }
- /// <summary>
- /// 卫星时刻(北京时间)
- /// </summary>
- [Display(Name = "卫星时刻")]
- public DateTime SatTime { get; set; }
- /// <summary>
- /// 星历时刻(北京时间)
- /// </summary>
- [Display(Name = "星历时刻")]
- public DateTime TleTime { get; set; }
- /// <summary>
- /// X坐标
- /// </summary>
- [Display(Name = "X")]
- public double X { get; set; }
- /// <summary>
- /// Y坐标
- /// </summary>
- [Display(Name = "Y")]
- public double Y { get; set; }
- /// <summary>
- /// Z坐标
- /// </summary>
- [Display(Name = "Z")]
- public double Z { get; set; }
- /// <summary>
- /// X方向速率
- /// </summary>
- [Display(Name = "VX")]
- public double VX { get; set; }
- /// <summary>
- /// Y方向速率
- /// </summary>
- [Display(Name = "VY")]
- public double VY { get; set; }
- /// <summary>
- /// Z方向速率
- /// </summary>
- [Display(Name = "VZ")]
- public double VZ { get; set; }
- public override string ToString()
- {
- return $"{X},{Y},{Z},{VX},{VY},{VZ}";
- }
- }
- }
|