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

📄 协调器app文件.c

📁 包含两个终端设备、一个协调器设备和一个简单的上位机程序。 在freescake的codewarrior下编程
💻 C
📖 第 1 页 / 共 3 页
字号:

/* Initialize the application. */
void BeeAppInit(void) 
{
  index_t i;

  /* Register the application endpoint(s), so we receive callbacks. */
  for (i = 0; i < gNum_EndPoints_c; ++i) 
  {
    (void) AF_RegisterEndPoint(endPointList[i].pEndpointDesc);
  }

  /* Start with all LEDs off */
  ASL_InitUserInterface("Wireless UART");
 // SetOneLed(LED1, (mInCharMode ? gLedOn_c : gLedOff_c));
  //SetOneLed(LED2, (mInLoopBackMode ? gLedOn_c : gLedOff_c));

  mBaudRateDisplayTimerID = TMR_AllocateTimer();
  mUartRxTimerID = TMR_AllocateTimer();
  mTxZigBeeDataRetryTimerID = TMR_AllocateTimer();
  mTxZigBeeThrottleTimerID = TMR_AllocateTimer();
  heartbeatTimerID = TMR_AllocateTimer();

  gSendingNwkData.gAddressMode = gZbAddrModeIndirect_c;
 // gSendingNwkData.gAddressMode = gZbAddrMode16Bit_c;
//gSendingNwkData.gAddressMode = gZbAddrModeGroup_c ;
  /* Only one endpoint is needed for this application. */
  appEndPoint = endPointList[0].pEndpointDesc->pSimpleDesc->endPoint;

  UartX_SetRxCallBack(UartRxCallBack);

              
        
        ASL_UpdateDevice(appEndPoint,gStartNetwork_c);

      
       ZDO_Start(gStartWithOutNvm_c);
      TMR_StartIntervalTimer(heartbeatTimerID,500,heartbeatTimerCallBack);
        
       
  
}                                       /* BeeAppInit() */

/****************************************************************************/

/* Handles all key events for this device. The UI has two modes:
 *  config-mode, for setting up the network, joining, forming, etc., and
 *  run-mode, for controlling the application.
 */
void BeeAppHandleKeys(key_event_t events) 
{
                                    /* switch (events) */
}                                       /* BeeAppHandleKeys() */

/****************************************************************************/

/* Application task. Responds to events for the application. */
void BeeAppTask(event_t events) 
{
  
   // Copy2Bytes(nwkaddress, NlmeGetRequest(gNwkShortAddress_c));
          
  if (events & mAppRetryZigBeeAckTx_c)      { TxZigBeeAck(); }
  if (events & mAppRetryUartDataTx_c)       { TxUartData(); }
  if (events & mAppRetryZigBeeDataTx_c)     { TxZigBeeData(); }

  if (events & gAppEvtDataConfirm_c)        { ProcessConfirmData(); }

  if (events & gAppEvtDataIndication_c)     { RxZigBeeData(); }
  if (events & mAppRxFromUart_c)            { RxUartData(); }

  if (events & gAppEvtAddGroup_c)           { ASL_ZclAddGroupHandler(); }
  if (events & gAppEvtSyncReq_c)            { ASL_Nlme_Sync_req(FALSE); }


}                                       /* BeeAppTask() */

/****************************************************************************/

void BeeAppUpdateDevice(zbEndPoint_t ep, uint8_t event) 
{
  ASL_UpdateDevice(ep, event);
}                                       /* BeeAppUpdateDevice() */



  static void DisplayLedInteger(index_t value) {
  mIsIntegerDisplayedOnLEDs = TRUE;
  SetAllLeds(value);
  TMR_StartSingleShotTimer(mBaudRateDisplayTimerID,
                           mBaudRateDisplayDuration_c,
                           RestoreLedShadowState);
}                                       /* DisplayLedInteger() */

/****************************************************************************/

