init
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
using DTS.Serialization.IRIGCH10.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DTS.Serialization.IRIGCH10
|
||||
{
|
||||
/// <summary>
|
||||
/// this class handles the root recorder index packet,
|
||||
/// it points to recorder index packets, it's the last packet in a ch10 file
|
||||
/// (but can be broken over multiple packets)
|
||||
/// </summary>
|
||||
public class RootRecorderIndexPacket : 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, 0x00, 0x00, 0x60};
|
||||
private long _rootPacketAddressLong;
|
||||
private readonly byte [] RootPacketAddress = new byte [8];
|
||||
public void SetRootPacketAddress(long address)
|
||||
{
|
||||
_rootPacketAddressLong = address;
|
||||
var bits = BitConverter.GetBytes(address);
|
||||
Buffer.BlockCopy(bits, 0, RootPacketAddress, 0, bits.Length);
|
||||
}
|
||||
|
||||
private List<RecordingIndexIndex> _indices = new List<RecordingIndexIndex>();
|
||||
|
||||
public void AddRecordingIndex(RecordingIndexIndex index)
|
||||
{
|
||||
_indices.Add(index);
|
||||
}
|
||||
private readonly DateTime _dt;
|
||||
public RootRecorderIndexPacket(DateTime dt)
|
||||
: base(DataFileDataTypes.ComputerGeneratedDataFormat3)
|
||||
{
|
||||
_dt = dt;
|
||||
_CheckSum = new byte[4];
|
||||
}
|
||||
public override byte[] GetBytes()
|
||||
{
|
||||
//the last index should apparently point back to this entry...
|
||||
_indices.Add(new RecordingIndexIndex(GetRTC(), _rootPacketAddressLong, _dt));
|
||||
//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 * RecordingIndexIndex.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 is a root recording index entry, it points at other recording indicies
|
||||
/// </summary>
|
||||
public class RecordingIndexIndex
|
||||
{
|
||||
public const int SIZE = 8+8+8;
|
||||
private byte [] RTC = new byte [8];
|
||||
private byte [] TimeDate = new byte[8];
|
||||
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);
|
||||
}
|
||||
|
||||
private void SetDateTime(DateTime 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 RecordingIndexIndex(long rtc, long offset, DateTime dt)
|
||||
{
|
||||
SetDataPacketOffset(offset);
|
||||
SetRTC(rtc);
|
||||
SetDateTime(dt);
|
||||
}
|
||||
public byte[] GetBytes()
|
||||
{
|
||||
var data = new byte[SIZE];
|
||||
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;
|
||||
Buffer.BlockCopy(DataPacketOffset, 0, data, curOffset, DataPacketOffset.Length);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user