2018-05-30 16:29:46 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace TBF.BenchControl.RegisterReaders.SerialStream
|
|
|
|
|
|
{
|
|
|
|
|
|
public class FrameFormat
|
|
|
|
|
|
{
|
|
|
|
|
|
public int FrameLength; /// Frame length in characters/bytes, 0 = unknown
|
2018-06-01 13:44:31 +00:00
|
|
|
|
public double FrameFrequency; /// Number of frames per second (Hz)
|
2018-05-30 16:29:46 +00:00
|
|
|
|
|
|
|
|
|
|
public readonly Config.Unit VolumeUnits;
|
2018-06-01 13:44:31 +00:00
|
|
|
|
public readonly double VolumeScaleFactor; /// Volume in VolumeInits = volmeRaw / VolumeScaleFactor
|
2018-05-30 16:29:46 +00:00
|
|
|
|
public readonly int VolumeFieldStart; /// Start of the volume field: 0-based index of the first character, -1 = no volume field in the frame
|
|
|
|
|
|
public readonly int VolumeFieldEnd; /// End of the volume field: 0-based index of the last character
|
|
|
|
|
|
public readonly FieldFormat VolumeFieldFormat; /// Hexadecimal or Decimal
|
|
|
|
|
|
|
|
|
|
|
|
public readonly Config.Unit TimeUnits;
|
2018-06-01 13:44:31 +00:00
|
|
|
|
public readonly double TimeScaleFactor; /// Time in TimeUnits = timeRaw / TimeScaleFactor
|
2018-05-30 16:29:46 +00:00
|
|
|
|
public readonly int TimeFieldStart; /// Start of the time field: 0-based index of the first character, -1 = no time field in the frame
|
|
|
|
|
|
public readonly int TimeFieldEnd; /// End of the time field: 0-based index of the last character
|
|
|
|
|
|
public readonly FieldFormat TimeFieldFormat; /// Hexadecimal or Decimal
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Calculated in constructor
|
|
|
|
|
|
///
|
|
|
|
|
|
public readonly int VolumeFieldLength;
|
|
|
|
|
|
public readonly UInt64 VolumeWindowMask;
|
|
|
|
|
|
public readonly Int64 VolumeWrapIncrement;
|
|
|
|
|
|
public readonly Int64 VolumeWrapThreshold;
|
|
|
|
|
|
|
|
|
|
|
|
public readonly int TimeFieldLength;
|
|
|
|
|
|
public readonly UInt64 TimeWindowMask;
|
|
|
|
|
|
public readonly Int64 TimeWrapIncrement;
|
|
|
|
|
|
public readonly Int64 TimeWrapThreshold;
|
|
|
|
|
|
|
2018-06-01 13:44:31 +00:00
|
|
|
|
public readonly long RawTimeIncrementPerFrame;
|
|
|
|
|
|
|
|
|
|
|
|
public FrameFormat(int frameLength, double frameFrequency,
|
2018-05-30 16:29:46 +00:00
|
|
|
|
Config.Unit volumeUnits, double volumeScaleFactor,
|
|
|
|
|
|
int volumeFieldStart, int volumeFieldEnd, FieldFormat volumeFieldFormat,
|
|
|
|
|
|
Config.Unit timeUnits, double timeScaleFactor,
|
|
|
|
|
|
int timeFieldStart, int timeFieldEnd, FieldFormat timeFieldFormat)
|
|
|
|
|
|
{
|
|
|
|
|
|
FrameLength = frameLength;
|
2018-06-01 13:44:31 +00:00
|
|
|
|
FrameFrequency = frameFrequency;
|
2018-05-30 16:29:46 +00:00
|
|
|
|
|
|
|
|
|
|
VolumeUnits = volumeUnits;
|
|
|
|
|
|
VolumeScaleFactor = volumeScaleFactor;
|
|
|
|
|
|
VolumeFieldStart = volumeFieldStart;
|
|
|
|
|
|
VolumeFieldEnd = volumeFieldEnd;
|
|
|
|
|
|
VolumeFieldFormat = volumeFieldFormat;
|
|
|
|
|
|
|
|
|
|
|
|
TimeUnits = timeUnits;
|
|
|
|
|
|
TimeScaleFactor = timeScaleFactor;
|
|
|
|
|
|
TimeFieldStart = timeFieldStart;
|
|
|
|
|
|
TimeFieldEnd = timeFieldEnd;
|
|
|
|
|
|
TimeFieldFormat = timeFieldFormat;
|
|
|
|
|
|
|
2018-06-01 13:44:31 +00:00
|
|
|
|
RawTimeIncrementPerFrame = (FrameFrequency != 0) ? (long)Math.Round(TimeScaleFactor / FrameFrequency) : 1L;
|
2018-05-30 16:29:46 +00:00
|
|
|
|
|
|
|
|
|
|
VolumeFieldLength = VolumeFieldEnd - VolumeFieldStart + 1;
|
|
|
|
|
|
|
|
|
|
|
|
if (volumeFieldFormat == FieldFormat.HexadecimalWindow &&
|
|
|
|
|
|
volumeFieldStart >= 0 && VolumeFieldLength >= 1 && VolumeFieldLength <= 8)
|
|
|
|
|
|
{
|
|
|
|
|
|
VolumeWindowMask = 0xFFFFFFFFFFFFFFFFUL << (4 * VolumeFieldLength);
|
|
|
|
|
|
VolumeWrapIncrement = 1L << (4 * VolumeFieldLength);
|
|
|
|
|
|
VolumeWrapThreshold = 1L << (4 * VolumeFieldLength - 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TimeFieldLength = TimeFieldEnd - TimeFieldStart + 1;
|
|
|
|
|
|
|
|
|
|
|
|
if (volumeFieldFormat == FieldFormat.HexadecimalWindow &&
|
|
|
|
|
|
volumeFieldStart >= 0 && TimeFieldLength >= 1 && TimeFieldLength <= 8)
|
|
|
|
|
|
{
|
|
|
|
|
|
TimeWindowMask = 0xFFFFFFFFFFFFFFFFUL << (4 * TimeFieldLength);
|
|
|
|
|
|
TimeWrapIncrement = 1L << (4 * TimeFieldLength);
|
|
|
|
|
|
TimeWrapThreshold = 1L << (4 * TimeFieldLength - 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-06-01 09:55:36 +00:00
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
|
{
|
|
|
|
|
|
return string.Format("L={0} V={1}-{2}-{3}-{4}-{5} T={6}-{7}-{8}-{9}-{10}",
|
|
|
|
|
|
FrameLength,
|
|
|
|
|
|
VolumeUnits, VolumeScaleFactor,
|
|
|
|
|
|
VolumeFieldStart, VolumeFieldEnd, VolumeFieldFormat,
|
|
|
|
|
|
TimeUnits, TimeScaleFactor,
|
|
|
|
|
|
TimeFieldStart, TimeFieldEnd, TimeFieldFormat);
|
|
|
|
|
|
}
|
2018-05-30 16:29:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|