This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,83 @@
using System;
using System.Linq;
namespace DTS.Serialization.IRIGCh10.Attributes
{
/// <summary>
/// this class is used to annotate enums with a version attribute
/// for example each data packet type has a corresponding version number
/// example TABLE 10-7. DATA TYPE NAMES AND DESCRIPTIONS in chapter 10.pdf
/// </summary>
[AttributeUsage(AttributeTargets.All)]
public class DataTypeVersionValueAttribute : Attribute
{
/// <summary>Specifies the default value for the <see cref="DataTypeVersionValueAttribute" />, which is 0x00. This <see langword="static" /> field is read-only.</summary>
public static readonly DataTypeVersionValueAttribute Default = new DataTypeVersionValueAttribute();
private byte _dataTypeVersion;
/// <summary>Initializes a new instance of the <see cref="DataTypeVersionValueAttribute" /> class with no parameters.</summary>
public DataTypeVersionValueAttribute()
: this(0x00)
{
}
/// <summary>Initializes a new instance of the <see cref="DataTypeVersionValueAttribute" /> class with a DataTypeVersionValue.</summary>
/// <param name="dataTypeVersion">The data type version. </param>
public DataTypeVersionValueAttribute(byte dataTypeVersion)
{
_dataTypeVersion = dataTypeVersion;
}
/// <summary>Gets the data type version stored in this attribute.</summary>
/// <returns>The data type version stored in this attribute.</returns>
public virtual byte DataTypeVersion => DataTypeVersionValue;
/// <summary>Gets or sets the byte stored as the datatype version.</summary>
/// <returns>The byte stored as the data type version. The default value is 0x00.</returns>
protected byte DataTypeVersionValue
{
get => _dataTypeVersion;
set => _dataTypeVersion = value;
}
/// <summary>Returns whether the value of the given object is equal to the current <see cref="DataTypeVersionValueAttribute" />.</summary>
/// <param name="obj">The object to test the value equality of. </param>
/// <returns>
/// <see langword="true" /> if the value of the given object is equal to that of the current; otherwise, <see langword="false" />.</returns>
public override bool Equals(object obj)
{
if (obj == this)
return true;
if (obj is DataTypeVersionValueAttribute attribute)
return attribute.DataTypeVersion == DataTypeVersion;
return false;
}
/// <summary>Returns the hash code for this instance.</summary>
/// <returns>A 32-bit signed integer hash code.</returns>
public override int GetHashCode()
{
return DataTypeVersion.GetHashCode();
}
/// <summary>Returns a value indicating whether this is the default <see cref="DataTypeVersionValueAttribute" /> instance.</summary>
/// <returns>
/// <see langword="true" />, if this is the default <see cref="DataTypeVersionValueAttribute" /> instance; otherwise, <see langword="false" />.</returns>
public override bool IsDefaultAttribute()
{
return Equals(Default);
}
public static byte GetDataTypeVersionValue(Enum value)
{
var fi = value.GetType().GetField(value.ToString());
var attributes = (DataTypeVersionValueAttribute[])fi.GetCustomAttributes(
typeof(DataTypeVersionValueAttribute), false);
if (attributes.Any())
{
return attributes.First().DataTypeVersionValue;
}
return Default.DataTypeVersionValue;
}
}
}

View File

@@ -0,0 +1,45 @@
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace IRIGCh10
{
/// <summary>
/// allows annotating enums with a description attribute, in chapter 10 this allows us
/// to associate an enum with a string to put in the TMATS file for that enum
/// </summary>
public static class DescriptionDecoder
{
public static string GetDescription(Enum value)
{
var fi = value.GetType().GetField(value.ToString());
var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(
typeof(DescriptionAttribute), false);
if (attributes.Any())
{
return attributes.First().Description;
}
return value.ToString();
}
}
/// <summary>
/// a lot of attributes in chapter 10 have a max length associated with them
/// note however though that max length in chapter 10 is just a suggested
/// max length, not a requirement ...
/// </summary>
public static class MaxLengthDecoder
{
public static int GetMaxLength(Enum value)
{
var fi = value.GetType().GetField(value.ToString());
var attributes = (MaxLengthAttribute[])fi.GetCustomAttributes(
typeof(MaxLengthAttribute), false);
if (attributes.Any())
{
return attributes.First().Length;
}
return 0;
}
}
}

View File

@@ -0,0 +1,82 @@
using System;
using System.Linq;
namespace DTS.Serialization.IRIGCh10.Attributes
{
/// <summary>
/// allows annotating an enum with a value,
/// see TABLE 10-7. DATA TYPE NAMES AND DESCRIPTIONS in Chapter 10 pdf
/// </summary>
[AttributeUsage(AttributeTargets.All)]
public class PacketHeaderValueAttribute : Attribute
{
/// <summary>Specifies the default value for the <see cref="PacketHeaderValueAttribute" />, which is 0x00. This <see langword="static" /> field is read-only.</summary>
public static readonly PacketHeaderValueAttribute Default = new PacketHeaderValueAttribute();
private byte _packetHeader;
/// <summary>Initializes a new instance of the <see cref="PacketHeaderValueAttribute" /> class with no parameters.</summary>
public PacketHeaderValueAttribute()
: this(0x00)
{
}
/// <summary>Initializes a new instance of the <see cref="PacketHeaderValueAttribute" /> class with a PacketHeader.</summary>
/// <param name="packetHeader">packet header value. </param>
public PacketHeaderValueAttribute(byte packetHeader)
{
_packetHeader = packetHeader;
}
/// <summary>Gets the packet header value stored in this attribute.</summary>
/// <returns>The packet header value stored in this attribute.</returns>
public virtual byte PacketHeader => PacketHeaderValue;
/// <summary>Gets or sets the byte stored as the packet header value.</summary>
/// <returns>The byte stored as the packet header version value. The default value is 0x00.</returns>
protected byte PacketHeaderValue
{
get => _packetHeader;
set => _packetHeader = value;
}
/// <summary>Returns whether the value of the given object is equal to the current <see cref="PacketHeaderValueAttribute" />.</summary>
/// <param name="obj">The object to test the value equality of. </param>
/// <returns>
/// <see langword="true" /> if the value of the given object is equal to that of the current; otherwise, <see langword="false" />.</returns>
public override bool Equals(object obj)
{
if (obj == this)
return true;
if (obj is PacketHeaderValueAttribute packetHeaderAttribute)
return packetHeaderAttribute.PacketHeader == PacketHeader;
return false;
}
/// <summary>Returns the hash code for this instance.</summary>
/// <returns>A 32-bit signed integer hash code.</returns>
public override int GetHashCode()
{
return PacketHeader.GetHashCode();
}
/// <summary>Returns a value indicating whether this is the default <see cref="PacketHeaderValueAttribute" /> instance.</summary>
/// <returns>
/// <see langword="true" />, if this is the default <see cref="PacketHeaderValueAttribute" /> instance; otherwise, <see langword="false" />.</returns>
public override bool IsDefaultAttribute()
{
return Equals(Default);
}
public static byte GetPacketHeaderValue(Enum value)
{
var fi = value.GetType().GetField(value.ToString());
var attributes = (PacketHeaderValueAttribute[])fi.GetCustomAttributes(
typeof(PacketHeaderValueAttribute), false);
if (attributes.Any())
{
return attributes.First().PacketHeaderValue;
}
return Default.PacketHeaderValue;
}
}
}