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

📄 apus_router.c

📁 TI 公司的Z-STACK 应用层开发程序
💻 C
📖 第 1 页 / 共 2 页
字号:
          dstEP = ZDO_NewDstAddr->dstAddrDstEP;
          dstAddr = &ZDO_NewDstAddr->dstAddr;
          Apus_DstAddr.addrMode = (afAddrMode_t)dstAddr->addrMode;
          Apus_DstAddr.endPoint = dstEP;

          Apus_DstAddr.addr.shortAddr = dstAddr->addr.shortAddr;
          break;

        case ZDO_STATE_CHANGE:
          Apus_NwkState = (devStates_t)(MSGpkt->hdr.status);
 /*
          if ( (Apus_NwkState == DEV_ZB_COORD)
              || (Apus_NwkState == DEV_ROUTER)
              || (Apus_NwkState == DEV_END_DEVICE) )
         */

          if ((Apus_NwkState == DEV_NWK_DISC)||(Apus_NwkState == DEV_ROUTER)||(DEV_NWK_JOINING))
          {  ZDApp_AutoFindDestination( APUS_ENDPOINT_OUT);

            // Start sending "the" message in a regular interval.
            osal_start_timer( APUS_SEND_SELECTEDDATA_EVT,  APUS_SEND_MSG_TIMEOUT );
          }

          break;

        default:
          break;
      }

      // Release the memory
      osal_msg_deallocate( (uint8 *)MSGpkt );

      // Next
      MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( Apus_TaskID );
    }

    // return unprocessed events
    return (events ^ SYS_EVENT_MSG);
  }

  // Send a message out - This event is generated by a timer
  //  (setup in Apus_Init()).
  if ( events & APUS_SEND_SELECTEDDATA_EVT)
  {


    // Send "the" message
    Apus_SendTheMessage();

    // Setup to send message again
    osal_start_timer( APUS_SEND_SELECTEDDATA_EVT,
                      APUS_SEND_MSG_TIMEOUT );

    // return unprocessed events
    return (events ^ APUS_SEND_SELECTEDDATA_EVT);
  }

  // Discard unknown events
  return 0;
}

/*********************************************************************
 * Event Generation Functions
 */
/*********************************************************************
 * @fn      Apus_HandleKeys
 *
 * @brief   Handles all key events for this device.
 *
 * @param   shift - true if in shift/alt.
 * @param   keys - bit field for key events. Valid entries:
 *                 HAL_KEY_SW_4
 *                 HAL_KEY_SW_3
 *                 HAL_KEY_SW_2
 *                 HAL_KEY_SW_1
 *
 * @return  none
 */
void Apus_HandleKeys( byte shift, byte keys )
{
  // Shift is used to make each button/switch dual purpose.
  if ( shift )
  {
    if ( keys & HAL_KEY_SW_1 )
    {
    }
    if ( keys & HAL_KEY_SW_2 )
    {
    }
    if ( keys & HAL_KEY_SW_3 )
    {
    }
    if ( keys & HAL_KEY_SW_4 )
    {
    }
  }
  else
  {
    if ( keys & HAL_KEY_SW_1 )
    {
      osal_set_event(Apus_TaskID,APUS_DISP_VAL_EVT);
    }

    if ( keys & HAL_KEY_SW_2 )
    {
      // Initiate an End Device Bind Request for the mandatory endpoint
      ZDApp_SendEndDeviceBindReq( APUS_ENDPOINT_OUT);
    }

    if ( keys & HAL_KEY_SW_3 )
    {
    }

    if ( keys & HAL_KEY_SW_4 )
    {
      // Initiate a Match Description Request (Service Discovery)
      //  for the mandatory endpoint
      ZDApp_AutoFindDestination( APUS_ENDPOINT_OUT );
    }
  }
}

/*********************************************************************
 * LOCAL FUNCTIONS
 */

/*********************************************************************
 * @fn      Apus_MessageMSGCB
 *
 * @brief   Data message processor callback.  This function processes
 *          any incoming data - probably from other devices.  So, based
 *          on cluster ID, perform the intended action.
 *
 * @param   none
 *
 * @return  none
 */
