// returns a ZCL status, EMBER_ZCL_STATUS_SUCCESS when it works. Sets newHue to the // current Hue attribute value static EmberAfStatus colorControlReadCurrentHue(uint8_t endpoint, uint8_t* hue) { EmberAfStatus status = emberAfReadServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_CURRENT_HUE_ATTRIBUTE_ID, hue, sizeof(uint8_t)); if (status != EMBER_ZCL_STATUS_SUCCESS) { emberAfColorControlClusterPrintln("ERR: reading current hue %x", status); } return status; }
// returns a ZCL status, EMBER_ZCL_STATUS_SUCCESS when it works. Sets newHue to the // current Hue attribute value static EmberAfStatus colorControlReadCurrentSaturation(uint8_t endpoint, uint8_t* saturation) { EmberAfStatus status = emberAfReadServerAttribute(endpoint, ZCL_COLOR_CONTROL_CLUSTER_ID, ZCL_COLOR_CONTROL_CURRENT_SATURATION_ATTRIBUTE_ID, saturation, sizeof(uint8_t)); if (status != EMBER_ZCL_STATUS_SUCCESS) { emberAfColorControlClusterPrintln("ERR: reading current saturation %x", status); } return status; }
/** @brief Server Attribute Changed * * On/off cluster, Server Attribute Changed * * @param endpoint Endpoint that is being initialized Ver.: always * @param attributeId Attribute that changed Ver.: always */ void emberAfOnOffClusterServerAttributeChangedCallback(int8u endpoint, EmberAfAttributeId attributeId) { // When the on/off attribute changes, set the LED appropriately. If an error // occurs, ignore it because there's really nothing we can do. if (attributeId == ZCL_ON_OFF_ATTRIBUTE_ID) { boolean onOff; if (emberAfReadServerAttribute(endpoint, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, (int8u *)&onOff, sizeof(onOff)) == EMBER_ZCL_STATUS_SUCCESS) { if (onOff) { halSetLed(LED); } else { halClearLed(LED); } } } }
/** @brief Connect Request * * * @param connectControl Ver.: always * @param idleTimeout Ver.: always * @param managerTarget Ver.: always * @param managerEndpoint Ver.: always */ bool emberAf11073ProtocolTunnelClusterConnectRequestCallback(uint8_t connectControl, uint16_t idleTimeout, uint8_t* managerTarget, uint8_t managerEndpoint) { bool connected = false; bool preemptible = false; EmberAfStatus status; // Check to see if we are already connected by looking at connected attribute status = emberAfReadServerAttribute(HC_11073_TUNNEL_ENDPOINT, CLUSTER_ID_11073_TUNNEL, ATTRIBUTE_11073_TUNNEL_CONNECTED, &connected, 1); // if we are already connected send back connection status ALREADY_CONNECTED if (connected) { emberAfFillCommand11073ProtocolTunnelClusterConnectStatusNotification( EMBER_ZCL_11073_TUNNEL_CONNECTION_STATUS_ALREADY_CONNECTED); emberAfSendResponse(); return true; } // if not already connected copy attributes connected = true; status = emberAfWriteServerAttribute(HC_11073_TUNNEL_ENDPOINT, CLUSTER_ID_11073_TUNNEL, ATTRIBUTE_11073_TUNNEL_CONNECTED, &connected, ZCL_BOOLEAN_ATTRIBUTE_TYPE); preemptible = connectControl & EMBER_ZCL_11073_CONNECT_REQUEST_CONNECT_CONTROL_PREEMPTIBLE; status = emberAfWriteServerAttribute(HC_11073_TUNNEL_ENDPOINT, CLUSTER_ID_11073_TUNNEL, ATTRIBUTE_11073_TUNNEL_PREEMPTIBLE, &preemptible, ZCL_BOOLEAN_ATTRIBUTE_TYPE); status = emberAfWriteServerAttribute(HC_11073_TUNNEL_ENDPOINT, CLUSTER_ID_11073_TUNNEL, ATTRIBUTE_11073_TUNNEL_IDLE_TIMEOUT, (uint8_t*)&idleTimeout, ZCL_INT16U_ATTRIBUTE_TYPE); status = emberAfWriteServerAttribute(HC_11073_TUNNEL_ENDPOINT, CLUSTER_ID_11073_TUNNEL, ATTRIBUTE_11073_TUNNEL_MANAGER_TARGET, (uint8_t*)managerTarget, ZCL_IEEE_ADDRESS_ATTRIBUTE_TYPE); status = emberAfWriteServerAttribute(HC_11073_TUNNEL_ENDPOINT, CLUSTER_ID_11073_TUNNEL, ATTRIBUTE_11073_TUNNEL_MANAGER_ENDPOINT, &managerEndpoint, ZCL_INT8U_ATTRIBUTE_TYPE); // if idle timer other than 0xffff, set timer to disconnect, reset timer when // rx data // Generate conection status connected back to manager emberAfFillCommand11073ProtocolTunnelClusterConnectStatusNotification( EMBER_ZCL_11073_TUNNEL_CONNECTION_STATUS_CONNECTED); emberAfSendResponse(); return true; }
/** @brief Disconnect Request * * * @param managerIEEEAddress Ver.: always */ bool emberAf11073ProtocolTunnelClusterDisconnectRequestCallback(uint8_t* managerIEEEAddress) { bool connected = false; EmberEUI64 currentManager; bool preemptible; EmberAfStatus status; // check to see if already connected status = emberAfReadServerAttribute(HC_11073_TUNNEL_ENDPOINT, CLUSTER_ID_11073_TUNNEL, ATTRIBUTE_11073_TUNNEL_CONNECTED, &connected, 1); // if not currently connected, generate connection status DISCONNECTED if (!connected) { emberAfFillCommand11073ProtocolTunnelClusterConnectStatusNotification( EMBER_ZCL_11073_TUNNEL_CONNECTION_STATUS_DISCONNECTED); emberAfSendResponse(); return true; } // if is connected, is ieee address same or is pre-emptible set to true? status = emberAfReadServerAttribute(HC_11073_TUNNEL_ENDPOINT, CLUSTER_ID_11073_TUNNEL, ATTRIBUTE_11073_TUNNEL_PREEMPTIBLE, &preemptible, 1); if(!preemptible) { status = emberAfReadServerAttribute(HC_11073_TUNNEL_ENDPOINT, CLUSTER_ID_11073_TUNNEL, ATTRIBUTE_11073_TUNNEL_MANAGER_TARGET, (uint8_t*)¤tManager, EUI64_SIZE); if (MEMCOMPARE(¤tManager, managerIEEEAddress, EUI64_SIZE) != 0) { emberAfFillCommand11073ProtocolTunnelClusterConnectStatusNotification( EMBER_ZCL_11073_TUNNEL_CONNECTION_STATUS_NOT_AUTHORIZED); emberAfSendResponse(); return true; } } // Set attribute to disconnected connected = false; status = emberAfWriteServerAttribute(HC_11073_TUNNEL_ENDPOINT, CLUSTER_ID_11073_TUNNEL, ATTRIBUTE_11073_TUNNEL_CONNECTED, &connected, ZCL_BOOLEAN_ATTRIBUTE_TYPE); // If it is authorized, then we can disconnect.Within 12 seconds device must send // DISCONNECTED notification to the manager device. Connected attribute set to // false to manager. emberAfFillCommand11073ProtocolTunnelClusterConnectStatusNotification( EMBER_ZCL_11073_TUNNEL_CONNECTION_STATUS_DISCONNECTED); emberAfSendResponse(); return true; // Send another DISCONNECTED connection event to sender of message. (may be same // as manager, may be some other device). return false; }
// Cluster: On/off, server EmberAfStatus emberAfOnOffClusterServerCommandParse(EmberAfClusterCommand *cmd) { boolean wasHandled = FALSE; int8u OnOfffCmdBeforeNumber; if (!cmd->mfgSpecific) { switch (cmd->apsFrame->destinationEndpoint){ case 1 : OnOfffCmdBeforeNumber = 1; break; case 3 : OnOfffCmdBeforeNumber = 2; break; case 5 : OnOfffCmdBeforeNumber = 3; break; case 7 : OnOfffCmdBeforeNumber = 4; break; case LedLightOptionEndpoint: OnOfffCmdBeforeNumber = 5; break; } if (CommonGetDurationTime(OnOffCmdBeforeTimer[OnOfffCmdBeforeNumber]) > 1000){ OnOffCmdBeforeTimer[OnOfffCmdBeforeNumber] = (int16u)halCommonGetInt32uMillisecondTick(); switch (cmd->commandId) { case ZCL_OFF_COMMAND_ID: { // Command is fixed length: 0 wasHandled = emberAfOnOffClusterOffCallback(); break; } case ZCL_ON_COMMAND_ID: { // Command is fixed length: 0 wasHandled = emberAfOnOffClusterOnCallback(); break; } case ZCL_TOGGLE_COMMAND_ID: { // Command is fixed length: 0 wasHandled = emberAfOnOffClusterToggleCallback(); break; } } // User Controller Command int8u CurrentState; emberAfReadServerAttribute(cmd->apsFrame->destinationEndpoint, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, &CurrentState, sizeof(CurrentState)); if (status(wasHandled, cmd->mfgSpecific) == EMBER_ZCL_STATUS_SUCCESS) { if (cmd->apsFrame->destinationEndpoint == LedLightOptionEndpoint) { if (CurrentState == 1) { halClearLed(LED_LIGHT); } else{ halSetLed(LED_LIGHT); } } else { if (CurrentState == 1) { UartSendSwitchControlNumber( (((cmd->apsFrame->destinationEndpoint) >> 1) + 1), OnRelay); } else { UartSendSwitchControlNumber( (((cmd->apsFrame->destinationEndpoint) >> 1) + 1), OffRelay); } // Send to Bind Device SendViaBindingTable(cmd->apsFrame->destinationEndpoint, CurrentState, OnOffType); // Send On-Off AttributeResponse, Zipato stupid update :D-----------------------------// SendOnOffControlReadAttribute(cmd->apsFrame->destinationEndpoint, CurrentState); // on-off led if (CurrentState == 1) { CommonSetLed(cmd->apsFrame->destinationEndpoint >> 1); } else {