#ifndef __STM_300_H__
#define __STM_300_H__

#include <stdio.h>
#include <malloc.h>
#include <math.h>

#include "common_utils.hpp"

//Normal Mode datagram identifiers
//Datagram content                                            Identifier  
//Rate                                                        0x90
//Rate and acceleration                                       0x91
//Rate and inclination                                        0x92
//Rate, acceleration and inclination                          0x93
//Rate and temperature                                        0x94
//Rate, acceleration and temperature                          0xA5
//Rate, inclination and temperature                           0xA6
//Rate, acceleration, inclination and temperature             0xA7
//Rate and AUX                                                0x98
//Rate, acceleration and AUX                                  0x99
//Rate, inclination and AUX                                   0x9A
//Rate, acceleration, inclination and AUX                     0x9B
//Rate, temperature and AUX                                   0x9C
//Rate, acceleration, temperature and AUX                     0xAD
//Rate, inclination, temperature and AUX                      0xAE
//Rate, acceleration, inclination, temperature and AUX        0xAF


#define P2_08       3.906250000000000E-03 /* 2^-08 */
#define P2_14       6.103515625000000E-05 /* 2^-14 */
#define P2_16       1.525878906250000E-05 /* 2^-16 */
#define P2_17       7.629394531250000E-06 /* 2^-17 */
#define P2_18       3.814697265625000E-06 /* 2^-18 */
#define P2_19       1.907348632812500E-06 /* 2^-19 */
#define P2_20       9.536743164062500E-07 /* 2^-20 */
#define P2_21       4.768371582031250E-07 /* 2^-21 */
#define P2_22       2.384185791015625E-07 /* 2^-22 */
#define P2_23       1.192092895507810E-07 /* 2^-23 */
#define P2_24       5.960464477539063E-08 /* 2^-24 */
#define P2_25       2.980232238769531E-08 /* 2^-25 */

#ifndef SYNC_BOARD_MSG_HEADER_LEN
#define SYNC_BOARD_MSG_HEADER_LEN	36
#endif

#define		STIM300_MSG_BUFF_SIZE	1024

#define		STIM300_0x91_LEN	42
#define		STIM300_0x92_LEN	42
#define		STIM300_0x93_LEN	42
#define		STIM300_0x94_LEN	42
#define		STIM300_0xA5_LEN	42
#define		STIM300_0xA6_LEN	42
#define		STIM300_0xA7_LEN	42
#define		STIM300_0x98_LEN	42
#define		STIM300_0x99_LEN	42
#define		STIM300_0x9A_LEN	42
#define		STIM300_0x9B_LEN	42
#define		STIM300_0x9C_LEN	42
#define		STIM300_0xAD_LEN	42
#define		STIM300_0xAE_LEN	42
#define		STIM300_0xAF_LEN	42

///////////////////////// DUMMY ///////////////////////////
#define		STIM300_0xB1_DUMMY	0
#define		STIM300_0xB3_DUMMY	0
#define		STIM300_0xB5_DUMMY	0
#define		STIM300_0xB7_DUMMY	0
#define		STIM300_0xB9_DUMMY	2
#define		STIM300_0xBB_DUMMY	2
#define		STIM300_0xBE_DUMMY	3
#define		STIM300_0xBF_DUMMY	3

#define		STIM300_0x90_DUMMY	2
#define		STIM300_0x91_DUMMY	0
#define		STIM300_0x92_DUMMY	0
#define		STIM300_0x93_DUMMY	2
#define		STIM300_0x94_DUMMY	3

#define		STIM300_0xA5_DUMMY	2
#define		STIM300_0xA6_DUMMY	2
#define		STIM300_0xA7_DUMMY	1

#define		STIM300_0x98_DUMMY	2
#define		STIM300_0x99_DUMMY	0

#define		STIM300_0x9A_DUMMY	0
#define		STIM300_0x9B_DUMMY	2
#define		STIM300_0x9C_DUMMY	3

#define		STIM300_0xAD_DUMMY	2
#define		STIM300_0xAE_DUMMY	2
#define		STIM300_0xAF_DUMMY	1
///////////////////////// DUMMY ///////////////////////////


