using System; using System.Collections.Generic; using System.Text; namespace XdCxRhDw.CpuCgTools { public class CorResult { /// /// 起始样点 /// public int Start { get; set; } /// /// 样点长度 /// public int Length { get; set; } /// /// 相关时差,单位:us /// public double Dto { get; set; } /// /// 相关频差:单位:Hz /// public double Dfo { get; set; } /// /// 相关信噪比,单位:db /// public double Snr { get; set; } /// /// 计算耗时,毫秒 /// public double UseTime { get; set; } /// /// 是否有效 /// public bool IsValid { get; set; } /// /// 相关峰列表 /// public List XgfList { get; set; } = new List(); public string Message { get; set; } = string.Empty; /// /// 参估结果 /// public CorResult() { } public static CorResult FromLine(string line, double snr) { if (string.IsNullOrWhiteSpace(line)) throw new ArgumentNullException(nameof(line)); CorResult corResult = new CorResult(); var cafItems = line.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); corResult.Message = line; if (cafItems.Length == 0) return corResult; int i = 0; var cafitem = cafItems[i]; var resitems = cafitem.Split(','); if (resitems.Length != 6) return corResult; corResult.Start = int.Parse(resitems[0]); corResult.Length = int.Parse(resitems[1]); corResult.Dto = double.Parse(resitems[2]); corResult.Dfo = double.Parse(resitems[3]); corResult.Snr = double.Parse(resitems[4]); corResult.UseTime = double.Parse(resitems[5]); corResult.IsValid = corResult.Snr > snr; if (cafItems.Length > 1) { for (i = 1; i < cafItems.Length; i++) { resitems = cafItems[i].Split(','); XgfItem xgfItem = new XgfItem() { Dto = double.Parse(resitems[0]), Dfo = double.Parse(resitems[1]), Snr = double.Parse(resitems[2]) }; corResult.XgfList.Add(xgfItem); } } return corResult; } public static CorResult[] FromLines(string result, double snr) { if (string.IsNullOrWhiteSpace(result)) return new CorResult[0]; var lines = result.Split(new string[] {"\r","\n"}, StringSplitOptions.RemoveEmptyEntries); CorResult[] results = new CorResult[lines.Length]; for (int i = 0; i < lines.Length; i++) { results[i] = FromLine(lines[i], snr); } return results; } } public class XgfItem { public XgfItem() { } public XgfItem(double dto, double dfo, double snr) { Dto = dto; Dfo = dfo; Snr = snr; } /// /// 时差(us) /// public double Dto { get; set; } /// /// 频差(Hz) /// public double Dfo { get; set; } /// /// 信噪比(dB) /// public double Snr { get; set; } } }