/* Transmit all buffers that are marked as in progress. */
static void FlushAllBuffers(void)
{
  if (uartTxDataBuffer.status == mBufStatusInProgress_c) {
    uartTxDataBuffer.status = mBufStatusReadyToSend_c;
  }
  TxUartData();

  if (zbTxAckBuffer.status == mBufStatusInProgress_c) {
    zbTxAckBuffer.status = mBufStatusReadyToSend_c;
    }
  TxZigBeeAck();

  if (zbTxDataBuffer.status == mBufStatusInProgress_c) {
    zbTxDataBuffer.status = mBufStatusReadyToSend_c;
  }
  TxZigBeeData();
}                                       /* FlushAllBuffers() */

/****************************************************************************/

/* Process incoming ZigBee over-the-air data confirms. */
/* The Wireless UART uses application-level ACKs and NAKs, not APS confirms. */
/* Any APS confirm that reaches this routine is not ours. */
static void ProcessConfirmData(void) {
  apsdeToAfMessage_t *pMsg;
  zbApsdeDataConfirm_t *pConfirm;

  while (MSG_Pending(&gAppDataConfirmQueue)) {

    pMsg = MSG_DeQueue(&gAppDataConfirmQueue);
    pConfirm = &(pMsg->msgData.dataConfirm);

    /* Action taken when confirmation is received. */
    if (pConfirm->status == gSuccess_c) {
      BeeAppUpdateDevice(appEndPoint, gToggleEvent_c);
    }

    /* Free memory allocated in Call Back function */
    MSG_Free(pMsg);
  }
}                                       /* ProcessConfirmData() */

/****************************************************************************/

/* Revert the LEDs to displaying their normal (shadow) state. */
static void RestoreLedShadowState(tmrTimerID_t timerID) {
  index_t i;

  (void) timerID;

  for (i = 0; i < NumberOfElements(maLedShadowStateTable); ++i) {
    ASL_SetLed(maLedShadowStateTable[i].number, maLedShadowStateTable[i].state);
  }

  mIsIntegerDisplayedOnLEDs = FALSE;
}                                       /* RestoreLedShadowState() */

/****************************************************************************/

/* Handle bytes arriving from the UART driver. */
static void RxUartData(void) {
  unsigned char byte;

  
}                                       /* RxUartData() */

/****************************************************************************/

