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,67 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTS.Serialization.IRIGCH10.Packets
{
/// <summary>
/// this class helps encapsulate a secondary time format header, but it's really
/// only designed for one type of format currently
/// </summary>
public class SecondaryTimeFormatHeader : ISecondaryTimeFormatHeader
{
private byte[] _bytes = new byte[SECONDARY_TIME_HEADER_LENGTH];
public int NanoSeconds { get; }
public int Seconds { get; }
public ushort Reserved { get; }
public ushort CheckSum { get; }
public DateTime LocalTime
{
get => (new DateTime(1970, 1, 1)).AddSeconds(Seconds).AddTicks(NanoSeconds / 100).ToLocalTime();
}
public SecondaryTimeFormatHeader(byte[] input)
{
Array.Copy(input, 0, _bytes, 0, SECONDARY_TIME_HEADER_LENGTH);
NanoSeconds = BitConverter.ToInt32(_bytes, 0);
Seconds = BitConverter.ToInt32(_bytes, 4);
Reserved = BitConverter.ToUInt16(_bytes, 8);
CheckSum = BitConverter.ToUInt16(_bytes, 10);
byte[] bytesToCompute;
using (var ms = new MemoryStream())
{
using (var bw = new BinaryWriter(ms))
{
bw.Write(BitConverter.GetBytes(NanoSeconds));
bw.Write(BitConverter.GetBytes(Seconds));
bw.Write(Reserved);
}
bytesToCompute = ms.ToArray();
}
var computedChecksum = Utils.Utils.GetCheckSum8(bytesToCompute);
if (computedChecksum != CheckSum)
{
System.Diagnostics.Trace.WriteLine("Secondary time header CRC does not match expectations");
}
}
public static byte[] GetBytes(int nanoseconds, int seconds)
{
using (var ms = new MemoryStream())
{
using (var bw = new BinaryWriter(ms))
{
bw.Write(BitConverter.GetBytes(nanoseconds));
bw.Write(BitConverter.GetBytes(seconds));
bw.Write((ushort)0);
bw.Write(Utils.Utils.GetCheckSum8(ms.ToArray()));
}
return ms.ToArray();
}
}
public const int SECONDARY_TIME_HEADER_LENGTH = 12;
}
}