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,240 @@
using System;
using System.Collections;
using System.Linq;
namespace DTS.Serialization.IRIGCH10.Packets
{
public class AnalogDataFormat1Packet : AbstractDataPacket, IDataPacket
{
public DateTime LocalTimeOfFirstSample
{
get;
private set;
}
//bit 28
public bool Same
{
get
{
var channelSpecificDataWord = BitConverter.GetBytes(ChannelSpecificDataWord);
var bits = new BitArray(channelSpecificDataWord);
return bits[28];
}
set
{
var channelSpecificDataWord = BitConverter.GetBytes(ChannelSpecificDataWord);
var b = new BitArray(channelSpecificDataWord);
b[28] = value;
var ret = new byte[sizeof(uint)];
b.CopyTo(ret, 0);
ChannelSpecificDataWord = BitConverter.ToUInt32(ret, 0);
}
}
//bits 27-24
public int Factor
{
get
{
var channelSpecificDataWord = BitConverter.GetBytes(ChannelSpecificDataWord);
var bits = new BitArray(channelSpecificDataWord);
return Utils.Utils.BitArrayToInt32(bits, 24, 27);
}
set
{
var channelSpecificDataWord = BitConverter.GetBytes(ChannelSpecificDataWord);
var b = new BitArray(channelSpecificDataWord);
Utils.Utils.SetBits(b, (uint)value, 24, 27);
var ret = new byte[sizeof(uint)];
b.CopyTo(ret, 0);
ChannelSpecificDataWord = BitConverter.ToUInt32(ret, 0);
}
}
//bits 23-16
public int TotChan
{
get
{
var channelSpecificDataWord = BitConverter.GetBytes(ChannelSpecificDataWord);
var bits = new BitArray(channelSpecificDataWord);
return Utils.Utils.BitArrayToInt32(bits, 16, 23);
}
set
{
var channelSpecificDataWord = BitConverter.GetBytes(ChannelSpecificDataWord);
var b = new BitArray(channelSpecificDataWord);
Utils.Utils.SetBits(b, (uint)value, 16, 23);
var ret = new byte[sizeof(uint)];
b.CopyTo(ret, 0);
ChannelSpecificDataWord = BitConverter.ToUInt32(ret, 0);
}
}
//bits 15-8
public long Subchan
{
get
{
var channelSpecificDataWord = BitConverter.GetBytes(ChannelSpecificDataWord);
var bits = new BitArray(channelSpecificDataWord);
return Utils.Utils.BitArrayToInt32(bits, 8, 15);
}
set
{
var channelSpecificDataWord = BitConverter.GetBytes(ChannelSpecificDataWord);
var b = new BitArray(channelSpecificDataWord);
Utils.Utils.SetBits(b, (uint)value, 8, 15);
var ret = new byte[sizeof(uint)];
b.CopyTo(ret, 0);
ChannelSpecificDataWord = BitConverter.ToUInt32(ret, 0);
}
}
//bits 7-2
public long Length
{
get
{
var channelSpecificDataWord = BitConverter.GetBytes(ChannelSpecificDataWord);
var bits = new BitArray(channelSpecificDataWord);
return Utils.Utils.BitArrayToInt32(bits, 2, 7);
}
set
{
var channelSpecificDataWord = BitConverter.GetBytes(ChannelSpecificDataWord);
var b = new BitArray(channelSpecificDataWord);
Utils.Utils.SetBits(b, (uint)value, 2, 7);
var ret = new byte[sizeof(uint)];
b.CopyTo(ret, 0);
ChannelSpecificDataWord = BitConverter.ToUInt32(ret, 0);
}
}
public enum Modes
{
DataIsPacked,
DataIsUnpackedLSBPadded,
Reserved,
DataIsUnpackedMSBPadded
}
//bits 1-0
public Modes Mode
{
get
{
var channelSpecificDataWord = BitConverter.GetBytes(ChannelSpecificDataWord);
var bits = new BitArray(channelSpecificDataWord);
var mode = Utils.Utils.BitArrayToInt32(bits, 0, 1);
switch (mode)
{
case 0: return Modes.DataIsPacked;
case 1: return Modes.DataIsUnpackedLSBPadded;
case 3: return Modes.DataIsUnpackedMSBPadded;
case 2:
default: return Modes.Reserved;
}
}
set
{
var channelSpecificDataWord = BitConverter.GetBytes(ChannelSpecificDataWord);
var b = new BitArray(channelSpecificDataWord);
Utils.Utils.SetBits(b, (uint)value, 0, 1);
var ret = new byte[sizeof(uint)];
b.CopyTo(ret, 0);
ChannelSpecificDataWord = BitConverter.ToUInt32(ret, 0);
}
}
public SampleData[] Samples = new SampleData[0];
public class SampleData
{
public short[] ChannelData { private set; get; }
protected SampleData() { }
public SampleData(short[] channels)
{
ChannelData = channels;
}
}
/// <summary>
/// it seems the EMC ch10 validation tool only supports CH10 106v5, so use this header value for the analog packet when in this mode
/// whether to include secondary time header or not
/// 33199 Add Time format 1 as an export option for CH 10 export
/// </summary>
private const byte DATA_VERSION_V105 = 0x01;
private const byte DATA_VERSION_DASSAULT = 0x06;
public AnalogDataFormat1Packet(int nanoseconds, int seconds,
Chapter10File.GetNextSampleDelegate getNextSample, int totalChannels, long channelLength, long rtc, long numSamples, long currentSample, byte sequenceNumber,
ushort channelId, bool includeSecondaryHeader) : base(Enums.DataFileDataTypes.AnalogDataFormat1, includeSecondaryHeader)
{
TotChan = totalChannels;
Subchan = 0;
Same = true;
Factor = 0;
Length = 16;
Mode = Modes.DataIsUnpackedMSBPadded;
var dataLength = Convert.ToUInt32(4 + sizeof(ushort) * totalChannels * numSamples); ;
var offset = CommonHeaderWork(channelId, includeSecondaryHeader ? DATA_VERSION_DASSAULT : DATA_VERSION_V105, sequenceNumber, rtc, dataLength, nanoseconds, seconds);
for (var sampleIdx = 0; sampleIdx < numSamples; sampleIdx++)
{
for (var chIdx = 0; chIdx < totalChannels; chIdx++)
{
var signed = getNextSample(chIdx);
var unsigned = (ushort)(((signed - 0x8000 & 0x00FF) << 8) | ((signed - 0x8000 >> 8) & 0x00FF));
var bytes = BitConverter.GetBytes(unsigned).Reverse().ToArray();
Buffer.BlockCopy(bytes, 0, _dataBytes, offset, 2);
offset += 2;
}
currentSample++;
}
}
public AnalogDataFormat1Packet() : base(Enums.DataFileDataTypes.AnalogDataFormat1, true)
{
}
public AnalogDataFormat1Packet(byte[] bytes) : base(bytes)
{
var offset = IRIGCH10.PacketHeader.PACKET_HEADER_LENGTH;
if (PacketHeader.SecondaryHeaderPresent)
{
var secondaryHeaderBytes = new byte[SecondaryTimeFormatHeader.SECONDARY_TIME_HEADER_LENGTH];
Buffer.BlockCopy(bytes, offset,
secondaryHeaderBytes, 0, SecondaryTimeFormatHeader.SECONDARY_TIME_HEADER_LENGTH);
var secondaryHeader = new SecondaryTimeFormatHeader(secondaryHeaderBytes);
LocalTimeOfFirstSample = secondaryHeader.LocalTime;
offset += SecondaryTimeFormatHeader.SECONDARY_TIME_HEADER_LENGTH;
}
ChannelSpecificDataWord = BitConverter.ToUInt32(bytes, offset);
offset += sizeof(uint);
var numChannels = TotChan;
var sizeOf1SampleForAllChannels = sizeof(ushort) * numChannels;
//There's a CSDW in the data section, then all ADC data. CSDW is uint, 4 bytes
var numSamples = (PacketHeader.DataLength - 4) / sizeOf1SampleForAllChannels;
Samples = new SampleData[numSamples];
for (var i = 0; i < Samples.Length; i++)
{
var channels = GetChannels(bytes, offset, numChannels);
Samples[i] = new SampleData(channels);
offset += sizeOf1SampleForAllChannels;
}
}
private short[] GetChannels(byte[] bytes, int sampleStart, int numChannels)
{
var ret = new short[numChannels];
for (var i = 0; i < numChannels; i++)
{
var unsignedBytes = new byte[2];
Buffer.BlockCopy(bytes, sampleStart + i * 2, unsignedBytes, 0, 2);
//we have to change the byte order here
var unsigned = BitConverter.ToUInt16(new[] { unsignedBytes[1], unsignedBytes[0] }, 0);
//go from unsigned to signed
var adc = (short)((((unsigned & 0x00FF) << 8) | ((unsigned >> 8) & 0x00FF)) + 0x8000);
ret[i] = adc;
}
return ret;
}
}
}