char displayBuf[10];
char displayBuf1[5];
void Apus_MessageMSGCB( afIncomingMSGPacket_t *pkt )
{

  uint16 shortAddr;
  char ch;
  char i;
  volatile uint16 temp,temp1;


  displayBuf[0] = 'N';
  displayBuf[1] = 'o';
  displayBuf[2] = 'd';
  displayBuf[3] = 'e';
  displayBuf[4] = ':';

  switch ( pkt->clusterId )
  {
    case APUS_CLUSTERID:
      shortAddr = pkt->srcAddr.addr.shortAddr;

      for (i=0; i<4; i++)
      {
        ch = (char ) (shortAddr >> (4* (3-i))) & 0x0f;

        displayBuf[5+i] = ch + (( ch < 10 ) ? '0' : '7');
      }

     displayBuf [9] = '\0';

      temp = BUILD_UINT16(pkt->cmd.Data[1], pkt->cmd.Data[0] );
      temp1=temp;
      displayBuf1[0]= ' ';
      displayBuf1[1]= temp/100 +'0';
      displayBuf1[2]= (temp % 100)/10+'0';
      temp%= 10;
      displayBuf1[3] = temp +'0';
      displayBuf1[4]='\0';

      if(temp1>temp2)
     {    // "the" message
        temp2=temp1;
     #if defined( LCD_SUPPORTED )
           HalLcdWriteScreen(displayBuf,displayBuf1);
     #elif defined( WIN32 )
           WPRINTSTR( pkt->cmd.Data );
     #endif
     }
      break;
  }
}

/*********************************************************************
 * @fn      Apus_SendTheMessage
 *
 * @brief   Send "the" message.
 *
 * @param   none
 *
 * @return  none
 */
void Apus_SendTheMessage( void )
{
  if ( AF_DataRequest( &Apus_DstAddr, (endPointDesc_t *)&Apus_epDescRouter,
                       APUS_CLUSTERID,
                       (byte)osal_strlen( displayBuf1 ) + 1,
                       (byte *)&displayBuf1,
                       &Apus_TransID,
                       AF_DISCV_ROUTE, AF_DEFAULT_RADIUS ) == afStatus_SUCCESS )
  {
    // Successfully requested to be sent.
  }
  else
  {
    // Error occurred in request to send.
  }
}


/******************************************************************************
*
* @fn  GetTemperature
*
* @brief
*      Return the temperature measured with the internal temperature sensor.
*
* Parameters:
*
* @param  none
*
* @return temperature
*
******************************************************************************/
/*int16 GetTemperature(void)
{
  uint16  value;

  ADCIF = 0;
  ADCCON3 = ( ADC_REF_1_25_V | ADC_14_BIT | ADC_TEMP_SENS );
  while( !ADCIF );

  value = ADCL;
  value |= (uint16) (ADCH << 8);

  return (int16) (ADC14_TO_CELSIUS(value));
}
******************************************************************************
*
* @fn  DispTemperature
*
* @brief
*       Disp the temperature
*
* Parameters:
*
* @param  void
*
* @return none
*
******************************************************************************/
/*void DispTemperature(void)
{

   temperature = GetTemperature();

  if (temperature < 0)
  {
    buf[0] = '-';
    temperature *= -1;
  }
  else
    buf[0] = ' ';


  buf[1] = temperature/100 + '0';
  if(buf[1] == '0')
    buf[1] = ' ';
  buf[2] = (temperature % 100)/10 + '0';
  buf[3] = '.';

  temperature %= 10;
  buf[4] = temperature + '0';

  buf[5] = 'C';
  buf[6] = '\0';


#if defined ( LCD_SUPPORTED )
 // HalLcdWriteString( "The Present", HAL_LCD_LINE_1 );
 // HalLcdWriteString( (char*)buf, HAL_LCD_LINE_2 );
#endif

}

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

⌨️ 快捷键说明

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