#ifdef WIN_DLL
#define EXPORT __declspec(dllexport) /* for Windows DLL */
#else
#define EXPORT
#endif

typedef struct {
	// 时间
	int     week;
	int     sow;
	int     usec;
	int     status;
	long    seq;

	// 角度增量，单位为radians
	double  DeltaAngleX;
	double  DeltaAngleY;
	double  DeltaAngleZ;

	// 速度增量，单位为m/sec
	double  DeltaVelocityX;
	double  DeltaVelocityY;
	double  DeltaVelocityZ;

	// 倾斜仪
	double	Inclinometer;

	// AUX
	double	AUX;
} raw_stim300_t;

typedef struct {
	int nbyte;          /* number of bytes in message buffer */
	int nbit;           /* number of bits in word buffer */
	int len;            /* message length (bytes) */
	int	dummy;
	int	crc_bit_pos;        /*  */
	unsigned char buff[STIM300_MSG_BUFF_SIZE]; /* message buffer */
	raw_stim300_t	rawImu;
} stim300_t;

//直接计算法计算crc
static unsigned int do_crc32_mpeg2(unsigned char *ptr, int len)
{
	unsigned int i;
	unsigned int crc = 0xFFFFFFFF;
	
	// 必须为四字节对齐
	if (len <= 0 || len % 4 != 0)
	    return crc;

	while (len--)
	{
		crc ^= (unsigned int)(*ptr++) << 24;
		for (i = 0; i < 8; ++i)
		{
			if (crc & 0x80000000)
				crc = (crc << 1) ^ 0x04C11DB7;
			else
				crc <<= 1;
		}
	}
	return crc;
}

// 成功返回0，失败返回-1
static int CalcCRC32(const unsigned char *Buffer, int ByteCount, unsigned int *CRC)
{
	int	iDummy = 0;
	int	ByteDummy = 0;
	int	ByteCount_New = 0;
	unsigned char *Buffer_New = NULL;

	if (Buffer == NULL || ByteCount <= 0 || CRC == NULL)
		return -1;

	// NUMBER OF BYTES MUST BE A MULTIPLY OF 4
	if (ByteCount % 4 != 0) {
		ByteDummy = 4 - ByteCount % 4;
		ByteCount_New = ByteCount + ByteDummy;
	}
	else
	{
		ByteDummy = 0;
		ByteCount_New = ByteCount;
	}

	if (ByteDummy > 0)
	{
		Buffer_New = (unsigned char *)calloc(ByteCount_New, sizeof(unsigned char));
		memcpy(Buffer_New, Buffer, ByteCount);

		// Add 0x00
		for (iDummy = ByteCount; iDummy < ByteCount_New; iDummy++)
			Buffer_New[iDummy] = 0x00;
	}
	else
	{
		Buffer_New = (unsigned char *)calloc(ByteCount, sizeof(unsigned char));
		memcpy(Buffer_New, Buffer, ByteCount);
	}

	*CRC = do_crc32_mpeg2(Buffer_New, ByteCount_New);

	free(Buffer_New);

	return 0;
}

static int decode_Gyr_Angular_Rate(const unsigned char *buff, const int pos,
	double *gyr_x, double *gyr_y, double *gyr_z)
{
	int		i = pos;

	if (pos < 0 || gyr_x == NULL || gyr_y == NULL || gyr_z == NULL)
		return 0;

	*gyr_x = getbits(buff, i, 24) / pow(2, 14); i += 24;
	*gyr_y = getbits(buff, i, 24) / pow(2, 14); i += 24;
	*gyr_z = getbits(buff, i, 24) / pow(2, 14); i += 24;
	return 1;
}

static int decode_Gyr_Incremental_Angle(const unsigned char *buff, const int pos,
	double *gyr_x, double *gyr_y, double *gyr_z)
{
	int		i = pos;

	if (pos < 0 || gyr_x == NULL || gyr_y == NULL || gyr_z == NULL)
		return 0;

	*gyr_x = getbits(buff, i, 24) / pow(2, 21); i += 24;
	*gyr_y = getbits(buff, i, 24) / pow(2, 21); i += 24;
	*gyr_z = getbits(buff, i, 24) / pow(2, 21); i += 24;
	return 1;
}

