Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*****************************************************************************
- *
- * MODULE: Window Covering Cluster
- *
- * COMPONENT: WindowCoveringCommands.c
- *
- * AUTHOR: Vesa 'ISO-B' Ylikyl�
- * DESCRIPTION: Send a window covering cluster command
- *
- * $HeadURL: $
- *
- * $Revision: 1 $
- *
- * $LastChangedBy: isob $
- *
- * $LastChangedDate: 2019-01-19 12:00:00 +0200 (Sat, 19 Jan 2018) $
- *
- * $Id: WindowCoveringCommands.c 1 2019-01-19 10:00:00Z isob $
- *
- ****************************************************************************/
- /****************************************************************************/
- /*** Include files ***/
- /****************************************************************************/
- #include <jendefs.h>
- #include "zcl.h"
- #include "zcl_customcommand.h"
- #include "WindowCovering.h"
- #include "WindowCovering_internal.h"
- #include "pdum_apl.h"
- #include "zps_apl.h"
- #include "zps_apl_af.h"
- #include "dbg.h"
- //#define DEBUG_CLD_WINDOWCOVERING
- #ifdef DEBUG_CLD_WINDOWCOVERING
- #define TRACE_WINDOWCOVERING TRUE
- #else
- #define TRACE_WINDOWCOVERING FALSE
- #endif
- /****************************************************************************/
- /*** Macro Definitions ***/
- /****************************************************************************/
- /****************************************************************************/
- /*** Type Definitions ***/
- /****************************************************************************/
- /****************************************************************************/
- /*** Local Function Prototypes ***/
- /****************************************************************************/
- /****************************************************************************/
- /*** Exported Variables ***/
- /****************************************************************************/
- /****************************************************************************/
- /*** Local Variables ***/
- /****************************************************************************/
- /****************************************************************************/
- /*** Public Functions ***/
- /****************************************************************************/
- #ifdef WINDOWCOVERING_CLIENT
- /****************************************************************************
- **
- ** NAME: eCLD_WindowCoveringCommandOpenCloseStopRequestSend
- **
- ** DESCRIPTION:
- ** Builds and sends a open, close or stop Request command
- **
- ** PARAMETERS: Name Usage
- ** uint8 u8SourceEndPointId Source EP Id
- ** uint8 u8DestinationEndPointId Destination EP Id
- ** tsZCL_Address *psDestinationAddress Destination Address
- ** uint8 *pu8TransactionSequenceNumber Sequence number Pointer
- **
- ** RETURN:
- ** teZCL_Status
- **
- ****************************************************************************/
- PUBLIC teZCL_Status eCLD_WindowCoveringCommandOpenCloseStopRequestSend(
- uint8 u8SourceEndPointId,
- uint8 u8DestinationEndPointId,
- tsZCL_Address *psDestinationAddress,
- uint8 *pu8TransactionSequenceNumber,
- teCLD_WindowCovering_CommandID eCommand)
- {
- DBG_vPrintf(TRACE_WINDOWCOVERING, "\nWindow Covering cluster 1 CMD: %d\n", eCommand);
- return eZCL_CustomCommandSend(u8SourceEndPointId,
- u8DestinationEndPointId,
- psDestinationAddress,
- CLOSURE_CLUSTER_ID_WINDOWCOVERING,
- FALSE,
- (uint8)eCommand,
- pu8TransactionSequenceNumber,
- 0,
- FALSE,
- 0,
- 0);
- }
- /****************************************************************************
- **
- ** NAME: eCLD_WindowCoveringCommandGotoValueResponseSend
- **
- ** DESCRIPTION:
- ** Builds and sends a Go To (Lift|Tilt) value request command
- **
- ** PARAMETERS: Name Usage
- ** uint8 u8SourceEndPointId Source EP Id
- ** uint8 u8DestinationEndPointId Destination EP Id
- ** tsZCL_Address *psDestinationAddress Destination Address
- ** uint8 *pu8TransactionSequenceNumber Sequence number Pointer
- **
- ** RETURN:
- ** teZCL_Status
- **
- ****************************************************************************/
- PUBLIC teZCL_Status eCLD_WindowCoveringCommandGotoValueRequestSend(
- uint8 u8SourceEndPointId,
- uint8 u8DestinationEndPointId,
- tsZCL_Address *psDestinationAddress,
- uint8 *pu8TransactionSequenceNumber,
- teCLD_WindowCovering_CommandID eCommand,
- tsCLD_WindowCovering_GoToValueRequestPayload *psPayload)
- {
- tsZCL_TxPayloadItem asPayloadDefinition[] = {
- {1, E_ZCL_UINT16, &psPayload->u16Value},
- };
- DBG_vPrintf(TRACE_WINDOWCOVERING, "\nWindow Covering cluster 2 CMD: %d PL: %x\n", eCommand, psPayload->u16Value);
- return eZCL_CustomCommandSend(u8SourceEndPointId,
- u8DestinationEndPointId,
- psDestinationAddress,
- CLOSURE_CLUSTER_ID_WINDOWCOVERING,
- FALSE,
- (uint8)eCommand,
- pu8TransactionSequenceNumber,
- asPayloadDefinition,
- FALSE,
- 0,
- sizeof(asPayloadDefinition) / sizeof(tsZCL_TxPayloadItem));
- }
- /****************************************************************************
- **
- ** NAME: eCLD_WindowCoveringCommandGotoPercentageResponseSend
- **
- ** DESCRIPTION:
- ** Builds and sends a Go To (Lift|Tilt) percentage request command
- **
- ** PARAMETERS: Name Usage
- ** uint8 u8SourceEndPointId Source EP Id
- ** uint8 u8DestinationEndPointId Destination EP Id
- ** tsZCL_Address *psDestinationAddress Destination Address
- ** uint8 *pu8TransactionSequenceNumber Sequence number Pointer
- **
- ** RETURN:
- ** teZCL_Status
- **
- ****************************************************************************/
- PUBLIC teZCL_Status eCLD_WindowCoveringCommandGotoPercentageRequestSend(
- uint8 u8SourceEndPointId,
- uint8 u8DestinationEndPointId,
- tsZCL_Address *psDestinationAddress,
- uint8 *pu8TransactionSequenceNumber,
- teCLD_WindowCovering_CommandID eCommand,
- tsCLD_WindowCovering_GoToPercentageRequestPayload *psPayload)
- {
- tsZCL_TxPayloadItem asPayloadDefinition[] = {
- {1, E_ZCL_UINT8, &psPayload->u8Percentage},
- };
- DBG_vPrintf(TRACE_WINDOWCOVERING, "\nWindow Covering cluster 3 CMD: %d PL: %x\n", eCommand, psPayload->u8Percentage);
- return eZCL_CustomCommandSend(u8SourceEndPointId,
- u8DestinationEndPointId,
- psDestinationAddress,
- CLOSURE_CLUSTER_ID_WINDOWCOVERING,
- FALSE,
- (uint8)eCommand,
- pu8TransactionSequenceNumber,
- asPayloadDefinition,
- FALSE,
- 0,
- sizeof(asPayloadDefinition) / sizeof(tsZCL_TxPayloadItem));
- }
- #endif
- #ifdef WINDOWCOVERING_SERVER
- teZCL_Status eCLD_WindowCoveringCommandOpenCLoseStopRequestReceive(
- ZPS_tsAfEvent *pZPSevent,
- uint8 *pu8TransactionSequenceNumber
- ) {
- return eZCL_CustomCommandReceive(
- pZPSevent,
- pu8TransactionSequenceNumber,
- 0,
- 0,
- E_ZCL_ACCEPT_EXACT);
- }
- teZCL_Status eCLD_WindowCoveringHandleGotoValueRequestReceive(
- ZPS_tsAfEvent *pZPSevent,
- uint8 *pu8TransactionSequenceNumber,
- tsCLD_WindowCovering_GoToValueRequestPayload *psPayload
- ) {
- uint16 u16ActualQuantity;
- tsZCL_RxPayloadItem asPayloadDefinition[] = {
- {1, &u16ActualQuantity, E_ZCL_UINT16, &psPayload->u16Value} };
- return eZCL_CustomCommandReceive(
- pZPSevent,
- pu8TransactionSequenceNumber,
- asPayloadDefinition,
- sizeof(asPayloadDefinition) / sizeof(tsZCL_RxPayloadItem),
- E_ZCL_ACCEPT_LESS | E_ZCL_DISABLE_DEFAULT_RESPONSE);
- }
- teZCL_Status eCLD_WindowCoveringHandleGotoPercentageRequestReceive(
- ZPS_tsAfEvent *pZPSevent,
- uint8 *pu8TransactionSequenceNumber,
- tsCLD_WindowCovering_GoToPercentageRequestPayload *psPayload
- ) {
- uint16 u16ActualQuantity;
- tsZCL_RxPayloadItem asPayloadDefinition[] = {
- {1, &u16ActualQuantity, E_ZCL_UINT8, &psPayload->u8Percentage} };
- return eZCL_CustomCommandReceive(
- pZPSevent,
- pu8TransactionSequenceNumber,
- asPayloadDefinition,
- sizeof(asPayloadDefinition) / sizeof(tsZCL_RxPayloadItem),
- E_ZCL_ACCEPT_LESS | E_ZCL_DISABLE_DEFAULT_RESPONSE);
- }
- PUBLIC teZCL_Status eCLD_WindowCoveringSetPercentagePosition(
- uint8 u8SourceEndPointId,
- uint8 u8PercentagePosition,
- teCLD_WindowCovering_Transition eTransition
- ) {
- teZCL_Status eStatus;
- tsZCL_EndPointDefinition *psEndPointDefinition;
- tsZCL_ClusterInstance *psClusterInstance;
- tsCLD_WindowCovering *psSharedStruct;
- tsCLD_WindowCoveringCustomDataStructure *psCommon;
- /* Find pointers to cluster */
- eStatus = eZCL_FindCluster(
- CLOSURE_CLUSTER_ID_WINDOWCOVERING,
- u8SourceEndPointId,
- TRUE,
- &psEndPointDefinition,
- &psClusterInstance,
- (void*)&psCommon);
- if (eStatus != E_ZCL_SUCCESS) {
- return eStatus;
- }
- if ((u8PercentagePosition > CLD_WINDOWCOVERING_POSITION_PERCENTAGE_MAX) ||
- (u8PercentagePosition < CLD_WINDOWCOVERING_POSITION_PERCENTAGE_MIN)) {
- return E_ZCL_ERR_INVALID_VALUE;
- }
- /* Point to shared struct */
- psSharedStruct = (tsCLD_WindowCovering *)psClusterInstance->pvEndPointSharedStructPtr;
- // get EP mutex
- #ifndef COOPERATIVE
- eZCL_GetMutex(psEndPointDefinition);
- #endif
- #ifdef CLD_WINDOWCOVERING_ATTR_ID_CURRENT_POSITION_LIFT_PERCENTAGE
- psSharedStruct->u8CurrentPositionLiftPercentage = u8PercentagePosition;
- #endif /* CLD_WINDOWCOVERING_ATTR_ID_CURRENT_POSITION_LIFT_PERCENTAGE */
- #ifdef CLD_WINDOWCOVERING_ATTR_ID_CURRENT_POSITION_TILT_PERCENTAGE
- psSharedStruct->u8CurrentPositionTiltPercentage = u8PercentagePosition;
- #endif /* CLD_WINDOWCOVERING_ATTR_ID_CURRENT_POSITION_TILT_PERCENTAGE */
- /* Fill Position */
- psCommon->sTransition.u8CurrentPositionPercentage = u8PercentagePosition;
- if ((E_CLD_WINDOWCOVERING_TRANSITION_STOP == eTransition) &&
- (psCommon->sTransition.eTransition != eTransition)) {
- psCommon->sCustomCallBackEvent.u8EndPoint = psEndPointDefinition->u8EndPointNumber;
- psCommon->sCustomCallBackEvent.psClusterInstance = psClusterInstance;
- psCommon->sCustomCallBackEvent.pZPSevent = NULL;
- psCommon->sCustomCallBackEvent.eEventType = E_ZCL_CBET_CLUSTER_UPDATE;
- /* Update target & Transition */
- // 2019.06.18 TrungTQ DEL
- // psCommon->sTransition.eTransition = eTransition;
- // 2019.06.18 TrungTQ END
- psCommon->sTransition.u8TargetPositionPercentage = u8PercentagePosition;
- psEndPointDefinition->pCallBackFunctions(&psCommon->sCustomCallBackEvent);
- }
- psCommon->sTransition.eTransition = eTransition;
- // 2019.06.18 TrungTQ DEL
- /* Update last */
- // psCommon->sTransition.u8LastPositionPercentage = u8PercentagePosition;
- // 2019.06.18 TrungTQ END
- /* release EP */
- #ifndef COOPERATIVE
- eZCL_ReleaseMutex(psEndPointDefinition);
- #endif
- return E_ZCL_SUCCESS;
- }
- PUBLIC teZCL_Status eCLD_WindowCoveringGetPercentagePosition(
- uint8 u8SourceEndPointId,
- uint8 *pu8PercentagePosition
- ) {
- teZCL_Status eStatus;
- tsZCL_EndPointDefinition *psEndPointDefinition;
- tsZCL_ClusterInstance *psClusterInstance;
- void *psCustomDataStructure;
- /* Find pointers to cluster */
- eStatus = eZCL_FindCluster(
- CLOSURE_CLUSTER_ID_WINDOWCOVERING,
- u8SourceEndPointId,
- TRUE,
- &psEndPointDefinition,
- &psClusterInstance,
- (void*)&psCustomDataStructure);
- if (eStatus != E_ZCL_SUCCESS) {
- return eStatus;
- }
- /* Get attribute state */
- #ifdef CLD_WINDOWCOVERING_ATTR_ID_CURRENT_POSITION_LIFT_PERCENTAGE
- *pu8PercentagePosition = ((tsCLD_WindowCovering*)(psClusterInstance->pvEndPointSharedStructPtr))->u8CurrentPositionLiftPercentage;
- #endif /* CLD_WINDOWCOVERING_ATTR_ID_CURRENT_POSITION_LIFT_PERCENTAGE */
- #ifdef CLD_WINDOWCOVERING_ATTR_ID_CURRENT_POSITION_TILT_PERCENTAGE
- *pu8PercentagePosition = ((tsCLD_WindowCovering*)(psClusterInstance->pvEndPointSharedStructPtr))->u8CurrentPositionTiltPercentage;
- #endif /* CLD_WINDOWCOVERING_ATTR_ID_CURRENT_POSITION_TILT_PERCENTAGE */
- return E_ZCL_SUCCESS;
- }
- #endif /* WINDOWCOVERING_SERVER */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement