예제 #1
0
void zclHomelink_zigbeeReset(void)
{
  uint16 clusters[2];
  zAddrType_t tempAddr = {{0}, (afAddrMode_t)AddrGroup};
  aps_Group_t tempGroup = {0, "SwitchX"};
  int i;
  
  for (i = HAL_NV_PAGE_BEG; i <= (HAL_NV_PAGE_BEG + HAL_NV_PAGE_CNT); i++)
  {
    HalFlashErase(i);
  }
  
  clusters[0] = ZCL_CLUSTER_ID_GEN_ON_OFF;
  clusters[1] = ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL;
  
  BindSetDefaultNV();
  aps_GroupsSetDefaultNV();
  
  // Initialize default groups.  Each button has a group ID built from the MAC.
  // The top 2 bits are for the endpoints.
  for(i = 0; i < NUM_BUTTONS; i ++) {
    tempGroup.ID =  i << 14 | (aExtendedAddress[1] & 0x3F) << 8 | aExtendedAddress[0];
    tempGroup.name[6] = '1' + i;
    tempAddr.addr.shortAddr = tempGroup.ID;
    bindAddEntry(ENDPOINT+i, &tempAddr, 0, 2, clusters);
    aps_AddGroup(ENDPOINT+i, &tempGroup);
  }
  BindWriteNV();
  aps_GroupsWriteNV();

  Onboard_soft_reset();
}
예제 #2
0
/***************************************************************************************************
 * @fn      MT_UtilBindAddEntry
 *
 * @brief   Add Binding Entry into Local Table.
 *
 * @param   pBuf - pointer to the received buffer
 *
 * @return  void
 ***************************************************************************************************/