static int decode_Gyr_Average_Angular_Rate(const unsigned char *buff, const int pos,
	double *gyr_x, double *gyr_y, double *gyr_z)
{
	int		i = pos;

	if (pos < 0 || gyr_x == NULL || gyr_y == NULL || gyr_z == NULL)
		return 0;

	*gyr_x = getbits(buff, i, 24) / pow(2, 14); i += 24;
	*gyr_y = getbits(buff, i, 24) / pow(2, 14); i += 24;
	*gyr_z = getbits(buff, i, 24) / pow(2, 14); i += 24;
	return 1;
}

static int decode_Gyr_Integrated_Angle(const unsigned char *buff, const int pos,
	double *gyr_x, double *gyr_y, double *gyr_z)
{
	int		i = pos;

	if (pos < 0 || gyr_x == NULL || gyr_y == NULL || gyr_z == NULL)
		return 0;

	*gyr_x = getbits(buff, i, 24) / pow(2, 21); i += 24;
	*gyr_y = getbits(buff, i, 24) / pow(2, 21); i += 24;
	*gyr_z = getbits(buff, i, 24) / pow(2, 21); i += 24;
	return 1;
}

// range 1 - 2g; 2 - 5g; 3 - 10g; 4 - 30g; 5 - 80g
static int decode_Acc_Acceleration(const unsigned char *buff, const int pos,
	double *acc_x, double *acc_y, double *acc_z, const int range = 3)
{
	int		i = pos;
	double	scale = 0.0;

	if (pos < 0 || acc_x == NULL || acc_y == NULL || acc_z == NULL)
		return 0;

	switch (range)
	{
	case 1: scale = pow(2, 21); break;
	case 2: scale = pow(2, 20); break;
	case 3: scale = pow(2, 19); break;
	case 4: scale = pow(2, 18); break;
	case 5: scale = pow(2, 16); break;
	default:
		fprintf(stdout, " error in decode_Acc_Acceleration, invalid range = %d\n", range);
		return 0;
	}

	*acc_x = getbits(buff, i, 24) / scale; i += 24;
	*acc_y = getbits(buff, i, 24) / scale; i += 24;
	*acc_z = getbits(buff, i, 24) / scale; i += 24;
	return 1;
}

// range 1 - 2g; 2 - 5g; 3 - 10g; 4 - 30g; 5 - 80g
static int decode_Acc_Incremental_Velocity(const unsigned char *buff, const int pos,
	double *acc_x, double *acc_y, double *acc_z, const int range = 3)
{
	int		i = pos;
	double	scale = 0.0;

	if (pos < 0 || acc_x == NULL || acc_y == NULL || acc_z == NULL)
		return 0;

	switch (range)
	{
	case 1: scale = pow(2, 24); break;
	case 2: scale = pow(2, 23); break;
	case 3: scale = pow(2, 22); break;
	case 4: scale = pow(2, 21); break;
	case 5: scale = pow(2, 19); break;
	default:
		fprintf(stdout, " error in decode_Acc_Incremental_Velocity, invalid range = %d\n", range);
		return 0;
	}

	*acc_x = getbits(buff, i, 24) / scale; i += 24;
	*acc_y = getbits(buff, i, 24) / scale; i += 24;
	*acc_z = getbits(buff, i, 24) / scale; i += 24;
	return 1;
}

// range 1 - 2g; 2 - 5g; 3 - 10g; 4 - 30g; 5 - 80g
static int decode_Acc_Average_Acceleration(const unsigned char *buff, const int pos,
	double *acc_x, double *acc_y, double *acc_z, const int range = 3)
{
	int		i = pos;
	double	scale = 0.0;

	if (pos < 0 || acc_x == NULL || acc_y == NULL || acc_z == NULL)
		return 0;

	switch (range)
	{
	case 1: scale = pow(2, 21); break;
	case 2: scale = pow(2, 20); break;
	case 3: scale = pow(2, 19); break;
	case 4: scale = pow(2, 18); break;
	case 5: scale = pow(2, 16); break;
	default:
		fprintf(stdout, " error in decode_Acc_Average_Acceleration, invalid range = %d\n", range);
		return 0;
	}

	*acc_x = getbits(buff, i, 24) / scale; i += 24;
	*acc_y = getbits(buff, i, 24) / scale; i += 24;
	*acc_z = getbits(buff, i, 24) / scale; i += 24;
	return 1;
}

