/***************************************************************************************************
* @fn MT_UartProcessZToolData
*
* @brief | SOP | Data Length | CMD | Data | FCS |
* | 1 | 1 | 2 | 0-Len | 1 |
*
* Parses the data and determine either is SPI or just simply serial data
* then send the data to correct place (MT or APP)
*
* @param port - UART port
* event - Event that causes the callback
*
*
* @return None
***************************************************************************************************/
void MT_UartProcessZToolData ( uint8 port, uint8 event )
{
uint8 ch,flag=0,i=0,num=0,rev_start=0; //flag 是判断有没有收到数据,j记录数据长度
uint8 buf[1]; //串口buffer最大缓冲默认是128,我们这里用12
uint8 rev_buf[100];
(void)event; // Intentionally unreferenced parameter
while (Hal_UART_RxBufLen(port)) //检测串口数据是否接收完成
{
HalUARTRead (port,&buf[0], 1); //把数据接收放到buf中
ch=buf[0];
if(ch=='$')
{
rev_start=1;
// rev_stop=0;
}
if(rev_start==1)
{
rev_buf[num++]=ch;
if(ch=='\n')
{
rev_buf[num]='\0';
rev_start=0;
// rev_stop=1;
flag=1; //已经从串口接收到信息
break;
}
}
}
if(flag==1) //已经从串口接收到信息
{ /* Allocate memory for the data */
//分配内存空间,为机构体内容+数据内容+1个记录长度的数据
pMsg = (mtOSALSerialData_t *)osal_msg_allocate( sizeof
( mtOSALSerialData_t )+num+2);
//事件号用原来的CMD_SERIAL_MSG
pMsg->hdr.event = CMD_SERIAL_MSG;
pMsg->msg = (uint8*)(pMsg+1); // 把数据定位到结构体数据部分
pMsg->msg [0]= num+1; //给上层的数据第一个是长度
for(i=0;i<num+1;i++) //从第二个开始记录数据
pMsg->msg [i+1]= rev_buf[i];
osal_msg_send( App_TaskID, (byte *)pMsg ); //登记任务,发往上层
/* deallocate the msg */
osal_msg_deallocate ( (uint8 *)pMsg ); //释放内存
}
}