Files
TelemetryIO/TelemetryIO/DataSlots.cs

60 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TelemetryIO
{
internal class DataSlots
{
static private int[] raw_imu = new int[6];
public DataSlots() { }
static public void setSlot(int slot, byte[] data, int offset, int len)
{
switch (slot)
{
case 0:
setSlot0(data, offset, len);
break;
case 1:
setSlot0(data, offset, len);
break;
}
}
static public void setSlot0(byte[]data, int offset, int len)
{
for(int i = 0; i < (int)(len/4); i++)
{
byte[]bs = new byte[4];
Array.Copy(data, i * 4, bs, 0, 4);
raw_imu[(int)(offset/4)] = bytes_to_int(bs, 0);
}
}
static public int[] getSlot0()
{
return raw_imu;
}
static public int bytes_to_int(byte[] bytes, int startPos)
{
byte[] bs = new byte[4];
Array.Copy(bytes, startPos, bs, 0, 4);
int ret = (int)(bs[0] | (bs[1] << 8) | (bs[2] << 16) | (bs[3] << 24));
return ret;
}
static public uint bytes_to_uint(byte[] bytes, int startPos)
{
byte[] bs = new byte[4];
Array.Copy(bytes, startPos, bs, 0, 4);
uint ret = (uint)(bs[0] | (bs[1] << 8) | (bs[2] << 16) | (bs[3] << 24));
return ret;
}
}
}