/********************************************************************* * @fn zclRouterVersion1_OnOffCB * * @brief Callback from the ZCL General Cluster Library when * it received an On/Off Command for this application. * * @param cmd - COMMAND_ON, COMMAND_OFF or COMMAND_TOGGLE * * @return none */ static void zclRouterVersion1_OnOffCB( uint8 cmd ) { afIncomingMSGPacket_t *pPtr = zcl_getRawAFMsg(); zclRouterVersion1_DstAddr.addr.shortAddr = pPtr->srcAddr.addr.shortAddr; uint8 command_data[] = {0}; //Data = Data << 8; osal_memcpy( (void *)command_data, (const void *) pPtr->cmd.Data, 4); // Turn on the light if ( cmd == COMMAND_ON ) { if (command_data[3] == 1) { HalLedSet(HAL_LED_2,HAL_LED_MODE_ON); } if (command_data[3] == 3) { P1_2 = 1; } if (command_data[3] == 6) { P1_3 = 1; } } // Turn off the light else if ( cmd == COMMAND_OFF ) { if (command_data[3] == 1) { HalLedSet(HAL_LED_2,HAL_LED_MODE_OFF); } if (command_data[3] == 3) { P1_2 = 0; } if (command_data[3] == 6) { P1_3 =0; } } // Toggle the light else if ( cmd == COMMAND_TOGGLE ) { if (command_data[3] == 1) { HalLedSet(HAL_LED_2,HAL_LED_MODE_TOGGLE); } if (command_data[3] == 3 ) { if(P1_2 == 0) { P1_2 = 1; } else { P1_2 = 0; } } if (command_data[3] == 6) { if(P1_3 == 0) { P1_3 = 1; } else { P1_3 = 0; } } } }
/********************************************************************* * @fn zclDiagnostic_ReadWriteAttrCB * * @brief Handle Diagnostics attributes. * * @param clusterId - cluster that attribute belongs to * @param attrId - attribute to be read or written * @param oper - ZCL_OPER_LEN, ZCL_OPER_READ, or ZCL_OPER_WRITE * @param pValue - pointer to attribute value, OTA endian * @param pLen - length of attribute value read, native endian * * @return status */ ZStatus_t zclDiagnostic_ReadWriteAttrCB( uint16 clusterId, uint16 attrId, uint8 oper, uint8 *pValue, uint16 *pLen ) { ZStatus_t status = ZSuccess; uint16 tempAttr; uint32 attrValue; afIncomingMSGPacket_t *origPkt; origPkt = zcl_getRawAFMsg(); switch ( oper ) { case ZCL_OPER_LEN: if ( ( attrId == ATTRID_DIAGNOSTIC_LAST_MESSAGE_LQI ) || ( attrId == ATTRID_DIAGNOSTIC_LAST_MESSAGE_RSSI ) ) { *pLen = 1; } else if ( attrId == ATTRID_DIAGNOSTIC_AVERAGE_MAC_RETRY_PER_APS_MESSAGE_SENT ) { *pLen = 2; } // The next function call only returns the length for attributes that are defined // in lower layers else if ( zclDiagnostic_GetAttribData( attrId, &tempAttr, pLen ) != ZSuccess ) { *pLen = 0; status = ZFailure; // invalid length } break; case ZCL_OPER_READ: // Identify if incoming msg is LQI or RSSI attribute // and return the LQI and RSSI of the incoming values if ( attrId == ATTRID_DIAGNOSTIC_LAST_MESSAGE_LQI ) { *pLen = 1; attrValue = origPkt->LinkQuality; } else if ( attrId == ATTRID_DIAGNOSTIC_LAST_MESSAGE_RSSI ) { //origPkt = zcl_getRawAFMsg(); *pLen = 1; attrValue = origPkt->rssi; } else if ( zclDiagnostic_GetStatsAttr( attrId, &attrValue, pLen ) == ZSuccess ) { if ( ( attrId == ATTRID_DIAGNOSTIC_MAC_TX_UCAST_RETRY ) || ( attrId == ATTRID_DIAGNOSTIC_MAC_TX_UCAST_FAIL ) ) { // The lower layer counter is a 32 bit counter, report the higher 16 bit value // util the lower layer counter wraps-up if ( attrValue > 0x0000FFFF ) { attrValue = 0x0000FFFF; } } } else { *pLen = 0; status = ZFailure; // invalid attribute } if ( *pLen == 1 ) { pValue[0] = BREAK_UINT32( attrValue, 0 ); } else if ( *pLen == 2 ) { pValue[0] = LO_UINT16( attrValue ); pValue[1] = HI_UINT16( attrValue ); } else if ( *pLen == 4 ) { pValue[0] = BREAK_UINT32( attrValue, 0 ); pValue[1] = BREAK_UINT32( attrValue, 1 ); pValue[2] = BREAK_UINT32( attrValue, 2 ); pValue[3] = BREAK_UINT32( attrValue, 3 ); } break; case ZCL_OPER_WRITE: status = ZFailure; // All attributes in Diagnostics cluster are READ ONLY break; } return ( status ); }