12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Runtime.InteropServices;
- using System.Threading.Tasks;
- using Uestc.Auto6.Dso.ComModel;
- namespace Uestc.Auto6.Dso.Hardware.Calibration.Data.Base
- {
- public class CoefficientsTable_Interpolation : ICaliData, ICoefficientsTable
- {
- public static CoefficientsTable_Interpolation Default = new CoefficientsTable_Interpolation();
- public const Int32 PerChannelDataCount = 600;
- private CoefficientsTable_Interpolation()
- {
- for (int channelID = 0; channelID < CaliConstants.Fixed_MaxPhysicsChannelCount; channelID++)
- data[channelID] = new Int32[PerChannelDataCount];
- }
- public CaliDataType DataType { get => CaliDataType.CoefficientsTable_Interpolation; }
- private Int32[/*channel*/][/*data*/] data = new Int32[CaliConstants.Fixed_MaxPhysicsChannelCount][];
- public Int32 TotalBytes
- {
- get
- {
- int totalBytes = CaliConstants.Fixed_MaxPhysicsChannelCount * PerChannelDataCount * sizeof(Int32);
- return totalBytes;
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="channelIndex"></param>
- /// <returns></returns>
- public Int32[] this[int channelIndex]
- {
- get => data[channelIndex];
- }
- /// <summary>
- /// [int channelIndex,int index]
- /// </summary>
- /// <param name="channelIndex"></param>
- /// <param name="index"></param>
- /// <returns></returns>
- public Int32 this[int channelIndex, int index]
- {
- get => data[channelIndex][index];
- set => data[channelIndex][index] = value;
- }
- public byte[] Serialize()
- {
- System.IO.MemoryStream memoryStream = new MemoryStream();
- for (int channelIndex = 0; channelIndex < CaliConstants.Fixed_MaxPhysicsChannelCount; channelIndex++)
- {
- for (int i = 0; i < PerChannelDataCount; i++)
- {
- memoryStream.Write(Helper.StructToBytes(data[channelIndex][i]));
- }
- }
- byte[] result = memoryStream.ToArray();
- memoryStream.Close();
- return result;
- }
- public byte[] SerializeByFpgaFormat(int channelID)
- {
- byte[] bytes = new byte[PerChannelDataCount * (24 / 8)];//24=24bits,8=byte's bits
- for (int i = 0; i < PerChannelDataCount; i++)
- {
- bytes[i * 3 + 0] = (byte)(data[channelID][i] & 0xff);
- bytes[i * 3 + 1] = (byte)(data[channelID][i] >> 8 & 0xff);
- bytes[i * 3 + 2] = (byte)(data[channelID][i] >> 16 & 0xff);
- }
- return bytes;
- }
- public void Deserialize(byte[] content)
- {
- if (content.Length < TotalBytes)
- return;
- for (int channelID = 0; channelID < CaliConstants.Fixed_MaxPhysicsChannelCount; channelID++)
- {
- for (int index = 0; index < PerChannelDataCount; index++)
- {
- data[channelID][index] = Helper.BytesToStruct<Int32>(content, channelID * PerChannelDataCount * sizeof(Int32) + index * sizeof(Int32), typeof(Int32));
- }
- }
- }
- }
- }
|