返回该小组首页 回复主题
jjh5600

jjh5600

小组等级:     E币:684  (E币换礼)

#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不发送信号
谁能帮忙看一下到底出了什么问题啊/?

emot

   小组等级:    E币:1152  (E币换礼)

#2

文章发表于:2008-08-05 11:55

04版没用过。

从RFD向COORD发数时,dstADDR.saddr赋的是0x0000吗?

如果是的话,那么COORD向RFD时就是写目的RFD的网络地址了。

jjh5600

   小组等级:    E币:684  (E币换礼)

#3

文章发表于:2008-08-05 14:44

那么COORD向RFD时就是写目的RFD的网络地址了
不明白什么意思.... coord向rfd时 dstADDR.saddr=0 应该是0x0000
如果只有一个rfd的话 加入网络 串口输出:my saddr:0x1699 这样的话coord向rfd时是不是dstADDR.saddr=0x1699呢?  我这样写了以后 加入网络coord不发送信号了..
如果改成广播发送的话 要怎么设置呢?
还有,应该有一个函数可以根据物理地址来提取网络地址吧?  如果按照物理地址发送信号的话 设置APS_DSTMODE_LONG  dstADDR.saddr=0xffffffffffffffff是否可以这样赋值呢?

jjh5600

   小组等级:    E币:684  (E币换礼)

#4

文章发表于:2008-08-06 11:16

谁能帮帮忙啊

hxqhit

   小组等级:    E币:520  (E币换礼)

#5

文章发表于:2008-08-10 02:44

           目的地址为0xffff,       表示协调器广播消息给所有节点

           目的地址为0x0000,表示所有子结点向协调器发送数据

jjh5600

   小组等级:    E币:684  (E币换礼)

#6

文章发表于:2008-08-19 10:59

解决了...

hxldhz

   小组等级:    E币:179  (E币换礼)

#7

文章发表于:2008-08-22 15:01

这位兄弟可真能贴啊

总共 , 当前 /

快速回复主题--如果想加入编辑器功能,建议使用 [高级回复]

您目前还不是小组成员,请先加入

回复贴子区

用户名:    您没有注册?

密码:    忘记了密码?

内容:

  • DesignDesign
  • HTMLHTML

浏览该小组的用户还看过...

所有小组精华文章