| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719 |
- using Microsoft.Win32.SafeHandles;
- using Org.BouncyCastle.Asn1.Pkcs;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Diagnostics;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Threading;
- using System.Threading.Tasks;
- using XdCxRhDW.Dto;
- using XdCxRhDW.Framework;
- namespace X3Leo1TaskServer54.Service
- {
- public class TaskService
- {
- public TaskSvrConfig _config;
- public TaskService()
- {
- try
- {
- Directory.CreateDirectory("tmp");
- _config = new TaskSvrConfig();
- _config.baseUrl = AppConfigHelper.Get("PosPlatformAddr").AppendUrlSuffix("api/");
- _config.capSeconds = AppConfigHelper.Get("CapSeconds", 60);
- _config.mainSatDelay = AppConfigHelper.Get<double?>("MainSatDelay");
- _config.adja1SatDelay = AppConfigHelper.Get<double?>("Adja1SatDelay");
- _config.adja2SatDelay = AppConfigHelper.Get<double?>("Adja2SatDelay");
- _config.checkFileType = AppConfigHelper.Get("CheckFileType", 0);
- _config.threadCount = AppConfigHelper.Get("ThreadCount", 0).NotLessThanZero();
- _config.posDtoFactor = AppConfigHelper.Get("PosDtoFactor", 1);
- _config.DtoErrus = AppConfigHelper.Get<double>("DtoErrus", 1);
- _config.EphErrm = AppConfigHelper.Get<double>("EphErrm", 10000);
- }
- catch (Exception ex)
- {
- XdCxRhDW.UI.Lib.LogHelper.Error("读取配置文件异常", ex).Wait(5000);
- }
- }
- //等待采集完成(根据文件字节大小判断是否完成,最多等待采集时长+5秒)
- internal async Task WaitFileEnd(int taskID, HistoryFile file, int capSeconds, CancellationTokenSource cts)
- {
- int idx = 0;
- Stopwatch sw = new Stopwatch();
- sw.Start();
- while (true)
- {
- FileInfo s = new FileInfo(file.FilePath);
- long fs = (long)file.FsHz;
- var fileSize = fs * capSeconds * 4;
- if (s.Length == fileSize)
- {
- break;
- }
- if (idx == 0)
- await XdCxRhDW.UI.Lib.LogHelper.Info($"【任务{taskID}】等待[{file.CapTime:yyyyMMddHHmmss}]时刻文件采集完成...");
- await Task.Delay(2000, cts.Token);
- if (sw.ElapsedMilliseconds / 1000 > capSeconds + 5)
- break;
- idx++;
- }
- sw.Stop();
- }
- /// <summary>
- /// 是否能打开文件
- /// </summary>
- /// <param name="taskID"></param>
- /// <param name="file"></param>
- /// <returns></returns>
- internal bool CanOpenFile(int taskID, HistoryFile file)
- {
- try
- {
- using (var fs = new FileStream(file.FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- {
- }
- return true;
- }
- catch (Exception ex)
- {
- XdCxRhDW.UI.Lib.LogHelper.Error($"【任务{taskID}】文件[{file.FilePath}]尝试打开失败", ex).Wait(5000);
- return false;
- }
- }
- /// <summary>
- /// 重置时间
- /// </summary>
- /// <param name="formatFlag"></param>
- /// <param name="time"></param>
- internal void ResetTime(int formatFlag, ref DateTime time)
- {
- if (formatFlag == 0)
- {
- time = DateTime.MaxValue;
- }
- else if (formatFlag == 1)
- {
- var newTime = new DateTime(time.Year, time.Month, time.Day, 0, 0, 0);
- time = newTime.AddHours(24);
- }
- else
- {
- var newTime = new DateTime(time.Year, time.Month, time.Day, time.Hour, 0, 0);
- time = newTime.AddHours(1);
- }
- }
- /// <summary>
- /// 获取采集文件信息
- /// </summary>
- /// <param name="dto"></param>
- /// <param name="filePath"></param>
- /// <param name="preTime"></param>
- /// <param name="ct"></param>
- /// <returns></returns>
- internal HistoryFile FileToHistoryFile(LeoSat3TaskHandleDto dto, string filePath, DateTime preTime, CancellationToken ct)
- {
- try
- {
- if (ct.IsCancellationRequested) return null;
- //读取采集文件
- //20240131100151_39206_310.850MHz_265.350MHz_C96000_CH2.dat
- HistoryFile historyFile = new HistoryFile();
- historyFile.FilePath = filePath;
- var fileName = Path.GetFileNameWithoutExtension(filePath);
- var strs = fileName.Split(new string[] { "_", "MHz", "CH", "ch", "C" }, StringSplitOptions.RemoveEmptyEntries);
- if (strs.Length == 6)
- { //采集时间
- var datestr = strs[0];
- DateTime dateTime;
- bool istime = DateTime.TryParseExact(datestr, "yyyyMMddHHmmss", null, DateTimeStyles.None, out dateTime);
- //卫星编号
- var satCodestr = strs[1];
- int.TryParse(satCodestr, out int satCode);
- //上行采集频点
- var upfreqstr = strs[2];
- double.TryParse(upfreqstr, out double upfreqMHz);
- //下行采集频点
- var downfreqstr = strs[3];
- double.TryParse(downfreqstr, out double downfreqMHz);
- //采样率
- var fsstr = strs[4];
- double.TryParse(fsstr, out double fsHz);
- var chstr = strs[5];
- int.TryParse(chstr, out int ch);
- historyFile.UpFreqHz = (long)((decimal)upfreqMHz * 1000000);
- historyFile.DownFreqHz = (long)((decimal)downfreqMHz * 1000000);
- historyFile.Ch = ch;
- historyFile.FsHz = fsHz;
- historyFile.XdIndex = 1;
- historyFile.SatId = satCode;
- historyFile.CapTime = dateTime;
- }
- else if (strs.Length == 13)
- {//采集时间
- var datestr = $"{strs[0]}{strs[1]}{strs[2]}{strs[3]}{strs[4]}{strs[5]}";
- DateTime dateTime;
- bool istime = DateTime.TryParseExact(datestr, "yyyyMMddHHmmss", null, DateTimeStyles.None, out dateTime);
- //采样率
- var fsstr = strs[8];
- Int64.TryParse(fsstr, out long fsHz);
- //卫星编号
- var satCodestr = strs[9];
- int.TryParse(satCodestr, out int satCode);
- //上行采集频点
- var upfreqstr = strs[10];
- double.TryParse(upfreqstr, out double upfreqMHz);
- //下行采集频点
- var downfreqstr = strs[11];
- double.TryParse(downfreqstr, out double downfreqMHz);
- var chstr = strs[12];
- int.TryParse(chstr, out int ch);
- historyFile.UpFreqHz = (long)((decimal)upfreqMHz * 1000000);
- historyFile.DownFreqHz = (long)((decimal)downfreqMHz * 1000000);
- historyFile.Ch = ch;
- historyFile.FsHz = fsHz;
- historyFile.XdIndex = 1;
- historyFile.SatId = satCode;
- historyFile.CapTime = dateTime;
- }
- else
- {
- return null;
- }
- return historyFile;
- }
- catch (Exception ex)
- {
- _=XdCxRhDW.UI.Lib.LogHelper.Error($"文件[{Path.GetFileName(filePath)}]名称格式异常,解析出错", ex);
- return null;
- }
- }
- internal bool IsLocal(string file)
- {
- if (file.StartsWith("\\")) return false;
- DirectoryInfo dir = new DirectoryInfo(file);
- foreach (DriveInfo d in DriveInfo.GetDrives())
- {
- if (string.Compare(dir.Root.FullName, d.Name, StringComparison.OrdinalIgnoreCase) == 0) //[drweb86] Fix for different case.
- {
- return (d.DriveType != DriveType.Network);
- }
- }
- return false;
- }
- internal List<List<IGrouping<long, HistoryFile>>> SplitFreqFiles(IEnumerable<IGrouping<long, HistoryFile>> multFreqFiles)
- {
- var thread = _config.threadCount;
- if (thread <= 0)
- thread = 1000;
- var list = new List<List<IGrouping<long, HistoryFile>>>();
- var count = multFreqFiles.Count();//10
- var countPackage = count / thread;//2
- if (countPackage == 0)
- countPackage = 1;
- for (int i = 0; i < thread; i++)//0-3
- {
- if (i * countPackage >= count) break;
- list.Add(multFreqFiles.Skip(i * countPackage).Take(countPackage).ToList());
- }
- for (int i = 0; i < list.Count; i++)
- {
- if (thread * countPackage + i >= count) break;
- list[i].AddRange(multFreqFiles.Skip(thread * countPackage + i).Take(1));
- }
- return list;
- }
- private bool GetLocalFile(ref long size, string localFile, string sourceFile, CancellationTokenSource cts)
- {
- using (FileStream fs = new FileStream(localFile, FileMode.Create))
- {
- using (FileStream fs2 = new FileStream(sourceFile, FileMode.Open))
- {
- size += fs2.Length;
- while (fs2.Position < fs2.Length)
- {
- if (cts.IsCancellationRequested) return false;
- byte[] data = new byte[1024];
- var len = fs2.Read(data, 0, 1024);
- data = data.Take(len).ToArray();
- fs.Write(data, 0, len);
- }
- }
- }
- return true;
- }
- private async Task<(bool, List<DetectResDto>)> DetectCalc(string cdbFile, string mainFile, BaseParamInfo paramInfo, CancellationTokenSource cts)
- {
- List<DetectResDto> deteRes = new List<DetectResDto>();
- DetectDto detectDto = new DetectDto()
- {
- file1 = cdbFile,//使用上行泄露信号进行检测
- dmcType = paramInfo.TaskSig.SigType,//上行信号检测目前的算法只能使用基于能量的KY或IBS检测
- fsHz = paramInfo.Minfo.FsHz,
- mergeRes = true,
- SigProc = true,
- // band = paramInfo.TaskSig.BandHz / 1e3,
- };
- if (_config.checkFileType == 0)//检测上行信号=0,检测主星下行信号=1
- {
- detectDto.dmcType = detectDto.dmcType & ~EnumSigCheckTypeDto.DAMA;//DAMA不支持上行信号检测,在这里移除掉
- if ((int)detectDto.dmcType == 0)
- {
- await XdCxRhDW.UI.Lib.LogHelper.Warning($"【任务{paramInfo.TaskSig.TaskInfoID}】信号[{paramInfo.TaskSig.FreqUp / 1e6:f3}MHz],上行信号不支持仅DAMA检测");
- return (false, deteRes);
- }
- }
- else
- {
- detectDto.file1 = mainFile;//使用主星下行信号进行检测
- }
- if (detectDto.dmcType == EnumSigCheckTypeDto.Normal)
- {
- await XdCxRhDW.UI.Lib.LogHelper.Warning($"【任务{paramInfo.TaskSig.TaskInfoID}】信号[{paramInfo.TaskSig.FreqUp / 1e6:f3}MHz],该服务不支持Normal类型信号");
- return (false, deteRes);
- }
- Stopwatch sw3 = new Stopwatch();
- sw3.Start();
- var deteResp = await HttpHelper.PostRequestAsync<List<DetectResDto>>(_config.baseUrl + "DetectCg/DetectCalc", detectDto, token: cts.Token);
- if (deteResp.code != 200)
- {
- if (deteResp.msg.Contains("超时"))
- await XdCxRhDW.UI.Lib.LogHelper.Error($"【任务{paramInfo.TaskSig.TaskInfoID}】信号[{paramInfo.TaskSig.FreqUp / 1e6:f3}MHz],{paramInfo.Minfo.CapTime:yyyyMMddHHmmss}时刻{deteResp.msg}");
- else
- await XdCxRhDW.UI.Lib.LogHelper.Error($"【任务{paramInfo.TaskSig.TaskInfoID}】信号[{paramInfo.TaskSig.FreqUp / 1e6:f3}MHz],{paramInfo.Minfo.CapTime:yyyyMMddHHmmss}时刻信号检测出错.{deteResp.msg}");
- return (false, deteRes);
- }
- sw3.Stop();
- await XdCxRhDW.UI.Lib.LogHelper.Info($"【任务{paramInfo.TaskSig.TaskInfoID}】信号[{paramInfo.TaskSig.FreqUp / 1e6:f3}MHz],{paramInfo.Minfo.CapTime:yyyyMMddHHmmss}时刻{_config.checkFileTypeStr}检测完成,共{deteResp.data.Count}个时隙,耗时{sw3.ElapsedMilliseconds}ms");
- deteRes.AddRange(deteResp.data);
- return (true, deteRes);
- }
- internal Task GetPosTask(LeoSat3TaskHandleDto dto, List<IGrouping<long, HistoryFile>> item, bool isLocal, CancellationTokenSource cts)
- {
- var task = Task.Run(async () =>
- {
- foreach (var xdInfos in item)//item中的数据串行处理
- {
- var finfos = xdInfos.ToList();
- var capTime = finfos.First().CapTime;
- if (dto.TaskType == EnumTaskTypeDto.History)
- {
- if (capTime < dto.StartTime) continue;
- if (capTime > dto.EndTime) continue;
- }
- if (finfos.Count < 3)
- {
- await XdCxRhDW.UI.Lib.LogHelper.Warning($"【任务{dto.ID}】{capTime:yyyyMMddHHmmss}时刻文件数量只有{finfos.Count}个,跳过此组数据");
- continue;
- }
- //主星
- var minfo = finfos.FirstOrDefault(m => m.SatId == dto.MainSatCode);
- if (minfo == null)
- {
- await XdCxRhDW.UI.Lib.LogHelper.Warning($"【任务{dto.ID}】{capTime:yyyyMMddHHmmss}时刻未找到主星信号文件,跳过此组数据");
- continue;
- }
- var taskSig = dto.Sigs.FirstOrDefault(p => p.FreqUp == minfo.UpFreqHz);
- if (taskSig == null)
- {
- continue;//跳过不是任务处理的频点
- }
- //邻1
- var n1info = finfos.FirstOrDefault(m => m.SatId == dto.Adja1SatCode);
- if (n1info == null)
- {
- await XdCxRhDW.UI.Lib.LogHelper.Info($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6}],{capTime:yyyyMMddHHmmss}时刻未找到邻星1信号文件,跳过此组数据");
- continue;
- }
- //主星
- var n2info = finfos.FirstOrDefault(m => m.SatId == dto.Adja2SatCode);
- if (n2info == null)
- {
- await XdCxRhDW.UI.Lib.LogHelper.Warning($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6}],{capTime:yyyyMMddHHmmss}时刻未找到邻星2信号文件,跳过此组数据");
- continue;
- }
- var paramInfo = new BaseParamInfo(taskSig, minfo, n1info, n2info);
- try
- {
- paramInfo.SetDelay(_config.mainSatDelay, _config.adja1SatDelay, _config.adja2SatDelay);
- string localFile1 = minfo.FilePath;
- string localFile2 = n1info.FilePath;
- string localFile3 = n2info.FilePath;
- if (!isLocal)
- {
- long size = 0;
- await XdCxRhDW.UI.Lib.LogHelper.Info($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6:f3}MHz],{capTime:yyyyMMddHHmmss}时刻三路采集文件正在拉取到本地...");
- Stopwatch sw22 = new Stopwatch();
- sw22.Start();
- localFile1 = $"wwwroot\\{Path.GetFileName(minfo.FilePath)}";
- bool ret = GetLocalFile(ref size, localFile1, minfo.FilePath, cts);
- if (!ret) return;
- localFile2 = $"wwwroot\\{Path.GetFileName(n1info.FilePath)}";
- ret = GetLocalFile(ref size, localFile2, n1info.FilePath, cts);
- if (!ret) return;
- localFile3 = $"wwwroot\\{Path.GetFileName(n2info.FilePath)}";
- ret = GetLocalFile(ref size, localFile3, n2info.FilePath, cts);
- if (!ret) return;
- sw22.Stop();
- var spped = size / 1024d / 1024d / (sw22.ElapsedMilliseconds / 1000d);
- await XdCxRhDW.UI.Lib.LogHelper.Info($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6:f3}MHz],{capTime:yyyyMMddHHmmss}时刻三路采集文件拉取到本地完成,共耗时{sw22.ElapsedMilliseconds}ms,平均速率{spped:f2}MB/s");
- }
- string mainFile = await HttpHelper.UploadFileAsync(localFile1, _config.baseUrl, token: cts.Token);//主星文件
- string adja1File = await HttpHelper.UploadFileAsync(localFile2, _config.baseUrl, token: cts.Token);//邻星文件
- string adja2File = await HttpHelper.UploadFileAsync(localFile3, _config.baseUrl, token: cts.Token);//超短文件
- if (!isLocal)
- {
- File.Delete(localFile1);
- File.Delete(localFile2);
- File.Delete(localFile3);
- }
- //检测
- (bool deret, List<DetectResDto> deteRes) = await DetectCalc(adja2File, mainFile, paramInfo, cts);
- if (!deret) continue;
- var smps = deteRes.Select(m => new SmpPosition(m.Start, m.Length)).ToList();//怎么补0?
- //double tarLon = 118.95, tarLat = 9.17;
- //var tarLoc = PhysicsHelper.GeoToEcef((tarLon, tarLat, 0));
- //var mxl = await GetSatEphAsync(paramInfo.Minfo.SatId, n2info.CapTime.AddSeconds(7));
- //var nx2 = await GetSatEphAsync(paramInfo.N2info.SatId, n2info.CapTime.AddSeconds(7));
- //var mx1Ecef = (mxl.X, mxl.Y, mxl.Z);
- //var nx21Ecef = (nx2.X, nx2.Y, nx2.Z);
- //var rec1 = PhysicsHelper.GeoToEcef((dto.MSatCapLon, dto.MSatCapLat, 0));
- //var rec2 = PhysicsHelper.GeoToEcef((dto.N2SatCapLon, dto.N2SatCapLat, 0));
- //var dt1 = PhysicsHelper.Dto(tarLoc, mx1Ecef, rec1);
- //var dt2 = PhysicsHelper.Dto(tarLoc, nx21Ecef, rec2);
- //var centerUs = (dt2 - dt1) * 1e6;
- //File.AppendAllText("1.txt", centerUs.ToString() + "\r\n");
- var cgDto = new CpuCgMultiDto()
- {
- dtCenter = -190000,
- dtRange = 80000,
- file1 = adja2File,
- file2 = mainFile,
- samplingRate = minfo.FsHz,
- smpPositions = smps,
- snrThreshold = taskSig.Snr,
- BandHz = 0,
- dfRange = 16384*4,
- };
- if (_config.checkFileType != 0)
- {
- cgDto.file1 = mainFile;
- cgDto.file2 = adja2File;
- }
- Stopwatch sw2 = new Stopwatch();
- sw2.Start();
- var result1 = await HttpHelper.PostRequestAsync<List<CpuCgResDto>>(_config.baseUrl + "DetectCg/CpuCgMultiCalc", cgDto, token: cts.Token);
- if (result1.code != 200)
- {
- if (result1.msg.Contains("超时"))
- await XdCxRhDW.UI.Lib.LogHelper.Error($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6:f3}MHz],{capTime:yyyyMMddHHmmss}时刻主星邻2{result1.msg}");
- else
- await XdCxRhDW.UI.Lib.LogHelper.Error($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6:f3}MHz],{capTime:yyyyMMddHHmmss}时刻主星邻2参估出错.{result1.msg}");
- continue;
- }
- sw2.Stop();
- await XdCxRhDW.UI.Lib.LogHelper.Info($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6:f3}MHz],{capTime:yyyyMMddHHmmss}时刻主星邻2参估完成,耗时{sw2.ElapsedMilliseconds}ms");
- cgDto = new CpuCgMultiDto()
- {
- dtCenter = 0,
- dtRange = 40000,
- file1 = adja2File,
- file2 = adja1File,
- samplingRate = minfo.FsHz,
- smpPositions = smps,
- snrThreshold = taskSig.Snr,
- BandHz = 0,
- dfRange = 16384,
- };
- if (_config.checkFileType != 0)
- {
- cgDto.file1 = mainFile;
- cgDto.file2 = adja1File;
- cgDto.dtCenter = 0;
- cgDto.dtRange = 40000;
- }
- sw2.Restart();
- var result2 = await HttpHelper.PostRequestAsync<List<CpuCgResDto>>(_config.baseUrl + "DetectCg/CpuCgMultiCalc", cgDto, token: cts.Token);
- if (result2.code != 200)
- {
- if (_config.checkFileType == 0)
- {
- if (result2.msg.Contains("超时"))
- await XdCxRhDW.UI.Lib.LogHelper.Error($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6:f3}MHz],{capTime:yyyyMMddHHmmss}时刻邻星超短{result2.msg}");
- else
- await XdCxRhDW.UI.Lib.LogHelper.Error($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6:f3}MHz],{capTime:yyyyMMddHHmmss}时刻邻星超短CPU参估出错.{result2.msg}");
- }
- else
- {
- if (result2.msg.Contains("超时"))
- await XdCxRhDW.UI.Lib.LogHelper.Error($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6:f3}MHz],{capTime:yyyyMMddHHmmss}时刻主星邻星1{result2.msg}");
- else
- await XdCxRhDW.UI.Lib.LogHelper.Error($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6:f3}MHz],{capTime:yyyyMMddHHmmss}时刻主星邻星1CPU参估出错.{result2.msg}");
- }
- continue;
- }
- sw2.Stop();
- if (_config.checkFileType == 0)
- await XdCxRhDW.UI.Lib.LogHelper.Info($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6:f3}MHz],{capTime:yyyyMMddHHmmss}时刻邻星超短CPU参估完成,耗时{sw2.ElapsedMilliseconds}ms");
- else
- await XdCxRhDW.UI.Lib.LogHelper.Info($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6:f3}MHz],{capTime:yyyyMMddHHmmss}时刻主星邻星1CPU参估完成,耗时{sw2.ElapsedMilliseconds}ms");
- await HttpHelper.DeleteFileAsync(_config.baseUrl, mainFile, adja1File, adja2File);
- var data1 = result2.data;//主星邻星1
- var data2 = result1.data;//主星邻星2
- if (data1.Count != data2.Count || data1.Count != deteRes.Count)
- {
- await XdCxRhDW.UI.Lib.LogHelper.Error($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6:f3}MHz],{capTime:yyyyMMddHHmmss}时刻参估结果个数和检测结果个数不匹配");
- continue;
- }
- string msg = $"【任务{dto.ID}】目标信号[{paramInfo.TaskSig.FreqUp / 1e6:f3}MHz]";
- //目标信号
- await DoX3NoRefPosAsync(dto, paramInfo, deteRes, data1, data2, cts, msg);
- }
- catch (TaskCanceledException)
- {
- }
- catch (Exception ex)
- {
- if (ex.InnerException != null && ex.InnerException.GetType() == typeof(TaskCanceledException))
- break;
- else
- await XdCxRhDW.UI.Lib.LogHelper.Error($"【任务{dto.ID}】信号[{taskSig.FreqUp / 1e6:f3}MHz],{capTime:yyyyMMddHHmmss}时刻文件处理异常", ex);
- continue;
- }
- }
- });
- return task;
- }
- private async Task DoX3NoRefPosAsync(LeoSat3TaskHandleDto dto, BaseParamInfo paramInfo, List<DetectResDto> deteRes, List<CpuCgResDto> data1, List<CpuCgResDto> data2, CancellationTokenSource cts, string msg)
- {
- for (int i = 0; i < data1.Count; i++)
- {
- try
- {
- if (cts.IsCancellationRequested) break;
- var detect = deteRes.First(r => r.Start == data1[i].Smpstart && r.Length == data1[i].Smplen);
- DateTime SigTime = paramInfo.Minfo.CapTime.AddSeconds(data1[i].Smpstart / paramInfo.Minfo.FsHz);
- var mxl = await GetSatEphAsync(paramInfo.Minfo.SatId, SigTime);
- var nxl = await GetSatEphAsync(paramInfo.N1info.SatId, SigTime);
- var nx2 = await GetSatEphAsync(paramInfo.N2info.SatId, SigTime);
- if (mxl == null || nxl == null || nx2 == null)
- {
- await XdCxRhDW.UI.Lib.LogHelper.Error($"{paramInfo.Minfo.CapTime:yyyyMMddHHmmss}时刻[{paramInfo.Minfo.SatId},{paramInfo.N1info.SatId},{paramInfo.N2info.SatId}]星历不存在");
- continue;
- }
- X3TwoDtoNoParPosDto x3 = new X3TwoDtoNoParPosDto()
- {
- TaskID = dto.ID,
- SigTime = SigTime,
- MainCode = paramInfo.Minfo.SatId,
- Adja1Code = paramInfo.N1info.SatId,
- Adja2Code = paramInfo.N2info.SatId,
- MainX = mxl.X,
- MainY = mxl.Y,
- MainZ = mxl.Z,
- MainVX = mxl.VX,
- MainVY = mxl.VY,
- MainVZ = mxl.VZ,
- Adja1X = nxl.X,
- Adja1Y = nxl.Y,
- Adja1Z = nxl.Z,
- Adja1VX = nxl.VX,
- Adja1VY = nxl.VY,
- Adja1VZ = nxl.VZ,
- Adja2X = nx2.X,
- Adja2Y = nx2.Y,
- Adja2Z = nx2.Z,
- Adja2VX = nx2.VX,
- Adja2VY = nx2.VY,
- Adja2VZ = nx2.VZ,
- MSatTxLon = dto.MSatCapLon,
- MSatTxLat = dto.MSatCapLat,
- N1SatTxLon = dto.N1SatCapLon,
- N1SatTxLat = dto.N1SatCapLat,
- N2SatTxLon = dto.N2SatCapLon,
- N2SatTxLat = dto.N2SatCapLat,
- FreqDown = paramInfo.Minfo.DownFreqHz,
- FreqUp = paramInfo.Minfo.UpFreqHz,
- CheckRes = new CheckResDto()
- {
- FileName = Path.GetFileName(paramInfo.Minfo.FilePath),
- ModRate = detect.ModRate,
- ModType = detect.ModType,
- SmpCount = detect.Length,
- SmpStart = detect.Start,
- UserName = detect.UserName,
- FfcHz = detect.FfcHz,
- Snr = detect.Snr,
- PosCheckType = detect.DmcType.GetEnumByDisplayName<EnumPosCheckTypeDto>(),
- }
- };
- double conValue = (666 + 2 / 3) * 2;//ddc不同算法的误差us
- if (data1[i].Snr > 0 && data2[i].Snr > 0)
- {
- x3.Dto1 = data1[i].Dt * _config.posDtoFactor - paramInfo.Delay1.Value + paramInfo.Delay2.Value;
- x3.Dfo1 = data1[i].Df;
- x3.Snr1 = data1[i].Snr;
- x3.Dto2 = data2[i].Dt * _config.posDtoFactor - paramInfo.Delay1.Value - conValue;
- x3.Dfo2 = data2[i].Df;
- x3.Snr2 = data2[i].Snr;
- }
- var result = await HttpHelper.PostRequestAsync<PosResDto>(_config.baseUrl + "Pos/PosX3LeoDtoNoParAsync", x3);
- if (result.code != 200)
- {
- await XdCxRhDW.UI.Lib.LogHelper.Error($"{msg},{paramInfo.Minfo.CapTime:yyyyMMddHHmmss}时刻时隙位置{data1[i].Smpstart}定位异常.{result.msg}");
- }
- else
- {
- var posRes = result.data;
- double posLon = posRes.PosLon;
- double posLat = posRes.PosLat;
- if (x3.Snr1 == 0 || x3.Snr2 == 0)
- {
- posLon = 0;
- posLat = 0;
- }
- ErrEllipseResDto errRes = new ErrEllipseResDto();
- if (posLon != 0 && posLat != 0 && posLon != 999 && posLat != 999)
- {
- var errDto = new ErrEllipseX3NoRefDto()
- {
- MainX = mxl.X,
- MainY = mxl.Y,
- MainZ = mxl.Z,
- Adja1X = nxl.X,
- Adja1Y = nxl.Y,
- Adja1Z = nxl.Z,
- Adja2X = nx2.X,
- Adja2Y = nx2.Y,
- Adja2Z = nx2.Z,
- PosLon = posLon,
- PosLat = posLat,
- //RefLon = dto.RefLon,
- // RefLat = dto.RefLat,
- OutputErrPoint = false,
- DtoErrus = _config.DtoErrus,
- EphErr = _config.EphErrm,
- };
- var errResRsp = await HttpHelper.PostRequestAsync<ErrEllipseResDto>(_config.baseUrl + "Ellipse/X3TwoDtoNoRef", errDto);
- if (errResRsp.code != 200)
- {
- await XdCxRhDW.UI.Lib.LogHelper.Error(errResRsp.msg);
- }
- else
- {
- errRes = errResRsp.data;
- }
- }
- PosResWriteDto wDto = new PosResWriteDto()
- {
- PosTypeDto = EnumPosTypeDto.X3LeoDto,
- SigTime = x3.SigTime,
- SigTimeLenMs = x3.CheckRes.SmpCount / (long)paramInfo.Minfo.FsHz * 1000,
- FreqDownMHz = paramInfo.Minfo.DownFreqHz * 1e-6,
- FreqUpMHz = paramInfo.Minfo.UpFreqHz * 1e-6,
- SigModType = detect.ModType,
- PosLon = posLon,
- PosLat = posLat,
- Dto1 = x3.Dto1,
- Dfo1 = x3.Dfo1,
- Snr1 = x3.Snr1,
- Dto2 = x3.Dto2,
- Dfo2 = x3.Dfo2,
- Snr2 = x3.Snr2,
- LongRadius = errRes.LongRadius,
- ShortRadius = errRes.ShortRadius,
- DipAngle = errRes.DipAngle,
- TsCount = data1.Count,
- PosType = 4,
- ModRate = detect.ModRate.HasValue ? detect.ModRate.Value : 0,
- };
- await HttpHelper.PostRequestAsync(_config.baseUrl + "Result/WritePosResToFile", wDto);
- }
- }
- catch (Exception ex)
- {
- await XdCxRhDW.UI.Lib.LogHelper.Error($"{msg},{paramInfo.Minfo.CapTime:yyyyMMddHHmmss}时刻时隙位置{data1[i].Smpstart}定位异常", ex);
- }
- }
- await XdCxRhDW.UI.Lib.LogHelper.Info($"{msg},{paramInfo.Minfo.CapTime:yyyyMMddHHmmss}时刻定位完成");
- }
- private async Task<SatEphResDto> GetSatEphAsync(int satcode, DateTime sigtime)
- {
- var result = await HttpHelper.PostRequestAsync<SatEphResDto>(_config.baseUrl + "Xl/XLCalc", new SatDto() { SatCode = satcode, SigTime = sigtime });
- if (result.code != 200)
- {
- await XdCxRhDW.UI.Lib.LogHelper.Error($"卫星:{satcode},{sigtime:yyyyMMddHHmmss}时刻获取星历异常.{result.msg}");
- return null;
- }
- return result.data;
- }
- private async Task<RefCafResultDto> GeRefCgDtAsync(int satcode, DateTime sigtime)
- {
- var result = await HttpHelper.PostRequestAsync<RefCafResultDto>(_config.baseUrl + "Task/GetRefCalcAsync", new SatDto() { SatCode = satcode, SigTime = sigtime });
- if (result.code != 200)
- {
- await XdCxRhDW.UI.Lib.LogHelper.Error($"卫星:{satcode},{sigtime:yyyyMMddHHmmss}时刻获取参考参估结果异常.{result.msg}");
- return null;
- }
- return result.data;
- }
- }
- }
|