1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- 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";
- /// <summary>
- /// 设置【DigitaDownConverter.exe】文件所在路径,支持相对路径
- /// </summary>
- public static void SetExePath(string path)
- {
- if (string.IsNullOrWhiteSpace(path)) return;
- if (path.StartsWith("\\"))//相对路径要么开头不带\,要么是 .\
- path = path.Remove(0, 1);
- exePath = path;
- }
- /// <summary>
- /// 对多个频点信号的AD文件做DDC
- /// </summary>
- /// <param name="file">输入文件</param>
- /// <param name="adTime">采集时刻</param>
- /// <param name="chNo">通道号0-3</param>
- /// <param name="fsHz">输入文件采样率Hz</param>
- /// <param name="freqCenterHz">中心频率Hz</param>
- /// <param name="outDir">输出目录</param>
- /// <param name="sigs">DDC信号参数</param>
- /// <param name="timeoutSeconds">超时时间(秒)</param>
- /// <returns>成功后返回DDC输出的文件</returns>
- public static List<string> DDC(string file, DateTime adTime, int chNo, long fsHz, long freqCenterHz,
- string outDir, IEnumerable<DDCSig> 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<string> list = new List<string>();
- 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
- {
- /// <summary>
- /// 信号下行频点Hz
- /// </summary>
- public int FreqDownHz { get; set; }
- /// <summary>
- /// 抽取倍数
- /// </summary>
- public int Mult { get; set; }
- public SlotsInfo Slots { get; set; }
- }
- }
|