// range 1 - 2g; 2 - 5g; 3 - 10g; 4 - 30g; 5 - 80g
static int decode_Inclinometer_Acceleration(const unsigned char *buff, const int pos, double *acc)
{
	int		i = pos;

	if (buff == NULL || pos < 0 || acc == NULL)
		return 0;

	*acc = getbits(buff, i, 24) / pow(2, 22); i += 24;
	return 1;
}

// range 1 - 2g; 2 - 5g; 3 - 10g; 4 - 30g; 5 - 80g
static int decode_Inclinometer_Incremental_Velocity(const unsigned char *buff, const int pos, double *acc)
{
	int		i = pos;

	if (buff == NULL || pos < 0 || acc == NULL)
		return 0;

	*acc = getbits(buff, i, 24) / pow(2, 25); i += 24;
	return 1;
}

static int decode_Inclinometer_Average_Acceleration(const unsigned char *buff, const int pos, double *acc)
{
	int		i = pos;

	if (buff == NULL || pos < 0 || acc == NULL)
		return 0;

	*acc = getbits(buff, i, 24) / pow(2, 22); i += 24;
	return 1;
}

static int decode_stim300_0x90(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	return 0;
}

static int decode_stim300_0x91(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	return 0;
}

static int decode_stim300_0x92(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	return 0;
}

static int decode_stim300_0x93(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	return 0;
}

static int decode_stim300_0x94(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	return 0;
}

// 增量
static int decode_stim300_0xA5(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	int		i = 8;
	unsigned int CRC = 0, CRC0 = 0;
	unsigned char dummy1 = 0x00, dummy2 = 0x00;

	if (len < STIM300_0xA5_LEN || buff[0] != 0xA5)
		return 0;

	double		gyr_x = 0.0, gyr_y = 0.0, gyr_z = 0.0;
	double		acc_x = 0.0, acc_y = 0.0, acc_z = 0.0;
	double		gyr_x_temp = 0.0, gyr_y_temp = 0.0, gyr_z_temp = 0.0;
	double		acc_x_temp = 0.0, acc_y_temp = 0.0, acc_z_temp = 0.0;
	int			gry_stat = 0, acc_stat = 0;
	int			gyr_temp_stat = 0, acc_temp_stat = 0;
	int			frame = 0, delay = 0;

	// 陀螺
	//decode_Gyr_Angular_Rate(buff, i, &gyr_x, &gyr_y, &gyr_z); i += 3 * 24;
	decode_Gyr_Incremental_Angle(buff, i, &gyr_x, &gyr_y, &gyr_z); i += 3 * 24;
	gry_stat = getbits(buff, i, 8); i += 8;

	// 加计
	decode_Acc_Incremental_Velocity(buff, i, &acc_x, &acc_y, &acc_z); i += 3 * 24;
	acc_stat = getbits(buff, i, 8); i += 8;
	//printf(" %9.6lf %9.6lf %9.6lf %9.6lf %9.6lf %9.6lf\n", gyr_x, gyr_y, gyr_z, acc_x, acc_y, acc_z);
	//printf("0xA5 %.5E %.5E\n", sqrt(gyr_x*gyr_x + gyr_y * gyr_y + gyr_z * gyr_z), sqrt(acc_x*acc_x + acc_y * acc_y + acc_z * acc_z));

	// 陀螺
	gyr_x_temp = getbits(buff, i, 16) / pow(2, 8); i += 16;
	gyr_y_temp = getbits(buff, i, 16) / pow(2, 8); i += 16;
	gyr_z_temp = getbits(buff, i, 16) / pow(2, 8); i += 16;
	gyr_temp_stat = getbits(buff, i, 8); i += 8;
	//printf(" gyr_temp %.6lf %.6lf %.6lf\n", gyr_x_temp, gyr_y_temp, gyr_z_temp);

	// 加计
	acc_x_temp = getbits(buff, i, 16) / pow(2, 8); i += 16;
	acc_y_temp = getbits(buff, i, 16) / pow(2, 8); i += 16;
	acc_z_temp = getbits(buff, i, 16) / pow(2, 8); i += 16;
	acc_temp_stat = getbits(buff, i, 8); i += 8;
	//printf(" acc_temp %.6lf %.6lf %.6lf\n", acc_x_temp, acc_y_temp, acc_z_temp);

	// 帧计数
	frame = getbitu(buff, i, 8); i += 8;

	// 延迟
	delay = getbitu(buff, i, 16); i += 16;

	// CRC
	CRC  = getbitu(buff, i, 32); i += 32;
	
	CRC0 = 0;
	CalcCRC32(buff, 38, &CRC0);
	//printf(" CRC = %X, CRC0 = %X\n", CRC, CRC0);
	if (CRC0 != CRC)
		return 0;
	
	if (stim300 != NULL)
	{        
        // 角度增量，单位为radians
        stim300->DeltaAngleX = gyr_x;
        stim300->DeltaAngleY = gyr_y;
        stim300->DeltaAngleZ = gyr_z;
	     
        // 速度增量，单位为m/sec
        stim300->DeltaVelocityX = acc_x;
        stim300->DeltaVelocityY = acc_y;
        stim300->DeltaVelocityZ = acc_z;  
	}
	
	return 1;
}

