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 { /// /// 同频对消处理服务(未完成,参数模型都是拷贝的参估的) /// public class TpdxService { private string exeName = "defruiter"; /// /// 开始 /// /// /// public async Task 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]); } /// /// 停止 /// public void Stop() { var pros = Process.GetProcessesByName(exeName); foreach (var item in pros) { try { item.Kill(); } catch { } } } /// /// /// /// 进程数 /// 单次处理样点数 默认 20==1M /// 输入文件 /// 输出文件 /// 采样率 /// 带宽 Hz /// 频偏移 Hz /// 模式 /// 开始位置 private List 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 lps = new List(); 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; } } }