using CliWrap; using CliWrap.Buffered; using Ips.Library.Entity; using System.Diagnostics; namespace Ips.Tpdx { public class TpdxUtil { static readonly string CliFile = Path.Combine(IpsPath.CliRootDir, "tpdx", "defruiter.exe"); public static async Task ExecAsync(string fileIn, string outDir, DxSigItem item, bool useGpu = false, CancellationToken token = default) { string ofile = Path.Combine(outDir, Path.GetFileNameWithoutExtension(fileIn) + "_tpdx.dat"); await Task.Run(() => { //Int64 fsample = 6250000; //double bandwidth = 2000000; //Hz //double fc = 0; //Hz 干扰-信号 //int Mod = (int)SignalMod._BPSK; double ps = -1; int order = 20; int proCount = 1; dxfun(proCount, order, fileIn, ofile, item.Fs, item.Bandwidth, item.Fc, ps, item.Mod); }); return ofile; } /// /// /// /// 进程数 /// 单次处理样点数 默认 20==1M /// 输入文件 /// 输出文件 /// 采样率 /// 带宽 Hz /// 频偏移 Hz /// 模式 private static void dxfun(int proCount, int order, String ifile, String ofile, Int64 fsample, double bandwidth, 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, fsample, fc, bandwidth, 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"); } /// /// /// /// 输入文件 /// 输出文件 /// 采样率 /// 频偏移 /// 带宽 /// 模式 /// 单次处理样点数 默认 20==1M /// 开始位置 /// 长度 /// private static Process proc(String ifile, String ofile, Int64 fs, double fc, double bw, double ps, int mod, int order, Int64 pos, Int64 len) { Process pro = new Process(); pro.StartInfo.CreateNoWindow = true; pro.StartInfo.UseShellExecute = false; pro.StartInfo.WorkingDirectory = Path.GetDirectoryName(CliFile); pro.StartInfo.FileName = CliFile; pro.StartInfo.Arguments = $"\"{ifile}\" \"{ofile}\" {fs} {fc} {bw} {ps} {mod} {order} {pos} {len}"; Console.WriteLine(pro.StartInfo.Arguments); pro.Start(); return pro; } } }