123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Uestc.Auto6.Dso.ComModel;
- using Uestc.Auto6.Dso.Core;
- using Uestc.Auto6.Dso.Core.Decode;
- using Uni_Trend.MSO7000X.Common.Helper;
- using Uni_Trend.MSO7000X.Language;
- using Uni_Trend.MSO7000X.UserControls;
- using Uni_Trend.MSO7000X.UserControls.Style;
- namespace Uestc.Auto6.Dso.Protocol.NRZ
- {
- [System.ComponentModel.ToolboxItem(false)]
- public partial class NRZSetControl : UserControl,IProtocolView
- {
- #region 属性定义
- protected new Boolean DesignMode
- {
- get
- {
- Boolean rtnflag = false;
- #if DEBUG
- rtnflag = DesignTimeHelper.InDesignMode(this);
- #endif
- return rtnflag;
- }
- }
- public NRZDecodePrsnt DestinDecodePrsnt
- {
- get => _DestinDecodePrsnt;
- set
- {
- if (_DestinDecodePrsnt != value)
- {
- _DestinDecodePrsnt = value;
- ///当有新的同步目标时,应先将目标中参数同步到本地<see cref="NRZDecodePrsnt"/>属性中
- if (DecodePrsnt != null && value != null)
- {
- typeof(NRZDecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite).ToList().ForEach(x =>
- {
- x.SetValue(DecodePrsnt, x.GetValue(value));
- });
- }
- }
- }
- }
- private NRZDecodePrsnt _DestinDecodePrsnt;
- private NRZDecodePrsnt DecodePrsnt => Presenter as NRZDecodePrsnt;
- public IProtocolPrsnt Presenter { get; set; }
- #endregion 属性定义
- public NRZSetControl()
- {
- InitializeComponent();
- }
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(this, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize);
- Init();
- }
- private void Init()
- {
- GetDestinPrsnt();
- InitSource1();
- InitSource2();
- InitSignalRate();
- InitRealBiteRate();
- InitThreshold();
- InitMSB();
- InitSourceType();
- InitIdelLevel();
- InitIdelTime();
- InitMode();
- UpdateView();
- }
- private void InitSourceType()
- {
- this.CbxSourceType.DataSource = Enum.GetValues<ProtocolNRZ.SignalType>().Select(x=>
- {
- String key = String.Empty;
- key = Properties.Resources.ResourceManager.GetString(x.GetType().ReflectedType.FullName + "." + x.GetType().Name + "." + x.ToString());
- if (String.IsNullOrEmpty(key))
- {
- key = x.ToString();
- }
- return new KeyValuePair<String, ProtocolNRZ.SignalType>(key, x);
- }).ToList();
- this.CbxSourceType.ValueMember = "Value";
- this.CbxSourceType.DisplayMember = "Key";
- this.CbxSourceType.SelectedValueChanged += (_, _) =>
- {
- DecodePrsnt.SignalType = (ProtocolNRZ.SignalType)this.CbxSourceType.SelectedValue;
- };
- }
- private void InitMode()
- {
- this.CbxMode.DataSource =Enum.GetValues<ProtocolNRZ.Mode>().Select(x=>
- {
- return new KeyValuePair<String, ProtocolNRZ.Mode>(x switch
- {
- ProtocolNRZ.Mode.NRZ => "NRZ",
- ProtocolNRZ.Mode._8_10B => "8/10B",
- ProtocolNRZ.Mode._64_66B => "64/66B",
- _ => "NRZ",
- },x);
- }).ToList();
- this.CbxMode.ValueMember = "Value";
- this.CbxMode.DisplayMember = "Key";
- this.CbxMode.SelectedValueChanged += (_, _) =>
- {
- DecodePrsnt.Mode = (ProtocolNRZ.Mode)this.CbxMode.SelectedValue;
- };
- }
- private void InitIdelTime()
- {
- this.NebIdelTime.MaxValue = DecodePrsnt.MaxIdleTime;
- this.NebIdelTime.MinValue = DecodePrsnt.MinIdleTime;
- this.NebIdelTime.Value = DecodePrsnt.IdleTime;
- this.NebIdelTime.Interval = 1;
- this.NebIdelTime.StringFormatFunc = (val) => $"{(UInt32)val}";
- this.NebIdelTime.ValueChanged += (sender, args) => DecodePrsnt.IdleTime = (UInt32)args.newValue;
- this.NebIdelTime.EditValueChicked += (_, _) => SetIdelTime();
- }
- private void SetIdelTime()
- {
- Boolean lastflag = true;
- if (this.FindForm() is FloatForm form)
- {
- lastflag = form.CanClose;
- form.CanClose = false;
- }
- FloatForm floatForm = new FloatForm();
- floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
- floatForm.BackColor = BackColor;
- floatForm.ForeColor = ForeColor;
- floatForm.Width = 380;
- floatForm.Height = 460 + floatForm.HeadHeight;
- floatForm.Title = "设置空闲阈值";
- Uni_Trend.MSO7000X.UserControls.HexNumberKeyboard numberKeyboard = new Uni_Trend.MSO7000X.UserControls.HexNumberKeyboard();
- numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize));
- numberKeyboard.Top = floatForm.HeadHeight;
- numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
- numberKeyboard.Width = floatForm.Width;
- numberKeyboard.ForeColor = ForeColor;
- numberKeyboard.BackColor = BackColor;
- numberKeyboard.Value = DecodePrsnt.IdleTime;
- numberKeyboard.MinValue = DecodePrsnt.MinIdleTime;
- numberKeyboard.MaxValue = DecodePrsnt.MaxIdleTime;
- numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Dec;
- numberKeyboard.OkClick += (sender, args) =>
- {
- this.DecodePrsnt.IdleTime = (UInt32)args.Data;
- floatForm?.Close();
- };
- numberKeyboard.CancelClick += (sender, args) => floatForm?.Close();
- floatForm.Controls.Add(numberKeyboard);
- DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize);
- floatForm.FormClosing += (_, _) =>
- {
- if (this.FindForm() is FloatForm form)
- form.CanClose = lastflag;
- };
- floatForm.ShowDialogByPosition();
- }
- private void InitIdelLevel()
- {
- this.RgbIdelLevel.ButtonItems = Enum.GetValues<ProtocolNRZ.IdleLevel>().Select(x =>
- {
- String key = String.Empty;
- key = Properties.Resources.ResourceManager.GetString(x.GetType().ReflectedType.FullName + "." + x.GetType().Name + "." + x.ToString());
- if (String.IsNullOrEmpty(key))
- {
- key = x.ToString();
- }
- return new RadioButtonItem()
- {
- Tag =x,
- Text = key,
- };
- }).ToArray();
- this.RgbIdelLevel.IndexChanged += (_, _) =>
- {
- DecodePrsnt.IdleLevel = (ProtocolNRZ.IdleLevel)this.RgbIdelLevel.ButtonItems[RgbIdelLevel.ChoosedButtonIndex].Tag;
- };
- }
- private void InitThreshold()
- {
- this.BtnThreshold.Click += (sender, args) => SetThreshold();
- }
- private void SetThreshold()
- {
- Boolean lastflag = true;
- if (this.FindForm() is FloatForm form)
- {
- lastflag = form.CanClose;
- form.CanClose = false;
- }
- FloatForm floatForm = new FloatForm();
- floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
- floatForm.BackColor = BackColor;
- floatForm.ForeColor = ForeColor;
- floatForm.Width = 380;
- floatForm.Height = 460 + floatForm.HeadHeight;
- floatForm.Title = "设置门限";
- Uni_Trend.MSO7000X.UserControls.NumberKeyboard numberKeyboard = new Uni_Trend.MSO7000X.UserControls.NumberKeyboard();
- numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize));
- numberKeyboard.Top = floatForm.HeadHeight;
- numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
- numberKeyboard.Width = floatForm.Width;
- numberKeyboard.ForeColor = ForeColor;
- numberKeyboard.BackColor = BackColor;
- numberKeyboard.DefaultValue = DecodePrsnt.Threshold;
- numberKeyboard.Unit = "V";
- numberKeyboard.MinValue = DecodePrsnt.MinThreshold;
- numberKeyboard.MaxValue = DecodePrsnt.MaxThreshold;
- numberKeyboard.DecimalNumber = 2;
- numberKeyboard.OkClickEvent += (sender, args) =>
- {
- this.DecodePrsnt.Threshold = args.Data;
- floatForm?.Close();
- };
- numberKeyboard.CancelEvent += (sender, args) => floatForm?.Close();
- floatForm.Controls.Add(numberKeyboard);
- DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize);
- floatForm.FormClosing += (_, _) =>
- {
- if (this.FindForm() is FloatForm form)
- form.CanClose = lastflag;
- };
- floatForm.ShowDialogByPosition();
- }
- private void InitSource1()
- {
- this.CbxSource.DataSource = ComModel.ChannelIdExt.GetAnalogs().Select(x => new ComboBoxData<ChannelId>(x.ToString(), x)).ToList();
- this.CbxSource.ValueMember = "Value";
- this.CbxSource.DisplayMember = "Key";
- this.CbxSource.SelectedValueChanged += (_, _) =>
- {
- DecodePrsnt.Source1 = (ChannelId)this.CbxSource.SelectedValue;
- };
- }
- private void InitSource2()
- {
- this.CbxSource2.DataSource = ComModel.ChannelIdExt.GetAnalogs().Select(x => new ComboBoxData<ChannelId>(x.ToString(), x)).ToList();
- this.CbxSource2.ValueMember = "Value";
- this.CbxSource2.DisplayMember = "Key";
- this.CbxSource2.SelectedValueChanged += (_, _) =>
- {
- DecodePrsnt.Source2 = (ChannelId)this.CbxSource2.SelectedValue;
- };
- }
- private void InitMSB()
- {
- this.RbgMSB.ButtonItems = Enum.GetValues<ProtocolNRZ.MSB_LSB>().Select(x =>
- {
- return new RadioButtonItem()
- {
- Tag = x,
- Text = x.ToString(),
- };
- }).ToArray();
- this.RbgMSB.IndexChanged += (_, _) =>
- {
- DecodePrsnt.MSB_LSB = (ProtocolNRZ.MSB_LSB)this.RbgMSB.ButtonItems[this.RbgMSB.ChoosedButtonIndex].Tag;
- };
- }
- private void InitSignalRate()
- {
- this.CbxBitRate.DataSource = Enum.GetValues<ProtocolNRZ.SignalRate>().Select(x => new KeyValuePair<String, ProtocolNRZ.SignalRate>(x switch
- {
- ProtocolNRZ.SignalRate.Speed_650M => "650Mbps",
- ProtocolNRZ.SignalRate.Speed_6_5G => "6.5Gbps",
- ProtocolNRZ.SignalRate.Speed_1G=>"1Gbps",
- ProtocolNRZ.SignalRate.Custom => "Custom",
- _ => "1Mbps",
- }, x)).ToList();
- this.CbxBitRate.ValueMember = "Value";
- this.CbxBitRate.DisplayMember = "Key";
- this.CbxBitRate.SelectedValueChanged += (_, _) =>
- {
- DecodePrsnt.SignalRate = (ProtocolNRZ.SignalRate)this.CbxBitRate.SelectedValue;
- };
- }
- private void InitRealBiteRate()
- {
- this.BtnRealBitRate.Click += (sender, args) => SetBitRate();
- }
- private void SetBitRate()
- {
- Boolean lastflag = true;
- if (this.FindForm() is FloatForm form)
- {
- lastflag = form.CanClose;
- form.CanClose = false;
- }
- FloatForm floatForm = new FloatForm();
- floatForm = new Uni_Trend.MSO7000X.UserControls.FloatForm();
- floatForm.BackColor = BackColor;
- floatForm.ForeColor = ForeColor;
- floatForm.Width = 380;
- floatForm.Height = 460 + floatForm.HeadHeight;
- floatForm.Title = "设置波特率";
- Uni_Trend.MSO7000X.UserControls.NumberKeyboard numberKeyboard = new Uni_Trend.MSO7000X.UserControls.NumberKeyboard();
- numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(x, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize));
- numberKeyboard.Top = floatForm.HeadHeight;
- numberKeyboard.Height = floatForm.Height - floatForm.HeadHeight;
- numberKeyboard.Width = floatForm.Width;
- numberKeyboard.ForeColor = ForeColor;
- numberKeyboard.BackColor = BackColor;
- numberKeyboard.DefaultValue = DecodePrsnt.RealSignalRate;
- numberKeyboard.Unit = "bps";
- numberKeyboard.MinValue = DecodePrsnt.MinSignalRate;
- numberKeyboard.MaxValue = DecodePrsnt.MaxSignalRate;
- numberKeyboard.DecimalNumber = 2;
- numberKeyboard.OkClickEvent += (sender, args) =>
- {
- this.DecodePrsnt.RealSignalRate = (Int64)args.Data;
- floatForm?.Close();
- };
- numberKeyboard.CancelEvent += (sender, args) => floatForm?.Close();
- floatForm.Controls.Add(numberKeyboard);
- DefaultStyleManager.Instance.RegisterControlRecursion(floatForm, StyleFlag.FontSize);
- floatForm.FormClosing += (_, _) =>
- {
- if (this.FindForm() is FloatForm form)
- form.CanClose = lastflag;
- };
- floatForm.ShowDialogByPosition();
- }
- [UpdateProperty(nameof(NRZDecodePrsnt.SignalType))]
- private void UpdateSignalType()
- {
- this.CbxSourceType.SelectedValue = DecodePrsnt.SignalType;
- LblSource2.Visible = DecodePrsnt.SignalType == ProtocolNRZ.SignalType.Difference;
- CbxSource2.Visible = LblSource2.Visible;
- }
- [UpdateProperty(nameof(NRZDecodePrsnt.SignalRate))]
- private void UpdateRate()
- {
- this.CbxBitRate.SelectedValue = DecodePrsnt.SignalRate;
- this.LblRealBitRate.Visible = DecodePrsnt.SignalRate == ProtocolNRZ.SignalRate.Custom;
- this.BtnRealBitRate.Visible = this.LblRealBitRate.Visible;
- }
- [UpdateProperty(nameof(NRZDecodePrsnt.RealSignalRate))]
- private void UpdateRealRate()
- {
- this.BtnRealBitRate.Text = SIHelper.ValueChangeToSI(DecodePrsnt.RealSignalRate, 2, "bps");
- }
- [UpdateProperty(nameof(NRZDecodePrsnt.Threshold))]
- private void UpdateThreshold()
- {
- this.BtnThreshold.Text = SIHelper.ValueChangeToSI(DecodePrsnt.Threshold, 2, "V");
- }
- [UpdateProperty(nameof(NRZDecodePrsnt.Mode))]
- private void UpdateMode()
- {
- this.CbxMode.SelectedValue = DecodePrsnt.Mode;
- }
- [UpdateProperty(nameof(NRZDecodePrsnt.IdleTime))]
- private void UpdateIdleTime()
- {
- this.NebIdelTime.Value = DecodePrsnt.IdleTime;
- }
- [UpdateProperty(nameof(NRZDecodePrsnt.IdleLevel))]
- private void UpdateIdelLevel()
- {
- this.RgbIdelLevel.ChoosedButtonIndex = Enum.GetValues<ProtocolNRZ.IdleLevel>().ToList().FindIndex(x => x == DecodePrsnt.IdleLevel);
- }
- [UpdateProperty(nameof(NRZDecodePrsnt.MSB_LSB))]
- private void UpdatePolarity()
- {
- this.RbgMSB.ChoosedButtonIndex = Enum.GetValues<ProtocolNRZ.MSB_LSB>().ToList().FindIndex(x => x == DecodePrsnt.MSB_LSB);
- }
- [UpdateProperty(nameof(NRZDecodePrsnt.Source1))]
- private void UpdateSource()
- {
- this.CbxSource.SelectedValue = DecodePrsnt.Source1;
- GetDestinPrsnt();
- }
- [UpdateProperty(nameof(NRZDecodePrsnt.Source2))]
- private void UpdateSource2()
- {
- this.CbxSource2.SelectedValue = DecodePrsnt.Source2;
- }
- [UpdateProperty(nameof(ProtocolNRZ.SignalType))]
- private void UpdateSourceType()
- {
- this.CbxSourceType.SelectedValue = DecodePrsnt.SignalType;
- }
- /// <summary>
- /// 获取需要同步的Prsnt
- /// 当<see cref="DecodePrsnt"/>为<see cref="null"/>时表示不需要与其他Prsnt进行同步
- /// </summary>
- private void GetDestinPrsnt()
- {
- if (DecodePrsnt == null)
- return;
- if (DecodePrsnt.IsTrigger)
- DestinDecodePrsnt = Presenter.GetChannlesDecodePrsnt().Where(x => x is NRZDecodePrsnt).Cast<NRZDecodePrsnt>().Where(x => x.Source1 == DecodePrsnt.Source1).OrderBy(x => x.Source1).FirstOrDefault();
- else
- {
- if (Presenter.GetTriggerDecodePrsnt() is NRZDecodePrsnt rs232decodePrsnt && rs232decodePrsnt.Source1 == DecodePrsnt.Source1)
- DestinDecodePrsnt = rs232decodePrsnt;
- else
- DestinDecodePrsnt = null;
- }
- }
- /// <summary>
- /// 同步两个Prsnt
- /// </summary>
- /// <param name="propertyName">属性名称</param>
- private void DecodeSynchronization(String propertyName)
- {
- if (DestinDecodePrsnt == null)
- return;
- if (propertyName == nameof(NRZDecodePrsnt.Source1))
- return;
- if (String.IsNullOrEmpty(propertyName))
- {
- typeof(NRZDecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite).ToList().ForEach(x =>
- {
- x.SetValue(DestinDecodePrsnt, x.GetValue(DecodePrsnt));
- });
- }
- else
- {
- PropertyInfo propertyInfo = typeof(NRZDecodePrsnt).GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
- if (propertyInfo != null && propertyInfo.CanWrite && propertyInfo.CanRead)
- propertyInfo.SetValue(DestinDecodePrsnt, propertyInfo.GetValue(DecodePrsnt));
- }
- }
- public void UpdateView(Object presenter, String propertyName)
- {
- DecodeSynchronization(propertyName);
- if (String.IsNullOrEmpty(propertyName))
- {
- UpdateView();
- return;
- }
- this.GetType()
- .GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)
- .Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null && x.GetCustomAttribute<UpdatePropertyAttribute>().PropertyName == propertyName)
- .ToList()
- .ForEach(x => x?.Invoke(this, null));
- }
- private void UpdateView()
- {
- this.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic).Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x => x?.Invoke(this, null));
- this.Refresh();
- }
- }
- }
|