ARINC429SetControl.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Reflection;
  6. using System.Windows.Forms;
  7. using Uestc.Auto6.Dso.ComModel;
  8. using Uestc.Auto6.Dso.Core;
  9. using Uestc.Auto6.Dso.Core.Decode;
  10. using Uni_Trend.MSO7000X.Common.Helper;
  11. using Uni_Trend.MSO7000X.Language;
  12. using Uni_Trend.MSO7000X.UserControls;
  13. namespace Uestc.Auto6.Dso.Protocol.ARINC429
  14. {
  15. [System.ComponentModel.ToolboxItem(false)]
  16. public partial class ARINC429SetControl : UserControl, IProtocolView
  17. {
  18. #region 属性定义
  19. protected new Boolean DesignMode
  20. {
  21. get
  22. {
  23. Boolean rtnflag = false;
  24. #if DEBUG
  25. rtnflag = DesignTimeHelper.InDesignMode(this);
  26. #endif
  27. return rtnflag;
  28. }
  29. }
  30. public ARINC429DecodePrsnt DestinDecodePrsnt
  31. {
  32. get => _DestinDecodePrsnt;
  33. set
  34. {
  35. if (_DestinDecodePrsnt != value)
  36. {
  37. _DestinDecodePrsnt = value;
  38. ///当有新的同步目标时,应先将目标中参数同步到本地<see cref="I2CDecodePrsnt"/>属性中
  39. if (DecodePrsnt != null && value != null)
  40. {
  41. typeof(ARINC429DecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite && x.CanRead).ToList().ForEach(x =>
  42. {
  43. x.SetValue(DecodePrsnt, x.GetValue(value));
  44. });
  45. }
  46. }
  47. }
  48. }
  49. private ARINC429DecodePrsnt _DestinDecodePrsnt;
  50. private ARINC429DecodePrsnt DecodePrsnt => Presenter as ARINC429DecodePrsnt;
  51. public IProtocolPrsnt Presenter { get; set; }
  52. private FloatForm _FloatForm;
  53. #endregion 属性定义
  54. public ARINC429SetControl()
  55. {
  56. InitializeComponent();
  57. InitView();
  58. }
  59. protected override void OnLoad(EventArgs e)
  60. {
  61. base.OnLoad(e);
  62. Init();
  63. }
  64. private void Init()
  65. {
  66. GetDestinPrsnt();
  67. SetDecodeMode();
  68. InitSignalRate();
  69. InitRealCustomBaud();
  70. //InitSignalRate();
  71. InitSource();
  72. InitSourceL();
  73. InitThresholdL();
  74. InitThresholdH();
  75. InitInputMode();
  76. UpdateView();
  77. }
  78. private void InitSource()
  79. {
  80. this.CbxSignalInput.DataSource = ChannelIdExt.GetAnalogs().Select(x => new KeyValuePair<String, ChannelId>(x.ToString(), x)).ToList();
  81. this.CbxSignalInput.ValueMember = "Value";
  82. this.CbxSignalInput.DisplayMember = "Key";
  83. this.CbxSignalInput.SelectedValueChanged += (_, _) =>
  84. {
  85. DecodePrsnt.Source = (ChannelId)this.CbxSignalInput.SelectedValue;
  86. };
  87. }
  88. private void InitSourceL()
  89. {
  90. this.CbxSourceL.DataSource = ChannelIdExt.GetAnalogs().Select(x => new KeyValuePair<String, ChannelId>(x.ToString(), x)).ToList();
  91. this.CbxSourceL.ValueMember = "Value";
  92. this.CbxSourceL.DisplayMember = "Key";
  93. this.CbxSourceL.SelectedValueChanged += (_, _) =>
  94. {
  95. DecodePrsnt.SourceL = (ChannelId)this.CbxSourceL.SelectedValue;
  96. };
  97. }
  98. private void InitView()
  99. {
  100. Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControlRecursion(this, Uni_Trend.MSO7000X.UserControls.Style.StyleFlag.FontSize);
  101. }
  102. /// <summary>
  103. /// 获取需要同步的Prsnt
  104. /// 当<see cref="DecodePrsnt"/>为<see cref="null"/>时表示不需要与其他Prsnt进行同步
  105. /// </summary>
  106. private void GetDestinPrsnt()
  107. {
  108. if (DecodePrsnt == null)
  109. return;
  110. if (DecodePrsnt.IsTrigger)
  111. DestinDecodePrsnt = Presenter.GetChannlesDecodePrsnt().Where(x => x is ARINC429DecodePrsnt).Cast<ARINC429DecodePrsnt>().Where(x => x.DecodeMode == DecodePrsnt.DecodeMode).OrderBy(x => x.DecodeMode).FirstOrDefault();
  112. else
  113. {
  114. if (Presenter.GetTriggerDecodePrsnt() is ARINC429DecodePrsnt ARINC429decodePrsnt && ARINC429decodePrsnt.DecodeMode == DecodePrsnt.DecodeMode)
  115. DestinDecodePrsnt = ARINC429decodePrsnt;
  116. else
  117. DestinDecodePrsnt = null;
  118. }
  119. }
  120. /// <summary>
  121. /// 同步两个Prsnt
  122. /// </summary>
  123. /// <param name="propertyName">属性名称</param>
  124. private void DecodeSynchronization(String propertyName)
  125. {
  126. if (DestinDecodePrsnt == null)
  127. return;
  128. if (String.IsNullOrEmpty(propertyName))
  129. {
  130. typeof(ARINC429DecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite && x.CanRead).ToList().ForEach(x =>
  131. {
  132. x.SetValue(DestinDecodePrsnt, x.GetValue(DecodePrsnt));
  133. });
  134. }
  135. else
  136. {
  137. PropertyInfo propertyInfo = typeof(ARINC429DecodePrsnt).GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic);
  138. if (propertyInfo != null && propertyInfo.CanWrite && propertyInfo.CanRead)
  139. propertyInfo.SetValue(DestinDecodePrsnt, propertyInfo.GetValue(DecodePrsnt));
  140. }
  141. }
  142. public void UpdateView(Object presenter, String propertyName)
  143. {
  144. DecodeSynchronization(propertyName);
  145. if (String.IsNullOrEmpty(propertyName))
  146. {
  147. UpdateView();
  148. return;
  149. }
  150. this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).Where(x =>
  151. {
  152. UpdatePropertyAttribute attribute = x.GetCustomAttribute<UpdatePropertyAttribute>();
  153. return attribute != null && attribute.PropertyName == propertyName;
  154. }).FirstOrDefault()?.Invoke(this, null);
  155. }
  156. private void UpdateView()
  157. {
  158. this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public).Where(x => x.GetCustomAttribute<UpdatePropertyAttribute>() != null).ToList().ForEach(x => x?.Invoke(this, null));
  159. this.Refresh();
  160. }
  161. #region 控件初始化
  162. private void InitSignalRate()
  163. {
  164. this.CbxSignalRate.DataSource = Enum.GetValues<ProtocolARINC429.SignalRate>().Select(x => new KeyValuePair<String, ProtocolARINC429.SignalRate>(x switch
  165. {
  166. ProtocolARINC429.SignalRate.SignalRate_12_5k => "12.5k",
  167. ProtocolARINC429.SignalRate.SignalRate_100k => "100k",
  168. ProtocolARINC429.SignalRate.SignalRate_custom => "Custom",
  169. _ => ((UInt32)x).ToString(),
  170. }, x)).ToList();
  171. this.CbxSignalRate.DisplayMember = "Key";
  172. this.CbxSignalRate.ValueMember = "Value";
  173. this.CbxSignalRate.SelectedValueChanged += (sender, args) =>
  174. {
  175. DecodePrsnt.SignalRate = (ProtocolARINC429.SignalRate)this.CbxSignalRate.SelectedValue;
  176. };
  177. UpdateSignalRate();
  178. }
  179. private void InitThresholdL()
  180. {
  181. this.BtnThresholdL.Click += (_, _) => SetThresholdL();
  182. }
  183. private void InitThresholdH()
  184. {
  185. this.BtnThresholdH.Click += (_, _) => SetThresholdH();
  186. }
  187. private void InitInputMode()
  188. {
  189. this.CbxInputMode.DataSource = Enum.GetValues<ProtocolARINC429.InputMode>().Select(x => new KeyValuePair<String, ProtocolARINC429.InputMode>(x switch
  190. {
  191. ProtocolARINC429.InputMode.ABDiff => "单端",
  192. ProtocolARINC429.InputMode.Diff => "差分",
  193. _ => "单端",
  194. }, x)).ToList();
  195. this.CbxInputMode.DisplayMember = "Key";
  196. this.CbxInputMode.ValueMember = "Value";
  197. this.CbxInputMode.SelectedValueChanged += (_, _) =>
  198. {
  199. DecodePrsnt.InputMode = (ProtocolARINC429.InputMode)this.CbxInputMode.SelectedValue;
  200. };
  201. }
  202. private void SetThresholdL()
  203. {
  204. Boolean lastflag = true;
  205. if (this.FindForm() is FloatForm form)
  206. {
  207. lastflag = form.CanClose;
  208. form.CanClose = false;
  209. }
  210. if (_FloatForm != null && !_FloatForm.IsDisposed)
  211. _FloatForm?.Close();
  212. _FloatForm = new FloatForm();
  213. _FloatForm.BackColor = BackColor;
  214. _FloatForm.ForeColor = ForeColor;
  215. _FloatForm.Title = "设置阈值";
  216. _FloatForm.Width = 380;
  217. _FloatForm.Height = 500 + _FloatForm.HeadHeight;
  218. NumberKeyboard numberKeyboard = new NumberKeyboard();
  219. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControl(x));
  220. numberKeyboard.Top = _FloatForm.HeadHeight;
  221. numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight;
  222. numberKeyboard.Width = _FloatForm.Width;
  223. numberKeyboard.ForeColor = ForeColor;
  224. numberKeyboard.BackColor = BackColor;
  225. numberKeyboard.MaxValue = DecodePrsnt.MaxThreshold;
  226. numberKeyboard.MinValue = DecodePrsnt.MinThreshold;
  227. numberKeyboard.Unit = "V";
  228. numberKeyboard.DecimalNumber = 2;
  229. numberKeyboard.DefaultValue = DecodePrsnt.ThresholdL;
  230. numberKeyboard.OkClickEvent += (sender, args) =>
  231. {
  232. DecodePrsnt.ThresholdL = args.Data;
  233. _FloatForm.Close();
  234. };
  235. numberKeyboard.CancelEvent += (_, _) => _FloatForm.Close();
  236. _FloatForm.Controls.Add(numberKeyboard);
  237. _FloatForm.FormClosing += (_, _) =>
  238. {
  239. if (this.FindForm() is FloatForm form)
  240. form.CanClose = lastflag;
  241. };
  242. _FloatForm.ShowDialogByPosition();
  243. }
  244. private void SetThresholdH()
  245. {
  246. Boolean lastflag = true;
  247. if (this.FindForm() is FloatForm form)
  248. {
  249. lastflag = form.CanClose;
  250. form.CanClose = false;
  251. }
  252. if (_FloatForm != null && !_FloatForm.IsDisposed)
  253. _FloatForm?.Close();
  254. _FloatForm = new FloatForm();
  255. _FloatForm.BackColor = BackColor;
  256. _FloatForm.ForeColor = ForeColor;
  257. _FloatForm.Title = "设置阈值";
  258. _FloatForm.Width = 380;
  259. _FloatForm.Height = 500 + _FloatForm.HeadHeight;
  260. NumberKeyboard numberKeyboard = new NumberKeyboard();
  261. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControl(x));
  262. numberKeyboard.Top = _FloatForm.HeadHeight;
  263. numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight;
  264. numberKeyboard.Width = _FloatForm.Width;
  265. numberKeyboard.ForeColor = ForeColor;
  266. numberKeyboard.BackColor = BackColor;
  267. numberKeyboard.MaxValue = DecodePrsnt.MaxThreshold;
  268. numberKeyboard.MinValue = DecodePrsnt.MinThreshold;
  269. numberKeyboard.Unit = "V";
  270. numberKeyboard.DecimalNumber = 2;
  271. numberKeyboard.DefaultValue = DecodePrsnt.ThresholdH;
  272. numberKeyboard.OkClickEvent += (sender, args) =>
  273. {
  274. DecodePrsnt.ThresholdH = args.Data;
  275. _FloatForm.Close();
  276. };
  277. numberKeyboard.CancelEvent += (_, _) => _FloatForm.Close();
  278. _FloatForm.Controls.Add(numberKeyboard);
  279. _FloatForm.FormClosing += (_, _) =>
  280. {
  281. if (this.FindForm() is FloatForm form)
  282. form.CanClose = lastflag;
  283. };
  284. _FloatForm.ShowDialogByPosition();
  285. }
  286. private void SetDecodeMode()
  287. {
  288. this.RbgDecodeMode.ButtonItems = Enum.GetValues<ProtocolARINC429.DecodeMode>().Select(x => new RadioButtonItem()
  289. {
  290. Tag = x,
  291. Text = x switch
  292. {
  293. ProtocolARINC429.DecodeMode.Mode_8_23_1=>"23bit",
  294. ProtocolARINC429.DecodeMode.Mode_8_2_19_1=>"19bit",
  295. _=>"19bit",
  296. }
  297. }).ToArray();
  298. this.RbgDecodeMode.IndexChanged += (sender, args) =>
  299. {
  300. DecodePrsnt.DecodeMode = (ProtocolARINC429.DecodeMode)RbgDecodeMode.ButtonItems[RbgDecodeMode.ChoosedButtonIndex].Tag;
  301. };
  302. this.RbgDecodeMode.ChoosedButtonIndex = Enum.GetValues<ProtocolARINC429.DecodeMode>().ToList().FindIndex(x => x == DecodePrsnt.DecodeMode);
  303. }
  304. private void InitCustomBaud()
  305. {
  306. Boolean lastflag = true;
  307. if (this.FindForm() is FloatForm form)
  308. {
  309. lastflag = form.CanClose;
  310. form.CanClose = false;
  311. }
  312. if (_FloatForm != null && !_FloatForm.IsDisposed)
  313. _FloatForm?.Close();
  314. _FloatForm = new FloatForm();
  315. _FloatForm.BackColor = BackColor;
  316. _FloatForm.ForeColor = ForeColor;
  317. _FloatForm.Title = "设置信号速率";
  318. _FloatForm.Width = 380;
  319. _FloatForm.Height = 500 + _FloatForm.HeadHeight;
  320. HexNumberKeyboard numberKeyboard = new HexNumberKeyboard();
  321. numberKeyboard.Controls.Cast<Control>().ToList().ForEach(x => Uni_Trend.MSO7000X.UserControls.Style.DefaultStyleManager.Instance.RegisterControl(x));
  322. numberKeyboard.Top = _FloatForm.HeadHeight;
  323. numberKeyboard.Height = _FloatForm.Height - _FloatForm.HeadHeight;
  324. numberKeyboard.Width = _FloatForm.Width;
  325. numberKeyboard.ForeColor = ForeColor;
  326. numberKeyboard.BackColor = BackColor;
  327. numberKeyboard.MaxValue = DecodePrsnt.MaxBaud;
  328. numberKeyboard.MinValue = DecodePrsnt.MinBaud;
  329. numberKeyboard.ValueType = HexNumberKeyboard.HexValueType.Dec;
  330. numberKeyboard.Value = (Int64)DecodePrsnt.CustomBaud;
  331. numberKeyboard.OkClick += (sender, args) =>
  332. {
  333. DecodePrsnt.CustomBaud = (Int32)args.Data;
  334. this.BtnCustomBaud.Text = DecodePrsnt.SignalRate.ToString();
  335. _FloatForm.Close();
  336. };
  337. numberKeyboard.CancelClick += (_, _) => _FloatForm.Close();
  338. _FloatForm.Controls.Add(numberKeyboard);
  339. _FloatForm.FormClosing += (_, _) =>
  340. {
  341. if (this.FindForm() is FloatForm form)
  342. form.CanClose = lastflag;
  343. };
  344. _FloatForm.ShowDialogByPosition();
  345. UpdateCustomBaud();
  346. }
  347. private void InitRealCustomBaud()
  348. {
  349. this.BtnCustomBaud.Click += (sender, args) => InitCustomBaud();
  350. }
  351. #endregion 控件初始化
  352. #region 更新数据
  353. [UpdateProperty(nameof(ARINC429DecodePrsnt.CustomBaud))]
  354. private void UpdateCustomBaud()
  355. {
  356. BtnCustomBaud.Text = DecodePrsnt.CustomBaud.ToString();
  357. }
  358. [UpdateProperty(nameof(ARINC429DecodePrsnt.SignalRate))]
  359. private void UpdateSignalRate()
  360. {
  361. this.CbxSignalRate.SelectedValue = DecodePrsnt.SignalRate;
  362. LblCustomBaud.Visible = DecodePrsnt.SignalRate == ProtocolARINC429.SignalRate.SignalRate_custom;
  363. BtnCustomBaud.Visible = LblCustomBaud.Visible;
  364. }
  365. [UpdateProperty(nameof(ARINC429DecodePrsnt.DecodeMode))]
  366. private void UpdateDecodeMode()
  367. {
  368. this.RbgDecodeMode.ChoosedButtonIndex = Enum.GetValues<ProtocolARINC429.DecodeMode>().ToList().FindIndex(x => x == DecodePrsnt.DecodeMode);
  369. }
  370. [UpdateProperty(nameof(ARINC429DecodePrsnt.Source))]
  371. private void UpdateSource()
  372. {
  373. this.CbxSignalInput.SelectedValue = DecodePrsnt.Source;
  374. }
  375. [UpdateProperty(nameof(ARINC429DecodePrsnt.InputMode))]
  376. private void UpdateInputMode()
  377. {
  378. this.CbxInputMode.SelectedValue = DecodePrsnt.InputMode;
  379. this.LblSourceL.Visible = DecodePrsnt.InputMode == ProtocolARINC429.InputMode.Diff;
  380. this.CbxSourceL.Visible = this.LblSourceL.Visible;
  381. }
  382. [UpdateProperty(nameof(ARINC429DecodePrsnt.SourceL))]
  383. private void UpdateSourceL()
  384. {
  385. this.CbxSourceL.SelectedValue = DecodePrsnt.SourceL;
  386. }
  387. [UpdateProperty(nameof(ARINC429DecodePrsnt.ThresholdL))]
  388. private void UpdateThresholdL()
  389. {
  390. this.BtnThresholdL.Text = SIHelper.ValueChangeToSI(DecodePrsnt.ThresholdL, 2, "V");
  391. }
  392. [UpdateProperty(nameof(ARINC429DecodePrsnt.ThresholdH))]
  393. private void UpdateThresholdH()
  394. {
  395. this.BtnThresholdH.Text = SIHelper.ValueChangeToSI(DecodePrsnt.ThresholdH, 2, "V");
  396. }
  397. #endregion 更新数据
  398. }
  399. }