static int decode_stim300_0xA6(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	return 0;
}

static int decode_stim300_0xA7(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	return 0;
}

static int decode_stim300_0x98(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	return 0;
}

static int decode_stim300_0x99(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	return 0;
}

static int decode_stim300_0x9A(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	return 0;
}

static int decode_stim300_0x9B(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	return 0;
}

static int decode_stim300_0x9C(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	return 0;
}

static int decode_stim300_0xAD(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	return 0;
}

static int decode_stim300_0xAE(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	return 0;
}

static int decode_stim300_0xAF(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	return 0;
}

EXPORT extern int decode_stim300(const unsigned char *buff, const int len, raw_stim300_t *stim300)
{
	int		ret = 0;
	int		type = getbitu(buff, 0, 8);
	
	//printf("decode_stim300 type = %X\n", type);
	switch (type)
	{
		case 0x90: ret = decode_stim300_0x90(buff, len, stim300);  break;
		case 0x91: ret = decode_stim300_0x91(buff, len, stim300);  break;
		case 0x92: ret = decode_stim300_0x92(buff, len, stim300);  break;
		case 0x93: ret = decode_stim300_0x93(buff, len, stim300);  break;
		case 0x94: ret = decode_stim300_0x94(buff, len, stim300);  break;
		case 0xA5: ret = decode_stim300_0xA5(buff, len, stim300);  break;
		case 0xA6: ret = decode_stim300_0xA6(buff, len, stim300);  break;
		case 0xA7: ret = decode_stim300_0xA7(buff, len, stim300);  break;
		case 0x98: ret = decode_stim300_0x98(buff, len, stim300);  break;
		case 0x99: ret = decode_stim300_0x99(buff, len, stim300);  break;
		case 0x9A: ret = decode_stim300_0x9A(buff, len, stim300);  break;
		case 0x9B: ret = decode_stim300_0x9B(buff, len, stim300);  break;
		case 0x9C: ret = decode_stim300_0x9C(buff, len, stim300);  break;
		case 0xAD: ret = decode_stim300_0xAD(buff, len, stim300);  break;
		case 0xAE: ret = decode_stim300_0xAE(buff, len, stim300);  break;
		case 0xAF: ret = decode_stim300_0xAF(buff, len, stim300);  break;
		default:   ret = 0; break;
	}

	return ret;
}


