using System; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Threading.Tasks; using System.Windows.Forms; using XdCxRhDW.App.CpuCgTools; using System.Collections; using System.Collections.Generic; using DevExpress.Drawing.Internal.Fonts.Interop; using System.Windows.Documents; using XdCxRhDW.App.WebAPI.DTO; using XdCxRhDw.Dto; namespace XdCxRhDW.App.CorTools { class XcorrStruct { public String file1 { get; set; } public String file2 { get; set; } public int smpStart { get; set; } //开始样点 public int 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; } } class XcorrUtils { static Process p = new Process(); // D:/data/test/r1.dat D:/data/test/r4.dat 1562500 -250000 20 16384 100000 1048576 11 public static async Task Calc(XcorrStruct xs) { CafResult res = new CafResult(); await Task.Run(() => { p.StartInfo.FileName = Path.Combine(p.StartInfo.WorkingDirectory, "xcorr\\XcorrCpu.exe"); p.StartInfo.Arguments = $"\"{xs.file1}\" \"{xs.file2}\" {(Int64)(xs.samplingRate)} {xs.dtCenter} {xs.dtRange} {xs.dfRange} {xs.smpStart} {xs.smpCount} {xs.snrThreshold}"; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.Start(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); p.WaitForExit(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; var str = p.StandardOutput.ReadToEnd(); res.FromLine(str); res.file1 = xs.file1; res.file2 = xs.file2; res.tm = Math.Round(stopWatch.Elapsed.TotalMilliseconds, 4); res.smpstart = xs.smpStart; res.smplen = xs.smpCount; }); return res; } public static async Task> DmcCheckAsync(string fileName, double fsHz, DmcType dmcType) { string dmcCmd = "all"; string pFileName = Path.Combine(p.StartInfo.WorkingDirectory, "xcorr\\dmc.exe"); string pArguments = string.Empty; switch (dmcType) { case DmcType.DAMA: dmcCmd = "dm"; pArguments = $"{dmcCmd} \"{fileName}\"";// -f {fs}" -c --dmfirst"; break; case DmcType.IBS: dmcCmd = "nd"; pArguments = $"{dmcCmd} \"{fileName}\"";// -f {fs}" -c --dmfirst"; break; case DmcType.Ky5758: pFileName = Path.Combine(p.StartInfo.WorkingDirectory, "xcorr\\enc.exe"); //enc.exe enc-test.dat 0.096 5 0全部文件 pArguments = $"{fileName} {fsHz * 1e-6} {5} {0}"; break; default: break; } return await Task.Run(() => { p.StartInfo.FileName = pFileName; p.StartInfo.Arguments = pArguments; p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.Start(); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); p.WaitForExit(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; var str = p.StandardOutput.ReadToEnd(); return ConvertDmcResult(str, ts.TotalMilliseconds); }); } public static IEnumerable ConvertDmcResult(string res, double tm) { var lines = res.Split(Environment.NewLine.ToArray(), StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { var items = line.Split('\t'); if (items.Length < 2) continue; int start = int.Parse(items[0]); int length = int.Parse(items[1]); string userName = ""; if (items.Length >= 3) userName = items[2]; yield return new DmcResult(start, length, userName, Math.Round(tm,4)); } } public static void Stop() { try { p.Kill(); } catch (Exception) { } } } }