static void MT_UtilBindAddEntry(uint8 *pBuf)
{
  uint8 srcEp;
  zAddrType_t dstAddr;
  uint8 dstEp;
  uint8 numClusterIds;
  uint16 *clusterIds;
  uint8 buf[sizeof(BindingEntry_t)];
  uint8 cmdId = pBuf[MT_RPC_POS_CMD1];
  pBuf += MT_RPC_FRAME_HDR_SZ;

  // Initialize the return buffer
  osal_memset( buf, 0xFF, sizeof(BindingEntry_t) );
  buf[2] = 0xFE;    // set the default value of INVALID_NODE_ADDR
  buf[3] = 0xFF;    // set the default value of INVALID_NODE_ADDR

  srcEp = *pBuf++;

  // Destination Address mode
  dstAddr.addrMode = *pBuf++;

  // Destination Address
  if ( dstAddr.addrMode == Addr64Bit )
  {
    uint8 *ptr; // Use this additional pointer because *pBuf is incremented later for both cases

    ptr = pBuf;
    osal_cpyExtAddr( dstAddr.addr.extAddr, ptr );
  }
  else
  {
    dstAddr.addr.shortAddr = BUILD_UINT16( pBuf[0], pBuf[1] );
  }
  // The short address occupies LSB two bytes
  pBuf += Z_EXTADDR_LEN;

  // DstEPInt
  dstEp = *pBuf++;

  numClusterIds = *pBuf++;

  if ( numClusterIds > 0 )
  {
    // copy list of clusters
    clusterIds = (uint16 *)osal_mem_alloc( numClusterIds * sizeof(uint16) );
    osal_memcpy( clusterIds, pBuf, numClusterIds * sizeof(uint16));

    if ( clusterIds != NULL )
    {
      // The response to MT interface has to be pack into buf
      packBindEntry_t( buf, bindAddEntry( srcEp, &dstAddr, dstEp, numClusterIds, clusterIds ));

      osal_mem_free( clusterIds );
    }
  }

  MT_BuildAndSendZToolResponse( ( (uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL ),
                                cmdId, sizeof(BindingEntry_t), buf );
}
예제 #3
0
/*********************************************************************
 * @fn      zcl_EZModeAction
 *
 * @brief   Called when the application needs to inform EZ-Mode of some action
 *          (now on the network, identify mode query, etc...)
 *
 * @param   action - which action has taken place
 *          pData  - the data unique to the action
 *
 * @return  none
 */
void zcl_EZModeAction(zclEzMode_Action_t action, zclEZMode_ActionData_t *pData)
{
  ZDO_MatchDescRsp_t *pMatchDescRsp;
  zAddrType_t dstAddr;

  // not in the EZ-Mode state machine, so do nothing
  if( zclEZModeState == EZMODE_STATE_READY )
    return;

  switch ( action )
  {
    case EZMODE_ACTION_PROCESS:
      zcl_ProcessEZMode();  // process next state
    break;

    case EZMODE_ACTION_NETWORK_STARTED:
      // once on the network, time to go on to the identify state
      if( zclEZModeState == EZMODE_STATE_JOINER )
      {
        // set local permit joining on locally only for joiners (openers turn it on across the network)
        NLME_PermitJoiningRequest( (byte)(EZMODE_TIME / 1000) ); // in seconds
        zcl_SetEZModeState( EZMODE_STATE_IDENTIFYING );
      }
    break;

    // received identify query
    case EZMODE_ACTION_IDENTIFY_QUERY:

      // targets just go to autoclose once they have been identified
      if ( !zclEZModeInvokeData.initiator )
      {
        zcl_SetEZModeState( EZMODE_STATE_AUTOCLOSE );
      }
    break;

    // received identify query response
    case EZMODE_ACTION_IDENTIFY_QUERY_RSP:

      // remember the node we found via identify query
      zclEZModeQueryRspNwkAddr = pData->pIdentifyQueryRsp->srcAddr->addr.shortAddr;
      zclEZModeQueryRspEP = pData->pIdentifyQueryRsp->srcAddr->endPoint;

      // initiate match descriptor request on the remote node
      dstAddr.addrMode = Addr16Bit;
      dstAddr.addr.shortAddr = zclEZModeQueryRspNwkAddr;
      ZDP_MatchDescReq( &dstAddr, zclEZModeQueryRspNwkAddr,
                        ZCL_HA_PROFILE_ID,
                        zclEZModeInvokeData.numActiveOutClusters, zclEZModeInvokeData.pActiveOutClusterIDs,
                        zclEZModeInvokeData.numActiveInClusters, zclEZModeInvokeData.pActiveInClusterIDs,
                        FALSE );
      zcl_SetEZModeState( EZMODE_STATE_WAITING_MATCHDESCRSP );
    break;

    // received match descriptor response, see if active clusters match
    case EZMODE_ACTION_MATCH_DESC_RSP:

      pMatchDescRsp = pData->pMatchDescRsp;
      if ( ( pMatchDescRsp && pMatchDescRsp->status == ZSuccess ) && ( pMatchDescRsp->cnt>0 ) )
      {
        zclEZModeMatched = TRUE;

        // BindingEntry_t *bindAddEntry( byte srcEpInt, zAddrType_t *dstAddr, byte dstEpInt, byte numClusterIds, uint16 *clusterIds )
        dstAddr.addr.shortAddr = zclEZModeQueryRspNwkAddr;
        dstAddr.addrMode = Addr16Bit;

        // bind each matching input cluster
        if ( zclEZModeInvokeData.numActiveInClusters )
        {
          bindAddEntry( zclEZModeInvokeData.endpoint, &dstAddr, zclEZModeQueryRspEP,
                        zclEZModeInvokeData.numActiveInClusters, zclEZModeInvokeData.pActiveInClusterIDs );
        }

        // bind each matching output cluster
        if ( zclEZModeInvokeData.numActiveOutClusters )
        {
          bindAddEntry( zclEZModeInvokeData.endpoint, &dstAddr, zclEZModeQueryRspEP,
                        zclEZModeInvokeData.numActiveOutClusters, zclEZModeInvokeData.pActiveOutClusterIDs );
        }
      }

      // time to close (wait a bit before finishing, to allow for multiple initiators)
      zcl_SetEZModeState( EZMODE_STATE_AUTOCLOSE );
    break;

    // timed out of EZ-Mode
    case EZMODE_ACTION_TIMED_OUT:
      // timed out
      if(zclEZModeState != EZMODE_STATE_READY)
      {
        zcl_SetEZModeError( EZMODE_ERR_TIMEDOUT );
        zcl_SetEZModeState( EZMODE_STATE_FINISH );
      }
    break;
  }   // switch ( action )

}