//Rate                                                        0x90
//Rate and acceleration                                       0x91
//Rate and inclination                                        0x92
//Rate, acceleration and inclination                          0x93
//Rate and temperature                                        0x94
//Rate, acceleration and temperature                          0xA5
//Rate, inclination and temperature                           0xA6
//Rate, acceleration, inclination and temperature             0xA7
//Rate and AUX                                                0x98
//Rate, acceleration and AUX                                  0x99
//Rate, inclination and AUX                                   0x9A
//Rate, acceleration, inclination and AUX                     0x9B
//Rate, temperature and AUX                                   0x9C
//Rate, acceleration, temperature and AUX                     0xAD
//Rate, inclination, temperature and AUX                      0xAE
//Rate, acceleration, inclination, temperature and AUX        0xAF
static int set_stim300_info(stim300_t *stim300, const unsigned char data)
{
	if (stim300 == NULL)
		return 0;

	if (data == 0x90)
	{
		return 1;
	}
	else if (data == 0x91)
	{
		stim300->len = STIM300_0x91_LEN;
		stim300->dummy = STIM300_0x91_DUMMY;
		return 1;
	}
	else if (data == 0x92)
	{
		stim300->len = STIM300_0x92_LEN;
		stim300->dummy = STIM300_0x92_DUMMY;
		return 1;
	}
	else if (data == 0x93)
	{
		stim300->len = STIM300_0x93_LEN;
		stim300->dummy = STIM300_0x93_DUMMY;
		return 1;
	}
	else if (data == 0x94)
	{
		stim300->len = STIM300_0x94_LEN;
		stim300->dummy = STIM300_0x94_DUMMY;
		return 1;
	}
	else if (data == 0xA5)
	{
		stim300->len = STIM300_0xA5_LEN;
		stim300->dummy = STIM300_0xA5_DUMMY;
		return 1;
	}
	else if (data == 0xA6)
	{
		stim300->len = STIM300_0xA6_LEN;
		stim300->dummy = STIM300_0xA6_DUMMY;
		return 1;
	}
	else if (data == 0xA7)
	{
		stim300->len = STIM300_0xA7_LEN;
		stim300->dummy = STIM300_0xA7_DUMMY;
		return 1;
	}
	else if (data == 0x98)
	{
		stim300->len = STIM300_0x98_LEN;
		stim300->dummy = STIM300_0x98_DUMMY;
		return 1;
	}
	else if (data == 0x99)
	{
		stim300->len = STIM300_0x99_LEN;
		stim300->dummy = STIM300_0x99_DUMMY;
		return 1;
	}
	else if (data == 0x9A)
	{
		stim300->len = STIM300_0x9A_LEN;
		stim300->dummy = STIM300_0x9A_DUMMY;
		return 1;
	}
	else if (data == 0x9B)
	{
		stim300->len = STIM300_0x9B_LEN;
		stim300->dummy = STIM300_0x9B_DUMMY;
		return 1;
	}
	else if (data == 0x9C)
	{
		stim300->len = STIM300_0x9C_LEN;
		stim300->dummy = STIM300_0x9C_DUMMY;
		return 1;
	}
	else if (data == 0xAD)
	{
		stim300->len = STIM300_0xAD_LEN;
		stim300->dummy = STIM300_0xAD_DUMMY;
		return 1;
	}
	else if (data == 0xAE)
	{
		stim300->len = STIM300_0xAE_LEN;
		stim300->dummy = STIM300_0xAE_DUMMY;
		return 1;
	}
	else if (data == 0xAF)
	{
		stim300->len = STIM300_0xAF_LEN;
		stim300->dummy = STIM300_0xAF_DUMMY;
		return 1;
	}

	return 0;
}

extern int input_stim300(stim300_t *stim300, const unsigned char data)
{
	if (stim300 == NULL)
		return 0;

	if (stim300->nbyte == 0) 
	{
		if (set_stim300_info(stim300, data) == 0)
			return 0;

		stim300->buff[stim300->nbyte++] = data;
		return 0;
	}
	stim300->buff[stim300->nbyte++] = data;

	if (stim300->nbyte < 1 || stim300->nbyte < stim300->len) 
		return 0;
	
	// 已经可以解码了, buff要清空
	stim300->nbyte = 0;

	// 解码
	return decode_stim300(stim300->buff, stim300->len, &stim300->rawImu);
}

#endif // __STM_300_H__