View File

@@ -0,0 +1,60 @@
/////////////////////////////////////////////////////////////////////////////
// ChannelDefinition.h
// --------------------
// Defines a data channel (based on DDAS testplan.h)
//
//
// AUTHOR: A. J. Owski
// LOC: 1250
// DEPT: 5260 Tool Development
// (formerly Instrument Systems)
//
// COPYRIGHT: (c) 2002 DaimlerChrysler Corp.
//
// REVISIONS: (most-recent at top of list).
//
// Date Init Description of Change
// ---- ---- ---------------------
// 11/08/04 wjp Remove redundant CalDate from Channel definition and label the
// field as spare bytes. Use the date in the transducer structure,
// which is part of the channel definition.
//
#if !defined( CHANNEL_H )
#define CHANNEL_H
#include "TransducerDefinition.h"
enum ChannelFlags{CHANFLAG_ACTIVE};
// Channel State Macro's
#define ISCHANACTIVE(pChan)(pChan->Flags&(1<<CHANFLAG_ACTIVE)?1:0)
#define SETCHANACTIVE(pChan)(pChan->Flags|=(1<<CHANFLAG_ACTIVE))
#define CLRCHANACTIVE(pChan)(pChan->Flags&=(~(1<<CHANFLAG_ACTIVE)))
// Channel Data Structure
typedef struct tagCHANNEL
{
short Size; // Size of this object
short Flags; // Channel Flags
char Name[64]; // Channel Name
char Sign[8]; // Sign +, -, or blank
char Axis[8]; // X,Y,Z,FX,MX,AX,...
float FilterFreq; // Channel Filter Class (in Hz)
float SetGain; // Gain setting (1 - n)
float ActGain; // Actual (measured?) gain setting.
float Rcal; // Shunt cal resistance
float Excitation; // Excitation Voltage (when programable)
// time_t CalDate; // Calibration date (Remove - redundant)
byte byteSpares[4]; // Spare bytes (was Cal Date)
TRANSDUCER Transducer; // "Snapshot" of transducer values
} CHANNEL;
typedef CHANNEL *PCHANNEL; // Pointer to a channel
typedef CHANNEL *PCHAN; // Even shorter version of above
#endif // !defined( CHANNEL_H )

