using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Uestc.Auto6.Dso.ComModel; namespace Uestc.Auto6.Dso.Hardware.Driver { internal class AbstractController_Decoder { protected Dictionary protocolConfigActionList = new Dictionary(); public static void Config() => Hd.currProduct?.Ctrl_Decoder?.DoConfig(); public void DoConfig() { SerialProtocolType protocolType = Hd.CurrHdMessage!.Trigger!.TrigDecoder!.ProtocolType; if (protocolType != SerialProtocolType.Close) { if (protocolConfigActionList.ContainsKey(protocolType)) { if (protocolType == SerialProtocolType.USB || protocolType == SerialProtocolType.SATA || protocolType == SerialProtocolType.PCIe)//采集板实现 { Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Decoder_ProtocolTypeForTrigger, (uint)protocolType); HdIO.WriteReg(ProcBdReg.W.Decoder_ProtocolTypeForTrigger, (uint)protocolType); Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Decoder_TrigTypeSelect, (uint)protocolType); HdIO.WriteReg((uint)AcqBdReg.W.Decoder_RamResetEnable, 0); HdIO.WriteReg(ProcBdReg.W.Decoder_RamResetEnable, 0); HdIO.Sleep(1); HdIO.WriteReg((uint)AcqBdReg.W.Decoder_RamResetEnable, 1); HdIO.WriteReg(ProcBdReg.W.Decoder_RamResetEnable, 1); } else { HdIO.WriteReg(ProcBdReg.W.Decoder_ProtocolTypeForTrigger, (uint)protocolType); HdIO.WriteReg(ProcBdReg.W.Decoder_TrigTypeSelect, (uint)protocolType); HdIO.WriteReg(ProcBdReg.W.Decoder_RamResetEnable, 0); HdIO.Sleep(1); HdIO.WriteReg(ProcBdReg.W.Decoder_RamResetEnable, 1); } protocolConfigActionList[Hd.CurrHdMessage!.Trigger!.TrigDecoder!.ProtocolType!]?.Invoke(); } } foreach (var decodeoption in Hd.CurrHdMessage!.Decoder!) { if (decodeoption.Active && decodeoption.ProtocolType != SerialProtocolType.Close) { if (protocolConfigActionList.ContainsKey(decodeoption.ProtocolType)) { if (decodeoption.ProtocolType == SerialProtocolType.USB || decodeoption.ProtocolType == SerialProtocolType.SATA || decodeoption.ProtocolType == SerialProtocolType.PCIe)//采集板实现 { Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Decoder_RamResetEnable, 0); HdIO.Sleep(1); Hd.currProduct?.AcqBd?.WriteToAllFpga(AcqBdReg.W.Decoder_RamResetEnable, 1); } protocolConfigActionList[decodeoption.ProtocolType]?.Invoke(); //设置比较电平 var ThresholdInfos = decodeoption.ProtocolOptions.GetThresholdInfos(); if (ThresholdInfos.Count > 0) { ChannelId lastChannelID = ThresholdInfos[0].ChannelId; foreach (var info in ThresholdInfos) { ChannelId currChannel = info.ChannelId; if ((int)currChannel (Constants.MAX_ADC_RES / 2 - 1)) up = Constants.MAX_ADC_RES / 2 - 1; if (dn < 0) dn = 0; else if (dn > (Constants.MAX_ADC_RES / 2 - 1)) dn = Constants.MAX_ADC_RES / 2 - 1; Hd.currProduct?.AcqBd?.WriteReg(AcqBdReg.W.Decoder_protocolcmplevelH1, acqBd.BdNo, (uint)up); Hd.currProduct?.AcqBd?.WriteReg(AcqBdReg.W.Decoder_protocolcmplevelL1, acqBd.BdNo, (uint)dn); if (decodeoption.ProtocolType == SerialProtocolType.ARINC429) { double voltage2 = info.Threshold2; 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; int up2 = (int)(compVoltage2 + 50); int dn2 = (int)(compVoltage2 - 50); if (up2 < 0) up2 = 0; else if (up2 > (Constants.MAX_ADC_RES / 2 - 1)) up2 = Constants.MAX_ADC_RES / 2 - 1; if (dn2 < 0) dn2 = 0; else if (dn2 > (Constants.MAX_ADC_RES / 2 - 1)) dn2 = Constants.MAX_ADC_RES / 2 - 1; Hd.currProduct?.AcqBd?.WriteReg(AcqBdReg.W.Decoder_protocolcmplevelH2, acqBd.BdNo, (uint)up2); Hd.currProduct?.AcqBd?.WriteReg(AcqBdReg.W.Decoder_protocolcmplevelL2, acqBd.BdNo, (uint)dn2); } } } } } } } } } } }