243 lines
8.0 KiB
Plaintext
243 lines
8.0 KiB
Plaintext
using DTS.Common.Enums;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace DTS.Common.Classes.DASFactory
|
|
{
|
|
/// <summary>
|
|
/// 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
|
|
/// </summary>
|
|
public class TMNSConfig
|
|
{
|
|
/// <summary>
|
|
/// the TMNS config implementation in firmware is just an array of uint32, so here's the same thing internally
|
|
/// </summary>
|
|
private uint[] _values;
|
|
/// <summary>
|
|
/// the TMNS PCM sub frame id
|
|
/// </summary>
|
|
public uint TMNS_PCMSubFrameId
|
|
{
|
|
get => GetValue(Fields.TMNS_PCMSubFrameID);
|
|
set => SetValue(Fields.TMNS_PCMSubFrameID, value);
|
|
}
|
|
/// <summary>
|
|
/// the TMNS message id
|
|
/// </summary>
|
|
public uint TMNS_MsgId
|
|
{
|
|
get => GetValue(Fields.TMNS_MsgId);
|
|
set => SetValue(Fields.TMNS_MsgId, value);
|
|
}
|
|
/// <summary>
|
|
/// the TMNS PCM minor per major setting
|
|
/// </summary>
|
|
public uint TMNS_PCMMinorPerMajor
|
|
{
|
|
get => GetValue(Fields.TMNS_PCMMinorPerMajor);
|
|
set => SetValue(Fields.TMNS_PCMMinorPerMajor, value);
|
|
}
|
|
/// <summary>
|
|
/// the TMNS TMATs port number setting
|
|
/// </summary>
|
|
public uint TMNS_TMATSPortNumber
|
|
{
|
|
get => GetValue(Fields.TMNS_TMATSPortNumber);
|
|
set => SetValue(Fields.TMNS_TMATSPortNumber, value);
|
|
}
|
|
/// <summary>
|
|
/// the IENA UDP source port number
|
|
/// </summary>
|
|
public uint IENAUDP_PortNumber
|
|
{
|
|
get => GetValue(Fields.IENAUDP_PortNumber);
|
|
set => SetValue(Fields.IENAUDP_PortNumber, value);
|
|
}
|
|
/// <summary>
|
|
/// reserved field 5
|
|
/// </summary>
|
|
public uint TMNS5
|
|
{
|
|
get => GetValue(Fields.TMNS5);
|
|
set => SetValue(Fields.TMNS5, value);
|
|
}
|
|
/// <summary>
|
|
/// reserved field 6
|
|
/// </summary>
|
|
public uint TMNS6
|
|
{
|
|
get => GetValue(Fields.TMNS6);
|
|
set => SetValue(Fields.TMNS6, value);
|
|
}
|
|
/// <summary>
|
|
/// reserved field 7
|
|
/// </summary>
|
|
public uint TMNS7
|
|
{
|
|
get => GetValue(Fields.TMNS7);
|
|
set => SetValue(Fields.TMNS7, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// all fields in the TMNS config unit array and their order
|
|
/// </summary>
|
|
public enum Fields
|
|
{
|
|
TMNS_PCMSubFrameID,
|
|
TMNS_MsgId,
|
|
TMNS_PCMMinorPerMajor,
|
|
TMNS_TMATSPortNumber,
|
|
IENAUDP_PortNumber,
|
|
TMNS5,
|
|
TMNS6,
|
|
TMNS7
|
|
}
|
|
/// <summary>
|
|
/// handles common init from all constructors
|
|
/// </summary>
|
|
private void CommonInit()
|
|
{
|
|
var fields = Enum.GetValues(typeof(Fields)).Cast<Fields>().ToArray();
|
|
_values = new uint[fields.Length];
|
|
}
|
|
/// <summary>
|
|
/// constructor that takes an array of uints in the same order as the TMNS config
|
|
/// </summary>
|
|
/// <param name="parameters"></param>
|
|
public TMNSConfig(uint [] parameters)
|
|
{
|
|
CommonInit();
|
|
if (null == parameters) { return; }
|
|
for (var i=0; i < parameters.Length && i < _values.Length; i++)
|
|
{
|
|
_values[i] = parameters[i];
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// constructor that takes an array of uints comma separated (and allows for enclosing () around whole string)
|
|
/// </summary>
|
|
/// <param name="parameters"></param>
|
|
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();
|
|
}
|
|
/// <summary>
|
|
/// sets indicated field to indicated value
|
|
/// </summary>
|
|
/// <param name="field"></param>
|
|
/// <param name="value"></param>
|
|
public void SetValue(Fields field, uint value)
|
|
{
|
|
_values[(int)field] = value;
|
|
}
|
|
/// <summary>
|
|
/// gets the value from the indicated field
|
|
/// </summary>
|
|
/// <param name="field"></param>
|
|
/// <returns></returns>
|
|
public uint GetValue(Fields field) => _values[(int)field];
|
|
|
|
public uint [] ToUintArray()
|
|
{
|
|
var copy = new uint[_values.Length];
|
|
_values.CopyTo(copy, 0);
|
|
return copy;
|
|
}
|
|
/// <summary>
|
|
/// returns a string suitable for storage (x,...n) of the TMNS config
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
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();
|
|
}
|
|
/// <summary>
|
|
/// returns true if the profile is a ch10 streaming profile
|
|
/// </summary>
|
|
/// <param name="profile"></param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// returns true if the streaming profile is an IENA profile
|
|
/// </summary>
|
|
/// <param name="profile"></param>
|
|
/// <returns></returns>
|
|
public static bool IsIENA(UDPStreamProfile profile)
|
|
{
|
|
switch (profile)
|
|
{
|
|
case UDPStreamProfile.IENA_PTYPE_STREAM: return true;
|
|
default: return false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// returns true if the streaming profile is a TMNS profile
|
|
/// </summary>
|
|
/// <param name="profile"></param>
|
|
/// <returns></returns>
|
|
public static bool IsTMNS(UDPStreamProfile profile)
|
|
{
|
|
switch(profile)
|
|
{
|
|
case UDPStreamProfile.TMNS_PCM_STANDARD:
|
|
case UDPStreamProfile.TMNS_PCM_SUPERCOM:
|
|
return true;
|
|
default: return false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// returns true if the streaming profile is a UART profile
|
|
/// </summary>
|
|
/// <param name="profile"></param>
|
|
/// <returns></returns>
|
|
public static bool IsUART(UDPStreamProfile profile)
|
|
{
|
|
switch (profile)
|
|
{
|
|
case UDPStreamProfile.UART_STREAM: return true;
|
|
default: return false;
|
|
}
|
|
}
|
|
}
|
|
}
|