示例#1
0
/*********************************************************************
 * @fn      oadManagerHandleNoti
 *
 * @brief   Handle Notifications and Indications.
 *
 * @return  none
 */
static void oadManagerHandleNoti(attHandleValueNoti_t *pNoti)
{
  if (pNoti->handle == oadManagerHandles[OAD_CHAR_IMG_IDENTIFY])
  {
#if (defined HAL_LCD && (HAL_LCD == TRUE))
    uint16 ver = BUILD_UINT16(pNoti->value[0], pNoti->value[1]);
    uint8 userId[12] = "UserId ";

    osal_memcpy(&(userId[7]), &(pNoti->value[4]), 4);
    userId[11] = '\0';

    if ( OAD_IMG_ID( ver ) == 0 )
    {
        HalLcdWriteStringValueValue("ImgA Id", OAD_VER_NUM( ver ), 16,
                                               BUILD_UINT16(pNoti->value[2], pNoti->value[3]), 16,
                                               HAL_LCD_LINE_2);
    }
    else
    {
        HalLcdWriteStringValueValue("ImgB Id", OAD_VER_NUM( ver ), 16,
                                               BUILD_UINT16(pNoti->value[2], pNoti->value[3]), 16,
                                               HAL_LCD_LINE_2);
    }

    HalLcdWriteString((char*)userId, HAL_LCD_LINE_3);
#endif
  }
  else if (pNoti->handle == oadManagerHandles[OAD_CHAR_IMG_BLOCK])
  {
    oadBlkNum = BUILD_UINT16(pNoti->value[0], pNoti->value[1]);
    attWriteReq_t req;

    req.handle = oadManagerHandles[OAD_CHAR_IMG_BLOCK];
    req.len = 2 + OAD_BLOCK_SIZE;
    req.sig = FALSE;
    req.cmd = TRUE;

    req.value[0] = LO_UINT16(oadBlkNum);
    req.value[1] = HI_UINT16(oadBlkNum);

    uint8 page = oadBlkNum / OAD_BLOCKS_PER_PAGE;
    uint16 oset = (oadBlkNum - (OAD_BLOCKS_PER_PAGE * page)) * OAD_BLOCK_SIZE;
    HalFlashRead(page+OAD_IMG_B_PAGE, oset, req.value+2, OAD_BLOCK_SIZE);

#if (defined HAL_LCD) && (HAL_LCD == TRUE)
    if (oadBlkNum == 0)
    {
      HalLcdWriteString("", HAL_LCD_LINE_3);
    }
    HalLcdDisplayPercentBar( "OAD Progress...", (oadBlkNum / (oadBlkTot / 100)) );
#endif

    VOID GATT_WriteNoRsp(oadManagerConnHandle, &req);

    VOID osal_start_timerEx( oadManagerTaskId, OAD_DOWNLOAD_EVT, OAD_DOWNLOAD_TIMEOUT );
  }
}
示例#2
0
/*********************************************************************
 * @fn      zllSampleLight_OffWithEffect
 *
 * @brief   Callback from the ZCL General Cluster Library when it
 *          received an Off with Effect Command for this application.
 *
 * @param   pCmd - Off with Effect parameters
 *
 * @return  none
 */
static void zllSampleLight_OnOff_OffWithEffectCB( zclOffWithEffect_t *pCmd )
{
  HalLcdWriteStringValueValue( "OffWithEff", pCmd->effectId, 16,
                               pCmd->effectVariant, 16, HAL_LCD_LINE_1 );
  if( zllSampleLight_GlobalSceneCtrl )
  {
    zclSceneReq_t req;
    req.scene = &zllSampleLight_GlobalScene;

    zllSampleLight_SceneStoreCB( &req );
    zllSampleLight_GlobalSceneCtrl = FALSE;
  }
  zllEffects_InitiateEffect( ZCL_CLUSTER_ID_GEN_ON_OFF, COMMAND_OFF_WITH_EFFECT,
                                 pCmd->effectId, pCmd->effectVariant );
}
示例#3
0
/*********************************************************************
 * @fn          zllSampleBridge_ProcessZDOMsg
 *
 * @brief       Process ZDO messages for Device Discovery
 *
 * @param       inMsg - Incoming ZDO message
 *
 * @return      none
 */
static void zllSampleBridge_ProcessZDOMsg( zdoIncomingMsg_t *inMsg )
{
  static zAddrType_t addr;
  addr.addrMode = Addr16Bit;

  switch ( inMsg->clusterID )
  {
    case Device_annce:
      {
        ZDO_DeviceAnnce_t devAnnce;

        ZDO_ParseDeviceAnnce( inMsg, &devAnnce );
        if ( ( lastDevAnnceAddr != INVALID_NODE_ADDR ) && ( lastDevAnnceAddr != devAnnce.nwkAddr ) )
        {
          zllSampleBridge_SendActiveEPReq( lastDevAnnceAddr );
        }
        lastDevAnnceAddr = devAnnce.nwkAddr;
        osal_start_timerEx( zllSampleBridge_TaskID, SAMPLEBRIDGE_DEV_ANNCE_EVT, DEVICE_DISCOVERY_DELAY );
      }
      break;

    case Active_EP_rsp:
      {
        ZDO_ActiveEndpointRsp_t *pActiveEPs = NULL;
        pActiveEPs = ZDO_ParseEPListRsp( inMsg );
        if ( pActiveEPs->status == ZSuccess )
        {
          for (uint8 i=0; i < pActiveEPs->cnt; i++ )
          {
            addr.addr.shortAddr = pActiveEPs->nwkAddr;
            ZDP_SimpleDescReq( &addr, pActiveEPs->nwkAddr, pActiveEPs->epList[i], 0 );
          }
        }

        if ( pActiveEPs != NULL )
        {
          osal_mem_free( pActiveEPs );
        }
      }
      break;

    case Simple_Desc_rsp:
      {
        ZDO_SimpleDescRsp_t simpleDescRsp;
        simpleDescRsp.simpleDesc.pAppInClusterList = simpleDescRsp.simpleDesc.pAppOutClusterList = NULL;
        ZDO_ParseSimpleDescRsp( inMsg, &simpleDescRsp );

        if ( ( simpleDescRsp.status == ZDP_SUCCESS ) && ( zllSampleBridge_SelectTargetSimpleDesc( &(simpleDescRsp.simpleDesc) ) ) )
        {
          epInfoRec_t rec;
          rec.nwkAddr = simpleDescRsp.nwkAddr;
          rec.endpoint = simpleDescRsp.simpleDesc.EndPoint;
          rec.profileID = simpleDescRsp.simpleDesc.AppProfId;
          rec.deviceID = simpleDescRsp.simpleDesc.AppDeviceId;
          rec.version = simpleDescRsp.simpleDesc.AppDevVer;
          zllSampleBridge_UpdateLinkedTarget( &rec );
          HalLcdWriteStringValueValue( "linked:", simpleDescRsp.nwkAddr, 16, simpleDescRsp.simpleDesc.EndPoint, 16, HAL_LCD_LINE_3 );
        }
        if ( simpleDescRsp.simpleDesc.pAppInClusterList != NULL )
        {
          osal_mem_free( simpleDescRsp.simpleDesc.pAppInClusterList );
        }
        if ( simpleDescRsp.simpleDesc.pAppOutClusterList != NULL )
        {
          osal_mem_free( simpleDescRsp.simpleDesc.pAppOutClusterList );
        }
      }
      break;

    default:
      break;
  }
}