接收函数:
//接收数据,参数为接收到的数据
void SampleApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )
{
uint16 flashTime;
byte buf[3];
switch ( pkt->clusterId ) //判断簇ID
{
case SAMPLEAPP_PERIODIC_CLUSTERID: //收到广播数据
osal_memset(buf, 0 , 3);
osal_memcpy(buf, pkt->cmd.Data, 2); //复制数据到缓冲区中
if(buf[0] == 'D' && buf[1] == '1') //判断收到的数据是否为"D1"
{
HalLedBlink(HAL_LED_1, 0, 50, 500);//如果是则Led1间隔500ms闪烁
#if defined(ZDO_COORDINATOR) //协调器收到"D1"后,返回"D1"给终端,让终端Led1也闪烁
SampleApp_SendPeriodicMessage();
#endif
}
else
{
HalLedSet(HAL_LED_1, HAL_LED_MODE_ON);
}
break;
case SAMPLEAPP_FLASH_CLUSTERID: //收到组播数据
flashTime = BUILD_UINT16(pkt->cmd.Data[1], pkt->cmd.Data[2] );
HalLedBlink( HAL_LED_4, 4, 50, (flashTime / 4) );
break;
}
}
|