View File

@@ -0,0 +1,279 @@
using DTS.Common.Utilities;
using DTS.Common.Utilities.DotNetProgrammingConstructs;
using DTS.Common.Utilities.Xml;
using System;
using System.Globalization;
using System.Xml;
using System.Xml.Schema;
namespace DTS.Serialization
{
public partial class Test
{
/// <summary>
/// Representation of serializable das timestamp information.
/// </summary>
[XmlSerializationTag("DasTimestamp")]
public partial class DasTimestamp : Exceptional
{
/// <summary>
/// The <see cref="DTS.Serialization.Test"/> that contains this module.
/// </summary>
public Test ParentTest
{
get => _ParentTest.Value;
private set => _ParentTest.Value = value;
}
private readonly Property<Test> _ParentTest
= new Property<Test>(
typeof(DasTimestamp).Namespace + ".Test.DasTimestamp.ParentTest",
null,
false
);
/// <summary>
/// Initialize an instance of the DTS.Serialization.Test.DasTimestamp class.
/// </summary>
///
/// <param name="parentTest">
/// The <see cref="DTS.Serialization.Test"/> containing this object.
/// </param>
///
public DasTimestamp(Test parentTest)
{
try
{
ParentTest = parentTest;
}
catch (System.Exception ex)
{
throw new Exception("encountered problem constructing " + GetType().Name, ex);
}
}
/// <summary>
/// Get/set the base serial number <see cref="string"/> for this DAS.
/// </summary>
[XmlSerializationTag("BaseSerialNumber")]
public string BaseSerialNumber
{
get => _BaseSerialNumber.Value;
set => _BaseSerialNumber.Value = value;
}
private readonly Property<string> _BaseSerialNumber
= new Property<string>(
typeof(DasTimestamp).Namespace + ".Test.DasTimestamp.BaseSerialNumber",
"",
true
);
/// <summary>
/// Get/set the number of samples in this test das.
/// </summary>
[XmlSerializationTag("NumberOfSamples")]
public UInt64 NumberOfSamples
{
get => _NumberOfSamples.Value;
set => _NumberOfSamples.Value = value;
}
private readonly Property<UInt64> _NumberOfSamples
= new Property<UInt64>(
typeof(DasTimestamp).Namespace + ".Test.DasTimestamp.NumberOfSamples",
0,
false
);
/// <summary>
/// Get/set the number of bits per sample timestamp in this test.
/// </summary>
[XmlSerializationTag("NumberOfBitsPerSample")]
public UInt32 NumberOfBitsPerSample
{
get => _NumberOfBitsPerSample.Value;
set => _NumberOfBitsPerSample.Value = value;
}
private readonly Property<UInt32> _NumberOfBitsPerSample
= new Property<UInt32>(
typeof(DasTimestamp).Namespace + ".Test.DasTimestamp.NumberOfBitsPerSample",
0,
false
);
/// <summary>
/// The name of the .bin file in the Binary folder that corresponds to this set of timestamps.
/// </summary>
[XmlSerializationTag("FileName")]
public string FileName
{
get => _fileName.Value;
set => _fileName.Value = value;
}
private readonly Property<string> _fileName
= new Property<string>(
typeof(DasTimestamp).Namespace + ".Test.DasTimestamp.FileName",
"",
false
);
/// <summary>
/// Write XML serialization for this object to the specified writer.
/// </summary>
///
/// <param name="writer">
/// The <see cref="XmlWriter"/> to which this object's XML serialization
/// will be written.
/// </param>
///
public void WriteXml(XmlWriter writer)
{
try
{
var cult = new CultureInfo("");
var attributeExtractor = new AttributeExtractor<XmlSerializationTagAttribute>();
//
// Write simple das timestamp properties.
//
// NOTE: The way this really should be done is to examine this object using reflection and just automatically
// assemble the list of properties that have been tagged with the serialization attribute. That way, when I
// add in a property after the fact, I don't have to worry about any of this crap below. It would just automatically
// get de/serialized. The equality check should also pick it's comparison properties that way. I'd do the conversion
// now, but we're under pressure for a release so it'll have to wait.
//
writer.WriteStartElement(attributeExtractor.ExtractAttachedAttributeFromObject(this).Value);
try
{
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "BaseSerialNumber").Value, BaseSerialNumber.ToString(cult));
}
catch (System.Exception)
{
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "BaseSerialNumber").Value, "NA");
}
writer.WriteAttributeString(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "NumberOfSamples").Value, NumberOfSamples.ToString(cult));
writer.WriteEndElement();
}
catch (System.Exception ex)
{
throw new Exception("encountered problem converting DTS.Serialization.Test.DasTimestamp object to XML", ex);
}
}
/// <summary>
/// Read XML serialization for this object from the specified reader.
/// </summary>
///
/// <param name="reader">
/// The <see cref="XmlReader"/> from which this object's XML serialization
/// will be read.
/// </param>
///
public void ReadXml(XmlReader reader)
{
try
{
var cult = new CultureInfo("");
var attributeExtractor = new AttributeExtractor<XmlSerializationTagAttribute>();
reader.MoveToContent();
//
// Read simple attributes.
//
try
{
BaseSerialNumber = reader.GetAttribute(attributeExtractor.ExtractAttachedAttributeFromProperty(this, "BaseSerialNumber").Value);
}
catch (Exception)
{
throw new Exception("error reading BaseSerialNumber");
}
if (
ulong.TryParse(
reader.GetAttribute(
attributeExtractor.ExtractAttachedAttributeFromProperty(this, "NumberOfSamples").Value),
NumberStyles.Any, cult, out ulong numberOfSamples))
{
NumberOfSamples = numberOfSamples;
}
else
{
throw new Exception("error reading NumberOfSamples");
}
if (
uint.TryParse(
reader.GetAttribute(
attributeExtractor.ExtractAttachedAttributeFromProperty(this, "NumberOfBitsPerSample").Value),
NumberStyles.Any, cult, out uint numberOfBitsPerSample))
{
NumberOfBitsPerSample = numberOfBitsPerSample;
}
else
{
//not written, set to standard size
NumberOfBitsPerSample = 8 * sizeof(ulong);
}
}
catch (System.Exception ex)
{
throw new Exception("encountered problem converting XML to DTS.Serialization.Test.DasTimestamp object", ex);
}
}
/// <summary>
/// Should normally return a schema representing the form of the XML
/// generated/consumed by WriteXml/ReadXml, but it never called during
/// the serialization process so ours just returns null.
/// </summary>
///
/// <returns>
/// Null <see cref="XmlSchema"/> reference, always.
/// </returns>
///
public XmlSchema GetSchema()
{
// This method is never invoked during XML object serialization.
return null;
}
/// <summary>
/// Test the specified object for equality with this object.
/// </summary>
///
/// <param name="obj">
/// The <see cref="object"/> to be tested for equality.
/// </param>
///
/// <returns>
/// <see cref="bool"/> true if the specified object has memeberwise equality with
/// this object; false otherwise.
/// </returns>
///
public override bool Equals(object obj)
{
try
{
return obj is DasTimestamp that
&& FileName.Equals(that.FileName)
&& NumberOfSamples.Equals(that.NumberOfSamples)
&& NumberOfBitsPerSample.Equals(that.NumberOfBitsPerSample)
&& BaseSerialNumber.Equals(that.BaseSerialNumber);
}
catch (System.Exception ex)
{
throw new Exception("encountered problem equality-testing object " + (null != obj ? "\"" + obj.ToString() + "\"" : "<<NULL>>"), ex);
}
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
}