using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace X3TaskServer54 { static class DDCHelper { private static string exePath = "AddIns\\DDC"; private const string exeName = "DigitaDownConverter.exe"; /// /// 设置【DigitaDownConverter.exe】文件所在路径,支持相对路径 /// public static void SetExePath(string path) { if (string.IsNullOrWhiteSpace(path)) return; if (path.StartsWith("\\"))//相对路径要么开头不带\,要么是 .\ path = path.Remove(0, 1); exePath = path; } /// /// 对多个频点信号的AD文件做DDC /// /// 输入文件 /// 采集时刻 /// 通道号0-3 /// 输入文件采样率Hz /// 中心频率Hz /// 输出目录 /// DDC信号参数 /// 超时时间(秒) /// 成功后返回DDC输出的文件 public static List DDC(string file, DateTime adTime, int chNo, long fsHz, long freqCenterHz, string outDir, IEnumerable sigs, int timeoutSeconds = 60) { if (string.IsNullOrWhiteSpace(exePath)) throw new Exception($"请先调用SetExePath指定{exeName}进程所在路径,支持相对路径"); if (!Directory.Exists(exePath)) throw new Exception($"路径[{exePath}]不存在"); var exeFile = Path.Combine(exePath, exeName); if (!File.Exists(exeFile)) throw new Exception($"文件[{exeFile}]不存在"); Process p = new Process(); p.StartInfo.WorkingDirectory = exePath; p.StartInfo.FileName = exeFile; StringBuilder sb = new StringBuilder(); sb.Append($"\"{file}\" \"{outDir}\" {adTime:yyyyMMddHHmmss} {chNo} {fsHz} {freqCenterHz} {sigs.Count()}"); List list = new List(); foreach (var sig in sigs) { sb.Append(" ").Append(sig.FreqDownHz).Append(" ").Append(sig.Mult); list.Add(Path.Combine(outDir, $"{adTime:yyyyMMddHHmmss}_{sig.FreqDownHz / 1e6:f3}_C{fsHz / sig.Mult}_CH{chNo}.dat")); } p.StartInfo.Arguments = sb.ToString(); p.StartInfo.CreateNoWindow = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.Start(); var succeed = p.WaitForExit(timeoutSeconds * 1000); if (!succeed) { throw new Exception($"进程[{exeName}]超时未完成!"); } return list.Where(x => File.Exists(x)).ToList(); } } class DDCSig { /// /// 信号下行频点Hz /// public int FreqDownHz { get; set; } /// /// 抽取倍数 /// public int Mult { get; set; } public SlotsInfo Slots { get; set; } } }