using DTS.Common.Enums; using DTS.Common.Interface.Sensors; using DTS.Common.Interface.Tags; using DTS.Common.Utilities.Logging; using System; using System.Collections.Generic; using System.Data; namespace DTS.Common.Classes.Sensors { public class StreamOutputRecord : TagAwareBase, IStreamOutputRecord { public override TagTypes TagType => TagTypes.Sensors; private int _id; public int Id { get => _id; set => SetProperty(ref _id, value, "Id"); } private string _serialNumber; public string SerialNumber { get => _serialNumber; set => SetProperty(ref _serialNumber, value, "SerialNumber"); } private DateTime _lastModified; public DateTime LastModified { get => _lastModified; set => SetProperty(ref _lastModified, value, "LastModified"); } private string _lastUpdatedBy; public string LastUpdatedBy { get => _lastUpdatedBy; set => SetProperty(ref _lastUpdatedBy, value, "LastUpdatedBy"); } private bool _doNotUse; public bool DoNotUse { get => _doNotUse; set => SetProperty(ref _doNotUse, value, "DoNotUse"); } private bool _broken; public bool Broken { get => _broken; set => SetProperty(ref _broken, value, "Broken"); } protected UDPStreamProfile _udpProfile = DEFAULT_UDP_PROFILE; public const UDPStreamProfile DEFAULT_UDP_PROFILE = UDPStreamProfile.CH10_ANALOG_2HDR; //supported on both S6A & TSRAIR public UDPStreamProfile StreamOutUDPProfile { get => _udpProfile; set => SetProperty(ref _udpProfile, value, "StreamOutUDPProfile"); } public const string DEFAULT_UDP_ADDRESS = "UDP://239.1.2.10:8400"; protected string _udpAddress = DEFAULT_UDP_ADDRESS; public string StreamOutUDPAddress { get => _udpAddress; set => SetProperty(ref _udpAddress, value, "StreamOutUDPAddress"); } public const ushort MINIMUM_STREAMOUT_TIMECHANNELID = 10; public const ushort MAXIMUM_STREAMOUT_TIMECHANNELID = 100; public const ushort DEFAULT_UDP_TIME_CHANNEL_ID = 1; protected ushort _udpTimeChannelId = DEFAULT_UDP_TIME_CHANNEL_ID; public ushort StreamOutUDPTimeChannelId { get => _udpTimeChannelId; set => SetProperty(ref _udpTimeChannelId, value, "StreamOutUDPTimeChannelId"); } public const ushort MINIMUM_STREAMOUT_DATACHANNELID = 10; public const ushort MAXIMUM_STREAMOUT_DATACHANNELID = 100; public const ushort DEFAULT_UDP_DATA_CHANNEL_ID = 3; protected ushort _udpDataChannelId = DEFAULT_UDP_DATA_CHANNEL_ID; public ushort StreamOutUDPDataChannelId { get => _udpDataChannelId; set => SetProperty(ref _udpDataChannelId, value, "StreamOutUDPDataChannelId"); } public const string DEFAULT_UDPTMNS_CONFIG = "(1,6,60,0,0,0,0,0)"; protected string _udpTmNSConfig = DEFAULT_UDPTMNS_CONFIG; public string StreamOutUDPTmNSConfig { get => _udpTmNSConfig; set => SetProperty(ref _udpTmNSConfig, value, "StreamOutUDPTmNSConfig"); } public const ushort MINIMUM_STREAMOUT_TDP_INTERVAL_MS = 10; public const ushort MAXIMUM_STREAMOUT_TDP_INTERVAL_MS = 1000; public const ushort DEFAULT_IRIG_TIME_DATA_PACKET_INTERVAL_MS = 500; protected ushort _irigTimeDataPacketIntervalMs = DEFAULT_IRIG_TIME_DATA_PACKET_INTERVAL_MS; public const ushort MINIMUM_STREAMOUT_TMATS_INTERVAL_MS = ushort.MinValue; public const ushort MAXIMUM_STREAMOUT_TMATS_INTERVAL_MS = ushort.MaxValue; private ushort _streamOutTMATSIntervalMs = DEFAULT_TMATS_INTERVAL_MS; /// /// time in MS between sending tmats information while streaming /// http://manuscript.dts.local/f/cases/29987/Add-CG-DP-TMATS-interval-UI-support /// public ushort StreamOutTMATSIntervalMs { get => _streamOutTMATSIntervalMs; set => SetProperty(ref _streamOutTMATSIntervalMs, value, "StreamOutTMATSIntervalMs"); } public ushort StreamOutIRIGTimeDataPacketIntervalMs { get => _irigTimeDataPacketIntervalMs; set => SetProperty(ref _irigTimeDataPacketIntervalMs, value, "StreamOutIRIGTimeDataPacketIntervalMs"); } public StreamOutputRecord(ISensorData sd) { try { Id = sd.DatabaseId; SerialNumber = sd.SerialNumber; StreamOutUDPProfile = sd.StreamOutUDPProfile; StreamOutUDPAddress = sd.StreamOutUDPAddress; StreamOutUDPTimeChannelId = sd.StreamOutUDPTimeChannelId; StreamOutUDPDataChannelId = sd.StreamOutUDPDataChannelId; StreamOutUDPTmNSConfig = sd.StreamOutUDPTmNSConfig; StreamOutIRIGTimeDataPacketIntervalMs = sd.StreamOutIRIGTimeDataPacketIntervalMs; StreamOutTMATSIntervalMs = sd.StreamOutTMATSIntervalMs; Broken = sd.Broken; DoNotUse = sd.DoNotUse; LastModified = sd.LastModified; LastUpdatedBy = sd.LastUpdatedBy; } catch (Exception ex) { APILogger.Log("Failed to process: ", ex); } } public StreamOutputRecord(IDataReader reader, int ClientDbVersion, int ConnectionDbVersion) { try { Id = Utility.GetInt(reader, "Id"); SerialNumber = Utility.GetString(reader, "SerialNumber"); StreamOutUDPProfile = (UDPStreamProfile)Enum.Parse(typeof(UDPStreamProfile), Utility.GetString(reader, "StreamProfile")); StreamOutUDPAddress = Utility.GetString(reader, "UDPAddress"); StreamOutUDPTimeChannelId = Utility.GetUShort(reader, "TimeChannelId"); StreamOutUDPDataChannelId = Utility.GetUShort(reader, "DataChannelId"); StreamOutUDPTmNSConfig = Utility.GetString(reader, "TmNSConfig"); StreamOutIRIGTimeDataPacketIntervalMs = Utility.GetUShort(reader, "IRIGTimeDataPacketIntervalMs"); Broken = Utility.GetBool(reader, "Broken"); DoNotUse = Utility.GetBool(reader, "DoNotUse"); LastModified = Utility.GetDateTime(reader, "LastModified", DateTime.MinValue); LastUpdatedBy = Utility.GetString(reader, "LastModifiedBy"); //only try to retrieve this field if both client and db are high enough level if (ClientDbVersion >= Constants.TMATS_INTERVAL_VERSION && ConnectionDbVersion >= Constants.TMATS_INTERVAL_VERSION) { StreamOutTMATSIntervalMs = Utility.GetUShort(reader, "TMATS_IntervalMS", StreamOutputRecord.DEFAULT_TMATS_INTERVAL_MS); } } catch (Exception ex) { APILogger.Log("Failed to process: ", ex); } } //28291 Reduce list of Stream profiles to choose from. //Define this here so that it only needs to be changed in one place, if a change needs to be made in the future. //30249 Add LTS behavior for case 30075 (ADC UART stream) public static UDPStreamProfile[] AvailableUDPStreamProfiles(int ConnectionDbVersion, bool UseAdvancedStreamingProfiles) { var profiles = new List(); if (UseAdvancedStreamingProfiles) { profiles.AddRange( new UDPStreamProfile[] { UDPStreamProfile.CH10_ANALOG, UDPStreamProfile.CH10_ANALOG_2HDR, UDPStreamProfile.CH10_PCM128_MM, UDPStreamProfile.CH10_PCM_128BIT_2HDR, UDPStreamProfile.TMNS_PCM_STANDARD, UDPStreamProfile.TMNS_PCM_SUPERCOM, UDPStreamProfile.IENA_PTYPE_STREAM, UDPStreamProfile.CH10_MANUAL_CONFIG }); if (ConnectionDbVersion >= Constants.ADC_TO_UART_DB_VERSION) { profiles.Add(UDPStreamProfile.UART_STREAM); } } else { // 31840 Basic / Advanced Streaming profiles profiles.AddRange( new UDPStreamProfile[] { UDPStreamProfile.CH10_ANALOG_2HDR, UDPStreamProfile.CH10_PCM_128BIT_2HDR }); } return profiles.ToArray(); } /// /// the default interval between sending out tmats information while streaming /// this is used if the value is not set or is null /// http://manuscript.dts.local/f/cases/29987/Add-CG-DP-TMATS-interval-UI-support /// public const ushort DEFAULT_TMATS_INTERVAL_MS = 1000; } }