using System; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Threading.Tasks; using System.Collections; using System.Collections.Generic; using XdCxRhDW.Dto; using System.Security.Policy; namespace CpuCgServer { public class XcorrStruct { public String file1 { get; set; } public String file2 { get; set; } public long smpStart { get; set; } //开始样点 public double smpCount { get; set; } //样点数 public double samplingRate { get; set; } //采样率 public double dtCenter { get; set; } //时差中心 public double dtRange { get; set; } //时差范围 public double dfRange { get; set; } //频差范围 public double snrThreshold { get; set; } //信噪比门限 public XcorrStruct Copy() { XcorrStruct xItem = new XcorrStruct(); xItem.file1 = file1; xItem.file2 = file2; xItem.smpCount = smpCount; xItem.samplingRate = samplingRate; xItem.dtCenter = dtCenter; xItem.dtRange = dtRange; xItem.dfRange = dfRange; xItem.smpStart = smpStart; xItem.snrThreshold = snrThreshold; return xItem; } } public class XcorrUtils { Process cafp; // D:/data/test/r1.dat D:/data/test/r4.dat 1562500 -250000 20 16384 100000 1048576 11 public async Task Calc(XcorrStruct xs) { CafResultDto res = new CafResultDto(); cafp = new Process(); await Task.Run(() => { int flag = 0; if (xs.smpStart == 0) { flag = 2;//文件参估,避免滑动时溢出 cafp.StartInfo.Arguments = $"{flag} \"{xs.file1}\" \"{xs.file2}\" {(Int64)(xs.samplingRate)} {xs.dtCenter} {xs.dtRange} {xs.dfRange} {xs.smpCount} {xs.snrThreshold}"; } else { var minStart = xs.dtRange / 2 / 1e6 * xs.samplingRate; if (xs.smpStart < minStart)//滑动计算起时值必须要大于等于此数 { xs.smpStart = (long)minStart; } cafp.StartInfo.Arguments = $"{flag} \"{xs.file1}\" \"{xs.file2}\" {(Int64)(xs.samplingRate)} {xs.dtCenter} {xs.dtRange} {xs.dfRange} {xs.smpStart} {xs.smpCount} {xs.snrThreshold}"; } var exePath= Path.Combine(cafp.StartInfo.WorkingDirectory, "AddIns"); cafp.StartInfo.WorkingDirectory = exePath; cafp.StartInfo.FileName = Path.Combine(exePath,"XcorrCpu.exe"); cafp.StartInfo.CreateNoWindow = true; cafp.StartInfo.RedirectStandardError = true; cafp.StartInfo.RedirectStandardOutput = true; cafp.StartInfo.UseShellExecute = false; cafp.Start(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); cafp.WaitForExit(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; var str = cafp.StandardOutput.ReadToEnd(); res.FromLine(str); res.file1 = xs.file1; res.file2 = xs.file2; res.tm = (int)stopWatch.Elapsed.TotalMilliseconds; res.smpstart = xs.smpStart; res.smplen = (long)xs.smpCount; }); return res; } } }