123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- using DevExpress.XtraCharts;
- using DevExpress.XtraEditors;
- using DevExpress.XtraExport.Helpers;
- using DevExpress.XtraGrid.Views.Grid;
- using DxHelper;
- using ExtensionsDev;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.ComponentModel.DataAnnotations;
- using System.Data;
- using System.Data.Entity;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Controls;
- using System.Windows.Documents;
- using System.Windows.Forms;
- using XzXdDw.App.EFContext;
- using XzXdDw.App.Model;
- namespace XzXdDw.App.UserControl
- {
- public partial class CtrlCgTool : DevExpress.XtraEditors.XtraUserControl
- {
- public List<CgCalcRes> list = new List<CgCalcRes>();
- public CtrlCgTool()
- {
- InitializeComponent();
- }
- private void CtrlCg_Load(object sender, EventArgs e)
- {
- if (File.Exists("CgTmp.txt"))
- {
- var obj = Newtonsoft.Json.JsonConvert.DeserializeObject<CgUIParam>(File.ReadAllText("CgTmp.txt"));
- txtDfoRange.Text = obj.dfoRange;
- txtDtoCenter.Text = obj.dtoCenter;
- txtDtoRange.Text = obj.dtoRange;
- txtF1.Text = obj.F1;
- txtF2.Text = obj.F2;
- txtFs.Text = obj.fs;
- txtSnr.Text = obj.snr;
- txtSampleCount.Text = obj.sampleCount;
- txtMode.Text = obj.pMode;
- }
- txtF1.UseChooseFile();
- txtF2.UseChooseFile();
- gridCgCalcRes.Init().UseFilter().UseMultiSelect().UseRowNumber().UseExportCsv().UseExportXlsx()
- .AddMenu("清除", SvgHelper.CreateClear(), () =>
- {
- list.Clear();
- this.gridView1.RefreshData();
- });
- gridCgCalcRes.DataSource = list;
- }
- private async void btnCalc_Click(object sender, EventArgs e)
- {
- this.layoutControl1.Enabled = false;
- await Task.Run(() =>
- {
- try
- {
- CgUIParam cp = new CgUIParam()
- {
- dfoRange = txtDfoRange.Text,
- dtoCenter = txtDtoCenter.Text,
- dtoRange = txtDtoRange.Text,
- F1 = txtF1.Text,
- F2 = txtF2.Text,
- fs = txtFs.Text,
- sampleCount = txtSampleCount.Text,
- snr = txtSnr.Text,
- pMode = txtMode.SelectedIndex.ToString()
- };
- var jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(cp);
- File.WriteAllText("CgTmp.txt", jsonStr);
- Stopwatch sw = new Stopwatch();
- sw.Start();
- string sampleCount = txtSampleCount.Text;
- if (string.IsNullOrWhiteSpace(txtSampleCount.Text) || Convert.ToInt32(txtSampleCount.Text) <= 0)
- {
- FileInfo f1 = new FileInfo(txtF1.Text);
- FileInfo f2 = new FileInfo(txtF2.Text);
- sampleCount = (f1.Length / 4).ToString();
- if (f1.Length > f2.Length)
- sampleCount = (f2.Length / 4).ToString();
- }
- double fs = Convert.ToDouble(txtFs.Text);
- Process p = new Process();
- p.StartInfo.WorkingDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "API\\粗估精估");
- p.StartInfo.FileName = Path.Combine(p.StartInfo.WorkingDirectory, "XcorrGpu.exe");
- // XcorrGpu.exe - m e:/ 1.dat - a e:/ 2.dat - s 8388608 - f 6250000 - c 1780 - r 500 - j 16384 - t 14 - p 0
- p.StartInfo.Arguments = $"-m \"{txtF1.Text}\" -a \"{txtF2.Text}\" -s {sampleCount} -f {(Int64)(fs * 1e6)}" +
- $" -c {txtDtoCenter.Text} -r {txtDtoRange.Text} -j {txtDfoRange.Text} -t {txtSnr.Text} -p {txtMode.SelectedIndex}";
- p.StartInfo.CreateNoWindow = true;
- p.StartInfo.RedirectStandardError = true;
- p.StartInfo.RedirectStandardOutput = true;
- p.StartInfo.UseShellExecute = false;
- p.Start();
- p.WaitForExit();
- var str = p.StandardOutput.ReadToEnd();
- sw.Stop();
- if (str != null && str.Contains(":") && str.Length > 3)
- {
- var arr = str.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[1].Split("+".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- int count = 0;
- foreach (var item in arr)
- {
- if (count >= 1) break;
- var dtDfSnr = item.Split("*".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- CgCalcRes calcResOne = new CgCalcRes()
- {
- Dto = Math.Round(Convert.ToDouble(dtDfSnr[0]), 3),
- Dfo = Math.Round(Convert.ToDouble(dtDfSnr[1]), 3),
- Snr = Math.Round(Convert.ToDouble(dtDfSnr[2]), 1),
- CostTime = sw.ElapsedMilliseconds,
- File1 = txtF1.Text,
- File2 = txtF2.Text,
- };
- list.Add(calcResOne);
- count++;
- }
- }
- }
- catch (Exception ex)
- {
- Serilog.Log.Error("参估计算出错", ex);
- this.Invoke(new Action(() => XtraMessageBox.Show("参估计算出错")));
- }
- });
- this.gridView1.RefreshData();
- this.layoutControl1.Enabled = true;
- }
- }
- public class CgUIParam
- {
- public string F1 { get; set; }
- public string F2 { get; set; }
- public string fs { get; set; }
- public string sampleCount { get; set; }
- public string dtoCenter { get; set; }
- public string dtoRange { get; set; }
- public string dfoRange { get; set; }
- public string snr { get; set; }
- public string pMode { get; set; }
- }
- public class CgCalcRes
- {
- [Display(Name = "文件1")]
- public string File1 { get; set; }
- [Display(Name = "文件2")]
- public string File2 { get; set; }
- [Display(Name = "时差(us)")]
- public double Dto { get; set; }
- [Display(Name = "频差(Hz)")]
- public double Dfo { get; set; }
- [Display(Name = "信噪比(dB)")]
- public double Snr { get; set; }
- [Display(Name = "耗时(ms)")]
- public double CostTime { get; set; }
- }
- }
|