using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using Newtonsoft.Json; using WUtilitiesV01.Helper; using WUtilitiesV01.Helper.IOHelper; using WUtilitiesV01.WLogs; namespace Ips.Adc.QfCard.Cli { class Program { static void Main(string[] args) { bool test = false; if (test) WLog.Instance.Error("启用测试模式!!!"); WLog.Instance.AddConsoleLogger(); var fileLogger = WLog.Instance.AddFileLogger(); WLog.Instance.Info("******************启动********************"); WLog.Instance.Info("args:" + args.ExtJoin(" ")); var paramModel = parseArgs(args); WLog.Instance.Info("启动时间:" + paramModel.startTime.ExtToStr()); Dictionary dict = new Dictionary(); var ps = ReflectionHelper.PropertyInfos(typeof(ParamModel)); foreach (var propertyInfo in ps) { dict.Add(propertyInfo.Name, propertyInfo.GetValue(paramModel, null)); } var smodel = SettingService.Instance.GetModel(); //var result = HttpHelper.Post(smodel.Ip, "getCardParam", null); //WLog.Instance.Info("getCardParam:" + result); var result = HttpHelper.Post(smodel.Ip, "writeParams", dict); WLog.Instance.Info("writeParams:" + result); if (test) { var now = DateTime.Now.AddSeconds(3); var timestamp = (now - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0))).TotalSeconds; paramModel.launchTime = (uint)timestamp; } //paramModel.launchTime -= 8;//定位实验平台会推迟10s采集,等待采集卡初始化。qf的fdata不需要初始化。 dict.Clear(); //{"mode":1,"launchTime": "2023-05-10 11:34:13", "startMode": 1} dict.Add("mode", 1); dict.Add("launchTime", paramModel.launchTime); dict.Add("startMode", 1); result = HttpHelper.Post(smodel.Ip, "startRun", dict); WLog.Instance.Info("startRun:" + result); Thread.Sleep(paramModel.capSize * 1000); //20230510094527_ch1_iq.dat var folder = Path.GetDirectoryName(paramModel.path); var fileName = Path.GetFileNameWithoutExtension(paramModel.path); int count = 0; while (paramModel.startTime.AddSeconds(3 + paramModel.capSize) > DateTime.Now) { count = 0; for (int i = 0; i < paramModel.channelNumber; i++) { var path = Path.Combine(folder, string.Format("{0}_ch{1}_iq.dat", fileName, i + 1)); WLog.Instance.LogDelLater("check file exist" + path); if (File.Exists(path) && !FileHelper.IsUsing(path)) { count++; } } count = Directory.GetFiles(folder, $"*{fileName}*.dat").Count(); if (count == paramModel.channelNumber) { WLog.Instance.Info("File all exists"); break; } Thread.Sleep(1000); } if (count < paramModel.channelNumber) WLog.Instance.Error("等待3秒后文件仍没有落盘," + paramModel.path); else { for (int i = 0; i < paramModel.channelNumber; i++) { var path = Path.Combine(folder, string.Format("{0}_ch{1}_iq.dat", fileName, i + 1)); //File.Move(path,path+".tmp"); } } WLog.Instance.Flush(); WLog.Instance.Info("******************停止********************"); WLog.Instance.LogEmptyLine(); Thread.Sleep(1500); fileLogger.Flush(); var fileNameIdx = paramModel.path.LastIndexOf('.'); if (fileNameIdx > -1) { string autoFolder = paramModel.path.Substring(0, fileNameIdx); if (Directory.Exists(autoFolder)) Directory.Delete(autoFolder); } } static void Main_gch(string[] args) { bool test = false; if (test) WLog.Instance.Error("启用测试模式!!!"); WLog.Instance.AddConsoleLogger(); var fileLogger = WLog.Instance.AddFileLogger(); WLog.Instance.Info("******************启动********************"); WLog.Instance.Info("args:" + args.ExtJoin(" ")); var paramModel = parseArgs(args); WLog.Instance.Info("启动时间:" + paramModel.startTime.ExtToStr()); Dictionary dict = new Dictionary(); var ps = ReflectionHelper.PropertyInfos(typeof(ParamModel)); foreach (var propertyInfo in ps) { dict.Add(propertyInfo.Name, propertyInfo.GetValue(paramModel, null)); } var smodel = SettingService.Instance.GetModel(); var result = HttpHelper.Post(smodel.Ip, "getCardParam", null); WLog.Instance.Info("getCardParam:" + result); result = HttpHelper.Post(smodel.Ip, "setCardParam", dict); WLog.Instance.Info("setCardParam:" + result); if (test) { var now = DateTime.Now.AddSeconds(3); var timestamp = (now - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0))).TotalSeconds; paramModel.launchTime = (uint)timestamp; } //paramModel.launchTime -= 8;//定位实验平台会推迟10s采集,等待采集卡初始化。qf的fdata不需要初始化。 dict.Clear(); //{"mode":1,"launchTime": "2023-05-10 11:34:13", "startMode": 1} dict.Add("mode", 1); dict.Add("launchTime", paramModel.launchTime); dict.Add("startMode", 1); result = HttpHelper.Post(smodel.Ip, "startRun", dict); WLog.Instance.Info("startRun:" + result); Thread.Sleep(paramModel.capSize * 1000); //20230510094527_ch1_iq.dat var folder = Path.GetDirectoryName(paramModel.path); var fileName = Path.GetFileNameWithoutExtension(paramModel.path); int count = 0; while (paramModel.startTime.AddSeconds(3 + paramModel.capSize) > DateTime.Now) { count = 0; for (int i = 0; i < paramModel.channelNumber; i++) { var path = Path.Combine(folder, string.Format("{0}_ch{1}_iq.dat", fileName, i + 1)); WLog.Instance.LogDelLater("check file exist" + path); if (File.Exists(path) && !FileHelper.IsUsing(path)) { count++; } } if (count == paramModel.channelNumber) { WLog.Instance.Info("File all exists"); break; } Thread.Sleep(1000); } if (count < paramModel.channelNumber) WLog.Instance.Error("等待3秒后文件仍没有落盘," + paramModel.path); else { for (int i = 0; i < paramModel.channelNumber; i++) { var path = Path.Combine(folder, string.Format("{0}_ch{1}_iq.dat", fileName, i + 1)); //File.Move(path,path+".tmp"); } } WLog.Instance.Flush(); WLog.Instance.Info("******************停止********************"); WLog.Instance.LogEmptyLine(); Thread.Sleep(1500); fileLogger.Flush(); } static ParamModel parseArgs(string[] ps) { Dictionary dict = new Dictionary(); for (int i = 0; i < ps.Length; i += 2) { dict.Add(ps[i].Trim(), ps[i + 1].Trim()); } ParamModel model = new ParamModel(); foreach (var kv in dict) { switch (kv.Key) { case "-s": model.launchTime = UInt32.Parse(kv.Value); break; case "-c": model.clockMode = Int32.Parse(kv.Value); break; case "-t": model.triggerMode = Int32.Parse(kv.Value); break; case "-d": model.ddcFreq = double.Parse(kv.Value); break; case "-f": model.sampleRate = double.Parse(kv.Value); break; case "-m": model.ddcFactor = int.Parse(kv.Value); break; case "-h": model.chEnable = int.Parse(kv.Value); break; case "-o": model.path = kv.Value; break; case "-l": model.capSize = int.Parse(kv.Value); break; } } model.Clairfy(); return model; } class ParamModel { [JsonProperty("launchTime")] public UInt32 launchTime { get; set; } public DateTime startTime { get; set; } public int clockMode { get; set; } public int triggerMode { get; set; } public double ddcFreq { get; set; } public double sampleRate { get; set; } public int ddcFactor { get; set; } public int chEnable { get; set; } public int channelNumber; public string path { get; set; } public int capSize { get; set; } public int capMode { get; set; } public int type { get; set; } public int dataType { get; set; } public ParamModel Clairfy() { startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1, 0, 0, 0)) .AddSeconds(launchTime); capMode = 1; type = 0;//本地存储 dataType = ddcFactor == 0 ? 2 : 0;//抽取倍数0,ADC,否则为DDC clockMode = new int[] { 1, -1, 2 }[clockMode]; triggerMode = new int[] { 1, 0 }[triggerMode]; channelNumber = chEnable; chEnable = new int[] { 0, 1, 3, 7, 15 }[chEnable]; ddcFreq = 70; return this; } } } }