/* Process incoming ZigBee over-the-air messages. */
/* Datagrams arrive here with cluster id == mDataClusterId_c. */
/* ACKs/NAKs from the remote node also arrive here, with cluster id == */
/* mAckClusterId_c. */
static void RxZigBeeData(void)
{
  ackDatagram_t *pAckDatagram;
  datagram_t *pDatagram;
  zbApsdeDataIndication_t *pIndication;
  apsdeToAfMessage_t *pMsg;
  bool_t messageAccepted;
  sequenceNumber_t sequenceNumber;
  uint8_t temp[8]={0,0,0,0,0,0,0,0};
   LED5TOGGLE;
   LED3TOGGLE;
  while (MSG_Pending(&gAppDataIndicationQueue)) {
    pMsg = MSG_DeQueue(&gAppDataIndicationQueue);
    //  SendZigBeeDataToUart(pMsg);
    pIndication = &(pMsg->msgData.dataIndication);

    if (   (pIndication->aClusterId[0] == (mDataClusterId_c & 0xFF))
        && (pIndication->aClusterId[1] == (mDataClusterId_c >> 8)))
 {

     
      
      FLib_MemCpy(temp,
              pIndication->pAsdu + sizeof(sequenceNumber_t),
              8);
              
    
    if((temp[0]==0xaa)&&(temp[7]==0xff)&&((temp[1]==0xac)||(temp[1]==0xbc))) 
    {
      nwkaddress[0]=temp[2];
      nwkaddress[1]=temp[3];
       //Copy2Bytes(afAddrInfo.dstAddr.aNwkAddr, nwkaddress);
       switch(temp[1]) 
      {
       
        case 0xac: Copy2Bytes(bindfornwk[0], nwkaddress);  break;
        case 0xbc: Copy2Bytes(bindfornwk[1], nwkaddress);  break;
      
        default:break;    
      }
      // messageAccepted = SendZigBeeDataToUart(pMsg);
      
       // SendZigBeeDataToUart(pMsg);
       //  LED5TOGGLE;
       zbTxDataBuffer.status = mBufStatusInProgress_c;
       zbTxDataBuffer.data.structured.payload[0]= 0xaa;
       if(temp[1]==0xac)
       zbTxDataBuffer.data.structured.payload[1]=0xad;
       if(temp[1]==0xbc)
       zbTxDataBuffer.data.structured.payload[1]=0xad;
       zbTxDataBuffer.data.structured.payload[2]=temp[2];
       zbTxDataBuffer.data.structured.payload[3]=temp[3];
       zbTxDataBuffer.data.structured.payload[4]=0xff;
       zbTxDataBuffer.data.structured.payload[5]=0xff;
       zbTxDataBuffer.data.structured.payload[6]=0xff;
       zbTxDataBuffer.data.structured.payload[7]=0xff;
       zbTxDataBuffer.status = mBufStatusReadyToSend_c;
       zbTxDataBuffer.data.structured.sequenceNumber = curZbTxSequenceNumber++;
       zbTxDataBuffer.len=9;
       TxZigBeeData();
       
      AF_FreeDataIndicationMsg(pMsg);
      return;
      
    }
    if((temp[0]==0xaa)&&(temp[7]==0xff)&&((temp[1]==0xfa)||(temp[1]==0xfb))) 
    {      
       pDatagram = (datagram_t *) pIndication->pAsdu;
       sequenceNumber = pDatagram->structured.sequenceNumber;
    // if((pIndication->asduLength==8)&&(temp[0]==0xaa))
      messageAccepted = SendZigBeeDataToUart(pMsg);
     // LED3TOGGLE;
         AF_FreeDataIndicationMsg(pMsg);
      return;
    }
  }
    else if (   (pIndication->aClusterId[0] == (mAckClusterId_c & 0xFF))
               && (pIndication->aClusterId[1] == (mAckClusterId_c >> 8))) 
    {


      /* Received an ACK or NAK from the remote node. Ignore it if we're not */
      /* in reliable mode. */
      if (mInReliableMode)
      	{
        /* The remote node responded, so we don't need a no-response timer. */
        TMR_StopTimer(mTxZigBeeDataRetryTimerID);

        /* If it was an ACK, mark the buffer as available. If it was a NAK, */
        /* send it again. */
        pAckDatagram = (ackDatagram_t *) pIndication->pAsdu;
        if (pAckDatagram->structured.ack)
        	{
          zbTxDataBuffer.status = mBufStatusFree_c;
          zbTxDataBuffer.len = 0;
             } 
        else 
       {
          zbTxDataBuffer.status = mBufStatusReadyToSend_c;
          TxZigBeeData();
        }                               /* if (pAckDatagram-> ... else */

        /* Free the indication message. */
       AF_FreeDataIndicationMsg(pMsg);
      }                                 /* if (mInReliableMode) */
    }
     else 
     {                            /* if (IsEqual2BytesInt( ... */
      /* Free the indication message. */
      AF_FreeDataIndicationMsg(pMsg);
     }
  }                                     /* while (MSG_Pending( ... */
}                                       /* RxZigBeeData() */



//////////////////////////////////////////////

  static bool_t SendZigBeeDataToZigBee(apsdeToAfMessage_t *pMsg) 
  { 
 
 }    



/****************************************************************************/

/* Send data received from the UART back out via the UART (loop back). */
/* Note that UART buffers don't need or want sequence numbers. */
/* Return TRUE if successful. */
static bool_t SendUartDataToUart(unsigned char byte) {
  
}                                       /* SendUartDataToUart() */

/****************************************************************************/

/* Send data received from the UART out OTA. */
/* Return TRUE if successful. */
static bool_t SendUartDataToZigBee(unsigned char byte) {
   
  
}                                       /* SendUartDataToZigBee() */

/****************************************************************************/

/* Send data received OTA out through the UART. */

⌨️ 快捷键说明

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