没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Zigbee 低功耗数据采集及传输系统源代码
1、协调器、路由器、终端节点共用一个程序架构
wxldemo.c
#include "wx_lrwpan.h"
#include "lcd128_64.h"
#ifndef LRWPAN_COORDINATOR
#define PING_DELAY 2 //wait before bouncing back
#else
#define PING_DELAY 0 //coordinator does not wait
#endif
#define RX_PING_TIMEOUT 5 //seconds
//this is assumed to be the long address of our coordinator, in little endian order
//used to test LONG ADDRESSING back to coordinator
UINT16 ping_cnt;
UINT32 my_timer;
UINT32 last_tx_start;
UINT8 LcdPage = 1;
UINT8 line1 = 0;
BOOL updateLcd = TRUE;
UINT8 active = 0;
UINT8 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 rxFlag; //set from within usrRxPacketCallback
BYTE payload[6];
char str1;
char str2;
char str3;
char str4;
char str5;
char str6;
UINT16 numTimeouts;
BOOL first_packet;
char *menuText[];
void SendData(void);
void SendData(void)
{
unsigned char *str="Zigbee";
UINT16 count =0;
apsFSM();
switch(ppState)
{
case PP_STATE_IDLE:
if(++count == 2500)
{
ppState=PP_STATE_SEND;
count =0;
}
break;
case PP_STATE_SEND:
{
payload[0]= (BYTE)(str[0]);
payload[1]= (BYTE)(str[1]);
payload[2]= (BYTE)(str[2]);
payload[3]= (BYTE)(str[3]);
payload[4]= (BYTE)(str[4]);
payload[5]= (BYTE)(str[5]);
ppState=PP_STATE_WAIT_FOR_TX;
aplSendMSG(APS_DSTMODE_SHORT,
&dstADDR,
2,
0,
1,
&payload[0],
6,
apsGenTSN(),
FALSE);
ppState=PP_STATE_WAIT_FOR_TX;
}
break;
case PP_STATE_WAIT_FOR_TX:
if(apsBusy())break;
if(aplGetStatus()==LRWPAN_STATUS_SUCCESS)
{
ppState=PP_STATE_IDLE;
}
else
{
ppState=PP_STATE_SEND;
}
break;
}
}
void main (void){
//this initialization set our SADDR to 0xFFFF,
//PANID to the default PANID
//HalInit, evbInit will have to be called by the user
numTimeouts = 0;
my_timer = 0;
first_packet = TRUE;
halInit();
evbInit();
initLcd();
LCD_clear();
//showLogo();
lcdUpdate((char *)"Albert",(char *)"");
aplInit(); //init the stack
ENABLE_GLOBAL_INTERRUPT();
/*char *menuText[] = {(char *)" Sender?", (char *)" Receiver?", (char *)" Set Freq?", (char *)"
Set MyAddr?", (char *)" SetRemoteAddr"};
while (TRUE)
{
JOYSTICK_DIRECTION jsv;
ENABLE_GLOBAL_INTERRUPT();
jsv = getJoystickDirection();
if(updateLcd){
lcdUpdate(menuText[line1], menuText[line1 + 1]);
if(line1 > 0)
lcdUpdateChar(LINE1, 15, ARROW_UP);
if(line1 + 1 < 5 - 1)
lcdUpdateChar(LINE2, 15, ARROW_DOWN);
if(active == line1){
lcdUpdateChar(LINE1,0,ARROW_RIGHT);
}
else{
lcdUpdateChar(LINE2,0,ARROW_RIGHT);
}
while((jsv = getJoystickDirection()) != CENTRED);
updateLcd = FALSE;
}
switch (jsv)
{
case UP:
lcdUpdate((char *)"123",(char *)"");
if(active > 0){
active--;
if (line1 != 0){
line1--;
}
updateLcd = TRUE;
}
break;
case DOWN:
lcdUpdate((char *)"456",(char *)"");
if(active < 5-1){
active++;
if (line1 < 5-2){
line1++;
}
updateLcd = TRUE;
}
break;
case LEFT:
lcdUpdate((char *)"789",(char *)"");
while(getJoystickDirection() != CENTRED);
break;
case RIGHT:
lcdUpdate((char *)"012",(char *)"");
x = active;
goto pt;
//while(getJoystickDirection() != CENTRED);
default:
break;
}
waitVisible(CLEARLY_VISIBLE);
}
pt:while(1){
if(x == 0){
lcdUpdate((char *)"Sender?",(char *)"");
goto pt1;
}
else if(x == 1){
lcdUpdate((char *)"Receiver?",(char *)"");
}
else if(x == 2){
lcdUpdate((char *)"Set Freq?",(char *)"");
}
else if(x == 3)
{
lcdUpdate((char *)"Set MyAddr?",(char *)"");
}
else {
lcdUpdate((char *)"SetRemoteAddr",(char *)"");
}
}
pt1:conPrintConfig();*/
//ENABLE_GLOBAL_INTERRUPT(); //enable interrupts
EVB_LED1_OFF();
EVB_LED2_OFF();
ping_cnt = 0;
rxFlag = 0;
//debug_level = 10;
#ifdef LRWPAN_COORDINATOR
aplFormNetwork();
while(apsBusy()) {apsFSM();} //wait for finish
conPrintROMString("Network formed, waiting for RX\n");
lcdUpdate((char *)"Network formed",(char *)"waiting for RX");
EVB_LED1_ON();
#else
do {
aplJoinNetwork();
while(apsBusy()) {apsFSM();} //wait for finish
if (aplGetStatus() == LRWPAN_STATUS_SUCCESS) {
EVB_LED1_ON();
LCD_clear();
#ifdef LRWPAN_ROUTER
//Print6(0,5,"--ZIGBEE_ROUTER-- ",1);
#endif
#ifdef LRWPAN_RFD
lcdUpdate((char *)"--ZIGBEE_RFD--",(char *)"Join succeeded!");
#endif
/*conPrintROMString("Network Join succeeded!\n");
lcdUpdate((char *)"Network Join succe",(char *)"");
lcdUpdate((char *)"",(char *)"eded!");
conPrintROMString("My ShortAddress is: ");
conPrintUINT16(aplGetMyShortAddress());
lcdUpdate((char *)"My SADDR:",(char *)"");
LcdPrintUINT16(aplGetMyShortAddress(),3,63);
conPCRLF();
conPrintROMString("Parent LADDR: ")
conPrintLADDR(aplGetParentLongAddress());
lcdUpdate((char *)"Parent LADDR:",(char *)"");
LcdPrintLADDR(aplGetParentLongAddress(),4,87);
conPrintROMString(", Parent SADDR: ");
conPrintUINT16(aplGetParentShortAddress());
conPCRLF();*/
break;
}else {
conPrintROMString("Network Join FAILED! Waiting, then Ttrying again\n");
LCD_clear();
#ifdef LRWPAN_ROUTER
//Print6(0,5,"--ZIGBEE_ROUTER-- ",1);
#endif
#ifdef LRWPAN_RFD
lcdUpdate((char *)"--ZIGBEE_RFD--",(char *)"");
#endif
halWait(100);
lcdUpdate((char *)"NetworkJoinFAILE",(char *)"Trying again");
my_timer= halGetMACTimer();
//wait for 2 seconds
while ((halMACTimerNowDelta(my_timer))< MSECS_TO_MACTICKS(2*1000));
}
} while(1);
#endif
#ifdef LRWPAN_RFD
//now send packets
dstADDR.saddr = 0; //RFD sends to the coordinator
ppState = PP_STATE_SEND;
conPrintROMString("Hit UP or DOWN switch to start!\n");
aplSetMacMaxFrameRetries(0);
lcdUpdate((char *)"Zigbee_Rfd",(char *)"be Sending");
while(1){SendData();}
#endif
#ifdef LRWPAN_COORDINATOR
aplSetMacMaxFrameRetries(0);
lcdUpdate((char *)"Zigbee_Coo",(char *)"be Receiving");
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();}
#endif
}
剩余54页未读,继续阅读
资源评论
Albertwpy
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功