123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- using DevExpress.Pdf;
- using Ips.Library.Basic;
- using Ips.Library.Entity;
- using Ips.Library.Signals;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Ips.Service.CpuServer
- {
- /// <summary>
- /// 同频对消处理服务(未完成,参数模型都是拷贝的参估的)
- /// </summary>
- public class TpdxService
- {
- private string exeName = "defruiter";
- /// <summary>
- /// 开始
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- public async Task<CorResult[]> StartAsync(CorParams dto)
- {
- //直接从采集上下载文件到本地
- string[] files = new string[] { dto.File1, dto.File2 };
- for (int i = 0; i < 2; i++)
- {
- string localFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Download", files[i]);
- if (!File.Exists(localFile))
- {
- var res = await HttpHelper.DownloadFileAsync(dto.AdFileDownloadUrl, files[i], localFile);
- if (!res)
- {
- throw new Exception($"文件下载失败,url=[{dto.AdFileDownloadUrl}?filename={files[i]}]");
- }
- }
- if (i == 0)
- dto.File1 = localFile;
- else
- dto.File2 = localFile;
- }
- return await Task.FromResult(new CorResult[0]);
- }
- /// <summary>
- /// 停止
- /// </summary>
- public void Stop()
- {
- var pros = Process.GetProcessesByName(exeName);
- foreach (var item in pros)
- {
- try
- {
- item.Kill();
- }
- catch
- { }
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="proCount">进程数</param>
- /// <param name="order">单次处理样点数 默认 20==1M</param>
- /// <param name="ifile">输入文件</param>
- /// <param name="ofile">输出文件</param>
- /// <param name="fs">采样率</param>
- /// <param name="bw">带宽 Hz</param>
- /// <param name="fc">频偏移 Hz</param>
- /// <param name="mod">模式</param>
- /// <param name="ps">开始位置</param>
- private List<Process> TpdxCpu(int proCount, int order, string ifile, string ofile, long fs, double bw, double fc, double ps, int mod)
- {
- int len = 1 << order;
- int firlen = 1 << (order - 5);
- FileInfo fi = new FileInfo(ifile);
- Int64 total = fi.Length / 4; // 总样点数
- int oversmpl = 40000; // 进程之间重复的点数
- int minSeg = 5;
- //可分小段的总数
- int totalSeg = (int)Math.Ceiling((total - len) * 1.0 / (len - firlen)) + 1;
- int maxProcCount = (int)(totalSeg / minSeg);
- if (proCount > maxProcCount) proCount = maxProcCount;
- int realSeg = (int)Math.Ceiling(totalSeg * 1.0 / proCount);
- int oneSmpCount = len;
- if (realSeg > 1)
- {
- oneSmpCount += ((realSeg - 1) * (len - firlen));
- }
- int woneSmpCount = oneSmpCount;
- Int64 pos = 0;
- List<Process> lps = new List<Process>();
- for (int idx = 0; idx < proCount; ++idx)
- {
- if (idx > 0)
- {
- pos = idx * (oneSmpCount - oversmpl);
- }
- if (idx == proCount - 1)
- {
- oneSmpCount = (int)(total - pos);
- }
- lps.Add(proc(ifile, ofile, fs, fc, bw, ps, mod, order, pos, oneSmpCount));
- }
- pos = 0;
- using (BinaryWriter binwriter = new BinaryWriter(File.Open(ofile, FileMode.Create)))
- {
- for (int idx = 0; idx < proCount; ++idx)
- {
- if (idx > 0)
- {
- pos = idx * (woneSmpCount - oversmpl);
- }
- if (idx == proCount - 1)
- {
- woneSmpCount = (int)(total - pos);
- }
- var tfile = $@"{ofile}_{pos}_{woneSmpCount}.~def";
- lps[idx].WaitForExit();
- using (BinaryReader binReader = new BinaryReader(File.OpenRead(tfile)))
- {
- if (idx != 0)
- {
- binReader.BaseStream.Seek(oversmpl * 4, SeekOrigin.Begin);
- }
- while (true)
- {
- var buff = binReader.ReadBytes(1024 * 1024 * 4);
- if (buff == null || buff.Length <= 0)
- {
- break;
- }
- binwriter.Write(buff, 0, buff.Length);
- }
- }
- File.Delete(tfile);
- Console.WriteLine($"{tfile} finish");
- }
- }
- Console.WriteLine($"finish");
- return lps;
- }
- Process proc(string ifile, string ofile, long fs, double fc, double bw, double ps, int mod, int order, long pos, long len)
- {
- Process pro = new Process();
- pro.StartInfo.CreateNoWindow = true;
- pro.StartInfo.UseShellExecute = false;
- pro.StartInfo.FileName = $"同频对消\\{exeName}.exe";
- pro.StartInfo.FileName = Path.Combine(pro.StartInfo.WorkingDirectory, "AddIns", "同频对消", "defruiter.exe");
- pro.StartInfo.Arguments = $"\"{ifile}\" \"{ofile}\" {fs} {fc} {bw} {ps} {mod} {order} {pos} {len}";
- pro.Start();
- return pro;
- }
-
- }
- }
|