123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- using DevExpress.Utils.Extensions;
- using DevExpress.XtraPrinting.Native.Properties;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Configuration;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using XdCxRhDw;
- using XdCxRhDW.Dto;
- namespace XdCxRhDW.TaskServer.Task
- {
- public class HistoryTaskI
- {
- protected internal virtual string baseUrl => $"{ConfigurationManager.AppSettings["PosPlatformAddr"].Trim()}/api/";
- protected internal virtual bool IsRuning { get; set; } = false;
- //变采样
- protected internal virtual int OutFsHz { get; set; } = 96000;
- protected internal virtual HistoryTaskProcessingDto TaskDto { get; set; }
- public virtual void Start(HistoryTaskProcessingDto dto)
- {
- }
- /// <summary>
- /// 根据下行频点获取卫星Id
- /// </summary>
- /// <param name="freqdown"></param>
- /// <returns></returns>
- public int GetSatId(double freqdown)
- {
- int satId = 0;
- try
- {
- // (洋区固定大写字母aì,不是数字1,查不到结果给出日志方便排查
- string sql = $"select 卫星ID from freguencysatid where 下行 = '{freqdown}'and 洋区 = 'I' LIMIT 1";
- var res = MySqlTools.ExecuteScalar(System.Data.CommandType.Text, sql);
- bool isInt = int.TryParse($"{res}", out satId);
- if (!isInt)
- {
- LogHelper.Error($"下行频点{freqdown * 1e-6}未找到卫星编号");
- }
- }
- catch (Exception ex)
- {
- LogHelper.Error($"下行频点{freqdown}找卫星编号异常:{ex.Message}");
- }
- return satId;
- }
- public virtual void Stop()
- {
- IsRuning = true;
- }
- //检测
- public async Task<IEnumerable<DetectResDto>> DAMAAsync(EnumTaskCheckTypeDto dmc, double fsHz, string mFile)
- {
- try
- {
- //主星变采样
- var resampleRes = await ToResampleAsync((int)fsHz, mFile);
- DetectDto dto = new DetectDto();
- dto.dmcType = (DmcType)dmc;
- dto.fsHz = resampleRes.OutFsHz;
- dto.file1 = await UploadFileAsync("DAMA检测", resampleRes.File);
- var dmcResult = await HttpHelper.PostRequestAsync<IEnumerable<DetectResDto>>(baseUrl + "DetectCg/DetectCalc", dto);
- if (dmcResult.code != 200)
- {
- throw new Exception($"执行DAMA检测异常:{dmcResult.msg}");
- }
- else
- {
- dmcResult.data.ForEach(m => m.File1 = resampleRes.File);
- return dmcResult.data;
- }
- }
- catch (Exception ex)
- {
- throw new Exception($"信号检测出错:{ex.Message}");
- }
- }
- public async Task<ResampleResponseDto> ToResampleAsync(int fsHz, string file)
- {
- ResampleResponseDto dtores = new ResampleResponseDto();
- dtores.File = file;
- dtores.OutFsHz = fsHz;
- string step = "变采样";
- //不需要变采样
- if (fsHz == OutFsHz)
- {
- return dtores;
- }
- string file1 = await UploadFileAsync(step, file);
- ResampleRequestDto dto = new ResampleRequestDto()
- {
- File = file1,
- FsHz = fsHz,
- };
- var response = await HttpHelper.PostRequestAsync<ResampleResponseDto>(baseUrl + "/DetectCg/Resample", dto, dto.TimeoutSeconds);
- if (response.code == 200)
- {
- string downloadFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "download");
- string outFile = Path.Combine(downloadFolder, Path.GetFileNameWithoutExtension(file1) + $"_Resample{response.data.OutFsHz}K.dat");
- await DownloadFileAsync(step, response.data.File, outFile);
- dtores.OutFsHz = response.data.OutFsHz;
- dtores.File = outFile;
- return dtores;
- }
- else
- {
- throw new Exception($"采样率:{fsHz}变采样{file}异常:{response.msg}");
- }
- }
- public async Task<string> UploadFileAsync(string step, string file)
- {
- try
- {
- string file1 = await HttpHelper.UploadFileAsync(file, baseUrl + "File/UploadFileAsync");
- return file1;
- }
- catch (Exception ex)
- {
- throw new Exception($"执行{step}上传文件异常:{ex.Message}");
- }
- }
- public async Task<bool> DownloadFileAsync(string step, string Infile, string outFile)
- {
- try
- {
- return await HttpHelper.DownloadFileAsync(baseUrl, Infile, outFile);
- }
- catch (Exception ex)
- {
- throw new Exception($"执行{step}下载文件{Infile}异常:{ex.Message}");
- }
- }
- //CPU计算
- public async Task<CpuCgResDto> CPUCalcAsync(string file1, string file2, double fsHz, DetectResDto detect, double dtCenter, double dtRange)
- {
- string step = "CPU计算";
- CpuCgDto dto = new CpuCgDto();
- dto.file1 = await UploadFileAsync(step, file1);
- dto.file2 = await UploadFileAsync(step, file2);
- dto.smpCount = detect.Length;
- dto.samplingRate = fsHz;
- dto.dtCenter = dtCenter;
- dto.dtRange = dtRange;
- dto.smpStart = detect.Start;
- dto.snrThreshold = 14;
- try
- {
- var result = await HttpHelper.PostRequestAsync<CpuCgResDto>(baseUrl + "DetectCg/CpuCgCalc", dto);
- if (result.code != 200)
- {
- throw new Exception($"CPU文件参估出错,{result.msg}");
- }
- return result.data;
- }
- catch (Exception ex)
- {
- throw new Exception($"CPU文件参估出错,{ex.Message}");
- }
- }
- //GPU计算
- public async Task<GpuCgResponseDto> GPUCalcAsync(string file1, string file2, double fsHz, double dtCenter, double dtRange)
- {
- string step = "GPU计算";
- GpuCgRequestDto dto = new GpuCgRequestDto();
- dto.file1 = await UploadFileAsync(step, file1);
- dto.file2 = await UploadFileAsync(step, file2);
- dto.samplingRate = fsHz;
- dto.dtCenter = dtCenter;
- dto.dtRange = dtRange;
- dto.snrThreshold = 14;
- try
- {
- var result = await HttpHelper.PostRequestAsync<List<GpuCgResponseDto>>(baseUrl + "DetectCg/GpuCgCalc", dto, dto.TimeoutSeconds);
- if (result.code != 200)
- {
- throw new Exception($"GPU文件参估出错,{result.msg}");
- }
- return result.data.Count > 0 ? result.data.First() : new GpuCgResponseDto();
- }
- catch (TaskCanceledException)
- {
- throw new Exception("GPU文件参估Http接口调用超时");
- }
- catch (Exception ex)
- {
- throw new Exception($"GPU文件参估出错{ex.Message}");
- }
- }
- }
- }
|