123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- using DevExpress.Utils.About;
- using MySql.Data.MySqlClient;
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Security.Policy;
- using System.Text;
- using System.Threading;
- 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;
- TaskDto = dto;
- 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)}");
- IEnumerable<string> files;
- try
- {
- files = Directory.EnumerateFiles(capfile, "*.dat");
- }
- catch (Exception ex)
- {
- LogHelper.Info($"查询历史任务:{dto.ID}采集数据异常:{ex.Message}");
- Thread.Sleep(1000);
- continue;
- }
- var groups = files.Select(f => FileToHistoryFile(f)).GroupBy(m => m.CapTime).OrderBy(m => m.Key);
- foreach (var item in groups)
- {
- if (!IsRuning)
- {
- break;
- }
- 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.FirstOrDefault(m => m.Ch == 1);
- if (dinfo == null)
- {
- LogHelper.Info($"历史任务:{dto.ID}采集时刻:{finfos.First().CapTime:yyyy-MM-dd HH:mm:ss}未找到超短波信号ch1文件,不满足");
- continue;
- }
- //主星
- var minfo = finfos.FirstOrDefault(m => m.Ch == 2);
- if (minfo == null)
- {
- LogHelper.Info($"历史任务:{dto.ID}采集时刻:{finfos.First().CapTime:yyyy-MM-dd HH:mm:ss}未找到主星信号ch2文件,不满足");
- continue;
- }
- //邻1
- var ninfo = finfos.FirstOrDefault(m => m.Ch == 3);
- if (ninfo == null)
- {
- LogHelper.Info($"历史任务:{dto.ID}采集时刻:{finfos.First().CapTime:yyyy-MM-dd HH:mm:ss}未找到邻星信号ch3文件,不满足");
- continue;
- }
- try
- {
- var txInfos = await GetTxInfoAsync();
- var satTx = txInfos.First(t => t.TxType == EnumTxType.Rec);
- var cdbTx = txInfos.First(t => t.TxType == EnumTxType.Cdb);
- var refTx = txInfos.First(t => t.TxType == EnumTxType.Ref);
- //根据信号类型执行检测或参数估计
- if (dto.SigType == EnumSigTypeDto.Normal)
- {
- var xd = await GPUCalcAsync(minfo.FilePath, dinfo.FilePath, minfo.FsHz, 260000, 40000);
- var sx = await GPUCalcAsync(minfo.FilePath, ninfo.FilePath, minfo.FsHz, 0, 40000);
- X2D1NoXlPosDto x2D1 = new X2D1NoXlPosDto()
- {
- SigTime = minfo.CapTime,
- MainCode = minfo.SatId,
- AdjaCode = ninfo.SatId,
- SxDto = sx.Dt,
- XdDto = xd.Dt,
- SatTxLon = satTx.Lon,
- SatTxLat = satTx.Lat,
- CdbTxLon = cdbTx.Lon,
- CdbTxLat = cdbTx.Lat,
- RefLon = refTx.Lon,
- RefLat = refTx.Lat,
- FreqDown = minfo.FreqHz * 1e-6,
- FreqUp = dinfo.FreqHz * 1e-6,
- XdDfo = xd.Df,
- XdSnr = xd.Snr,
- SxDfo = sx.Df,
- SxSnr = sx.Snr,
- };
- await X2D1NoXlAsync(x2D1);
- }
- else
- {
- var mDetect = await DAMAAsync(dto.TaskCheckType, 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)
- {
- if (!IsRuning)
- {
- break;
- }
- try
- {
- var xd = await CPUCalcAsync(deitem.File1, dfile.File, dfile.OutFsHz, deitem, 260000, 40000);
- Thread.Sleep(100);
- var sx = await CPUCalcAsync(deitem.File1, nfile.File, nfile.OutFsHz, deitem, 0, 40000);
- X2D1NoXlPosDto x2D1 = new X2D1NoXlPosDto()
- {
- SigTime = minfo.CapTime.AddSeconds(deitem.Start / nfile.OutFsHz),
- MainCode = minfo.SatId,
- AdjaCode = ninfo.SatId,
- SxDto = sx.Dt,
- XdDto = xd.Dt,
- SatTxLon = satTx.Lon,
- SatTxLat = satTx.Lat,
- CdbTxLon = cdbTx.Lon,
- CdbTxLat = cdbTx.Lat,
- RefLon = refTx.Lon,
- RefLat = refTx.Lat,
- FreqDown = minfo.FreqHz * 1e-6,
- FreqUp = dinfo.FreqHz * 1e-6,
- XdDfo = xd.Df,
- XdSnr = xd.Snr,
- SxDfo = sx.Df,
- SxSnr = sx.Snr,
- CheckRes = new CheckResDto()
- {
- FileName = deitem.File1,
- ModRate = deitem.ModRate,
- ModType = deitem.ModType,
- SmpCount = deitem.Length,
- SmpStart = deitem.Start,
- UserName = deitem.UserName,
- PosCheckType = deitem.DmcType.GetEnumByDisplayName<EnumPosCheckTypeDto>(),
- }
- };
- await X2D1NoXlAsync(x2D1);
- }
- catch (Exception ex)
- {
- LogHelper.Info($"历史任务:{dto.ID}异常:{ex.Message}");
- continue;
- }
- }
- }
- }
- 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;
- }
- private async Task<List<TxInfo>> GetTxInfoAsync()
- {
- List<TxInfo> infos = new List<TxInfo>();
- var result = await HttpHelper.GetRequestAsync<(TxInfo recTx, TxInfo cdbTx, TxInfo cxTx, TxInfo refLoc)>(baseUrl + "Tx/GetTxInfoAsync");
- if (result.code != 200)
- {
- infos.Add(new TxInfo() { TxType = EnumTxType.Rec });
- infos.Add(new TxInfo() { TxType = EnumTxType.Cdb });
- infos.Add(new TxInfo() { TxType = EnumTxType.Cx });
- infos.Add(new TxInfo() { TxType = EnumTxType.Ref });
- LogHelper.Error($"历史任务获取天线信息失败");
- return infos;
- }
- infos.Add(result.data.recTx == null ? new TxInfo() { TxType = EnumTxType.Rec } : result.data.recTx);
- infos.Add(result.data.cdbTx == null ? new TxInfo() { TxType = EnumTxType.Cdb } : result.data.cdbTx);
- infos.Add(result.data.cxTx == null ? new TxInfo() { TxType = EnumTxType.Cx } : result.data.cxTx);
- infos.Add(result.data.refLoc == null ? new TxInfo() { TxType = EnumTxType.Ref } : result.data.refLoc);
- return infos;
- }
- /// <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));
- DateTime dateTime;
- bool istime = DateTime.TryParseExact(datestr, "yyyy_MM_dd_HH_mm_ss", null, DateTimeStyles.None, out dateTime);
- if (!istime) return historyFile;
- historyFile.CapTime = dateTime;
- //采集通道
- 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;
- }
- }
- }
|