1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using Ips.Library.Basic;
- using Ips.Library.Entity;
- using Ips.Library.Signals;
- using Microsoft.Extensions.Logging;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ips.Service.CapServer
- {
- /// <summary>
- /// 采集处理服务
- /// </summary>
- public class AdcService
- {
- private bool isBusy = false;
- /// <summary>
- /// 启动采集
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<AdcResult> StartAsync(AdcOptions dto)
- {
- if (isBusy)
- {
- throw new Exception("上次采集未结束");
- }
- try
- {
- if (dto.CardType.GetEnumDisplayName() != AppConst.CardType.GetEnumDisplayName())
- {
- throw new Exception($"采集卡类型不匹配,采集服务配置={AppConst.CardType.GetEnumDisplayName()},任务设置={dto.CardType.GetEnumDisplayName()}");
- }
- isBusy = true;
- string test = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "test.dat");//测试数据
- var bytes = File.ReadAllBytes(test);
- var res = await Task.Run(() =>
- {
- var freqs = dto.Channels[0].Signals.Select(p => p.FreqUp / 1e6);
- IpsLogger.Info($"接收【常规采集】任务,存储目录[{dto.StorePath}],频点[{string.Join(",", freqs)}]");
- string addate = Path.Combine(dto.StorePath, dto.StartTime.ToString("yyyyMMdd_HH"));//20240131_10
- Directory.CreateDirectory(addate);
- AdcResult adcResult = new AdcResult(dto.StartTime, dto.StorePath);
- List<SignalFile> signalFiles = new List<SignalFile>();
- string downloadUrl = $"http://{AppConst.LocalIp}:{AppConst.LocalPort}/api/AdFile/Download";
- for (int i = 0; i < dto.Channels.Count; i++)
- {
- var channel = dto.Channels[i];
- for (int j = 0; j < channel.Signals.Count; j++)
- {
- var chsignal = channel.Signals[j];
- var fsad = dto.ClockFreq / dto.Mutil;
- SignalFile signal = new SignalFile()
- {
- AdcCode = channel.AdcCode,
- ChNum = channel.ChNum,
- BandWidth = chsignal.BandWidth,
- Fs = (int)fsad,
- SiteCode = channel.SiteCode,
- SatNum = chsignal.SigName,
- SigFreq = chsignal.FreqUp,
- SigTime = dto.StartTime,
- DownloadUrl = downloadUrl,
- };
- File.WriteAllBytes(Path.Combine(dto.StorePath, signal.DirectoryName, signal.FileName), bytes);
- signalFiles.Add(signal);
- }
- }
- adcResult.FileList = signalFiles;
- IpsLogger.Info($"采集完成,数据下载url=[{downloadUrl}?fileName=]");
- return adcResult;
- });
- isBusy = false;
- return res;
- }
- finally
- {
- await Task.Delay(5000);
- isBusy = false;
- }
- }
- }
- }
|