static void PDM_HandleAvailableRequest(void *pvUser, uint16_t u16Length, void *pvMessage) { user_zigbeePDM_log("Host PDM availability request\n"); if (eSL_SendMessage(E_SL_MSG_PDM_AVAILABLE_RESPONSE, 0, NULL, NULL) != E_SL_OK) { user_zigbeePDM_log("Error sending message\n"); } }
static void PDM_HandleDeleteAllRequest(void *pvUser, uint16_t u16Length, void *pvMessage) { //sqlite3_stmt *psStatement; char *pcSQL; struct _tPDMDeleteAllResponse { uint8_t u8Status; } sDeleteAllResponse; mico_rtos_lock_mutex(&sLock); sDeleteAllResponse.u8Status = 0; user_zigbeePDM_log("Delete all records\n"); //pcSQL = sqlite3_mprintf("DELETE FROM pdm"); user_zigbeePDM_log("Execute SQL '%s'\n", pcSQL); //if (sqlite3_prepare_v2(pDb, pcSQL, -1, &psStatement, NULL) != SQLITE_OK) { user_zigbeePDM_log("Error preparing query\n"); } //else { //switch(sqlite3_step(psStatement)) { //case(SQLITE_DONE): // sDeleteAllResponse.u8Status = 1; // break; //case (SQLITE_ERROR): // user_zigbeePDM_log(DBG_PDM, "Error during SQL operation(%s)\n", sqlite3_errmsg(pDb)); // sDeleteAllResponse.u8Status = 0; // break; //default: // user_zigbeePDM_log("Unhandled return from sqlite3\n"); // sDeleteAllResponse.u8Status = 0; } } if (eSL_SendMessage(E_SL_MSG_PDM_DELETE_ALL_RECORDS_RESPONSE, sizeof(struct _tPDMDeleteAllResponse), &sDeleteAllResponse, NULL) != E_SL_OK) { user_zigbeePDM_log("Error sending message\n"); } user_zigbeePDM_log("Finished handling request\n"); //if (sqlite3_finalize(psStatement) != SQLITE_OK) { user_zigbeePDM_log("Error finalizing statement\n"); } mico_rtos_unlock_mutex(&sLock); //sqlite3_free(pcSQL); }
teZcbStatus eZBZLL_OnOff(tsZCB_Node *psZCBNode, uint8_t u8EndpointID, uint16_t u16GroupAddress, uint8_t u8Mode) { tsZCB_Node *psControlBridge; tsZCB_NodeEndpoint *psSourceEndpoint; tsZCB_NodeEndpoint *psDestinationEndpoint; uint8_t u8SequenceNo; #pragma pack(1) struct { uint8_t u8TargetAddressMode; uint16_t u16TargetAddress; uint8_t u8SourceEndpoint; uint8_t u8DestinationEndpoint; uint8_t u8Mode; } sOnOffMessage; #pragma pack() //user_ZigbeeZLL_log("On/Off (Set Mode=%d)", u8Mode); if (u8Mode > 2) { /* Illegal value */ return E_ZCB_ERROR; } psControlBridge = psZCB_FindNodeControlBridge(); if (!psControlBridge) { return E_ZCB_ERROR; } psSourceEndpoint = psZCB_NodeFindEndpoint(psControlBridge, E_ZB_CLUSTERID_ONOFF); if (!psSourceEndpoint) { user_ZigbeeZLL_log("Cluster ID 0x%04X not found on control bridge\n", E_ZB_CLUSTERID_ONOFF); return E_ZCB_ERROR; } sOnOffMessage.u8SourceEndpoint = psSourceEndpoint->u8Endpoint; mico_rtos_unlock_mutex(&psControlBridge->sLock); if (psZCBNode) { if (bZCB_EnableAPSAck) { sOnOffMessage.u8TargetAddressMode = E_ZB_ADDRESS_MODE_SHORT; } else { sOnOffMessage.u8TargetAddressMode = E_ZB_ADDRESS_MODE_SHORT_NO_ACK; } sOnOffMessage.u16TargetAddress = htons(psZCBNode->u16ShortAddress); if(u8EndpointID != 0) { psDestinationEndpoint = psZCB_NodeFindEndpointID(psZCBNode, u8EndpointID); } else { psDestinationEndpoint = psZCB_NodeFindEndpoint(psZCBNode, E_ZB_CLUSTERID_ONOFF); } if (psDestinationEndpoint) { sOnOffMessage.u8DestinationEndpoint = psDestinationEndpoint->u8Endpoint; } else { sOnOffMessage.u8DestinationEndpoint = ZB_DEFAULT_ENDPOINT_ZLL; } mico_rtos_unlock_mutex(&psZCBNode->sLock); } else { sOnOffMessage.u8TargetAddressMode = E_ZB_ADDRESS_MODE_GROUP; sOnOffMessage.u16TargetAddress = htons(u16GroupAddress); sOnOffMessage.u8DestinationEndpoint = ZB_DEFAULT_ENDPOINT_ZLL; } sOnOffMessage.u8Mode = u8Mode; if (eSL_SendMessage(E_SL_MSG_ONOFF, sizeof(sOnOffMessage), &sOnOffMessage, &u8SequenceNo) != E_SL_OK) { return E_ZCB_COMMS_FAILED; } if (psZCBNode) { return eZCB_GetDefaultResponse(u8SequenceNo); } else { return E_ZCB_OK; } }
teZcbStatus eZBZLL_ColourLoopSet(tsZCB_Node *psZCBNode, uint16_t u16GroupAddress, uint8_t u8UpdateFlags, uint8_t u8Action, uint8_t u8Direction, uint16_t u16Time, uint16_t u16StartHue) { tsZCB_Node *psControlBridge; tsZCB_NodeEndpoint *psSourceEndpoint; tsZCB_NodeEndpoint *psDestinationEndpoint; uint8_t u8SequenceNo; #pragma pack(1) struct { uint8_t u8TargetAddressMode; uint16_t u16TargetAddress; uint8_t u8SourceEndpoint; uint8_t u8DestinationEndpoint; uint8_t u8UpdateFlags; uint8_t u8Action; uint8_t u8Direction; uint16_t u16Time; uint16_t u16StartHue; } sColourLoopSetMessage; #pragma pack() user_ZigbeeZLL_log("Colour loop set\n"); psControlBridge = psZCB_FindNodeControlBridge(); if (!psControlBridge) { return E_ZCB_ERROR; } psSourceEndpoint = psZCB_NodeFindEndpoint(psControlBridge, E_ZB_CLUSTERID_COLOR_CONTROL); if (!psSourceEndpoint) { user_ZigbeeZLL_log("Cluster ID 0x%04X not found on control bridge\n", E_ZB_CLUSTERID_COLOR_CONTROL); return E_ZCB_ERROR; } sColourLoopSetMessage.u8SourceEndpoint = psSourceEndpoint->u8Endpoint; mico_rtos_unlock_mutex(&psControlBridge->sLock); if (psZCBNode) { if (bZCB_EnableAPSAck) { sColourLoopSetMessage.u8TargetAddressMode = E_ZB_ADDRESS_MODE_SHORT; } else { sColourLoopSetMessage.u8TargetAddressMode = E_ZB_ADDRESS_MODE_SHORT_NO_ACK; } sColourLoopSetMessage.u16TargetAddress = htons(psZCBNode->u16ShortAddress); psDestinationEndpoint = psZCB_NodeFindEndpoint(psZCBNode, E_ZB_CLUSTERID_COLOR_CONTROL); if (psDestinationEndpoint) { sColourLoopSetMessage.u8DestinationEndpoint = psDestinationEndpoint->u8Endpoint; } else { sColourLoopSetMessage.u8DestinationEndpoint = ZB_DEFAULT_ENDPOINT_ZLL; } mico_rtos_unlock_mutex(&psZCBNode->sLock); } else { sColourLoopSetMessage.u8TargetAddressMode = E_ZB_ADDRESS_MODE_GROUP; sColourLoopSetMessage.u16TargetAddress = htons(u16GroupAddress); sColourLoopSetMessage.u8DestinationEndpoint = ZB_DEFAULT_ENDPOINT_ZLL; } sColourLoopSetMessage.u8UpdateFlags = u8UpdateFlags; sColourLoopSetMessage.u8Action = u8Action; sColourLoopSetMessage.u8Direction = u8Direction; sColourLoopSetMessage.u16Time = htons(u16Time); sColourLoopSetMessage.u16StartHue = htons(u16StartHue); if (eSL_SendMessage(E_SL_MSG_COLOUR_LOOP_SET, sizeof(sColourLoopSetMessage), &sColourLoopSetMessage, &u8SequenceNo) != E_SL_OK) { return E_ZCB_COMMS_FAILED; } if (psZCBNode) { return eZCB_GetDefaultResponse(u8SequenceNo); } else { return E_ZCB_OK; } }
teZcbStatus eZBZLL_MoveColourTemperature(tsZCB_Node *psZCBNode, uint16_t u16GroupAddress, uint8_t u8Mode, uint16_t u16Rate, uint16_t u16ColourTemperatureMin, uint16_t u16ColourTemperatureMax) { tsZCB_Node *psControlBridge; tsZCB_NodeEndpoint *psSourceEndpoint; tsZCB_NodeEndpoint *psDestinationEndpoint; uint8_t u8SequenceNo; #pragma pack(1) struct { uint8_t u8TargetAddressMode; uint16_t u16TargetAddress; uint8_t u8SourceEndpoint; uint8_t u8DestinationEndpoint; uint8_t u8Mode; uint16_t u16Rate; uint16_t u16ColourTemperatureMin; uint16_t u16ColourTemperatureMax; } sMoveColourTemperatureMessage; #pragma pack() user_ZigbeeZLL_log("Move colour temperature\n"); psControlBridge = psZCB_FindNodeControlBridge(); if (!psControlBridge) { return E_ZCB_ERROR; } psSourceEndpoint = psZCB_NodeFindEndpoint(psControlBridge, E_ZB_CLUSTERID_COLOR_CONTROL); if (!psSourceEndpoint) { user_ZigbeeZLL_log("Cluster ID 0x%04X not found on control bridge\n", E_ZB_CLUSTERID_COLOR_CONTROL); return E_ZCB_ERROR; } sMoveColourTemperatureMessage.u8SourceEndpoint = psSourceEndpoint->u8Endpoint; mico_rtos_unlock_mutex(&psControlBridge->sLock); if (psZCBNode) { if (bZCB_EnableAPSAck) { sMoveColourTemperatureMessage.u8TargetAddressMode = E_ZB_ADDRESS_MODE_SHORT; } else { sMoveColourTemperatureMessage.u8TargetAddressMode = E_ZB_ADDRESS_MODE_SHORT_NO_ACK; } sMoveColourTemperatureMessage.u16TargetAddress = htons(psZCBNode->u16ShortAddress); psDestinationEndpoint = psZCB_NodeFindEndpoint(psZCBNode, E_ZB_CLUSTERID_COLOR_CONTROL); if (psDestinationEndpoint) { sMoveColourTemperatureMessage.u8DestinationEndpoint = psDestinationEndpoint->u8Endpoint; } else { sMoveColourTemperatureMessage.u8DestinationEndpoint = ZB_DEFAULT_ENDPOINT_ZLL; } mico_rtos_unlock_mutex(&psZCBNode->sLock); } else { sMoveColourTemperatureMessage.u8TargetAddressMode = E_ZB_ADDRESS_MODE_GROUP; sMoveColourTemperatureMessage.u16TargetAddress = htons(u16GroupAddress); sMoveColourTemperatureMessage.u8DestinationEndpoint = ZB_DEFAULT_ENDPOINT_ZLL; } sMoveColourTemperatureMessage.u8Mode = u8Mode; sMoveColourTemperatureMessage.u16Rate = htons(u16Rate); sMoveColourTemperatureMessage.u16ColourTemperatureMin = htons(u16ColourTemperatureMin); sMoveColourTemperatureMessage.u16ColourTemperatureMax = htons(u16ColourTemperatureMax); if (eSL_SendMessage(E_SL_MSG_MOVE_COLOUR_TEMPERATURE, sizeof(sMoveColourTemperatureMessage), &sMoveColourTemperatureMessage, &u8SequenceNo) != E_SL_OK) { return E_ZCB_COMMS_FAILED; } if (psZCBNode) { return eZCB_GetDefaultResponse(u8SequenceNo); } else { return E_ZCB_OK; } }
teZcbStatus eZBZLL_MoveToLevel(tsZCB_Node *psZCBNode, uint16_t u16GroupAddress, uint8_t u8OnOff, uint8_t u8Level, uint16_t u16TransitionTime) { tsZCB_Node *psControlBridge; tsZCB_NodeEndpoint *psSourceEndpoint; tsZCB_NodeEndpoint *psDestinationEndpoint; uint8_t u8SequenceNo; #pragma pack(1) struct { uint8_t u8TargetAddressMode; uint16_t u16TargetAddress; uint8_t u8SourceEndpoint; uint8_t u8DestinationEndpoint; uint8_t u8OnOff; uint8_t u8Level; uint16_t u16TransitionTime; } sLevelMessage; #pragma pack() user_ZigbeeZLL_log("Set Level %d\n", u8Level); if (u8Level > 254) { u8Level = 254; } psControlBridge = psZCB_FindNodeControlBridge(); if (!psControlBridge) { return E_ZCB_ERROR; } psSourceEndpoint = psZCB_NodeFindEndpoint(psControlBridge, E_ZB_CLUSTERID_LEVEL_CONTROL); if (!psSourceEndpoint) { user_ZigbeeZLL_log("Cluster ID 0x%04X not found on control bridge\n", E_ZB_CLUSTERID_LEVEL_CONTROL); return E_ZCB_ERROR; } sLevelMessage.u8SourceEndpoint = psSourceEndpoint->u8Endpoint; mico_rtos_unlock_mutex(&psControlBridge->sLock); if (psZCBNode) { if (bZCB_EnableAPSAck) { sLevelMessage.u8TargetAddressMode = E_ZB_ADDRESS_MODE_SHORT; } else { sLevelMessage.u8TargetAddressMode = E_ZB_ADDRESS_MODE_SHORT_NO_ACK; } sLevelMessage.u16TargetAddress = htons(psZCBNode->u16ShortAddress); psDestinationEndpoint = psZCB_NodeFindEndpoint(psZCBNode, E_ZB_CLUSTERID_LEVEL_CONTROL); if (psDestinationEndpoint) { sLevelMessage.u8DestinationEndpoint = psDestinationEndpoint->u8Endpoint; } else { sLevelMessage.u8DestinationEndpoint = ZB_DEFAULT_ENDPOINT_ZLL; } mico_rtos_unlock_mutex(&psZCBNode->sLock); } else { sLevelMessage.u8TargetAddressMode = E_ZB_ADDRESS_MODE_GROUP; sLevelMessage.u16TargetAddress = htons(u16GroupAddress); sLevelMessage.u8DestinationEndpoint = ZB_DEFAULT_ENDPOINT_ZLL; } sLevelMessage.u8OnOff = u8OnOff; sLevelMessage.u8Level = u8Level; sLevelMessage.u16TransitionTime = htons(u16TransitionTime); // sOnOffMessage.u8Gradient = u8Gradient; if (eSL_SendMessage(E_SL_MSG_MOVE_TO_LEVEL_ONOFF, sizeof(sLevelMessage), &sLevelMessage, &u8SequenceNo) != E_SL_OK) { return E_ZCB_COMMS_FAILED; } if (psZCBNode) { return eZCB_GetDefaultResponse(u8SequenceNo); } else { return E_ZCB_OK; } }