|
@@ -3,19 +3,27 @@ using Google.Protobuf.WellKnownTypes;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Configuration;
|
|
|
+using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using XdCxRhDW.Dto;
|
|
|
|
|
|
-namespace X2D1TaskServer54.Service
|
|
|
+namespace X3TaskServer54.Service
|
|
|
{
|
|
|
//业务逻辑处理类
|
|
|
public class HistoryTaskService
|
|
|
{
|
|
|
private readonly string baseUrl;
|
|
|
CancellationTokenSource cts;
|
|
|
+
|
|
|
+ string DetectDir;
|
|
|
+ string CapDir;
|
|
|
+ string DdcDir;
|
|
|
+ string PosResDir;
|
|
|
+ int MainSatCode, Adja1SatCode, Adja2SatCode;
|
|
|
+ double[] MainSatXYZ, Adja1SatXYZ, Adja2SatXYZ;
|
|
|
public HistoryTaskService()
|
|
|
{
|
|
|
var posPlatformAddr = ConfigurationManager.AppSettings["PosPlatformAddr"].Trim();//like http://127.0.0.1:8091 or http://127.0.0.1:8091/
|
|
@@ -23,8 +31,13 @@ namespace X2D1TaskServer54.Service
|
|
|
this.baseUrl = posPlatformAddr + "api/";
|
|
|
else
|
|
|
this.baseUrl = posPlatformAddr + "/api/";
|
|
|
+
|
|
|
+ DetectDir = ConfigurationManager.AppSettings["DetectDir"].Trim();
|
|
|
+ CapDir = ConfigurationManager.AppSettings["CapDir"].Trim();
|
|
|
+ DdcDir = ConfigurationManager.AppSettings["DdcDir"].Trim();
|
|
|
+ PosResDir = ConfigurationManager.AppSettings["PosResDir"].Trim();
|
|
|
}
|
|
|
- public void StartAsync(X2D1HistoryTaskHandleDto taskInfo)
|
|
|
+ public void StartAsync(X2D1HistoryTaskHandleDto dto)
|
|
|
{
|
|
|
cts = new CancellationTokenSource();
|
|
|
Task.Run(async () =>
|
|
@@ -34,43 +47,208 @@ namespace X2D1TaskServer54.Service
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- #region 第1步,上传检测参估需要的数据文件执行检测
|
|
|
- string mainFile = await HttpHelper.UploadFileAsync("E:\\1.dat", baseUrl + "File/UploadFileAsync", token: cts.Token);//主星文件
|
|
|
- string adjaFile = await HttpHelper.UploadFileAsync("E:\\2.dat", baseUrl + "File/UploadFileAsync", token: cts.Token);//邻星文件
|
|
|
- string cdbFile = await HttpHelper.UploadFileAsync("E:\\2.dat", baseUrl + "File/UploadFileAsync", token: cts.Token);//超短文件
|
|
|
- string url = baseUrl + "POST/Api/DetectCg/DetectCalc";//信号检测
|
|
|
- var httpResp1 = await HttpHelper.PostRequestAsync<List<DetectResDto>>(url, new DetectDto()
|
|
|
+ #region 第1步,读取需要的配置信息
|
|
|
+ if (!Directory.Exists(DetectDir))
|
|
|
{
|
|
|
- file1 = mainFile,//用到文件的地方必须使用先上传后返回的文件
|
|
|
- fsHz = 96000,
|
|
|
- dmcType = DmcType.DAMA
|
|
|
- });
|
|
|
- if (httpResp1.code == 0)
|
|
|
+ StopTask(dto.ID, $"检测结果目录[{DetectDir}]不存在");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!Directory.Exists(CapDir))
|
|
|
{
|
|
|
- LogHelper.Error(httpResp1.msg);
|
|
|
+ StopTask(dto.ID, $"AD采集目录[{CapDir}]不存在");
|
|
|
+ return;
|
|
|
}
|
|
|
- var slots = httpResp1.data;
|
|
|
- #endregion
|
|
|
-
|
|
|
- #region 第2步,多时隙参估
|
|
|
- url = baseUrl + "POST/Api/DetectCg/CpuCgMultiCalc";//CPU参估(多个时隙)
|
|
|
- var httpResp2 = await HttpHelper.PostRequestAsync<List<CpuCgResDto>>(url, new CpuCgMultiDto(), token: cts.Token);
|
|
|
- if (httpResp2.code == 0)
|
|
|
+ Directory.CreateDirectory(DdcDir);
|
|
|
+ try
|
|
|
{
|
|
|
- LogHelper.Error(httpResp2.msg);
|
|
|
+ var mainInfo = ConfigurationManager.AppSettings["MainSatInfo"].Replace(",", ",").Trim();
|
|
|
+ var adja1Info = ConfigurationManager.AppSettings["Adja1SatInfo"].Replace(",", ",").Trim();
|
|
|
+ var adja2Info = ConfigurationManager.AppSettings["Adja2SatInfo"].Replace(",", ",").Trim();
|
|
|
+ var arr1 = mainInfo.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
+ var arr2 = adja1Info.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
+ var arr3 = adja2Info.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
+ MainSatCode = Convert.ToInt32(arr1[0]);
|
|
|
+ Adja1SatCode = Convert.ToInt32(arr2[0]);
|
|
|
+ Adja2SatCode = Convert.ToInt32(arr3[0]);
|
|
|
+ MainSatXYZ = new double[3] { Convert.ToDouble(arr1[1]), Convert.ToDouble(arr1[2]), Convert.ToDouble(arr1[3]) };
|
|
|
+ Adja1SatXYZ = new double[3] { Convert.ToDouble(arr2[1]), Convert.ToDouble(arr2[2]), Convert.ToDouble(arr2[3]) };
|
|
|
+ Adja2SatXYZ = new double[3] { Convert.ToDouble(arr3[1]), Convert.ToDouble(arr3[2]), Convert.ToDouble(arr3[3]) };
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ StopTask(dto.ID, $"任务处理服务配置文件卫星信息解析出错");
|
|
|
+ return;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
- #region 第3步,每个时隙调用定位算法
|
|
|
- url = baseUrl + "Pos/PosX2D1NoXlNoParAsync";//两星一地无参无星历定位
|
|
|
- foreach (var slot in slots)
|
|
|
+ #region 第2步,扫描检测结果目录
|
|
|
+ var groupFiles = Directory.EnumerateFiles(DetectDir, "*.dat", SearchOption.TopDirectoryOnly).Select(p => StringToCheckResFile(p))
|
|
|
+ .GroupBy(m => Convert.ToInt64(m.DayTime.ToString("yyyyMMdd") + m.FlagNo)).OrderBy(m => m.Key);
|
|
|
+ if (!groupFiles.Any())
|
|
|
+ {
|
|
|
+ LogHelper.Info($"【任务{dto.ID}】等待扫描文件...");
|
|
|
+ await Task.Delay(10000);
|
|
|
+ }
|
|
|
+ foreach (var groupFile in groupFiles)//每一组文件代表同一个时刻的
|
|
|
{
|
|
|
if (cts.IsCancellationRequested) break;
|
|
|
- var httpResp3 = await HttpHelper.PostRequestAsync<PosResDto>(url, new X2D1NoXlNoParlPosDto(), token: cts.Token);
|
|
|
- if (httpResp3.code == 0)
|
|
|
+ List<SlotsInfo> listSlotsInfo = new List<SlotsInfo>();//多个频点的时隙结果
|
|
|
+ foreach (var item in groupFile)
|
|
|
{
|
|
|
- LogHelper.Error(httpResp3.msg);
|
|
|
+ var slotsInfo = SlotHelper.GetFileSlots(item.File);//某个频点的所有时隙
|
|
|
+ if (slotsInfo.Slots.Any())
|
|
|
+ listSlotsInfo.Add(slotsInfo);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LogHelper.Warning($"【任务{dto.ID}】{slotsInfo.AdTime:yyyyMMddHHmmss}时刻频点{slotsInfo.FreqDownMHz}MHz无检测结果,跳过此组文件");
|
|
|
+ }
|
|
|
}
|
|
|
+ if (!listSlotsInfo.Any()) continue;
|
|
|
+ var adFiles = Directory.EnumerateFiles(CapDir, "*.dat", SearchOption.TopDirectoryOnly).Select(p => StringToAdFile(p))
|
|
|
+ .Where(p => p.AdTime == listSlotsInfo.First().AdTime);
|
|
|
+ var first = listSlotsInfo.First();
|
|
|
+ var sigs = listSlotsInfo.Select(p => new DDCSig() { FreqDownHz = (int)(p.FreqDownMHz * 1e6), Mult = (int)first.Multi, Slots = p });
|
|
|
+ List<DDCFile> chDDCFiles = new List<DDCFile>();//同一个时刻多个频点多个通道的DDC数据
|
|
|
+ LogHelper.Info($"【任务{dto.ID}】{listSlotsInfo.First().AdTime:yyyyMMddHHmmss}时刻DDC处理开始...");
|
|
|
+ Parallel.ForEach(adFiles, adFile =>
|
|
|
+ {
|
|
|
+
|
|
|
+ //227=变频器频点255-(140-112))
|
|
|
+ var ddcRes = DDCHelper.DDC(adFile.File, adFile.AdTime, adFile.ChNo, (long)(first.FsampleM * 1e6), (long)(227 * 1e6), DdcDir, sigs);
|
|
|
+ chDDCFiles.AddRange(StringToDDCFile(ddcRes));
|
|
|
+ });
|
|
|
+ LogHelper.Info($"【任务{dto.ID}】{listSlotsInfo.First().AdTime:yyyyMMddHHmmss}时刻DDC处理完成");
|
|
|
+ if (!chDDCFiles.Any())
|
|
|
+ {
|
|
|
+ LogHelper.Error($"【任务{dto.ID}】{listSlotsInfo.First().AdTime:yyyyMMddHHmmss}时刻DDC处理无结果");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ var groupDDCFiles = chDDCFiles.GroupBy(p => p.FreqDownMHz);
|
|
|
+ foreach (var group in groupDDCFiles)
|
|
|
+ {
|
|
|
+ //group:同一个时刻同一个频点的多个通道数据
|
|
|
+ var capTime = group.First().AdTime;
|
|
|
+ var ch0File = group.Where(p => p.ChNo == 0).FirstOrDefault();
|
|
|
+ var ch1File = group.Where(p => p.ChNo == 1).FirstOrDefault();
|
|
|
+ var ch2File = group.Where(p => p.ChNo == 2).FirstOrDefault();
|
|
|
+ if (ch0File == null)
|
|
|
+ {
|
|
|
+ LogHelper.Warning($"【任务{dto.ID}】{capTime:yyyyMMddHHmmss}时刻未找到主星信号ch0文件,跳过此组数据");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (ch1File == null)
|
|
|
+ {
|
|
|
+ LogHelper.Warning($"【任务{dto.ID}】{capTime:yyyyMMddHHmmss}时刻未找到邻1星信号ch1文件,跳过此组数据");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (ch2File == null)
|
|
|
+ {
|
|
|
+ LogHelper.Warning($"【任务{dto.ID}】{capTime:yyyyMMddHHmmss}时刻未找到邻2星信号ch2文件,跳过此组数据");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ string mainFile = await HttpHelper.UploadFileAsync(ch0File.File, baseUrl + "File/UploadFileAsync", token: cts.Token);//主星文件
|
|
|
+ string adja1File = await HttpHelper.UploadFileAsync(ch1File.File, baseUrl + "File/UploadFileAsync", token: cts.Token);//邻1星文件
|
|
|
+ string adja2File = await HttpHelper.UploadFileAsync(ch2File.File, baseUrl + "File/UploadFileAsync", token: cts.Token);//邻2星文件
|
|
|
+
|
|
|
+
|
|
|
+ var sig = sigs.FirstOrDefault(p => p.FreqDownHz == (int)(group.Key * 1e6));
|
|
|
+ var cgDto = new CpuCgMultiDto()
|
|
|
+ {
|
|
|
+ dtCenter = 0,
|
|
|
+ dtRange = 40000,
|
|
|
+ file1 = mainFile,
|
|
|
+ file2 = adja1File,
|
|
|
+ samplingRate = ch0File.Fs,
|
|
|
+ smpPositions = sig.Slots.Slots.Select(p => new SmpPosition() { smpStart = p.StartPoint, smpCount = p.Len }).ToList(),
|
|
|
+ snrThreshold = 15,
|
|
|
+ };
|
|
|
+ var result1 = await HttpHelper.PostRequestAsync<List<CpuCgResDto>>(baseUrl + "DetectCg/CpuCgMultiCalc", cgDto, token: cts.Token);
|
|
|
+ if (result1.code != 200)
|
|
|
+ {
|
|
|
+ LogHelper.Error($"【任务{dto.ID}】{capTime:yyyyMMddHHmmss}时刻主星邻1星CPU参估出错.{result1.msg}");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ LogHelper.Info($"【任务{dto.ID}】{capTime:yyyyMMddHHmmss}时刻主星邻1星CPU参估完成.");
|
|
|
+ cgDto = new CpuCgMultiDto()
|
|
|
+ {
|
|
|
+ dtCenter = 0,
|
|
|
+ dtRange = 40000,
|
|
|
+ file1 = mainFile,
|
|
|
+ file2 = adja2File,
|
|
|
+ samplingRate = ch0File.Fs,
|
|
|
+ smpPositions = sig.Slots.Slots.Select(p => new SmpPosition() { smpStart = p.StartPoint, smpCount = p.Len }).ToList(),
|
|
|
+ snrThreshold = 15,
|
|
|
+ };
|
|
|
+ var result2 = await HttpHelper.PostRequestAsync<List<CpuCgResDto>>(baseUrl + "DetectCg/CpuCgMultiCalc", cgDto, token: cts.Token);
|
|
|
+ if (result2.code != 200)
|
|
|
+ {
|
|
|
+ LogHelper.Error($"【任务{dto.ID}】{capTime:yyyyMMddHHmmss}时刻主星邻2星CPU参估出错.{result2.msg}");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ File.Delete(ch0File.File);
|
|
|
+ File.Delete(ch1File.File);
|
|
|
+ File.Delete(ch2File.File);
|
|
|
+ LogHelper.Info($"【任务{dto.ID}】{capTime:yyyyMMddHHmmss}时刻主星邻2星CPU参估完成");
|
|
|
+ var data1 = result1.data;
|
|
|
+ var data2 = result2.data;
|
|
|
+ if (data1.Count != data2.Count || data1.Count != cgDto.smpPositions.Count)
|
|
|
+ {
|
|
|
+ LogHelper.Error($"【任务{dto.ID}】{capTime:yyyyMMddHHmmss}时刻参估结果个数和检测结果个数不匹配");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < data1.Count; i++)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (cts.IsCancellationRequested) break;
|
|
|
+ X3TwoDtoNoParPosDto x2D1 = new X3TwoDtoNoParPosDto()
|
|
|
+ {
|
|
|
+ TaskID = dto.ID,
|
|
|
+ SigTime = capTime.AddSeconds(data1[i].Smpstart / ch0File.Fs),
|
|
|
+ MainCode = MainSatCode,
|
|
|
+ Adja1Code = Adja1SatCode,
|
|
|
+ Adja2Code = Adja2SatCode,
|
|
|
+ MainX = MainSatXYZ[0],
|
|
|
+ MainY = MainSatXYZ[1],
|
|
|
+ MainZ = MainSatXYZ[2],
|
|
|
+ Adja1X = Adja1SatXYZ[0],
|
|
|
+ Adja1Y = Adja1SatXYZ[1],
|
|
|
+ Adja1Z = Adja1SatXYZ[2],
|
|
|
+ Adja2X = Adja2SatXYZ[0],
|
|
|
+ Adja2Y = Adja2SatXYZ[1],
|
|
|
+ Adja2Z = Adja2SatXYZ[2],
|
|
|
+ Dto1 = -data1[i].Dt,
|
|
|
+ Dfo1 = data1[i].Df,
|
|
|
+ Snr1 = data1[i].Snr,
|
|
|
+ Dto2 = -data2[i].Dt,
|
|
|
+ Dfo2 = data2[i].Df,
|
|
|
+ Snr2 = data2[i].Df,
|
|
|
+ SatTxLon = dto.CapLon,
|
|
|
+ SatTxLat = dto.CapLat,
|
|
|
+ FreqDown = ch0File.FreqDownMHz * 1e6,
|
|
|
+ CheckRes = new CheckResDto()
|
|
|
+ {
|
|
|
+ FileName = Path.GetFileName(ch0File.File),
|
|
|
+ SmpCount = sig.Slots.Slots[i].StartPoint,
|
|
|
+ SmpStart = sig.Slots.Slots[i].Len,
|
|
|
+ PosCheckType = EnumPosCheckTypeDto.DAMA,
|
|
|
+ }
|
|
|
+ };
|
|
|
+ var result = await HttpHelper.PostRequestAsync<PosResDto>(baseUrl + "Pos/PosX3TwoDtoNoParAsync", x2D1);
|
|
|
+ if (result.code != 200)
|
|
|
+ {
|
|
|
+ LogHelper.Error($"【任务{dto.ID}】{capTime:yyyyMMddHHmmss}时刻时隙位置{data1[i].Smpstart}定位异常.{result.msg}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogHelper.Error($"【任务{dto.ID}】{capTime:yyyyMMddHHmmss}时刻时隙位置{data1[i].Smpstart}定位异常", ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ LogHelper.Info($"【任务{dto.ID}】{capTime:yyyyMMddHHmmss}时刻定位完成");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
@@ -79,11 +257,83 @@ namespace X2D1TaskServer54.Service
|
|
|
LogHelper.Error("任务执行出错", ex);
|
|
|
}
|
|
|
}
|
|
|
- },cts.Token);
|
|
|
+ }, cts.Token);
|
|
|
}
|
|
|
public void Stop()
|
|
|
{
|
|
|
cts?.Cancel();
|
|
|
}
|
|
|
+ void StopTask(int taskID, string stopReason)
|
|
|
+ {
|
|
|
+ TaskStopHandleDto stopDto = new TaskStopHandleDto() { ID = taskID, StopReason = stopReason };
|
|
|
+ if (string.IsNullOrWhiteSpace(stopReason))
|
|
|
+ LogHelper.Info($"【任务{taskID}】正常结束");
|
|
|
+ else
|
|
|
+ LogHelper.Error($"【任务{taskID}】{stopReason}");
|
|
|
+
|
|
|
+ var stopResp = HttpHelper.PostRequestAsync(baseUrl + "Task/StopTask", stopDto).Result;
|
|
|
+ if (stopResp.code != 200)
|
|
|
+ {
|
|
|
+ LogHelper.Error($"【任务{taskID}】停止异常.{stopResp.msg}");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private CheckResFile StringToCheckResFile(string file)
|
|
|
+ {
|
|
|
+ //YUFO_252.050MHz_20240409_1398.dat
|
|
|
+ string fileName = Path.GetFileNameWithoutExtension(file).ToUpper();
|
|
|
+ var arr = fileName.Split(new string[] { "_", "MHZ" }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
+ var dayTime = DateTime.ParseExact(arr[2], "yyyyMMdd", null);
|
|
|
+ CheckResFile res = new CheckResFile()
|
|
|
+ {
|
|
|
+ DayTime = dayTime,
|
|
|
+ File = file,
|
|
|
+ FreqDownMHz = Convert.ToDouble(arr[1]),
|
|
|
+ FlagNo = Convert.ToInt64(arr[3]),
|
|
|
+ };
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ private AdFile StringToAdFile(string file)
|
|
|
+ {
|
|
|
+ //20240409094240_ADC_ch02.dat
|
|
|
+ var name = Path.GetFileNameWithoutExtension(file).ToUpper();
|
|
|
+ var arr = name.Split(new string[] { "_", "CH" }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
+ var time = DateTime.ParseExact(arr[0], "yyyyMMddHHmmss", null);
|
|
|
+ AdFile adFile = new AdFile()
|
|
|
+ {
|
|
|
+ File = file,
|
|
|
+ AdTime = time,
|
|
|
+ ChNo = Convert.ToInt32(arr[2]),
|
|
|
+ };
|
|
|
+ return adFile;
|
|
|
+ }
|
|
|
+ public DDCFile StringToDDCFile(string file)
|
|
|
+ {
|
|
|
+ //20240409094240_252.025_C109375_ch0.dat
|
|
|
+ var name = Path.GetFileNameWithoutExtension(file).ToUpper();
|
|
|
+ var arr = name.Split(new string[] { "_", "MHz", "C", "H" }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
+ var time = DateTime.ParseExact(arr[0], "yyyyMMddHHmmss", null);
|
|
|
+ double freqDown = Convert.ToDouble(arr[1]);
|
|
|
+ int fs = Convert.ToInt32(arr[2]);
|
|
|
+ int chNo = Convert.ToInt32(arr[3]);
|
|
|
+ return new DDCFile()
|
|
|
+ {
|
|
|
+ AdTime = time,
|
|
|
+ ChNo = chNo,
|
|
|
+ File = file,
|
|
|
+ FreqDownMHz = freqDown,
|
|
|
+ Fs = fs
|
|
|
+ };
|
|
|
+ }
|
|
|
+ public List<DDCFile> StringToDDCFile(List<string> files)
|
|
|
+ {
|
|
|
+ List<DDCFile> list = new List<DDCFile>();
|
|
|
+ foreach (var item in files)
|
|
|
+ {
|
|
|
+ list.Add(StringToDDCFile(item));
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
}
|
|
|
}
|