AbstractController_Decoder.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Uestc.Auto6.Dso.ComModel;
  7. namespace Uestc.Auto6.Dso.Hardware.Driver
  8. {
  9. internal class AbstractController_Decoder
  10. {
  11. protected Dictionary<SerialProtocolType, Action?> protocolConfigActionList = new Dictionary<SerialProtocolType, Action?>();
  12. public static void Config() => Hd.currProduct?.Ctrl_Decoder?.DoConfig();
  13. public void DoConfig()
  14. {
  15. SerialProtocolType protocolType = Hd.CurrHdMessage!.Trigger!.TrigDecoder!.ProtocolType;
  16. if (protocolType != SerialProtocolType.Close)
  17. {
  18. if (protocolConfigActionList.ContainsKey(protocolType))
  19. {
  20. if (protocolType == SerialProtocolType.USB || protocolType == SerialProtocolType.SATA || protocolType == SerialProtocolType.PCIe)//采集板实现
  21. {
  22. Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Decoder_ProtocolTypeForTrigger, (uint)protocolType);
  23. HdIO.WriteReg(ProcBdReg.W.Decoder_ProtocolTypeForTrigger, (uint)protocolType);
  24. Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Decoder_TrigTypeSelect, (uint)protocolType);
  25. HdIO.WriteReg((uint)AcqBdReg.W.Decoder_RamResetEnable, 0);
  26. HdIO.WriteReg(ProcBdReg.W.Decoder_RamResetEnable, 0);
  27. HdIO.Sleep(1);
  28. HdIO.WriteReg((uint)AcqBdReg.W.Decoder_RamResetEnable, 1);
  29. HdIO.WriteReg(ProcBdReg.W.Decoder_RamResetEnable, 1);
  30. }
  31. else
  32. {
  33. HdIO.WriteReg(ProcBdReg.W.Decoder_ProtocolTypeForTrigger, (uint)protocolType);
  34. HdIO.WriteReg(ProcBdReg.W.Decoder_TrigTypeSelect, (uint)protocolType);
  35. HdIO.WriteReg(ProcBdReg.W.Decoder_RamResetEnable, 0);
  36. HdIO.Sleep(1);
  37. HdIO.WriteReg(ProcBdReg.W.Decoder_RamResetEnable, 1);
  38. }
  39. protocolConfigActionList[Hd.CurrHdMessage!.Trigger!.TrigDecoder!.ProtocolType!]?.Invoke();
  40. }
  41. }
  42. foreach (var decodeoption in Hd.CurrHdMessage!.Decoder!)
  43. {
  44. if (decodeoption.Active && decodeoption.ProtocolType != SerialProtocolType.Close)
  45. {
  46. if (protocolConfigActionList.ContainsKey(decodeoption.ProtocolType))
  47. {
  48. if (decodeoption.ProtocolType == SerialProtocolType.USB || decodeoption.ProtocolType == SerialProtocolType.SATA
  49. || decodeoption.ProtocolType == SerialProtocolType.PCIe)//采集板实现
  50. {
  51. Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Decoder_RamResetEnable, 0);
  52. HdIO.Sleep(1);
  53. Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Decoder_RamResetEnable, 1);
  54. }
  55. protocolConfigActionList[decodeoption.ProtocolType]?.Invoke();
  56. //设置比较电平
  57. var ThresholdInfos = decodeoption.ProtocolOptions.GetThresholdInfos();
  58. if (ThresholdInfos.Count > 0)
  59. {
  60. ChannelId lastChannelID = ThresholdInfos[0].ChannelId;
  61. foreach (var info in ThresholdInfos)
  62. {
  63. ChannelId currChannel = info.ChannelId;
  64. if ((int)currChannel<ChannelIdExt.AnaChnlNum)
  65. {
  66. var acqBd = Hd.currProduct.Acquirer_AnalogChannel.GetChannelAcqBdAdcInputCorresponding((int)currChannel);
  67. if (acqBd != null)
  68. {
  69. double voltage = info.Threshold1;
  70. double compVoltage = (Hd.CurrHdMessage!.Analog[(int)currChannel].Position + voltage * 1000) / Hd.CurrHdMessage!.Analog[(int)currChannel].Scale * Constants.SAMPS_PER_YDIV + Constants.MAX_ADC_RES / 2;
  71. int up = (int)(compVoltage + 50);
  72. int dn = (int)(compVoltage - 50);
  73. if (up < 0)
  74. up = 0;
  75. else if (up > (Constants.MAX_ADC_RES / 2 - 1))
  76. up = Constants.MAX_ADC_RES / 2 - 1;
  77. if (dn < 0)
  78. dn = 0;
  79. else if (dn > (Constants.MAX_ADC_RES / 2 - 1))
  80. dn = Constants.MAX_ADC_RES / 2 - 1;
  81. Hd.currProduct?.AcqBd?.WriteReg(AcqBdReg.W.Decoder_protocolcmplevelH1, acqBd.BdNo, (uint)up);
  82. Hd.currProduct?.AcqBd?.WriteReg(AcqBdReg.W.Decoder_protocolcmplevelL1, acqBd.BdNo, (uint)dn);
  83. if (decodeoption.ProtocolType == SerialProtocolType.ARINC429)
  84. {
  85. double voltage2 = info.Threshold2;
  86. double compVoltage2 = (Hd.CurrHdMessage!.Analog[(int)currChannel].Position + voltage2 * 1000) / Hd.CurrHdMessage!.Analog[(int)currChannel].Scale * Constants.SAMPS_PER_YDIV + Constants.MAX_ADC_RES / 2;
  87. int up2 = (int)(compVoltage2 + 50);
  88. int dn2 = (int)(compVoltage2 - 50);
  89. if (up2 < 0)
  90. up2 = 0;
  91. else if (up2 > (Constants.MAX_ADC_RES / 2 - 1))
  92. up2 = Constants.MAX_ADC_RES / 2 - 1;
  93. if (dn2 < 0)
  94. dn2 = 0;
  95. else if (dn2 > (Constants.MAX_ADC_RES / 2 - 1))
  96. dn2 = Constants.MAX_ADC_RES / 2 - 1;
  97. Hd.currProduct?.AcqBd?.WriteReg(AcqBdReg.W.Decoder_protocolcmplevelH2, acqBd.BdNo, (uint)up2);
  98. Hd.currProduct?.AcqBd?.WriteReg(AcqBdReg.W.Decoder_protocolcmplevelL2, acqBd.BdNo, (uint)dn2);
  99. }
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }
  109. }