public static void ParseWhole(byte[] data, RawSensorSensitivity sensitivity, Action <RawSensorData> onCompleted) { int metaLength = 4; int metaOffset = 0; UInt32 timestamp = 1; while ((metaOffset + metaLength < data.Length) && (timestamp > 0)) { UInt32 meta = 0; int add = 0; meta = BitConverter.ToUInt32(data, metaOffset); int messageOffset = 0; int messageLength = 0; if (meta > 0) { UInt32 packetType = (meta & (UInt32)(0x80000000)) >> 31; timestamp = (UInt32)(meta & (UInt32)(0x7fffffff)); RawSensorDataType type = RawSensorDataType.None; if (timestamp == 0) { return; } if (packetType == 0) { messageOffset = metaOffset + metaLength; messageLength = 12; type = RawSensorDataType.IMU; add = 12; } else if (packetType == 1) { messageOffset = metaOffset + metaLength; messageLength = 30; add = 30; type = RawSensorDataType.Device; } else { return; } if (type != RawSensorDataType.None) { if (messageOffset + messageLength < data.Length) { RawSensorDataParser.ParseSingle(type, timestamp, data.Skip(messageOffset).Take(messageLength).ToArray(), sensitivity, onCompleted); } } if (add == 0) { return; } } else { return; } metaOffset = metaOffset + metaLength + add; } }
public static RawSensorData Create(RawSensorDataType _type, UInt32 _timestamp, byte[] dataArray, RawSensorSensitivity sensitivitiy) { if (_type == RawSensorDataType.None) { return(null); } List <Point3> pointsInProcess = new List <Point3>(); string pointSensitivity = _type == RawSensorDataType.Device ? RawSensorSensitivity.kDeviceAccelerometer : RawSensorSensitivity.kIMUGyro; int pointsDataOffset = 0; int pointsDataLength = 6; while (pointsDataOffset < dataArray.Length) { if (pointsDataOffset + pointsDataLength - 1 < dataArray.Length) { double sens = sensitivitiy.getSensitivity(pointSensitivity); Point3 point = Point3.Create(dataArray.Skip(pointsDataOffset).Take(pointsDataLength).ToArray(), sens); if (point != null) { pointsInProcess.Add(point); } else { return(null); } pointsDataOffset += pointsDataLength; if (_type == RawSensorDataType.IMU) { pointSensitivity = RawSensorSensitivity.kIMUAccelerometer; } } else { return(null); } } if (_type == RawSensorDataType.IMU) { if (pointsInProcess.Count != 2) { return(null); } } else if (_type == RawSensorDataType.Device) { if (pointsInProcess.Count != 5) { return(null); } } return(new RawSensorData(_type, _timestamp, pointsInProcess.ToArray())); }
private static void ParseSingle(RawSensorDataType type, UInt32 timestamp, byte[] data, RawSensorSensitivity sensitivity, Action <RawSensorData> onCompleted) { RawSensorData rsData = RawSensorData.Create(type, timestamp, data, sensitivity); if (rsData != null) { onCompleted(rsData); } }
private TAPInputMode(string _mode, RawSensorSensitivity _sensitivity = null) { this.mode = validateModeString(_mode); this.sensitivity = _sensitivity; }
public static TAPInputMode RawSensor(RawSensorSensitivity sensitivity) { return(new TAPInputMode(TAPInputMode.kRawSensor, sensitivity)); }