using DTS.Common.Enums; using System; using System.Linq; using System.Text; namespace DTS.Common.Classes.DASFactory { /// /// this class encapsulates/replaces a uint array that was already in use in FWTU and DP /// it adds some named fields and some to and from just to make things a little easier /// public class TMNSConfig { /// /// the TMNS config implementation in firmware is just an array of uint32, so here's the same thing internally /// private uint[] _values; /// /// the TMNS PCM sub frame id /// public uint TMNS_PCMSubFrameId { get => GetValue(Fields.TMNS_PCMSubFrameID); set => SetValue(Fields.TMNS_PCMSubFrameID, value); } /// /// the TMNS message id /// public uint TMNS_MsgId { get => GetValue(Fields.TMNS_MsgId); set => SetValue(Fields.TMNS_MsgId, value); } /// /// the TMNS PCM minor per major setting /// public uint TMNS_PCMMinorPerMajor { get => GetValue(Fields.TMNS_PCMMinorPerMajor); set => SetValue(Fields.TMNS_PCMMinorPerMajor, value); } /// /// the TMNS TMATs port number setting /// public uint TMNS_TMATSPortNumber { get => GetValue(Fields.TMNS_TMATSPortNumber); set => SetValue(Fields.TMNS_TMATSPortNumber, value); } /// /// the IENA UDP source port number /// public uint IENAUDP_PortNumber { get => GetValue(Fields.IENAUDP_PortNumber); set => SetValue(Fields.IENAUDP_PortNumber, value); } /// /// reserved field 5 /// public uint TMNS5 { get => GetValue(Fields.TMNS5); set => SetValue(Fields.TMNS5, value); } /// /// reserved field 6 /// public uint TMNS6 { get => GetValue(Fields.TMNS6); set => SetValue(Fields.TMNS6, value); } /// /// reserved field 7 /// public uint TMNS7 { get => GetValue(Fields.TMNS7); set => SetValue(Fields.TMNS7, value); } /// /// all fields in the TMNS config unit array and their order /// public enum Fields { TMNS_PCMSubFrameID, TMNS_MsgId, TMNS_PCMMinorPerMajor, TMNS_TMATSPortNumber, IENAUDP_PortNumber, TMNS5, TMNS6, TMNS7 } /// /// handles common init from all constructors /// private void CommonInit() { var fields = Enum.GetValues(typeof(Fields)).Cast().ToArray(); _values = new uint[fields.Length]; } /// /// constructor that takes an array of uints in the same order as the TMNS config /// /// public TMNSConfig(uint[] parameters) { CommonInit(); if (null == parameters) { return; } for (var i = 0; i < parameters.Length && i < _values.Length; i++) { _values[i] = parameters[i]; } } /// /// constructor that takes an array of uints comma separated (and allows for enclosing () around whole string) /// /// public TMNSConfig(string parameters) { CommonInit(); parameters = parameters.Replace("(", "").Replace(")", ""); var tokens = parameters.Split(new[] { ',' }); for (var i = 0; i < tokens.Length && i < _values.Length; i++) { if (uint.TryParse(tokens[i], out var temp)) { _values[i] = temp; } } } public TMNSConfig() { CommonInit(); } /// /// sets indicated field to indicated value /// /// /// public void SetValue(Fields field, uint value) { _values[(int)field] = value; } /// /// gets the value from the indicated field /// /// /// public uint GetValue(Fields field) => _values[(int)field]; public uint[] ToUintArray() { var copy = new uint[_values.Length]; _values.CopyTo(copy, 0); return copy; } /// /// returns a string suitable for storage (x,...n) of the TMNS config /// /// public string ToCSVString() { var sb = new StringBuilder(); sb.Append("("); for (var i = 0; i < _values.Length; i++) { if (i > 0) { sb.Append(","); } sb.Append(_values[i]); } sb.Append(")"); return sb.ToString(); } /// /// returns true if the profile is a ch10 streaming profile /// /// /// public static bool IsCh10(UDPStreamProfile profile) { switch (profile) { case UDPStreamProfile.CH10_MANUAL_CONFIG: case UDPStreamProfile.CH10_PCM128_MM: case UDPStreamProfile.CH10_ANALOG: case UDPStreamProfile.CH10_PCM_STANDARD: case UDPStreamProfile.CH10_PCM_SUPERCOM: case UDPStreamProfile.CH10_PCM_128BIT_2HDR: case UDPStreamProfile.CH10_ANALOG_2HDR: case UDPStreamProfile.CH10_PCM_STANDARD_2HDR: case UDPStreamProfile.CH10_PCM_SUPERCOM_2HDR: return true; default: return false; } } /// /// returns true if the streaming profile is an IENA profile /// /// /// public static bool IsIENA(UDPStreamProfile profile) { switch (profile) { case UDPStreamProfile.IENA_PTYPE_STREAM: return true; default: return false; } } /// /// returns true if the streaming profile is a TMNS profile /// /// /// public static bool IsTMNS(UDPStreamProfile profile) { switch (profile) { case UDPStreamProfile.TMNS_PCM_STANDARD: case UDPStreamProfile.TMNS_PCM_SUPERCOM: return true; default: return false; } } /// /// returns true if the streaming profile is a UART profile /// /// /// public static bool IsUART(UDPStreamProfile profile) { switch (profile) { case UDPStreamProfile.UART_STREAM: return true; default: return false; } } } }