根据weebee的例子改了一下。我每次发送 FE 02 41 80 01 01 00.(这里的CM0 CM1是在另一个例子里看来的,不知道是什么意思) 1S发一次,协调器接到串口时间之后,把数据广播出去。发送数据一多,协调器就再也收不到数据了。
不知道是什么原因。求大神指教。
void MT_UartProcessZToolData ( uint8 port, uint8 event )
{
uint8 ch;
uint8 bytesInRxBuffer;
(void)event; // Intentionally unreferenced parameter
while (Hal_UART_RxBufLen(port))
{
HalUARTRead (port, &ch, 1);
//HalLedSet(HAL_LED_1,HAL_LED_MODE_TOGGLE);
switch (state)
{
case SOP_STATE:
if (ch == MT_UART_SOF)
state = LEN_STATE;
break;
case LEN_STATE:
LEN_Token = ch;
tempDataLen = 0;
/* Allocate memory for the data */
pMsg = (mtOSALSerialData_t *)osal_msg_allocate( sizeof ( mtOSALSerialData_t ) +
MT_RPC_FRAME_HDR_SZ + LEN_Token );
if (pMsg)
{
/* Fill up what we can */
pMsg->hdr.event = CMD_SERIAL_MSG;
pMsg->msg = (uint8*)(pMsg+1);
pMsg->msg[MT_RPC_POS_LEN] = LEN_Token;
state = CMD_STATE1;
}
else
{
state = SOP_STATE;
return;
}
break;
case CMD_STATE1:
pMsg->msg[MT_RPC_POS_CMD0] = ch;
state = CMD_STATE2;
break;
case CMD_STATE2:
pMsg->msg[MT_RPC_POS_CMD1] = ch;
/* If there is no data, skip to FCS state */
if (LEN_Token)
{
state = DATA_STATE;
}
else
{
state = FCS_STATE;
}
break;
case DATA_STATE:
/* Fill in the buffer the first byte of the data */
pMsg->msg[MT_RPC_FRAME_HDR_SZ + tempDataLen++] = ch;
/* Check number of bytes left in the Rx buffer */
bytesInRxBuffer = Hal_UART_RxBufLen(port);
/* If the remain of the data is there, read them all, otherwise, just read enough */
if (bytesInRxBuffer <= LEN_Token - tempDataLen)
{
HalUARTRead (port, &pMsg->msg[MT_RPC_FRAME_HDR_SZ + tempDataLen], bytesInRxBuffer);
tempDataLen += bytesInRxBuffer;
}
else
{
HalUARTRead (port, &pMsg->msg[MT_RPC_FRAME_HDR_SZ + tempDataLen], LEN_Token - tempDataLen);
tempDataLen += (LEN_Token - tempDataLen);
}
/* If number of bytes read is equal to data length, time to move on to FCS */
if ( tempDataLen == LEN_Token )
state = FCS_STATE;
break;
case FCS_STATE:
FSC_Token = ch;
/* Make sure it's correct */
//if ((MT_UartCalcFCS ((uint8*)&pMsg->msg[0], MT_RPC_FRAME_HDR_SZ + LEN_Token) == FSC_Token))
// {
osal_msg_send( App_TaskID, (byte *)pMsg );
// }
// else
// {
/* deallocate the msg */
// osal_msg_deallocate ( (uint8 *)pMsg );
// }
/* Reset the state, send or discard the buffers at this point */
state = SOP_STATE;
break;
default:
break;
}
}
}
复制代码
调试发现下面的提示串口输出代码,只要都注释掉,就很容易就死掉了。
放着就能正常工作挺久。
void SampleApp_SerialCMD(mtOSALSerialData_t *cmdMsg)
{
uint8 i,len,*str=NULL; //len有用数据长度
str=cmdMsg->msg; //指向数据开头
len=*str; //msg里的第1个字节代表后面的数据长度
/********打印出串口接收到的数据,用于提示*********/
//Onboard_wait(300);
//for(i=0;i<=len+2;i++)
//HalUARTWrite(0,str+i,1 );
HalUARTWrite(0,"\n",1 );//换行
HalLedSet(HAL_LED_1,HAL_LED_MODE_TOGGLE);
/*******发送出去***参考网蜂 1小时无线数据传输教程*********/
if ( AF_DataRequest( &SampleApp_Periodic_DstAddr, &SampleApp_epDesc,
SAMPLEAPP_PERIODIC_CLUSTERID,//自己定义一个
len+3, // 数据长度
str, //数据内容
&SampleApp_TransID,
AF_DISCV_ROUTE,
AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
{
}
else
{
// Error occurred in request to send.
}
}
复制代码转载
|