PosController.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity;
  4. using System.Data.SqlClient;
  5. using System.Data.SQLite;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Web.Http;
  10. using PosResAnalysis;
  11. using Serilog;
  12. using XdCxRhDw.Dto;
  13. using XdCxRhDW.App.Api;
  14. using XdCxRhDW.App.EFContext;
  15. using XdCxRhDW.App.Model;
  16. using XdCxRhDW.App.WebAPI.DTO;
  17. using XdCxRhDW.Dto;
  18. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
  19. using static XdCxRhDw.CpuCgTools.FormCpuCg;
  20. using CgRes = XdCxRhDW.App.Model.CgRes;
  21. namespace XdCxRhDW.App.WebAPI
  22. {
  23. /// <summary>
  24. /// 定位功能相关接口
  25. /// </summary>
  26. public class PosController : BaseController
  27. {
  28. /// <summary>
  29. /// 执行两星一地定位
  30. /// </summary>
  31. /// <returns></returns>
  32. [HttpPost]
  33. public async Task<AjaxResult> PosX2D1Async(X2D1PosDto dto)
  34. {
  35. using (RHDWContext db = new RHDWContext())
  36. {
  37. var runTask = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running && p.PosType == EnumPosType.X2D1).FirstOrDefaultAsync();
  38. if (runTask == null)
  39. {
  40. Serilog.Log.Warning($"接收到两星一地定位参数,由于任务没有运行中忽略本次定位!");
  41. return Error($"多模式融合定位平台没有启动两星一地定位任务");
  42. }
  43. var listTx = await db.TxInfos.ToListAsync();
  44. var parameter1 = new SQLiteParameter("@sigTime", dto.SigTime);
  45. var parameter2 = new SQLiteParameter("@satcode", dto.MainSatID);
  46. var parameter3 = new SQLiteParameter("@satcode", dto.AdjaSatID);
  47. var xlInfo1 = await db.XlInfos.SqlQuery("select * from XlInfo where ABS(JULIANDAY(TimeBJ)-JULIANDAY(@sigTime))=(select min(ABS(JULIANDAY(TimeBJ)-JULIANDAY(@sigTime))) from XlInfo where satcode=@satcode)", parameter1, parameter2).FirstOrDefaultAsync();
  48. if (xlInfo1 == null)
  49. {
  50. Serilog.Log.Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  51. return Error($"未找到卫星[{dto.MainSatID}]的双行根数星历");
  52. }
  53. var xlInfo2 = await db.XlInfos.SqlQuery("select * from XlInfo where ABS(JULIANDAY(TimeBJ)-JULIANDAY(@sigTime))=(select min(ABS(JULIANDAY(TimeBJ)-JULIANDAY(@sigTime))) from XlInfo where satcode=@satcode)", parameter1, parameter3).FirstOrDefaultAsync();
  54. if (xlInfo2 == null)
  55. {
  56. Serilog.Log.Error($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  57. return Error($"未找到卫星[{dto.AdjaSatID}]的双行根数星历");
  58. }
  59. Serilog.Log.Information($"卫星{dto.MainSatID}使用{xlInfo1.TwoLine}进行星历推算");
  60. Serilog.Log.Information($"卫星{dto.AdjaSatID}使用{xlInfo2.TwoLine}进行星历推算");
  61. var ephMain = EphHelper.Calc(xlInfo1.TwoLine, dto.SigTime);
  62. var ephAdja = EphHelper.Calc(xlInfo2.TwoLine, dto.SigTime);
  63. var cgRes = db.CgRes.Add(new Model.CgRes()
  64. {
  65. SigTime = dto.SigTime,
  66. DtoSx = dto.SxDto,
  67. DfoSx = dto.SxDfo,
  68. SnrSx = dto.SxSnr,
  69. DtoCdb = dto.XdDto,
  70. DfoCdb = dto.XdDfo,
  71. SnrCdb = dto.XdSnr,
  72. YbMain = dto.MainYbDto,
  73. YbAdja = dto.AdjaYbDto,
  74. MainX = ephMain.X,
  75. MainY = ephMain.Y,
  76. MainZ = ephMain.Z,
  77. AdjaX = ephAdja.X,
  78. AdjaY = ephAdja.Y,
  79. AdjaZ = ephAdja.Z,
  80. });
  81. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  82. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  83. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  84. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  85. double[] mainSat = new double[3] { ephMain.X, ephMain.Y, ephMain.Z };
  86. double[] adjaSat = new double[3] { ephAdja.X, ephAdja.Y, ephAdja.Z };
  87. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  88. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  89. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  90. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  91. double[] res = new double[6];
  92. PosApi.X2D1_POS_Core(mainSat, adjaSat, cdbStation, satStation, satStation, satStation, satStation, satStation, refStation, zone, dto.SxDto / 1e6, dto.XdDto / 1e6, dto.MainYbDto / 1e6, dto.AdjaYbDto / 1e6, res);
  93. PosRes posRes = new PosRes()
  94. {
  95. SigTime = dto.SigTime,
  96. TaskID = runTask.ID,
  97. CgResID = cgRes.ID,
  98. TarName = string.IsNullOrWhiteSpace(dto.TarName) ? "未知目标" : dto.TarName,
  99. TsName = dto.TsName,
  100. PosLon = res[0],
  101. PosLat = res[1],
  102. MirrLon = res[3],
  103. MirrLat = res[4],
  104. };
  105. db.PosRes.Add(posRes);
  106. await db.SaveChangesAsync();
  107. }
  108. return Success();
  109. }
  110. /// <summary>
  111. /// 推送时有星厉
  112. /// </summary>
  113. /// <param name="dto"></param>
  114. /// <returns></returns>
  115. readonly Random r = new Random();
  116. [HttpPost]
  117. public async Task<AjaxResult<double[]>> PosX1D1Async(IEnumerable<SendDto> dtoList)
  118. {
  119. using (RHDWContext db = new RHDWContext())
  120. {
  121. foreach (var dto in dtoList)
  122. {
  123. var sigTime = DateTime.Now;
  124. var cgRes = db.CgRes.Add(new CgRes()
  125. {
  126. SigTime = sigTime,
  127. DtoSx = dto.SxDto * 1e6,
  128. DfoSx = 200 + r.Next(1, 5) + Math.Round(r.NextDouble(), 3),
  129. SnrSx = r.Next(18, 24) + Math.Round(r.NextDouble(), 1),
  130. DtoCdb = dto.XdDto * 1e6,
  131. DfoCdb = 600 + r.Next(1, 5) + Math.Round(r.NextDouble(), 3),
  132. SnrCdb = r.Next(22, 32) + Math.Round(r.NextDouble(), 1),
  133. YbMain = dto.MainYbDto * 1e6,
  134. YbAdja = dto.AdjaYbDto * 1e6,
  135. MainX = dto.MainX,
  136. MainY = dto.MainY,
  137. MainZ = dto.MainZ,
  138. AdjaX = dto.AdjaX,
  139. AdjaY = dto.AdjaY,
  140. AdjaZ = dto.AdjaZ,
  141. });
  142. }
  143. }
  144. var satTx = listTx.Find(p => p.TxType == EnumTxType.MainSat);
  145. var cdbTx = listTx.Find(p => p.TxType == EnumTxType.Cdb);
  146. var cxTx = listTx.Find(p => p.TxType == EnumTxType.Cx);
  147. var refTx = listTx.Find(p => p.TxType == EnumTxType.Ref);
  148. double[] mainSat = new double[3] { cgRes.MainX, cgRes.MainY, cgRes.MainZ };
  149. double[] satStation = new double[3] { satTx.Lon, satTx.Lat, 0 };
  150. double[] cdbStation = new double[3] { cdbTx.Lon, cdbTx.Lat, 0 };
  151. double[] cxStation = new double[3] { cxTx.Lon, cxTx.Lat, 0 };
  152. double[] refStation = new double[3] { refTx.Lon, refTx.Lat, 0 };
  153. double[] zone = new double[] { -85, 85, -180, 180 }; //定位区域
  154. double theta = cxRes.Fx;//单位°
  155. double[] res = new double[6];
  156. PosApi.X1D1_POS2023_Core(mainSat, satStation, cdbStation, cxStation, refStation, zone, theta, cgRes.DtoCdb / 1e6, cgRes.YbMain / 1e6, res);
  157. return Success(res.Select(p => Math.Round(p, 4)).ToArray());
  158. }
  159. [HttpPost]
  160. //public async Task<AjaxResult<double[]>> PosX1D1NoXlAsync(CgRes cgRes, List<TxInfo> listTx, CxRes cxRes)
  161. //{
  162. //}
  163. /// <summary>
  164. /// 查询定位结果(暂未实现)
  165. /// </summary>
  166. /// <param name="dto"></param>
  167. /// <returns></returns>
  168. /// <exception cref="Exception"></exception>
  169. [HttpGet]
  170. public async Task<AjaxResult<PosResDto>> GetPosRes(PosResQueryDto dto)
  171. {
  172. await Task.Delay(100);
  173. return Error<PosResDto>("该功能暂未实现!");
  174. }
  175. }
  176. }