⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rfd.c

📁 这是在Microchip公司提供的源代码的Zigbee协议栈的下开发的三点网络应用程序。
💻 C
📖 第 1 页 / 共 2 页
字号:
      }    }    if (last_channel != current_channel) {      //trying a different channel, restart timer      startTime = TickGet();      last_channel = current_channel;    }  }//end while(1)  if (errcode != ZCODE_NO_ERROR) {    // Disable watchdog before returning.    DISABLE_WDT();  }  return(errcode);}//******************************************************************************// Binding Task//******************************************************************************// this endpoint binding does NOT SLEEP.BOOL BindingTask( void ){    static SM_BIND smBind = SM_BIND_INIT;    APLSetEP( ZDOEndpointHandle );    switch (smBind)    {        case SM_BIND_INIT:            SendEndDeviceBindReq();#ifndef MY_RX_IS_ALWAYS_ON_OR_SYNCED_WITH_BEACON	    while( !APLIsPutReady() )	      {		APLTask();		KeepRxAlive();  	      }	    APLRequestMessages();#endif            //smBind = SM_BIND_SLEEP;	    smBind = SM_BIND_CHECK_RESPONSE;            break;        case SM_BIND_CHECK_RESPONSE:            if (endDeviceBindInfo.flags.bits.bResponseReceived)            {                if (endDeviceBindInfo.flags.bits.bBindSuccessful)                {		  D1 = 0; //turn off to indicate successful bind		  if( appFlags.bits.bIsNotBound ) {		    ConsolePutROMString((ROM char *) "Unbind Successful!\n\r");		  }else {		    ConsolePutROMString((ROM char *) "Bind Successful!\n\r");		  }		  smBind = SM_BIND_INIT;		  return TRUE;                }                else                {                    ConsolePutROMString((ROM char *)  "End Device Bind/Unbind unsuccessful.\r\n" );                    smBind = SM_BIND_INIT;                    return TRUE;                }            }            else if (TickGetDiff(TickGet(), endDeviceBindInfo.requestStart) >= BIND_WAIT_DURATION)            {                ConsolePutROMString((ROM char *) "No one is answering our bind request\r\n" );                smBind = SM_BIND_INIT;                return TRUE;            }	    //in this demo, assume nodes do not sleep            // See if we've waited long enough for messages, and can            // go back to sleep.#ifndef MY_RX_IS_ALWAYS_ON_OR_SYNCED_WITH_BEACON            else if (APLMessageRequestDone() )            {	      APLRequestMessages();  //request again            }#endif            break;#if 0        case SM_BIND_SLEEP:            if ( APLIsIdle() )            {                DEBUG_OUT("Going to sleep during bind...\r\n");                // Disable the stack.                APLDisable();                SLEEP();                NOP();                DEBUG_OUT("Just woke-up from sleep...\r\n");                GIEL = 1;                // Reenable the stack.                APLEnable();                // Ask for messages, since the coordinator knows we are                // usually asleep.                if ( APLIsPutReady() )                {                    APLRequestMessages();                    messageRequestTime = TickGet();                }                smBind = SM_BIND_CHECK_RESPONSE;            }            break;#endif    }    return FALSE;}/********************************************************************* * Function:        static void SendEndDeviceBindReq( void ) * * PreCondition:    Node is associated with a coordinator * * Input:           None * * Output:          None * * Side Effects:    None * * Overview:        Sends an end device bind request message to the *                  coordinator's ZDO.  If implemented, the coordinator *                  will bind us to a complementary device. * * Note:            None ********************************************************************/// WARNING! THIS DEPENDS ON NUMBER OF CLUSTERS YOU ARE SENDING!!#define BIND_INFO_SIZE  9               static void SendEndDeviceBindReq( void ){    BYTE        dataBuffer[BIND_INFO_SIZE];    BYTE        *dataPtr;    TRANS_ID    transID;    // Make sure we are able to transmit messages. If not, we will block    // until it is ready.    while( !APLIsPutReady() )    {        APLTask();        KeepRxAlive();      }    // Initialize the End Device Bind flags bResponseReceived and    // bBindSuccessful to FALSE.    endDeviceBindInfo.flags.Val = 0;    APLSetEP( ZDOEndpointHandle );    dataPtr = dataBuffer;    // Load the coordinator short address.  Right now, this is always 0.    *dataPtr++ = 0;      *dataPtr++ = 0;      // Load our End Point number.    *dataPtr++ = EP_RFD;      // Load the Profile ID.    *dataPtr++ = (MY_PROFILE_ID) & 0x00FF;    *dataPtr++ = (MY_PROFILE_ID >> 8) & 0x00FF;    // Load the number of input clusters we're going to pass    *dataPtr++ = 1;     // Load the input clusters.    *dataPtr++ = MSSTATE_COORDOUT_CLUSTER_ID;    // Load the number of output clusters we're going to pass    *dataPtr++ = 1;     // Load the output clusters.    *dataPtr++ = MSSTATE_RFDOUT_CLUSTER_ID;    // Since we have no output clusters, load nothing.    //    APLSendMSGDirect( transID, MY_PROFILE_ID, END_DEVICE_BIND_REQ, EP_ZDO,    //            macCoordInfo.shortAddr, EP_ZDO, BIND_INFO_SIZE, dataBuffer,    //            GENERATE_TRANS_ID,DEFAULT_RADIUS,ROUTE_DISCOVERY_SUPPRESS );    APLSendMSGDirect( transID, MY_PROFILE_ID, END_DEVICE_BIND_REQ, EP_ZDO,            macCoordInfo.shortAddr, EP_ZDO, BIND_INFO_SIZE, dataBuffer,            GENERATE_TRANS_ID,DEFAULT_RADIUS,ROUTE_DISCOVERY_ENABLE );    if (transID == TRANS_ID_INVALID)    {        // The message was not send successfully.  Set the flags so we will        // fall through the state machine quickly.        endDeviceBindInfo.requestStart = TickGet();        endDeviceBindInfo.flags.bits.bResponseReceived = 1;    }    else    {        // Set our initial time so we can check for timeout.        endDeviceBindInfo.requestStart = TickGet();        // Make sure the message gets MAC-level acknowledged or timeout before continuing.        while(1)        {            CLRWDT();            APLTask();	    KeepRxAlive();              APLSetEP( ZDOEndpointHandle );            if ( APLIsConfirmed() )            {                // We received a MAC-level ACK, so we should get a response.                APLRemoveFrame();                break;            }            else if ( APLIsTimedOut() )            {                // We did not receive a MAC-level ACK, so don't expect a response.                // Set the flags so we'll drop through the state machine.                endDeviceBindInfo.flags.bits.bResponseReceived = 1;                APLRemoveFrame();                break;            }        }    }}// Callback to an end device.// Called when a suitable coordinator is found as part of associate process.// Return TRUE if okay to associate.// May use PANDesc.for more information about this coordinator.// See MAC.h for definition of PANDesc.BOOL AppOkayToAssociate(void){    return TRUE;}// Callback to process the End Device Bind responsevoid AppProcess_END_DEVICE_BIND_RSP( BOOL statusIsValid, BYTE status ){    endDeviceBindInfo.flags.bits.bResponseReceived = 1;    if (!statusIsValid)        status = APLGet();    if (status == SUCCESS)    {       endDeviceBindInfo.flags.bits.bBindSuccessful = 1;    }}ROM char * const channel_fmt     = "In channel: %d\r\n" ;ROM char * const reject_channel_fmt     = "Rejecting channel: %d\r\n" ;BOOL AppOkayToUseChannel(BYTE channel){    // This demo uses all available channels    // You may check given channel against your allowable channels and return TRUE    // or FALSE as needed.    // For 2.4GHz, channel = 11 through 26.  // see if its ok to use this channel  // Channel map is used by MSU_ConfigTask to try different channels  current_channel = channel;  if ( channel_map & (((int)1) << (channel - 11))) {    sprintf(tmpbuf,channel_fmt,channel);    ConsolePutString((BYTE *)tmpbuf);    return TRUE;  } else {    sprintf(tmpbuf,reject_channel_fmt,channel);    ConsolePutString((BYTE *)tmpbuf);    return FALSE;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -