| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 | 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 (!outDir.Contains(":"))            {                outDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, outDir);            }            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; }    }}
 |