|
本帖最后由 Jimmyy 于 2016-4-18 15:56 编辑
ZigBee问题:一、问题背景:
1、Z-stack,SAMPLE工程;
2、一个协调器,一个终端设备;
3、协调器、终端设备均与STM32连接,与协调器连接的以下称为MCU1,另一个称为MCU2;(模仿无线透传传输)
4、欲实现目的:
①MCU2有数据及时通过UART传至终端设备,然后终端设备向协调器点对点发送数据,显示屏显示收到的数据;
②MCU1有数据及时通过UART传至协调器,然后协调器向终端设备广播数据,显示屏显示收到的数据。
二、出现的问题:
协调器能够收到终端设备点对点发来的数据,终端设备收不到协调器广播来的数据。
三、预解决:
1、Packet Sniffer抓包分析:
①终端设备向协调器点对点发送数据数据包情况:
描述:1、终端设备请求一次数据,协调器应答一下,然后终端设备点对点发送,协调器应答;
2、协调器能够收到终端设备的数据;
②协调器广播数据数据包情况:
发现的问题:1、终端设备向协调器请求一次数据,协调器有时发送一个数据包,有时发送两个数据包(PS:这个数据包是期 望发送的数据包);
2、协调器发送数据包后,终端设备没有应答;
3、终端设备收不到协调器广播来的数据。
2、ZigBee、MCU角色互换,问题仍得不到解决!
四、主要程序附件:
1、事件处理函数如下:
- uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events )
- {
- afIncomingMSGPacket_t *MSGpkt;
- (void)task_id; // Intentionally unreferenced parameter
- if ( events & SYS_EVENT_MSG )//事件提取
- {
- MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );
- while ( MSGpkt )
- {
- switch ( MSGpkt->hdr.event )
- {
- case CMD_SERIAL_MSG:/*串口收到数据*/
- SampleApp_MyFunction_SendMessage((mtOSALSerialData_t *)MSGpkt);/*路由到空中*/
- break;
-
- // Received when a messages is received (OTA) for this endpoint
- case AF_INCOMING_MSG_CMD:/*天线收到数据*/
- SampleApp_MessageMSGCB( MSGpkt );/*传送至PC端或MCU*/
- break;
- default:
- break;
- }
- // Release the memory
- osal_msg_deallocate( (uint8 *)MSGpkt );
- // Next - if one is available
- MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );
- }
- // return unprocessed events
- return (events ^ SYS_EVENT_MSG);
- }
- // Discard unknown events
- return 0;
- }
复制代码 2、无线数据接收函数:
- void SampleApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )//接收无线数据
- {
- switch ( pkt->clusterId )
- {
- #if defined (MCU)
- case SAMPLEAPP_MYCLUSTERID_P2P_SendMessage:
-
- HalUARTWrite ( //uint8 port
- 0,
- //uint8 *pBuffer
- pkt->cmd.Data,
- //uint16 length
- pkt->cmd.DataLength
- );
- break;
-
- #elif defined (SLAVE)
- case SAMPLEAPP_MYCLUSTERID_Broadcast_SendMessage:
-
- HalUARTWrite ( //uint8 port
- 0,
- //uint8 *pBuffer
- pkt->cmd.Data,
- //uint16 length
- pkt->cmd.DataLength
- );
- break;
- #endif
- }
- }
复制代码 3、串口数据发送函数:
- void SampleApp_MyFunction_SendMessage( mtOSALSerialData_t *cmdMsg )
- {
- #if defined (PC)/*MCU对SLAVE广播*/
- if ( AF_DataRequest( &SampleApp_Broadcast_DstAddr, &SampleApp_epDesc,
- //A valid cluster ID as specified by the Profile
- SAMPLEAPP_MYCLUSTERID_Broadcast_SendMessage,
- //Number of bytes of data pointed to by next param
- *cmdMsg->msg,//取出头字节
- //A pointer to the data bytes to send
- cmdMsg->msg+1, //指向发送的数据
- &SampleApp_TransID,
- AF_DISCV_ROUTE,
- AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
- {
- }
-
- #elif defined (SLAVE)/*SLAVE对MCU点播数据*/
- if ( AF_DataRequest( &SampleApp_P2P_DstAddr, &SampleApp_epDesc,
- //A valid cluster ID as specified by the Profile
- SAMPLEAPP_MYCLUSTERID_P2P_SendMessage,
- //Number of bytes of data pointed to by next param
- *cmdMsg->msg,//取出头字节
- //A pointer to the data bytes to send
- cmdMsg->msg+1, //指向发送的数据
- &SampleApp_TransID,
- AF_DISCV_ROUTE,
- AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
- {
- }
- #endif
- else
- {
- // Error occurred in request to send.
- }
- }
复制代码
新人小白,若有问的不妥的地方,还请大家多多包涵,也恳请大家帮忙查找问题,谢谢大家!
|
|