新手求助
实验室拿到两个zigbee节点,于是我按照书<ZigBee无线传感器网络设计与实现>配置并运行了第一个实验,使终端节点发送字符“LED”到协调器节点,然后协调器节点闪烁,代码如下
但是奇怪的是节点并没有按预期的那样工作,刷写完成后重新打开节点,节点没有任何反应
使用IAR在终端节点上进行调试,在函数UINT16 GenericApp_ProcessEvent(byte task_id, UINT16 events)处打上断点,但运行后代码并不会停止在断点处,设备会显示busy
我使用的IAR版本为10.20.1,Zstack版本为3.0.1
硬件应该是正常的,我进行刷写程序之前两个节点还是可以正常通信
代码如下:
Coordinator.h
#ifndef COORDINATOR_H #define COORDINATOR_H #include "zComDef.h" #define GENERICAPP_ENDPOINT 10 #define GENERICAPP_PROFID 0x0F04 #define GENERICAPP_DEVICEID 0x0001 #define GENERICAPP_DEVICE_VERSION 0 #define GENERICAPP_FLAGS 0 #define GENERICAPP_MAX_CLUSTERS 1 #define GENERICAPP_CLUSTERID 1 extern void GenericApp_Init( byte task_id ); extern UINT16 GenericApp_ProcessEvent( byte task_id, UINT16 events ); #endif
Coordinator.c
#include "OSAL.h"
#include "AF.h"
#include "ZDApp.h"
#include "ZDObject.h"
#include "ZDProfile.h"
#include "math.h"
#include "stdlib.h"
#include "Coordinator.h"
#include "DebugTrace.h"
#if !defined( WIN32 )
#include "OnBoard.h"
#endif
#include "hal_lcd.h"
#include "hal_led.h"
#include "hal_key.h"
#include "hal_uart.h"
const cId_t GenericApp_ClusterList[GENERICAPP_MAX_CLUSTERS] =
{
GENERICAPP_CLUSTERID
};
const SimpleDescriptionFormat_t GenericApp_SimpleDesc =
{
GENERICAPP_ENDPOINT, // int Endpoint;
GENERICAPP_PROFID, // uint16 AppProfId[2];
GENERICAPP_DEVICEID, // uint16 AppDeviceId[2];
GENERICAPP_DEVICE_VERSION, // int AppDevVer:4;
GENERICAPP_FLAGS, // int AppFlags:4;
GENERICAPP_MAX_CLUSTERS, // byte AppNumInClusters;
(cId_t *)GenericApp_ClusterList, // byte *pAppInClusterList;
0, // byte AppNumInClusters;
(cId_t *)NULL // byte *pAppInClusterList;
};
endPointDesc_t GenericApp_epDesc;
byte GenericApp_TaskID; // Task ID for internal task/event processing
byte GenericApp_TransID; // This is the unique message ID (counter)
void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pckt );
void GenericApp_SendTheMessage( void );
void GenericApp_Init( byte task_id )
{
GenericApp_TaskID = task_id;
GenericApp_TransID = 0;
GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT;
GenericApp_epDesc.task_id = &GenericApp_TaskID;
GenericApp_epDesc.simpleDesc
= (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc;
GenericApp_epDesc.latencyReq = noLatencyReqs;
afRegister( &GenericApp_epDesc );
}
UINT16 GenericApp_ProcessEvent( byte task_id, UINT16 events )
{
afIncomingMSGPacket_t *MSGpkt;
if ( events & SYS_EVENT_MSG )
{
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID );
while ( MSGpkt )
{
switch ( MSGpkt->hdr.event )
{
case AF_INCOMING_MSG_CMD:
GenericApp_MessageMSGCB( MSGpkt );
break;
default:
break;
}
osal_msg_deallocate( (uint8 *)MSGpkt );
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID );
}
return (events ^ SYS_EVENT_MSG);
}
return 0;
}
void GenericApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )
{
unsigned char buffer[4] = " ";
switch (pkt->clusterId)
{
case GENERICAPP_CLUSTERID:
osal_memcpy(buffer, pkt->cmd.Data,3);
if((buffer[0]=='L')||(buffer[1]=='E')||(buffer[2]=='D'))
{
HalLedBlink(HAL_LED_2,0,50,500);
}
else
{
HalLedSet(HAL_LED_2,HAL_LED_MODE_ON);
}
break;
}
}
Enddevice.c
#include "OSAL.h"
#include "AF.h"
#include "ZDApp.h"
#include "ZDObject.h"
#include "ZDProfile.h"
#include "Coordinator.h"
#include "DebugTrace.h"
#if !defined( WIN32 )
#include "OnBoard.h"
#endif
#include "hal_lcd.h"
#include "hal_led.h"
#include "hal_key.h"
#include "hal_uart.h"
#define SEND_DATA_EVENT 0x01
const cId_t GenericApp_ClusterList[GENERICAPP_MAX_CLUSTERS] =
{
GENERICAPP_CLUSTERID
};
const SimpleDescriptionFormat_t GenericApp_SimpleDesc =
{
GENERICAPP_ENDPOINT, // int Endpoint;
GENERICAPP_PROFID, // uint16 AppProfId[2];
GENERICAPP_DEVICEID, // uint16 AppDeviceId[2];
GENERICAPP_DEVICE_VERSION, // int AppDevVer:4;
GENERICAPP_FLAGS, // int AppFlags:4;
0, // byte AppNumInClusters;
(cId_t*)NULL, // byte *pAppInClusterList;
GENERICAPP_MAX_CLUSTERS, // byte AppNumInClusters;
(cId_t*)GenericApp_ClusterList, // byte *pAppInClusterList;
};
endPointDesc_t GenericApp_epDesc;
byte GenericApp_TaskID; // Task ID for internal task/event processing
byte GenericApp_TransID; // This is the unique message ID (counter)
devStates_t GenericApp_NwkState;
void GenericApp_MessageMSGCB(afIncomingMSGPacket_t* pckt);
void GenericApp_SendTheMessage(void);
int8 readTemp(void);
uint16 ReadHumi(void);
void To_string(uint8* dest, uint8* src, uint8 l);
void GenericApp_Init(byte task_id)
{
GenericApp_TaskID = task_id;
GenericApp_NwkState = DEV_INIT;
GenericApp_TransID = 0;
GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT;
GenericApp_epDesc.task_id = &GenericApp_TaskID;
GenericApp_epDesc.simpleDesc
= (SimpleDescriptionFormat_t*)&GenericApp_SimpleDesc;
GenericApp_epDesc.latencyReq = noLatencyReqs;
afRegister(&GenericApp_epDesc);
}
UINT16 GenericApp_ProcessEvent(byte task_id, UINT16 events)
{
afIncomingMSGPacket_t* MSGpkt;
if (events & SYS_EVENT_MSG)
{
MSGpkt = (afIncomingMSGPacket_t*)osal_msg_receive(GenericApp_TaskID);
while (MSGpkt)
{
switch (MSGpkt->hdr.event)
{
case ZDO_STATE_CHANGE:
GenericApp_NwkState = (devStates_t)(MSGpkt->hdr.status);
if (GenericApp_NwkState == DEV_END_DEVICE || GenericApp_NwkState == DEV_ROUTER)
{
GenericApp_SendTheMessage();
}
break;
default:
break;
}
osal_msg_deallocate((uint8*)MSGpkt);
MSGpkt = (afIncomingMSGPacket_t*)osal_msg_receive(GenericApp_TaskID);
}
return (events ^ SYS_EVENT_MSG);
}
return 0;
}
void GenericApp_SendTheMessage(void)
{
unsigned char theMessageData[4] = "LED";
afAddrType_t my_DstAddr;
my_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
my_DstAddr.endPoint = GENERICAPP_ENDPOINT;
my_DstAddr.addr.shortAddr = 0x0000;
AF_DataRequest(&my_DstAddr, &GenericApp_epDesc,
GENERICAPP_CLUSTERID,
3,
theMessageData,
&GenericApp_TransID,
AF_DISCV_ROUTE,
AF_DEFAULT_RADIUS);
HalLedBlink(HAL_LED_2,0,50,500);
}
void To_string(uint8* dest, uint8* src, uint8 l)
{
uint8* xad;
uint8 i = 0;
uint8 ch;
xad = src + l - 1;
for (i = 0;i < l;i++, xad--)
{
ch = (*xad >> 4) & 0x0F;
dest[i << 1] = ch + ((ch < 10) ? '0' : '7');
ch = *xad & 0x0F;
dest[(i << 1) + 1] = ch + ((ch < 10) ? '0' : '7');
}
}
有人能帮帮我吗?谢谢!