X2D1Task.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using DevExpress.Utils.About;
  2. using MySql.Data.MySqlClient;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Security.Policy;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using XdCxRhDw;
  11. using XdCxRhDW.Dto;
  12. using ZstdSharp.Unsafe;
  13. namespace XdCxRhDW.TaskServer.Task
  14. {
  15. public class X2D1Task : HistoryTaskI
  16. {
  17. public override void Start(HistoryTaskProcessingDto dto)
  18. {
  19. IsRuning = true;
  20. System.Threading.Tasks.Task.Run(async () =>
  21. {
  22. DateTime preTime = dto.StartTime;
  23. while (IsRuning || dto.EndTime.HasValue && dto.EndTime <= DateTime.Now)
  24. {
  25. string capfile = Path.Combine(dto.CapDir, $"{preTime.ToString(dto.DateDirFormat)}");
  26. var files = Directory.EnumerateFiles(capfile, "*.dat");
  27. /* ch1 = 超短波信号
  28. ch2 = 主星
  29. ch3 = 邻1
  30. ch4 = 采集卡4通道采集没接信号的那一路,不用管这路文件*/
  31. var groups = files.Select(f => FileToHistoryFile(f)).GroupBy(m => m.CapTime).OrderBy(m => m.Key);
  32. foreach (var item in groups)
  33. {
  34. var finfos = item.ToList();
  35. if (finfos.Count < 3)
  36. {
  37. LogHelper.Info($"历史任务:{dto.ID}采集时刻:{finfos.First().CapTime:yyyy-MM-dd HH:mm:ss}文件数量只有{finfos.Count}个,不满足");
  38. continue;
  39. }
  40. //超短波信号
  41. var dinfo = finfos.First(m => m.Ch == 1);
  42. //主星
  43. var minfo = finfos.First(m => m.Ch == 2);
  44. //邻1
  45. var ninfo = finfos.First(m => m.Ch == 3);
  46. try
  47. {
  48. //根据信号类型执行检测或参数估计
  49. if (dto.SigType == EnumSigTypeDto.Normal)
  50. {
  51. var xd = await GPUCalcAsync(minfo.FilePath, dinfo.FilePath, minfo.FsHz);
  52. var sx = await GPUCalcAsync(minfo.FilePath, ninfo.FilePath, minfo.FsHz);
  53. X2D1NoXlPosDto x2D1 = new X2D1NoXlPosDto()
  54. {
  55. SigTime = minfo.CapTime,
  56. MainCode = minfo.SatId,
  57. AdjaCode = ninfo.SatId,
  58. SxDto = sx.Dt * 1e6,
  59. XdDto = xd.Dt * 1e6,
  60. /* MainYbDto = Convert.ToDouble(items[2]) * 1e6,
  61. /AdjaYbDto = Convert.ToDouble(items[3]) * 1e6,
  62. SatTxLon = IniFiles.ReadValue<double>("Station_Data2023.ini", "卫星接收天线", "Lon"),
  63. SatTxLat = IniFiles.ReadValue<double>("Station_Data2023.ini", "卫星接收天线", "Lat"),
  64. CdbTxLon = IniFiles.ReadValue<double>("Station_Data2023.ini", "超短波接收天线", "Lon"),
  65. CdbTxLat = IniFiles.ReadValue<double>("Station_Data2023.ini", "超短波接收天线", "Lat"),
  66. RefLon = IniFiles.ReadValue<double>("Station_Data2023.ini", "参考站", "Lon"),
  67. RefLat = IniFiles.ReadValue<double>("Station_Data2023.ini", "参考站", "Lat"),
  68. FreqDown = 295.425e6,//For Api Test
  69. FreqUp = 260.425e6,//For Api Test*/
  70. XdDfo = xd.Df,
  71. XdSnr = xd.Snr,
  72. SxDfo = sx.Df,
  73. SxSnr = sx.Snr,
  74. };
  75. await X2D1NoXlAsync(x2D1);
  76. }
  77. else
  78. {
  79. var mDetect = await DAMAAsync(DmcTypeDto.DAMA, minfo.FsHz, minfo.FilePath);
  80. var dfile = await ToResampleAsync((int)dinfo.FsHz, dinfo.FilePath);
  81. var nfile = await ToResampleAsync((int)ninfo.FsHz, ninfo.FilePath);
  82. foreach (var deitem in mDetect)
  83. {
  84. var xd = await CPUCalcAsync(deitem.File1, dfile.File, dfile.OutFsHz, deitem);
  85. var sx = await CPUCalcAsync(deitem.File1, nfile.File, nfile.OutFsHz, deitem);
  86. X2D1NoXlPosDto x2D1 = new X2D1NoXlPosDto()
  87. {
  88. SigTime = minfo.CapTime.AddSeconds(deitem.Start / nfile.OutFsHz),
  89. MainCode = minfo.SatId,
  90. AdjaCode = ninfo.SatId,
  91. SxDto = sx.Dt * 1e6,
  92. XdDto = xd.Dt * 1e6,
  93. /* MainYbDto = Convert.ToDouble(items[2]) * 1e6,
  94. /AdjaYbDto = Convert.ToDouble(items[3]) * 1e6,
  95. SatTxLon = IniFiles.ReadValue<double>("Station_Data2023.ini", "卫星接收天线", "Lon"),
  96. SatTxLat = IniFiles.ReadValue<double>("Station_Data2023.ini", "卫星接收天线", "Lat"),
  97. CdbTxLon = IniFiles.ReadValue<double>("Station_Data2023.ini", "超短波接收天线", "Lon"),
  98. CdbTxLat = IniFiles.ReadValue<double>("Station_Data2023.ini", "超短波接收天线", "Lat"),
  99. RefLon = IniFiles.ReadValue<double>("Station_Data2023.ini", "参考站", "Lon"),
  100. RefLat = IniFiles.ReadValue<double>("Station_Data2023.ini", "参考站", "Lat"),
  101. FreqDown = 295.425e6,//For Api Test
  102. FreqUp = 260.425e6,//For Api Test*/
  103. XdDfo = xd.Df,
  104. XdSnr = xd.Snr,
  105. SxDfo = sx.Df,
  106. SxSnr = sx.Snr,
  107. };
  108. await X2D1NoXlAsync(x2D1);
  109. }
  110. }
  111. }
  112. catch (Exception ex)
  113. {
  114. LogHelper.Info($"执行历史任务:{dto.ID}异常:{ex.Message}");
  115. continue;
  116. }
  117. }
  118. preTime = preTime.AddHours(1);
  119. }
  120. });
  121. }
  122. private async Task<bool> X2D1NoXlAsync(X2D1NoXlPosDto x2D1)
  123. {
  124. var result = await HttpHelper.PostRequestAsync<PosResDto>(baseUrl + "Pos/PosX2D1NoXlAsync", x2D1);
  125. if (result.code != 200)
  126. {
  127. return false;
  128. }
  129. return true;
  130. }
  131. /// <summary>
  132. /// 获取采集文件信息
  133. /// </summary>
  134. /// <param name="filePath"></param>
  135. /// <returns></returns>
  136. private HistoryFile FileToHistoryFile(string filePath)
  137. { //读取采集文件
  138. //2024_01_31_10_01_51_000000000_ch11_-1__Nxx.xxxxxx_Exx.xxxxxx_xxxxx.xxxHz_xxx.xxxMHz_ch1_xd1.dat
  139. HistoryFile historyFile = new HistoryFile();
  140. historyFile.FilePath = filePath;
  141. var fileName = Path.GetFileNameWithoutExtension(filePath);
  142. var strs = fileName.Split(new string[] { "_", "MHz", "Hz", "ch" }, StringSplitOptions.RemoveEmptyEntries);
  143. //采集时间
  144. var datestr = string.Join("_", strs.Take(6));
  145. historyFile.CapTime = DateTime.ParseExact(datestr, "yyyy_MM_dd_HH_mm_ss", null);
  146. //采集通道
  147. var chstr = strs.Skip(strs.Length - 2).Take(1).First();
  148. int ch;
  149. int.TryParse(chstr, out ch);
  150. //采集频点
  151. var freqstr = strs.Skip(strs.Length - 3).Take(1).First();
  152. double freqMHz;
  153. double.TryParse(freqstr, out freqMHz);
  154. //采样率
  155. var fsstr = strs.Skip(strs.Length - 4).Take(1).First();
  156. double fsHz;
  157. double.TryParse(fsstr, out fsHz);
  158. historyFile.FreqHz = freqMHz * 1e6;
  159. historyFile.Ch = ch;
  160. historyFile.FsHz = fsHz;
  161. if (ch > 1)
  162. {
  163. historyFile.SatId = GetSatId(historyFile.FreqHz);
  164. }
  165. return historyFile;
  166. }
  167. }
  168. }