123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- 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;
- namespace Uestc.Auto6.Dso.Protocol.ARINC429
- {
- [System.ComponentModel.ToolboxItem(false)]
- public partial class ARINC429SetControl : UserControl, IProtocolView
- {
- #region 属性定义
- protected new Boolean DesignMode
- {
- get
- {
- Boolean rtnflag = false;
- #if DEBUG
- rtnflag = DesignTimeHelper.InDesignMode(this);
- #endif
- return rtnflag;
- }
- }
- public ARINC429DecodePrsnt DestinDecodePrsnt
- {
- get => _DestinDecodePrsnt;
- set
- {
- if (_DestinDecodePrsnt != value)
- {
- _DestinDecodePrsnt = value;
- ///当有新的同步目标时,应先将目标中参数同步到本地<see cref="I2CDecodePrsnt"/>属性中
- if (DecodePrsnt != null && value != null)
- {
- typeof(ARINC429DecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite && x.CanRead).ToList().ForEach(x =>
- {
- x.SetValue(DecodePrsnt, x.GetValue(value));
- });
- }
- }
- }
- }
- private ARINC429DecodePrsnt _DestinDecodePrsnt;
- private ARINC429DecodePrsnt DecodePrsnt => Presenter as ARINC429DecodePrsnt;
- public IProtocolPrsnt Presenter { get; set; }
- private FloatForm _FloatForm;
- #endregion 属性定义
- public ARINC429SetControl()
- {
- InitializeComponent();
- InitView();
- }
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- Init();
- }
- private void Init()
- {
- GetDestinPrsnt();
- SetDecodeMode();
- InitSignalRate();
- InitRealCustomBaud();
- //InitSignalRate();
- InitSource();
- InitSourceL();
- InitThresholdL();
- InitThresholdH();
- InitInputMode();
- UpdateView();
- }
- private void InitSource()
- {
- this.CbxSignalInput.DataSource = ChannelIdExt.GetAnalogs().Select(x => new KeyValuePair<String, ChannelId>(x.ToString(), x)).ToList();
- this.CbxSignalInput.ValueMember = "Value";
- this.CbxSignalInput.DisplayMember = "Key";
- this.CbxSignalInput.SelectedValueChanged += (_, _) =>
- {
- DecodePrsnt.Source = (ChannelId)this.CbxSignalInput.SelectedValue;
- };
- }
- private void InitSourceL()
- {
- this.CbxSourceL.DataSource = ChannelIdExt.GetAnalogs().Select(x => new KeyValuePair<String, ChannelId>(x.ToString(), x)).ToList();
- this.CbxSourceL.ValueMember = "Value";
- this.CbxSourceL.DisplayMember = "Key";
- this.CbxSourceL.SelectedValueChanged += (_, _) =>
- {
- DecodePrsnt.SourceL = (ChannelId)this.CbxSourceL.SelectedValue;
- };
- }
- private void InitView()
- {
- Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(this, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize);
- }
- /// <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 ARINC429DecodePrsnt).Cast<ARINC429DecodePrsnt>().Where(x => x.DecodeMode == DecodePrsnt.DecodeMode).OrderBy(x => x.DecodeMode).FirstOrDefault();
- else
- {
- if (Presenter.GetTriggerDecodePrsnt() is ARINC429DecodePrsnt ARINC429decodePrsnt && ARINC429decodePrsnt.DecodeMode == DecodePrsnt.DecodeMode)
- DestinDecodePrsnt = ARINC429decodePrsnt;
- else
- DestinDecodePrsnt = null;
- }
- }
- /// <summary>
- /// 同步两个Prsnt
- /// </summary>
- /// <param name="propertyName">属性名称</param>
- private void DecodeSynchronization(String propertyName)
- {
- if (DestinDecodePrsnt == null)
- return;
- if (String.IsNullOrEmpty(propertyName))
- {
- typeof(ARINC429DecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite && x.CanRead).ToList().ForEach(x =>
- {
- x.SetValue(DestinDecodePrsnt, x.GetValue(DecodePrsnt));
- });
- }
- else
- {
- PropertyInfo propertyInfo = typeof(ARINC429DecodePrsnt).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.NonPublic | BindingFlags.Instance | BindingFlags.Public).Where(x =>
- {
- UpdatePropertyAttribute attribute = x.GetCustomAttribute<UpdatePropertyAttribute>();
- return attribute != null && attribute.PropertyName == propertyName;
- }).FirstOrDefault()?.Invoke(this, null);
- }
- private void UpdateView()
- {
- this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x => x?.Invoke(this, null));
- this.Refresh();
- }
- #region 控件初始化
- private void InitSignalRate()
- {
- this.CbxSignalRate.DataSource = Enum.GetValues<ProtocolARINC429.SignalRate>().Select(x => new KeyValuePair<String, ProtocolARINC429.SignalRate>(x switch
- {
- ProtocolARINC429.SignalRate.SignalRate_12_5k => "12.5k",
- ProtocolARINC429.SignalRate.SignalRate_100k => "100k",
- ProtocolARINC429.SignalRate.SignalRate_custom => "Custom",
- _ => ((UInt32)x).ToString(),
- }, x)).ToList();
- this.CbxSignalRate.DisplayMember = "Key";
- this.CbxSignalRate.ValueMember = "Value";
- this.CbxSignalRate.SelectedValueChanged += (sender, args) =>
- {
- DecodePrsnt.SignalRate = (ProtocolARINC429.SignalRate)this.CbxSignalRate.SelectedValue;
- };
- UpdateSignalRate();
- }
- private void InitThresholdL()
- {
- this.BtnThresholdL.Click += (_, _) => SetThresholdL();
- }
- private void InitThresholdH()
- {
- this.BtnThresholdH.Click += (_, _) => SetThresholdH();
- }
- private void InitInputMode()
- {
- this.CbxInputMode.DataSource = Enum.GetValues<ProtocolARINC429.InputMode>().Select(x => new KeyValuePair<String, ProtocolARINC429.InputMode>(x switch
- {
- ProtocolARINC429.InputMode.ABDiff => "单端",
- ProtocolARINC429.InputMode.Diff => "差分",
- _ => "单端",
- }, x)).ToList();
- this.CbxInputMode.DisplayMember = "Key";
- this.CbxInputMode.ValueMember = "Value";
- this.CbxInputMode.SelectedValueChanged += (_, _) =>
- {
- DecodePrsnt.InputMode = (ProtocolARINC429.InputMode)this.CbxInputMode.SelectedValue;
- };
- }
- private void SetThresholdL()
- {
- Boolean lastflag = true;
- if (this.FindForm() is FloatForm form)
- {
- lastflag = form.CanClose;
- form.CanClose = false;
- }
- if (_FloatForm != null && !_FloatForm.IsDisposed)
- _FloatForm?.Close();
- _FloatForm = new FloatForm();
- _FloatForm.BackColor = BackColor;
- _FloatForm.ForeColor = ForeColor;
- _FloatForm.Title = "设置阈值";
- _FloatForm.Width = 380;
- _FloatForm.Height = 500 + _FloatForm.HeadHeight;
- NumberKeyboard numberKeyboard = new NumberKeyboard();
- numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControl(x));
- numberKeyboard.Top = _FloatForm.HeadHeight;
- numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight;
- numberKeyboard.Width = _FloatForm.Width;
- numberKeyboard.ForeColor = ForeColor;
- numberKeyboard.BackColor = BackColor;
- numberKeyboard.MaxValue = DecodePrsnt.MaxThreshold;
- numberKeyboard.MinValue = DecodePrsnt.MinThreshold;
- numberKeyboard.Unit = "V";
- numberKeyboard.DecimalNumber = 2;
- numberKeyboard.DefaultValue = DecodePrsnt.ThresholdL;
- numberKeyboard.OkClickEvent += (sender, args) =>
- {
- DecodePrsnt.ThresholdL = args.Data;
- _FloatForm.Close();
- };
- numberKeyboard.CancelEvent += (_, _) => _FloatForm.Close();
- _FloatForm.Controls.Add(numberKeyboard);
- _FloatForm.FormClosing += (_, _) =>
- {
- if (this.FindForm() is FloatForm form)
- form.CanClose = lastflag;
- };
- _FloatForm.ShowDialogByPosition();
- }
- private void SetThresholdH()
- {
- Boolean lastflag = true;
- if (this.FindForm() is FloatForm form)
- {
- lastflag = form.CanClose;
- form.CanClose = false;
- }
- if (_FloatForm != null && !_FloatForm.IsDisposed)
- _FloatForm?.Close();
- _FloatForm = new FloatForm();
- _FloatForm.BackColor = BackColor;
- _FloatForm.ForeColor = ForeColor;
- _FloatForm.Title = "设置阈值";
- _FloatForm.Width = 380;
- _FloatForm.Height = 500 + _FloatForm.HeadHeight;
- NumberKeyboard numberKeyboard = new NumberKeyboard();
- numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControl(x));
- numberKeyboard.Top = _FloatForm.HeadHeight;
- numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight;
- numberKeyboard.Width = _FloatForm.Width;
- numberKeyboard.ForeColor = ForeColor;
- numberKeyboard.BackColor = BackColor;
- numberKeyboard.MaxValue = DecodePrsnt.MaxThreshold;
- numberKeyboard.MinValue = DecodePrsnt.MinThreshold;
- numberKeyboard.Unit = "V";
- numberKeyboard.DecimalNumber = 2;
- numberKeyboard.DefaultValue = DecodePrsnt.ThresholdH;
- numberKeyboard.OkClickEvent += (sender, args) =>
- {
- DecodePrsnt.ThresholdH = args.Data;
- _FloatForm.Close();
- };
- numberKeyboard.CancelEvent += (_, _) => _FloatForm.Close();
- _FloatForm.Controls.Add(numberKeyboard);
- _FloatForm.FormClosing += (_, _) =>
- {
- if (this.FindForm() is FloatForm form)
- form.CanClose = lastflag;
- };
- _FloatForm.ShowDialogByPosition();
- }
- private void SetDecodeMode()
- {
- this.RbgDecodeMode.ButtonItems = Enum.GetValues<ProtocolARINC429.DecodeMode>().Select(x => new RadioButtonItem()
- {
- Tag = x,
- Text = x switch
- {
- ProtocolARINC429.DecodeMode.Mode_8_23_1=>"23bit",
- ProtocolARINC429.DecodeMode.Mode_8_2_19_1=>"19bit",
- _=>"19bit",
- }
- }).ToArray();
- this.RbgDecodeMode.IndexChanged += (sender, args) =>
- {
- DecodePrsnt.DecodeMode = (ProtocolARINC429.DecodeMode)RbgDecodeMode.ButtonItems[RbgDecodeMode.ChoosedButtonIndex].Tag;
- };
- this.RbgDecodeMode.ChoosedButtonIndex = Enum.GetValues<ProtocolARINC429.DecodeMode>().ToList().FindIndex(x => x == DecodePrsnt.DecodeMode);
- }
- private void InitCustomBaud()
- {
- Boolean lastflag = true;
- if (this.FindForm() is FloatForm form)
- {
- lastflag = form.CanClose;
- form.CanClose = false;
- }
- if (_FloatForm != null && !_FloatForm.IsDisposed)
- _FloatForm?.Close();
- _FloatForm = new FloatForm();
- _FloatForm.BackColor = BackColor;
- _FloatForm.ForeColor = ForeColor;
- _FloatForm.Title = "设置信号速率";
- _FloatForm.Width = 380;
- _FloatForm.Height = 500 + _FloatForm.HeadHeight;
- HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
- numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControl(x));
- numberKeyboard.Top = _FloatForm.HeadHeight;
- numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight;
- numberKeyboard.Width = _FloatForm.Width;
- numberKeyboard.ForeColor = ForeColor;
- numberKeyboard.BackColor = BackColor;
- numberKeyboard.MaxValue = DecodePrsnt.MaxBaud;
- numberKeyboard.MinValue = DecodePrsnt.MinBaud;
- numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Dec;
- numberKeyboard.Value = (Int64)DecodePrsnt.CustomBaud;
- numberKeyboard.OkClick += (sender, args) =>
- {
- DecodePrsnt.CustomBaud = (Int32)args.Data;
- this.BtnCustomBaud.Text = DecodePrsnt.SignalRate.ToString();
- _FloatForm.Close();
- };
- numberKeyboard.CancelClick += (_, _) => _FloatForm.Close();
- _FloatForm.Controls.Add(numberKeyboard);
- _FloatForm.FormClosing += (_, _) =>
- {
- if (this.FindForm() is FloatForm form)
- form.CanClose = lastflag;
- };
- _FloatForm.ShowDialogByPosition();
- UpdateCustomBaud();
- }
- private void InitRealCustomBaud()
- {
- this.BtnCustomBaud.Click += (sender, args) => InitCustomBaud();
- }
- #endregion 控件初始化
- #region 更新数据
- [UpdateProperty(nameof(ARINC429DecodePrsnt.CustomBaud))]
- private void UpdateCustomBaud()
- {
- BtnCustomBaud.Text = DecodePrsnt.CustomBaud.ToString();
- }
- [UpdateProperty(nameof(ARINC429DecodePrsnt.SignalRate))]
- private void UpdateSignalRate()
- {
- this.CbxSignalRate.SelectedValue = DecodePrsnt.SignalRate;
- LblCustomBaud.Visible = DecodePrsnt.SignalRate == ProtocolARINC429.SignalRate.SignalRate_custom;
- BtnCustomBaud.Visible = LblCustomBaud.Visible;
- }
- [UpdateProperty(nameof(ARINC429DecodePrsnt.DecodeMode))]
- private void UpdateDecodeMode()
- {
- this.RbgDecodeMode.ChoosedButtonIndex = Enum.GetValues<ProtocolARINC429.DecodeMode>().ToList().FindIndex(x => x == DecodePrsnt.DecodeMode);
- }
- [UpdateProperty(nameof(ARINC429DecodePrsnt.Source))]
- private void UpdateSource()
- {
- this.CbxSignalInput.SelectedValue = DecodePrsnt.Source;
- }
- [UpdateProperty(nameof(ARINC429DecodePrsnt.InputMode))]
- private void UpdateInputMode()
- {
- this.CbxInputMode.SelectedValue = DecodePrsnt.InputMode;
- this.LblSourceL.Visible = DecodePrsnt.InputMode == ProtocolARINC429.InputMode.Diff;
- this.CbxSourceL.Visible = this.LblSourceL.Visible;
- }
- [UpdateProperty(nameof(ARINC429DecodePrsnt.SourceL))]
- private void UpdateSourceL()
- {
- this.CbxSourceL.SelectedValue = DecodePrsnt.SourceL;
- }
- [UpdateProperty(nameof(ARINC429DecodePrsnt.ThresholdL))]
- private void UpdateThresholdL()
- {
- this.BtnThresholdL.Text = SIHelper.ValueChangeToSI(DecodePrsnt.ThresholdL, 2, "V");
- }
- [UpdateProperty(nameof(ARINC429DecodePrsnt.ThresholdH))]
- private void UpdateThresholdH()
- {
- this.BtnThresholdH.Text = SIHelper.ValueChangeToSI(DecodePrsnt.ThresholdH, 2, "V");
- }
- #endregion 更新数据
- }
- }
|