#1楼主:程序问题 关于cc2430的
文章发表于:2008-08-05 10:26
#include "wx_lrwpan.h"
#ifndef LRWPAN_COORDINATOR
#define PING_DELAY 2 //wait before bouncing back
#else
#define PING_DELAY 0 //coordinator does not wait
#endif
UINT32 my_timer;
UINT32 last_tx_start;
UINT8 LcdPage = 2;
unsigned char x=0;
LADDR_UNION dstADDR;
typedef enum _PP_STATE_ENUM {
PP_STATE_IDLE,
PP_STATE_SEND,
PP_STATE_WAIT_FOR_TX
}PP_STATE_ENUM;
PP_STATE_ENUM ppState;
BYTE payload[2];
unsigned char cishu[4]={0x01,0x02,0x03,0x04};
void LampStateDisplay(void)
{
static INT16U count=0;
apsFSM();
switch(ppState)
{
case PP_STATE_IDLE:
if(++count>=250)
{
ppState=PP_STATE_SEND;
count=0;
}
break;
case PP_STATE_SEND:
if ((halMACTimerNowDelta(my_timer))> MSECS_TO_MACTICKS(PING_DELAY*1000)){
payload[0]=cishu[x];
payload[1]=payload[0];
x++;
if(x==4){x=0;}
aplSendMSG (APS_DSTMODE_LONG,
&dstADDR,
2, //dst EP
0, //cluster is ignored for direct message
1, //src EP
&payload[0],
2, //msg length
apsGenTSN(),
FALSE);
ppState=PP_STATE_WAIT_FOR_TX;
}
break;
case PP_STATE_WAIT_FOR_TX:
if(apsBusy()) break;
if(aplGetStatus()==LRWPAN_STATUS_SUCCESS)
{
if(payload[0]==0x01)
{
P1_1=0;
}
else
{
P1_2=0;
}
ppState=PP_STATE_IDLE;
}
break;
}
}
void main(void)
{
P1SEL=0x00;
P1DIR=0x07;
my_timer=0;
halInit();
evbInit();
InitLcd();
TurnOnDisp();
ClearScreen();
aplInit();
conPrintConfig();
ENABLE_GLOBAL_INTERRUPT();
EVB_LED1_OFF();
EVB_LED2_OFF();
#ifdef LRWPAN_COORDINATOR
aplFormNetwork();
while(apsBusy()) {apsFSM();} //wait for finish
conPrintROMString("Network formed, waiting for RX\n");
Print6(7,3,"Network formed!",1);
#else
do {
aplJoinNetwork();
while(apsBusy()) {apsFSM();} //wait for finish
if (aplGetStatus() == LRWPAN_STATUS_SUCCESS) {
ClearScreen();
#ifdef LRWPAN_ROUTER
Print8(0,25,"--ROUTER-- ",1);
#endif
#ifdef LRWPAN_RFD
Print8(0,45,"--RFD-- ",1);
#endif
conPrintROMString("Network Join succeeded!\n");
Print6(2,3,"Network Join succeed!",1);
// Print6(3,3,"eded!",1);
conPrintROMString("My ShortAddress is: ");
conPrintUINT16(aplGetMyShortAddress());
Print6(3,3,"My SADDR: ",1);
LcdPrintUINT16(aplGetMyShortAddress(),3,63);
conPCRLF();
conPrintROMString("Parent LADDR: ")
conPrintLADDR(aplGetParentLongAddress());
Print6(4,3,"Parent LADDR: ",1);
LcdPrintLADDR(aplGetParentLongAddress(),4,87);
conPrintROMString(", Parent SADDR: ");
conPrintUINT16(aplGetParentShortAddress());
conPCRLF();
break;
}else {
conPrintROMString("Network Join FAILED! Waiting, then trying again\n");
ClearScreen();
#ifdef LRWPAN_ROUTER
Print8(0,25,"--ROUTER-- ",1);
#endif
#ifdef LRWPAN_RFD
Print8(0,40,"--RFD-- ",1);
#endif
halWait(100);
Print6(2,3,"Network Join FAILED! ",1);
Print6(3,3,"Waiting, then trying",1);
Print6(4,3,"again!",1);
my_timer= halGetMACTimer();
//wait for 2 seconds
while ((halMACTimerNowDelta(my_timer))< MSECS_TO_MACTICKS(2*1000));
}
} while(1);
#endif
#ifdef LRWPAN_COORDINATOR
aplSetMacMaxFrameRetries(0);
while(1){
apsFSM();
}
#endif
#ifdef LRWPAN_COORDINATION
aplSetMacMaxFrameRetries(0);
dstAddr.laddr.bytes[0]=0x63;
dstAddr.laddr.bytes[1]=0x00;
dstAddr.laddr.bytes[2]=0x00;
dstAddr.laddr.bytes[3]=0x00;
dstAddr.laddr.bytes[4]=0x00;
dstAddr.laddr.bytes[5]=0x00;
dstAddr.laddr.bytes[6]=0x00;
dstAddr.laddr.bytes[7]=0x00;
ppState=PP_STATE_IDLE;
while(1)
{
LampStateDisplay();
}
#endif
#ifdef LRWPAN_RFD
dstADDR.saddr=0;
aplSetMacMaxFrameRetries(0);
while(1)
{
apsFSM();
}
#endif
#ifdef LRWPAN_ROUTER
//router does nothing, just routes
DEBUG_PRINTNEIGHBORS(DBG_INFO);
conPrintROMString("Router, doing its thing.!\n");
Print6(7,3,"Router is running!",1);
while(1) {
apsFSM();
RouterWork();
}
#endif
}
//########## Callbacks ##########
//callback for anytime the Zero Endpoint RX handles a command
//user can use the APS functions to access the arguments
//and take additional action is desired.
//the callback occurs after the ZEP has already taken
//its action.
LRWPAN_STATUS_ENUM usrZepRxCallback(void){
#ifdef LRWPAN_COORDINATOR
if (aplGetRxCluster() == ZEP_END_DEVICE_ANNOUNCE) {
//a new end device has announced itself, print out the
//the neightbor table and address map
dbgPrintNeighborTable();
}
#endif
return LRWPAN_STATUS_SUCCESS;
}
//callback from APS when packet is received
//user must do something with data as it is freed
//within the stack upon return.
LRWPAN_STATUS_ENUM usrRxPacketCallback(void) {
if(LcdPage == 2)
{
ClearScreen();
}
UINT16 ping_cnt;
BYTE len, *ptr;
conPrintROMString("User Data Packet Received: \n");
conPrintROMString("SrcSADDR: ");
conPrintUINT16(aplGetRxSrcSADDR());
conPrintROMString(", DstEp: ");
conPrintUINT8(aplGetRxDstEp());
conPrintROMString(", Cluster: ");
conPrintUINT8(aplGetRxCluster());
conPrintROMString(", MsgLen: ");
len = aplGetRxMsgLen();
conPrintUINT8(len);
conPrintROMString(",RSSI: ");
conPrintUINT8(aplGetRxRSSI());
conPCRLF();
conPrintROMString("PingCnt: ");
ptr = aplGetRxMsgData();
ping_cnt = *ptr;
ptr++;
ping_cnt += ((UINT16)*ptr)<<8;
conPrintUINT16(ping_cnt);
if(LcdPage >= 8)
{
LcdPage = 2;
}
conPCRLF();
#ifdef LRWPAN_RFD
switch((INT8U)*aplGetRxMsgData())
{
case 0x01:
P1&=0xfc;
break;
case 0x02:
P1&=0xfd;
break;
case 0x03:
P1&=0xfe;
break;
case 0x04:
P1&=0xff;
break;
}
#endif
return LRWPAN_STATUS_SUCCESS;
}
#ifdef LRWPAN_FFD
//Callback to user level to see if OK for this node
//to join - implement Access Control Lists here based
//upon IEEE address if desired
BOOL usrJoinVerifyCallback(LADDR *ptr, BYTE capinfo){\
#if 0 //set this to '1' if you want to test through a router
//only accept routers.
//only let routers join us if we are coord
#ifdef LRWPAN_COORDINATOR
if (LRWPAN_GET_CAPINFO_DEVTYPE(capinfo)) {
//this is a router, let it join
conPrintROMString("Accepting router\n");
return TRUE;
}else {
conPrintROMString("Rejecting non-router\n");
return FALSE;
}
#else
return TRUE;
#endif
#else
return TRUE;
#endif
}
BOOL usrJoinNotifyCallback(LADDR *ptr){
//allow anybody to join
conPrintROMString("Node joined: ");
conPrintLADDR(ptr);
ClearScreen();
#ifdef LRWPAN_COORDINATOR
conPrintROMString("Coordinator, ");
Print8(0,30,"--COORD-- ",1);
#endif
#ifdef LRWPAN_ROUTER
conPrintROMString("Router, ");
Print8(0,25,"--ROUTER-- ",1);
#endif
#ifdef LRWPAN_RFD
conPrintROMString("RFD, ");
Print8(0,40,"--RFD-- ",1);
#endif
Print6(2,3,"Node joined: ",1);
LcdPrintLADDR(ptr,2,81);
conPCRLF();
DEBUG_PRINTNEIGHBORS(DBG_INFO);
return TRUE;
}
#endif
//called when the slow timer interrupt occurs
#ifdef LRWPAN_ENABLE_SLOW_TIMER
void usrSlowTimerInt(void ) {}
#endif
//general interrupt callback , when this is called depends on the HAL layer.
void usrIntCallback(void){}
这个程序是coord向rfd发送1-4 rfd受到后分别作出不同的LED闪烁动作
没有error和warning
可是下载到板子上组网成功 用协议分析仪察看 发现没有信号 就是说coord不发送信号
谁能帮忙看一下到底出了什么问题啊/?