123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- using DevExpress.Utils.About;
- using MySql.Data.MySqlClient;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Security.Policy;
- using System.Text;
- using System.Threading.Tasks;
- using XdCxRhDw;
- using XdCxRhDW.Dto;
- using ZstdSharp.Unsafe;
- namespace XdCxRhDW.TaskServer.Task
- {
- public class X2D1Task : HistoryTaskI
- {
- public override void Start(HistoryTaskProcessingDto dto)
- {
- IsRuning = true;
- System.Threading.Tasks.Task.Run(async () =>
- {
- DateTime preTime = dto.StartTime;
- while (IsRuning || dto.EndTime.HasValue && dto.EndTime <= DateTime.Now)
- {
- string capfile = Path.Combine(dto.CapDir, $"{preTime.ToString(dto.DateDirFormat)}");
- var files = Directory.EnumerateFiles(capfile, "*.dat");
- /* ch1 = 超短波信号
- ch2 = 主星
- ch3 = 邻1
- ch4 = 采集卡4通道采集没接信号的那一路,不用管这路文件*/
- var groups = files.Select(f => FileToHistoryFile(f)).GroupBy(m => m.CapTime).OrderBy(m => m.Key);
- foreach (var item in groups)
- {
- var finfos = item.ToList();
- if (finfos.Count < 3)
- {
- LogHelper.Info($"历史任务:{dto.ID}采集时刻:{finfos.First().CapTime:yyyy-MM-dd HH:mm:ss}文件数量只有{finfos.Count}个,不满足");
- continue;
- }
- //超短波信号
- var dinfo = finfos.First(m => m.Ch == 1);
- //主星
- var minfo = finfos.First(m => m.Ch == 2);
- //邻1
- var ninfo = finfos.First(m => m.Ch == 3);
- try
- {
- //根据信号类型执行检测或参数估计
- if (dto.SigType == EnumSigTypeDto.Normal)
- {
- var xd = await GPUCalcAsync(minfo.FilePath, dinfo.FilePath, minfo.FsHz);
- var sx = await GPUCalcAsync(minfo.FilePath, ninfo.FilePath, minfo.FsHz);
- X2D1NoXlPosDto x2D1 = new X2D1NoXlPosDto()
- {
- SigTime = minfo.CapTime,
- MainCode = minfo.SatId,
- AdjaCode = ninfo.SatId,
- SxDto = sx.Dt * 1e6,
- XdDto = xd.Dt * 1e6,
- /* MainYbDto = Convert.ToDouble(items[2]) * 1e6,
- /AdjaYbDto = Convert.ToDouble(items[3]) * 1e6,
- SatTxLon = IniFiles.ReadValue<double>("Station_Data2023.ini", "卫星接收天线", "Lon"),
- SatTxLat = IniFiles.ReadValue<double>("Station_Data2023.ini", "卫星接收天线", "Lat"),
- CdbTxLon = IniFiles.ReadValue<double>("Station_Data2023.ini", "超短波接收天线", "Lon"),
- CdbTxLat = IniFiles.ReadValue<double>("Station_Data2023.ini", "超短波接收天线", "Lat"),
- RefLon = IniFiles.ReadValue<double>("Station_Data2023.ini", "参考站", "Lon"),
- RefLat = IniFiles.ReadValue<double>("Station_Data2023.ini", "参考站", "Lat"),
- FreqDown = 295.425e6,//For Api Test
- FreqUp = 260.425e6,//For Api Test*/
- XdDfo = xd.Df,
- XdSnr = xd.Snr,
- SxDfo = sx.Df,
- SxSnr = sx.Snr,
- };
- await X2D1NoXlAsync(x2D1);
- }
- else
- {
- var mDetect = await DAMAAsync(DmcTypeDto.DAMA, minfo.FsHz, minfo.FilePath);
- var dfile = await ToResampleAsync((int)dinfo.FsHz, dinfo.FilePath);
- var nfile = await ToResampleAsync((int)ninfo.FsHz, ninfo.FilePath);
- foreach (var deitem in mDetect)
- {
- var xd = await CPUCalcAsync(deitem.File1, dfile.File, dfile.OutFsHz, deitem);
- var sx = await CPUCalcAsync(deitem.File1, nfile.File, nfile.OutFsHz, deitem);
- X2D1NoXlPosDto x2D1 = new X2D1NoXlPosDto()
- {
- SigTime = minfo.CapTime.AddSeconds(deitem.Start / nfile.OutFsHz),
- MainCode = minfo.SatId,
- AdjaCode = ninfo.SatId,
- SxDto = sx.Dt * 1e6,
- XdDto = xd.Dt * 1e6,
- /* MainYbDto = Convert.ToDouble(items[2]) * 1e6,
- /AdjaYbDto = Convert.ToDouble(items[3]) * 1e6,
- SatTxLon = IniFiles.ReadValue<double>("Station_Data2023.ini", "卫星接收天线", "Lon"),
- SatTxLat = IniFiles.ReadValue<double>("Station_Data2023.ini", "卫星接收天线", "Lat"),
- CdbTxLon = IniFiles.ReadValue<double>("Station_Data2023.ini", "超短波接收天线", "Lon"),
- CdbTxLat = IniFiles.ReadValue<double>("Station_Data2023.ini", "超短波接收天线", "Lat"),
- RefLon = IniFiles.ReadValue<double>("Station_Data2023.ini", "参考站", "Lon"),
- RefLat = IniFiles.ReadValue<double>("Station_Data2023.ini", "参考站", "Lat"),
- FreqDown = 295.425e6,//For Api Test
- FreqUp = 260.425e6,//For Api Test*/
- XdDfo = xd.Df,
- XdSnr = xd.Snr,
- SxDfo = sx.Df,
- SxSnr = sx.Snr,
- };
- await X2D1NoXlAsync(x2D1);
- }
- }
- }
- catch (Exception ex)
- {
- LogHelper.Info($"执行历史任务:{dto.ID}异常:{ex.Message}");
- continue;
- }
- }
- preTime = preTime.AddHours(1);
- }
- });
- }
- private async Task<bool> X2D1NoXlAsync(X2D1NoXlPosDto x2D1)
- {
- var result = await HttpHelper.PostRequestAsync<PosResDto>(baseUrl + "Pos/PosX2D1NoXlAsync", x2D1);
- if (result.code != 200)
- {
- return false;
- }
- return true;
- }
- /// <summary>
- /// 获取采集文件信息
- /// </summary>
- /// <param name="filePath"></param>
- /// <returns></returns>
- private HistoryFile FileToHistoryFile(string filePath)
- { //读取采集文件
- //2024_01_31_10_01_51_000000000_ch11_-1__Nxx.xxxxxx_Exx.xxxxxx_xxxxx.xxxHz_xxx.xxxMHz_ch1_xd1.dat
- HistoryFile historyFile = new HistoryFile();
- historyFile.FilePath = filePath;
- var fileName = Path.GetFileNameWithoutExtension(filePath);
- var strs = fileName.Split(new string[] { "_", "MHz", "Hz", "ch" }, StringSplitOptions.RemoveEmptyEntries);
- //采集时间
- var datestr = string.Join("_", strs.Take(6));
- historyFile.CapTime = DateTime.ParseExact(datestr, "yyyy_MM_dd_HH_mm_ss", null);
- //采集通道
- var chstr = strs.Skip(strs.Length - 2).Take(1).First();
- int ch;
- int.TryParse(chstr, out ch);
- //采集频点
- var freqstr = strs.Skip(strs.Length - 3).Take(1).First();
- double freqMHz;
- double.TryParse(freqstr, out freqMHz);
- //采样率
- var fsstr = strs.Skip(strs.Length - 4).Take(1).First();
- double fsHz;
- double.TryParse(fsstr, out fsHz);
- historyFile.FreqHz = freqMHz * 1e6;
- historyFile.Ch = ch;
- historyFile.FsHz = fsHz;
- if (ch > 1)
- {
- historyFile.SatId = GetSatId(historyFile.FreqHz);
- }
- return historyFile;
- }
- }
- }
|