using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Uestc.Auto6.Dso.ComModel { public partial record HdMessage { #region 解码触发结构参数 public record TrigDecoderOptions(SerialProtocolType ProtocolType) { public ITrigDecoderConditionsOptions? DecoderConditionsOptions { get; init; } public IDecoderOptions? ProtocolOptions { get; init; } } public interface ITrigDecoderConditionsOptions { } public record TrigCloseConditionsOptions() : ITrigDecoderConditionsOptions { } public record TrigNRZConditionOptions(ProtocolNRZ.Condition Condition):ITrigDecoderConditionsOptions { public ProtocolNRZ.DataRelation Relation { get; init; } public Byte Data { get; init; } } public record TrigFlexRayConditionOptions(ProtocolFlexRay.Condition Condition):ITrigDecoderConditionsOptions { public ProtocolFlexRay.Realtion Relation { get; init; } public UInt16 ID { get; init; } public Byte[]? Data { get; init; } public Byte CycleData { get; init; } public Byte ByteCount { get;init; } public ProtocolFlexRay.Indicator Indicator { get; init; } public ProtocolFlexRay.FrameError FrameError { get;init; } public ProtocolFlexRay.FrameTail FrameTail { get;init; } } public record TrigEthernetConditionsOptions(ProtocolEthernet.Condition Condition):ITrigDecoderConditionsOptions { public Byte Data { get; init; } public Byte[]? SrcMAC { get; init; } public Byte[]? DestMAC { get; init; } public ProtocolEthernet.DataRelation Relation { get; init; } } public record TrigLINConditionsOptions(ProtocolLIN.Condition Condition) : ITrigDecoderConditionsOptions { public ProtocolLIN.DataRelation DataRelation { get; init ; } public Byte ID { get; init; } public Byte Data { get; init; } } public record TrigRS232ConditionsOptions(ProtocolRS232.Conditions Conditions) : ITrigDecoderConditionsOptions { public PulseCondition Compare { get; init; } public Char Data { get; init; } public Char EOPChar { get; init; } } public record TrigPCIeConditionsOptions(ProtocolPCIe.Condition Condition):ITrigDecoderConditionsOptions { public ProtocolPCIe.TLPType TLPType { get; init; } public UInt16 SeqID { get; init; } public Byte TCData { get; init; } public Byte ATData { get; init; } public Byte TagData { get; init; } public UInt16 ReqIDData { get; init; } public Byte MsgCodeData { get; init; } public Byte DataLenght { get; init; } public Int64 Data { get; init; } public Int64 AddressData { get; init; } public ProtocolPCIe.DataRelation DataRelation { get;init; } } public record TrigMILConditionsOptions(ProtocolMIL.Condition Condition):ITrigDecoderConditionsOptions { } public record TrigI2SConditionsOptions(ProtocolAudioBus.Condition Condition):ITrigDecoderConditionsOptions { public UInt32 Data { get;init; } public ProtocolAudioBus.DataRelation DataRelation { get;init; } } public record TrigSPMIConditionsOptions(ProtocolSPMI.Condition Condition):ITrigDecoderConditionsOptions { } public record TrigI2CConditionsOptions(ProtocolI2C.Condition Condition) : ITrigDecoderConditionsOptions { /// /// 数据方向 /// 当的值为时有效 /// public ProtocolI2C.DataDirection Direction { get; init; } /// /// 地址值 /// public UInt16 AddressData { get; init; } /// /// 比较方式 /// public ProtocolI2C.DataRelation Relation { get; init; } /// /// 字节数 /// 当的值为时有效 /// public Byte DataBytesCount { get; init; } /// /// 字节号,从0开始 /// 当的值为时有效 /// public Int32 DataByteIndex { get; init; } /// /// 数据 /// 当的值为时有效 /// public Int64 Data { get; init; } } public record TrigSATAConditionsOptions(ProtocolSATA.Condition Condition) :ITrigDecoderConditionsOptions { public Int64 Data { get;init; } public ProtocolSATA.DataRelation Relation { get;init; } public Byte DataCount { get; init; } public ProtocolSATA.FISTypeFlag FISType { get; init; } } public record TrigSPIConditionsOptions(ComModel.ProtocolSPI.Condition Condition) : ITrigDecoderConditionsOptions { public ComModel.ProtocolSPI.DataTriggerSource DataSource { get; init; } public Int32 FrameCount { get; init; } public Int64 FrameData { get; init; } } public record TrigARINC429ConditionsOptions(ProtocolARINC429.Condition Condition) : ITrigDecoderConditionsOptions { public UInt32 SSM { get; init; } public UInt32 SDI { get; init; } public UInt32 Label { get; init; } public UInt32 Data { get; init; } public ProtocolARINC429.DataRelation DataRelation { get; init; } } public record TrigCANFDConditionsOptions(ProtocolCANFD.Condition Condition) : ITrigDecoderConditionsOptions { public ProtocolCANFD.FrameType FrameType { get; init; } public ProtocolCANFD.IDStandard IDStandard { get; init; } public ProtocolCANFD.IDFrameDirection IDFrameDirection { get; init; } public Int32 StandardID { get; init; } public Int32 ExtendedID { get; init; } public Int32 ByteCount { get; init; } public Int32 ByteIndex { get; init; } public Int64 Data { get; init; } public ProtocolCANFD.DataRelation DataRelation { get; init; } public ProtocolCANFD.ErrorPacketType ErrorPacketType { get;init; } } public record TrigUSBConditionsOptions(ProtocolUSB.Condition Condition):ITrigDecoderConditionsOptions { public ProtocolUSB.DataRelation DataRelation { get;init; } public UInt16 Data { get;init; } public ProtocolUSB.TokenPackageType TokenPackageType { get;init; } public ProtocolUSB.HandshakePackageType HandshakePackageType { get;init; } public ProtocolUSB.DataPackageType DataPackageType { get;init; } public ProtocolUSB.ErrorPackageType ErrorPackageType { get;init; } public ProtocolUSB.SpecialPacketType SpecialPacketType { get;init; } } public record TrigCANConditionsOptions(ProtocolCAN.Condition Condition) : ITrigDecoderConditionsOptions { public ProtocolCAN.FrameType FrameType { get; init; } public ProtocolCAN.IDStandard IDStandard { get; init; } public ProtocolCAN.IDFrameDirection IDFrameDirection { get; init; } public Int32 StandardID { get; init; } public Int32 ExtendedID { get; init; } public ProtocolCAN.DataRelation DataRelation { get; init; } public Int32 ByteIndex { get; init; } public Int32 ByteCount { get; init; } public Int64 Data { get; init; } public ProtocolCAN.ErrorPacketType ErrorPacketType { get;init; } } public record TrigJTAGConditionsOptions(ComModel.ProtocolJTAG.Condition Condition) : ITrigDecoderConditionsOptions { public ComModel.ProtocolJTAG.DataRelation DataRelation { get; init; } public Byte[]? Data { get; init; } } public record TrigSENTConditionsOptions(ProtocolSENT.Condition Condition) : ITrigDecoderConditionsOptions { public ProtocolSENT.DataRelation DataRelation { get; init; } public UInt32 Data { get; init; } } #endregion 解码触发结构参数 #region 解码结构参数 public record DecoderOptions(Boolean Active, SerialProtocolType ProtocolType) { public Double Position { get; init; } public IDecoderOptions? ProtocolOptions { get; init; } } public interface IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos(); } public record ProtocolCloseOptions() : IDecoderOptions { //无参数 public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { return new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>(); } } public record ProtocolEthernetOptions():IDecoderOptions { public ProtocolEthernet.EthernetVersion Version { get; init; } /// /// 数据源的阈值 /// public Double Signal1ThresholdH { get; init; } /// /// 数据源的阈值 /// public Double Signal1ThresholdL { get; init; } public ChannelId SignalInput1 { get; init; } public ChannelId SignalInput2 { get; init; } public ProtocolEthernet.SignalType SignalType { get; init; } public ProtocolEthernet.EthernetSpeed Speed { get; init; } public Double Signal1Threshold { get; init; } public Double Signal2Threshold { get; init; } public Byte QFlag { get; init; } public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { var tempinfos = new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>(); if(SignalType == ProtocolEthernet.SignalType.Single) { tempinfos.Add((SignalInput1, Signal1Threshold, 0)); tempinfos.Add((SignalInput2, Signal2Threshold, 0)); } else { tempinfos.Add((SignalInput1, Signal1ThresholdH, Signal1ThresholdL)); } return tempinfos; } } public record ProtocolUSBOptions():IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { return new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>() { (Source1,Source1Threshold,0), (Source2,Source2Threshold,0), }; } public ChannelId Source1 { get;init; } public ChannelId Source2 { get;init; } public Double Source1Threshold { get;init; } public Double Source2Threshold { get;init; } public ProtocolUSB.SignalRate SignalRate { get;init; } public UInt16 ByteCount { get;init; } } public record ProtocolRS232Options() : IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { var tempinfos = new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>(); if (SignalType == ProtocolRS232.SignalType.Single) { tempinfos.Add((Source, Threshold, 0)); } else { tempinfos.Add((Source, Threshold, 0)); tempinfos.Add((SourceL, Threshold, 0)); } return tempinfos; } public ChannelId Source { get; init; } public ChannelId SourceL { get; init; } public ProtocolRS232.DataBitWidth DataBitWidth { get; init; } public ProtocolRS232.OddEvenCheck OddEvenCheck { get; init; } public ProtocolRS232.StopBit StopBit { get; init; } public ProtocolRS232.MSB_LSB BitSeq { get; init; } public ProtocolRS232.Polarity Polarity { get; init; } public UInt32 Baud { get; init; } public ProtocolRS232.SignalType SignalType { get; init; } public Double Threshold { get;init; } } public record ProtocolPCIeOptions():IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { var tempinfos = new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>(); if (SignalType == ProtocolPCIe.SignalType.Single) { tempinfos.Add((SignalInput, Threshold, 0)); } else { tempinfos.Add((SignalInput, Threshold, 0)); tempinfos.Add((SignalIutput1, Threshold, 0)); } return tempinfos; } public ChannelId SignalInput { get;init; } public ChannelId SignalIutput1 { get;init; } public ProtocolPCIe.PCIeVersion Version { get;init; } public ProtocolPCIe.SignalType SignalType { get;init; } public Double Threshold { get;init; } public UInt16 ByetsCount { get;init; } } public record ProtocolI2SOptions():IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { return new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>() { (SCL,SCLThreshold,0), (WS,WSThreshold,0), (SDA,SDAThreshold,0), }; } public ProtocolAudioBus.SubType SubType { get; init; } public ProtocolAudioBus.SyncPolarity SyncPolarity { get; init; } public ProtocolAudioBus.ClockEdge ClockEdge { get; init; } public ProtocolAudioBus.DataPolarity DataPolarity { get; init; } public ProtocolAudioBus.MSB_LSB MSB_LSB { get; init; } public ProtocolAudioBus.SoundChannel SoundChannel { get; init; } public Int32 BitDelayCount { get; init; } public Int32 DataBitCount { get; init; } public Int32 ClockBitCount { get; init; } public Int32 SoundChannelCount { get; init; } public ChannelId SCL { get;init; } public ChannelId WS { get;init; } public ChannelId SDA { get;init; } public Double SCLThreshold { get;init; } public Double WSThreshold { get;init; } public Double SDAThreshold { get;init; } } public record ProtocolI2COptions() : IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { return new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>() { (SCLK,SCLKThreshold,0), (SDA,SDAThreshold,0), }; } public ChannelId SCLK { get; init; } public ChannelId SDA { get; init; } public Double SCLKThreshold { get; init; } public Double SDAThreshold { get; init; } public ProtocolI2C.AddrBitWidth BitWidth { get;init; } } public record ProtocolSPIOptions() : IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { var tempinfos = new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>(); tempinfos.Add((CLK, CLKThreshold, 0)); if(FramingMode == ProtocolSPI.FramingMode.Slave) { tempinfos.Add((CS, CSThreshold, 0)); } switch(DecodeChannel) { case ProtocolSPI.DecodeChannel.MOMI: tempinfos.Add((MISO, MISOThreshold, 0)); tempinfos.Add((MOSI, MISOThreshold, 0)); break; case ProtocolSPI.DecodeChannel.MOSI: tempinfos.Add((MOSI, MOSIThreshold, 0)); break; case ProtocolSPI.DecodeChannel.MISO: tempinfos.Add((MISO, MISOThreshold, 0)); break; } return tempinfos; } public ComModel.ProtocolSPI.FramingMode FramingMode { get; init; } public ComModel.ProtocolSPI.DecodeChannel DecodeChannel { get; init; } public Int32 FrameCount { get; init; } public ComModel.ChannelId CLK { get; init; } public ComModel.ChannelId MOSI { get; init; } public ComModel.ChannelId MISO { get; init; } public ComModel.ChannelId CS { get; init; } public Double IdleTime { get; init; } public Double CLKThreshold { get; init; } public Double MOSIThreshold { get; init; } public Double MISOThreshold { get; init; } public ComModel.ProtocolSPI.MSB_LSB ByteOrder { get; init; } public ComModel.ProtocolSPI.Polarity MISOPolarity { get; init; } public ComModel.ProtocolSPI.Polarity MOSIPolarity { get; init; } public ComModel.ProtocolSPI.LevelState CSLevelState { get; init; } public ComModel.ProtocolSPI.EdgeState CLKState { get; init; } public Double CSThreshold { get; init; } } public record ProtocolSATAOptions():IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { var tempinfos = new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>(); tempinfos.Add((Source, Threshold, 0)); return tempinfos; } public ProtocolSATA.SATAVersion Version { get;init; } public ChannelId Source { get;init; } public ChannelId Source1 { get;init; } public Double Threshold { get;init; } public UInt16 BytesCount { get;init; } } public record ProtocolARIN429Options() : IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { var tempinfos = new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>(); tempinfos.Add((SignalInputA, ThresholdH, ThresholdL)); if (InputMode == ProtocolARINC429.InputMode.Diff) { tempinfos.Add((SignalInputB, ThresholdH, ThresholdL)); } return tempinfos; } public ProtocolARINC429.DecodeMode DecodeMode { get; init; } public ChannelId SignalInputA { get; init; } public ProtocolARINC429.InputMode InputMode { get;init; } public ChannelId SignalInputB { get;init; } public Int32 Baud//自定义速率 { get; init; } /// /// 数据源的阈值 /// public Double ThresholdH { get; init; } public Double ThresholdL { get; init; } } public record ProtocolSPMIOptions() : IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { return new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>() { (SCLK,CLKThreshold,0), (SData,DataThreshold,0), }; } public Double CLKThreshold { get; init; } public Double DataThreshold { get; init; } public ChannelId SData { get; init; } public ChannelId SCLK { get; init; } public ProtocolSPMI.Version Version { get; init; } public ProtocolSPMI.CheckType CheckType { get; init; } } public record ProtocolMILOptions():IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { return new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>() { (Source,Threshold,0), }; } public Int32 SignalRate { get; init; } public Double Threshold { get; init; } public ChannelId Source { get; init; } public ProtocolMIL.Polarity Polarity { get; init; } } public record ProtocolNRZOptions():IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { var tempinfos = new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>(); if(SignalType == ProtocolNRZ.SignalType.Single) { tempinfos.Add((Source1, Threshold, 0)); } else { tempinfos.Add((Source1, Threshold, 0)); tempinfos.Add((Source2, Threshold, 0)); } return tempinfos; } public Int64 SignalRate { get; init; } public ProtocolNRZ.SignalType SignalType { get; init; } public ChannelId Source1 { get; init; } public ChannelId Source2 { get; init; } public Double Threshold { get; init; } public ProtocolNRZ.MSB_LSB MSB_LSB { get; init; } public UInt32 IdleTime { get; init; } public ProtocolNRZ.IdleLevel IdleLevel { get; init; } public ProtocolNRZ.Mode Mode { get; init; } } public record ProtocolCANOptions() : IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { var tempinfos = new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>(); if (SignalType == ProtocolCAN.SignalType.Diff) { tempinfos.Add((SignalInput1, SDAThreshold, 0)); tempinfos.Add((SignalInput2, SDAThreshold, 0)); } else { tempinfos.Add((SignalInput1, SDAThreshold, 0)); } return tempinfos; } public Int64 SignalRate { get; init; } //信号类型 public ProtocolCAN.SignalType SignalType { get; init; } //输入1 public ChannelId SignalInput1 { get; init; } //输入2(信号类型选择"差分"时使用) public ChannelId SignalInput2 { get; init; } //采样点 public Int32 SamplePoint { get; init; } /// /// 数据源的阈值 /// public Double SDAThreshold { get; init; } } public record ProtocolCANFDOptions() : IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { var tempinfos = new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>(); if (SignalType == ProtocolCANFD.SignalType.Diff) { tempinfos.Add((SignalInput1, SDAThreshold, 0)); tempinfos.Add((SignalInput2, SDAThreshold, 0)); } else { tempinfos.Add((SignalInput1, SDAThreshold, 0)); } return tempinfos; } public Int64 SDSignalRate { get; init; } public Int64 FDSignalRate { get; init; } //信号类型 public ProtocolCANFD.SignalType SignalType { get; init; } //输入1 public ChannelId SignalInput1 { get; init; } //输入2(信号类型选择"差分"时使用) public ChannelId SignalInput2 { get; init; } //采样点 public Int32 SamplePoint { get; init; } /// /// 数据源的阈值 /// public Double SDAThreshold { get; init; } } public record ProtocolJTAGOptions : IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { var tempinfos = new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>(); tempinfos.Add((TCK, TCKThreshold, 0)); tempinfos.Add((TDI, TDIThreshold, 0)); tempinfos.Add((TDO, TDOThreshold, 0)); tempinfos.Add((TMS, TMSThreshold, 0)); return tempinfos; } public ChannelId TCK { get; init; } public Double TCKThreshold { get; init; } public ChannelId TMS { get; init; } public Double TMSThreshold { get; init; } public ChannelId TDI { get; init; } public Double TDIThreshold { get; init; } public ChannelId TDO { get; init; } public Double TDOThreshold { get; init; } public ComModel.ProtocolJTAG.DecodeChannel DecodeChannel { get; init; } public UInt32 BitRate { get; init; } } public record ProtocolLINOptions:IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { var tempinfos = new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>(); tempinfos.Add((Source, Threshold, 0)); return tempinfos; } public ChannelId Source { get; init ; } public ProtocolLIN.Standard Standard { get; init ; } public ProtocolLIN.Polarity Polarity { get; init; } public ProtocolLIN.PIncludeOddEven PIncludeOddEven { get; init; } public Double Threshold { get; init; } public Int32 BPS { get; init; } public Int32 DataCount { get;init; } } public record ProtocolFlexRayOptions : IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { var tempinfos = new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>(); if (SourceType == ProtocolFlexRay.SourceType.BDiff) { tempinfos.Add((Source, Threshold, 0)); tempinfos.Add((SourceL, Threshold, 0)); } else { tempinfos.Add((Source, Threshold, 0)); } return tempinfos; } public ChannelId Source { get; init; } public ChannelId SourceL { get;init; } public ProtocolFlexRay.ChannelType ChannelType { get; init; } public ProtocolFlexRay.SourceType SourceType { get; init; } public Int64 SignalRate { get; init; } public Double Threshold { get; init; } public Int32 ByteOffset { get;init; } public Int32 PayLoadLength { get;init; } } public record ProtocolSENTOptions : IDecoderOptions { public List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)> GetThresholdInfos() { var tempinfos = new List<(ChannelId ChannelId, Double Threshold1, Double Threshold2)>(); tempinfos.Add((Source, Threshold, 0)); return tempinfos; } public ComModel.ChannelId Source { get; init; } public ProtocolSENT.PauseBit PauseBit { get; init; } public ProtocolSENT.SENTCRC CRC { get; init; } public ProtocolSENT.DataLength DataLength { get; init; } public ProtocolSENT.Polarity Polarity { get; init; } public Int64 SignalRate { get; init; } public Double Threshold { get; init; } } #endregion 解码结构参数 } }