121 lines
4.8 KiB
Plaintext
121 lines
4.8 KiB
Plaintext
|
|
using DTS.Serialization.IRIGCH10.Enums;
|
||
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Linq;
|
||
|
|
|
||
|
|
namespace DTS.Serialization.IRIGCH10
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// this packet just points to specific time data packets as part of an indexing system
|
||
|
|
/// </summary>
|
||
|
|
public class RecorderIndexPacket : AbstractDataPacket, IDataPacket
|
||
|
|
{
|
||
|
|
//not confident on breaking out the individual properties of this dataword yet
|
||
|
|
//(root index, file size, presence of data header, etc, so just use a
|
||
|
|
//prefilled one for now ...
|
||
|
|
private readonly byte [] ChannelSpecificDataWord = new byte[] {0x8D, 0x02, 0x00, 0xE0};
|
||
|
|
private readonly byte [] RootPacketAddress = new byte [8];
|
||
|
|
public void SetRootPacketAddress(long address)
|
||
|
|
{
|
||
|
|
var bits = BitConverter.GetBytes(address);
|
||
|
|
Buffer.BlockCopy(bits, 0, RootPacketAddress, 0, bits.Length);
|
||
|
|
}
|
||
|
|
|
||
|
|
private List<RecordingIndex> _indices = new List<RecordingIndex>();
|
||
|
|
|
||
|
|
public DateTime GetDateTime()
|
||
|
|
{
|
||
|
|
return _indices.First().GetDateTime();
|
||
|
|
}
|
||
|
|
public int NumberOfEntries => _indices.Count;
|
||
|
|
public void AddRecordingIndex(RecordingIndex index)
|
||
|
|
{
|
||
|
|
_indices.Add(index);
|
||
|
|
}
|
||
|
|
|
||
|
|
public RecorderIndexPacket()
|
||
|
|
: base(DataFileDataTypes.ComputerGeneratedDataFormat3)
|
||
|
|
{
|
||
|
|
_CheckSum = new byte[4];
|
||
|
|
}
|
||
|
|
public override byte[] GetBytes()
|
||
|
|
{
|
||
|
|
//we just need to make sure data bytes is populated then we can let the base class do it's thing
|
||
|
|
_dataBytes = new byte[_indices.Count * RecordingIndex.SIZE + RootPacketAddress.Length +
|
||
|
|
ChannelSpecificDataWord.Length];
|
||
|
|
Buffer.BlockCopy(ChannelSpecificDataWord, 0, _dataBytes, 0, ChannelSpecificDataWord.Length);
|
||
|
|
Buffer.BlockCopy(RootPacketAddress, 0, _dataBytes, ChannelSpecificDataWord.Length, RootPacketAddress.Length);
|
||
|
|
var offset = ChannelSpecificDataWord.Length + RootPacketAddress.Length;
|
||
|
|
foreach (var index in _indices)
|
||
|
|
{
|
||
|
|
var bytes = index.GetBytes();
|
||
|
|
Buffer.BlockCopy(bytes, 0, _dataBytes, offset, bytes.Length);
|
||
|
|
offset += bytes.Length;
|
||
|
|
}
|
||
|
|
return base.GetBytes();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
/// <summary>
|
||
|
|
/// here's a structure for the recording indicies in the recording index packet
|
||
|
|
/// </summary>
|
||
|
|
public class RecordingIndex
|
||
|
|
{
|
||
|
|
public const int SIZE = 8+8+2+1+1+8;
|
||
|
|
private byte [] RTC = new byte [8];
|
||
|
|
private byte [] TimeDate = new byte[8];
|
||
|
|
private DateTime _dt;
|
||
|
|
private readonly ushort ChannelId = ushort.MaxValue;
|
||
|
|
private readonly byte DataType = 0x11;
|
||
|
|
private readonly byte Reserved = 0x00;
|
||
|
|
private byte[] DataPacketOffset = new byte[8];
|
||
|
|
|
||
|
|
private void SetRTC(long rtc)
|
||
|
|
{
|
||
|
|
var bits = BitConverter.GetBytes(rtc);
|
||
|
|
Buffer.BlockCopy(bits, 0, RTC, 0, bits.Length);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void SetDataPacketOffset(long offset)
|
||
|
|
{
|
||
|
|
var bits = BitConverter.GetBytes(offset);
|
||
|
|
Buffer.BlockCopy(bits, 0, DataPacketOffset, 0, bits.Length);
|
||
|
|
}
|
||
|
|
public DateTime GetDateTime(){ return _dt; }
|
||
|
|
private void SetDateTime(DateTime dt)
|
||
|
|
{
|
||
|
|
_dt = dt;
|
||
|
|
TimeDate[0] = Utils.Utils.GetBCDBytes(dt.Millisecond/10)[0];
|
||
|
|
TimeDate[1] = Utils.Utils.GetBCDBytes(dt.Second)[0];
|
||
|
|
TimeDate[2] = Utils.Utils.GetBCDBytes(dt.Minute)[0];
|
||
|
|
TimeDate[3] = Utils.Utils.GetBCDBytes(dt.Hour)[0];
|
||
|
|
TimeDate[4] = Utils.Utils.GetBCDBytes(dt.Day)[0];
|
||
|
|
TimeDate[5] = Utils.Utils.GetBCDBytes(dt.Month)[0];
|
||
|
|
TimeDate[6] = Utils.Utils.GetBCDBytes(dt.Year)[0];
|
||
|
|
TimeDate[7] = Utils.Utils.GetBCDBytes(dt.Year)[1];
|
||
|
|
}
|
||
|
|
|
||
|
|
public RecordingIndex(long rtc, long offset, DateTime dt)
|
||
|
|
{
|
||
|
|
SetDataPacketOffset(offset);
|
||
|
|
SetRTC(rtc);
|
||
|
|
SetDateTime(dt);
|
||
|
|
}
|
||
|
|
public byte[] GetBytes()
|
||
|
|
{
|
||
|
|
var data = new byte[8 + 8 + 2 + 1 + 1 + 8];
|
||
|
|
var curOffset = 0;
|
||
|
|
Buffer.BlockCopy(RTC, 0, data, 0, RTC.Length);
|
||
|
|
curOffset += RTC.Length;
|
||
|
|
Buffer.BlockCopy(TimeDate, 0, data, curOffset, TimeDate.Length);
|
||
|
|
curOffset += TimeDate.Length;
|
||
|
|
var bytes = BitConverter.GetBytes(ChannelId);
|
||
|
|
Buffer.BlockCopy(bytes, 0, data, curOffset, 2);
|
||
|
|
curOffset += 2;
|
||
|
|
data[curOffset++] = DataType;
|
||
|
|
data[curOffset++] = Reserved;
|
||
|
|
Buffer.BlockCopy(DataPacketOffset, 0, data, curOffset, DataPacketOffset.Length);
|
||
|
|
return data;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|