#include "include.h"
/******************************************************************
**函数名称:void Data_Send_02(unsigned short int *pst)
**函数功能:向匿名上位机发送九轴传感器数据
**函数输入:九轴数据存放数组,长度为9
**函数返回:无
*****************************************************************/
void UartData_Send_02(unsigned short int *pst)
{
unsigned char _cnt=0;
unsigned char sum = 0;
unsigned char i=0;
unsigned char data_to_send[23];
data_to_send[_cnt++]=0xAA;
data_to_send[_cnt++]=0xAA;
data_to_send[_cnt++]=0x02;
data_to_send[_cnt++]=0;
data_to_send[_cnt++]=(unsigned char)(pst[0]>>8);
data_to_send[_cnt++]=(unsigned char)pst[0];
data_to_send[_cnt++]=(unsigned char)(pst[1]>>8);
data_to_send[_cnt++]=(unsigned char)pst[1];
data_to_send[_cnt++]=(unsigned char)(pst[2]>>8);
data_to_send[_cnt++]=(unsigned char)pst[2];
data_to_send[_cnt++]=(unsigned char)(pst[3]>>8);
data_to_send[_cnt++]=(unsigned char)pst[3];
data_to_send[_cnt++]=(unsigned char)(pst[4]>>8);
data_to_send[_cnt++]=(unsigned char)pst[4];
data_to_send[_cnt++]=(unsigned char)(pst[5]>>8);
data_to_send[_cnt++]=(unsigned char)pst[5];
data_to_send[_cnt++]=(unsigned char)(pst[6]>>8);
data_to_send[_cnt++]=(unsigned char)pst[6];
data_to_send[_cnt++]=(unsigned char)(pst[7]>>8);
data_to_send[_cnt++]=(unsigned char)pst[7];
data_to_send[_cnt++]=(unsigned char)(pst[8]>>8);
data_to_send[_cnt++]=(unsigned char)pst[8];
data_to_send[3] = _cnt-4;
sum = 0;
for(i=0;i<_cnt;i++)
{
sum += data_to_send[i];
}
data_to_send[_cnt++] = sum;
for(i=0;i<_cnt;i++)
{
UART4_PutChar(data_to_send[i]);
}
}
/****************************************************************************************
**函数名称:void Data_Send_F1(int *pst,unsigned char len)
**函数功能:向匿名上位机发送len个int型数据
**函数输入:pst:数据存放数组,len要发送的数据长度(1-20)
**函数返回:无
**备 注:传送7个数据需要1680us,每多1个数据需要再加168us(不包括数据赋值过程中的运算)
比如传送9个数据就需 1680+168*2 = 2016(us)
***************************************************************************************/
void UartData_Send_F1(int *pst,unsigned char len)
{
unsigned char sum = 0;
unsigned char i;
unsigned char data_to_send[45];
data_to_send[0] = 0xAA;
data_to_send[1] = 0xAA;
data_to_send[2] = 0xF1;
data_to_send[3] = 2*len;
for(i=0;i<len;i++)
{
data_to_send[2*i+4] = (unsigned char)(pst[i]>>8);
data_to_send[2*i+5] = (unsigned char)pst[i];
}
for(i=0;i<2*len+4;i++)
{
sum += data_to_send[i];
}
data_to_send[2*len+4] = sum;
for(i=0;i<2*len+5;i++)
{
UART4_PutChar(data_to_send[i]);
}
}