Advertisement
tranthudo

WindowCoveringCommands.c

Jul 2nd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 14.98 KB | None | 0 0
  1. /*****************************************************************************
  2.  *
  3.  * MODULE:             Window Covering Cluster
  4.  *
  5.  * COMPONENT:          WindowCoveringCommands.c
  6.  *
  7.  * AUTHOR:             Vesa 'ISO-B' Ylikyl�
  8.  * DESCRIPTION:        Send a window covering cluster command
  9.  *
  10.  * $HeadURL:  $
  11.  *
  12.  * $Revision: 1 $
  13.  *
  14.  * $LastChangedBy: isob $
  15.  *
  16.  * $LastChangedDate: 2019-01-19 12:00:00 +0200 (Sat, 19 Jan 2018) $
  17.  *
  18.  * $Id: WindowCoveringCommands.c 1 2019-01-19 10:00:00Z isob $
  19.  *
  20.  ****************************************************************************/
  21.  
  22. /****************************************************************************/
  23. /***        Include files                                                 ***/
  24. /****************************************************************************/
  25. #include <jendefs.h>
  26.  
  27. #include "zcl.h"
  28. #include "zcl_customcommand.h"
  29.  
  30. #include "WindowCovering.h"
  31. #include "WindowCovering_internal.h"
  32.  
  33. #include "pdum_apl.h"
  34. #include "zps_apl.h"
  35. #include "zps_apl_af.h"
  36.  
  37.  
  38. #include "dbg.h"
  39.  
  40. //#define DEBUG_CLD_WINDOWCOVERING
  41.  
  42. #ifdef DEBUG_CLD_WINDOWCOVERING
  43. #define TRACE_WINDOWCOVERING    TRUE
  44. #else
  45. #define TRACE_WINDOWCOVERING    FALSE
  46. #endif
  47.  
  48. /****************************************************************************/
  49. /***        Macro Definitions                                             ***/
  50. /****************************************************************************/
  51.  
  52. /****************************************************************************/
  53. /***        Type Definitions                                              ***/
  54. /****************************************************************************/
  55.  
  56. /****************************************************************************/
  57. /***        Local Function Prototypes                                     ***/
  58. /****************************************************************************/
  59.  
  60. /****************************************************************************/
  61. /***        Exported Variables                                            ***/
  62. /****************************************************************************/
  63.  
  64. /****************************************************************************/
  65. /***        Local Variables                                               ***/
  66. /****************************************************************************/
  67.  
  68. /****************************************************************************/
  69. /***        Public Functions                                              ***/
  70. /****************************************************************************/
  71. #ifdef WINDOWCOVERING_CLIENT
  72. /****************************************************************************
  73.  **
  74.  ** NAME:       eCLD_WindowCoveringCommandOpenCloseStopRequestSend
  75.  **
  76.  ** DESCRIPTION:
  77.  ** Builds and sends a open, close or stop Request command
  78.  **
  79.  ** PARAMETERS:                 Name                           Usage
  80.  ** uint8                       u8SourceEndPointId             Source EP Id
  81.  ** uint8                       u8DestinationEndPointId        Destination EP Id
  82.  ** tsZCL_Address              *psDestinationAddress           Destination Address
  83.  ** uint8                      *pu8TransactionSequenceNumber   Sequence number Pointer
  84.  **
  85.  ** RETURN:
  86.  ** teZCL_Status
  87.  **
  88.  ****************************************************************************/
  89. PUBLIC  teZCL_Status eCLD_WindowCoveringCommandOpenCloseStopRequestSend(
  90.                                         uint8              u8SourceEndPointId,
  91.                                         uint8           u8DestinationEndPointId,
  92.                                         tsZCL_Address   *psDestinationAddress,
  93.                                         uint8           *pu8TransactionSequenceNumber,
  94.                                         teCLD_WindowCovering_CommandID      eCommand)
  95. {
  96.  
  97.     DBG_vPrintf(TRACE_WINDOWCOVERING, "\nWindow Covering cluster 1 CMD: %d\n", eCommand);
  98.     return eZCL_CustomCommandSend(u8SourceEndPointId,
  99.                                   u8DestinationEndPointId,
  100.                                   psDestinationAddress,
  101.                                   CLOSURE_CLUSTER_ID_WINDOWCOVERING,
  102.                                   FALSE,
  103.                                   (uint8)eCommand,
  104.                                   pu8TransactionSequenceNumber,
  105.                                   0,
  106.                                   FALSE,
  107.                                   0,
  108.                                   0);
  109.  
  110. }
  111.  
  112. /****************************************************************************
  113.  **
  114.  ** NAME:       eCLD_WindowCoveringCommandGotoValueResponseSend
  115.  **
  116.  ** DESCRIPTION:
  117.  ** Builds and sends a Go To (Lift|Tilt) value request command
  118.  **
  119.  ** PARAMETERS:                 Name                           Usage
  120.  ** uint8                       u8SourceEndPointId             Source EP Id
  121.  ** uint8                       u8DestinationEndPointId        Destination EP Id
  122.  ** tsZCL_Address              *psDestinationAddress           Destination Address
  123.  ** uint8                      *pu8TransactionSequenceNumber   Sequence number Pointer
  124.  **
  125.  ** RETURN:
  126.  ** teZCL_Status
  127.  **
  128.  ****************************************************************************/
  129. PUBLIC  teZCL_Status  eCLD_WindowCoveringCommandGotoValueRequestSend(
  130.                     uint8                       u8SourceEndPointId,
  131.                     uint8                       u8DestinationEndPointId,
  132.                     tsZCL_Address               *psDestinationAddress,
  133.                     uint8                       *pu8TransactionSequenceNumber,
  134.                     teCLD_WindowCovering_CommandID     eCommand,
  135.                     tsCLD_WindowCovering_GoToValueRequestPayload *psPayload)
  136. {
  137.  
  138.     tsZCL_TxPayloadItem asPayloadDefinition[] = {
  139.         {1, E_ZCL_UINT16, &psPayload->u16Value},
  140.     };
  141.  
  142.     DBG_vPrintf(TRACE_WINDOWCOVERING, "\nWindow Covering cluster 2 CMD: %d PL: %x\n", eCommand, psPayload->u16Value);
  143.     return eZCL_CustomCommandSend(u8SourceEndPointId,
  144.                                   u8DestinationEndPointId,
  145.                                   psDestinationAddress,
  146.                                   CLOSURE_CLUSTER_ID_WINDOWCOVERING,
  147.                                   FALSE,
  148.                                   (uint8)eCommand,
  149.                                   pu8TransactionSequenceNumber,
  150.                                   asPayloadDefinition,
  151.                                   FALSE,
  152.                                   0,
  153.                                   sizeof(asPayloadDefinition) / sizeof(tsZCL_TxPayloadItem));
  154. }
  155.  
  156. /****************************************************************************
  157.  **
  158.  ** NAME:       eCLD_WindowCoveringCommandGotoPercentageResponseSend
  159.  **
  160.  ** DESCRIPTION:
  161.  ** Builds and sends a Go To (Lift|Tilt) percentage request command
  162.  **
  163.  ** PARAMETERS:                 Name                           Usage
  164.  ** uint8                       u8SourceEndPointId             Source EP Id
  165.  ** uint8                       u8DestinationEndPointId        Destination EP Id
  166.  ** tsZCL_Address              *psDestinationAddress           Destination Address
  167.  ** uint8                      *pu8TransactionSequenceNumber   Sequence number Pointer
  168.  **
  169.  ** RETURN:
  170.  ** teZCL_Status
  171.  **
  172.  ****************************************************************************/
  173. PUBLIC  teZCL_Status  eCLD_WindowCoveringCommandGotoPercentageRequestSend(
  174.                     uint8                       u8SourceEndPointId,
  175.                     uint8                       u8DestinationEndPointId,
  176.                     tsZCL_Address               *psDestinationAddress,
  177.                     uint8                       *pu8TransactionSequenceNumber,
  178.                     teCLD_WindowCovering_CommandID     eCommand,
  179.                     tsCLD_WindowCovering_GoToPercentageRequestPayload *psPayload)
  180. {
  181.  
  182.     tsZCL_TxPayloadItem asPayloadDefinition[] = {
  183.         {1, E_ZCL_UINT8, &psPayload->u8Percentage},
  184.     };
  185.     DBG_vPrintf(TRACE_WINDOWCOVERING, "\nWindow Covering cluster 3 CMD: %d PL: %x\n", eCommand, psPayload->u8Percentage);
  186.     return eZCL_CustomCommandSend(u8SourceEndPointId,
  187.                                   u8DestinationEndPointId,
  188.                                   psDestinationAddress,
  189.                                   CLOSURE_CLUSTER_ID_WINDOWCOVERING,
  190.                                   FALSE,
  191.                                   (uint8)eCommand,
  192.                                   pu8TransactionSequenceNumber,
  193.                                   asPayloadDefinition,
  194.                                   FALSE,
  195.                                   0,
  196.                                   sizeof(asPayloadDefinition) / sizeof(tsZCL_TxPayloadItem));
  197. }
  198. #endif
  199.  
  200. #ifdef WINDOWCOVERING_SERVER
  201. teZCL_Status  eCLD_WindowCoveringCommandOpenCLoseStopRequestReceive(
  202.     ZPS_tsAfEvent                       *pZPSevent,
  203.     uint8                               *pu8TransactionSequenceNumber
  204. ) {
  205.     return eZCL_CustomCommandReceive(
  206.                     pZPSevent,
  207.                     pu8TransactionSequenceNumber,
  208.                     0,
  209.                     0,
  210.                     E_ZCL_ACCEPT_EXACT);
  211. }
  212.  
  213. teZCL_Status  eCLD_WindowCoveringHandleGotoValueRequestReceive(
  214.     ZPS_tsAfEvent           *pZPSevent,
  215.     uint8                   *pu8TransactionSequenceNumber,
  216.     tsCLD_WindowCovering_GoToValueRequestPayload *psPayload
  217. ) {
  218.     uint16 u16ActualQuantity;
  219.  
  220.     tsZCL_RxPayloadItem asPayloadDefinition[] = {
  221.         {1, &u16ActualQuantity, E_ZCL_UINT16,   &psPayload->u16Value} };
  222.  
  223.     return eZCL_CustomCommandReceive(
  224.                     pZPSevent,
  225.                     pu8TransactionSequenceNumber,
  226.                     asPayloadDefinition,
  227.                     sizeof(asPayloadDefinition) / sizeof(tsZCL_RxPayloadItem),
  228.                     E_ZCL_ACCEPT_LESS | E_ZCL_DISABLE_DEFAULT_RESPONSE);
  229. }
  230.  
  231. teZCL_Status  eCLD_WindowCoveringHandleGotoPercentageRequestReceive(
  232.     ZPS_tsAfEvent           *pZPSevent,
  233.     uint8                   *pu8TransactionSequenceNumber,
  234.     tsCLD_WindowCovering_GoToPercentageRequestPayload   *psPayload
  235. ) {
  236.     uint16 u16ActualQuantity;
  237.  
  238.     tsZCL_RxPayloadItem asPayloadDefinition[] = {
  239.         {1, &u16ActualQuantity, E_ZCL_UINT8,   &psPayload->u8Percentage} };
  240.  
  241.     return eZCL_CustomCommandReceive(
  242.                     pZPSevent,
  243.                     pu8TransactionSequenceNumber,
  244.                     asPayloadDefinition,
  245.                     sizeof(asPayloadDefinition) / sizeof(tsZCL_RxPayloadItem),
  246.                     E_ZCL_ACCEPT_LESS | E_ZCL_DISABLE_DEFAULT_RESPONSE);
  247. }
  248.  
  249.  
  250. PUBLIC teZCL_Status eCLD_WindowCoveringSetPercentagePosition(
  251.     uint8                       u8SourceEndPointId,
  252.     uint8                       u8PercentagePosition,
  253.     teCLD_WindowCovering_Transition eTransition
  254. ) {
  255.     teZCL_Status eStatus;
  256.     tsZCL_EndPointDefinition *psEndPointDefinition;
  257.     tsZCL_ClusterInstance *psClusterInstance;
  258.     tsCLD_WindowCovering *psSharedStruct;
  259.     tsCLD_WindowCoveringCustomDataStructure *psCommon;
  260.  
  261.     /* Find pointers to cluster */
  262.     eStatus = eZCL_FindCluster(
  263.                         CLOSURE_CLUSTER_ID_WINDOWCOVERING,
  264.                         u8SourceEndPointId,
  265.                         TRUE,
  266.                         &psEndPointDefinition,
  267.                         &psClusterInstance,
  268.                         (void*)&psCommon);
  269.  
  270.     if (eStatus != E_ZCL_SUCCESS) {
  271.         return eStatus;
  272.     }
  273.  
  274.     if ((u8PercentagePosition > CLD_WINDOWCOVERING_POSITION_PERCENTAGE_MAX) ||
  275.         (u8PercentagePosition < CLD_WINDOWCOVERING_POSITION_PERCENTAGE_MIN)) {
  276.         return E_ZCL_ERR_INVALID_VALUE;
  277.     }
  278.  
  279.     /* Point to shared struct */
  280.     psSharedStruct = (tsCLD_WindowCovering *)psClusterInstance->pvEndPointSharedStructPtr;
  281.  
  282.     // get EP mutex
  283.     #ifndef COOPERATIVE
  284.         eZCL_GetMutex(psEndPointDefinition);
  285.     #endif
  286.  
  287.     #ifdef CLD_WINDOWCOVERING_ATTR_ID_CURRENT_POSITION_LIFT_PERCENTAGE
  288.         psSharedStruct->u8CurrentPositionLiftPercentage = u8PercentagePosition;
  289.     #endif /* CLD_WINDOWCOVERING_ATTR_ID_CURRENT_POSITION_LIFT_PERCENTAGE */
  290.  
  291.     #ifdef CLD_WINDOWCOVERING_ATTR_ID_CURRENT_POSITION_TILT_PERCENTAGE
  292.         psSharedStruct->u8CurrentPositionTiltPercentage = u8PercentagePosition;
  293.     #endif /* CLD_WINDOWCOVERING_ATTR_ID_CURRENT_POSITION_TILT_PERCENTAGE */
  294.  
  295.     /* Fill Position */
  296.     psCommon->sTransition.u8CurrentPositionPercentage = u8PercentagePosition;
  297.  
  298.     if ((E_CLD_WINDOWCOVERING_TRANSITION_STOP == eTransition) &&
  299.         (psCommon->sTransition.eTransition != eTransition)) {
  300.        
  301.         psCommon->sCustomCallBackEvent.u8EndPoint = psEndPointDefinition->u8EndPointNumber;
  302.         psCommon->sCustomCallBackEvent.psClusterInstance = psClusterInstance;
  303.         psCommon->sCustomCallBackEvent.pZPSevent = NULL;
  304.         psCommon->sCustomCallBackEvent.eEventType = E_ZCL_CBET_CLUSTER_UPDATE;
  305.        
  306.         /* Update target & Transition */
  307.         // 2019.06.18 TrungTQ DEL
  308.         // psCommon->sTransition.eTransition = eTransition;
  309.         // 2019.06.18 TrungTQ END
  310.         psCommon->sTransition.u8TargetPositionPercentage = u8PercentagePosition;
  311.  
  312.         psEndPointDefinition->pCallBackFunctions(&psCommon->sCustomCallBackEvent);
  313.     }
  314.  
  315.     psCommon->sTransition.eTransition = eTransition;
  316.  
  317.     // 2019.06.18 TrungTQ DEL
  318.     /* Update last */
  319.     // psCommon->sTransition.u8LastPositionPercentage = u8PercentagePosition;
  320.     // 2019.06.18 TrungTQ END
  321.  
  322.     /* release EP */
  323.     #ifndef COOPERATIVE
  324.         eZCL_ReleaseMutex(psEndPointDefinition);
  325.     #endif
  326.  
  327.     return E_ZCL_SUCCESS;
  328. }
  329.  
  330. PUBLIC teZCL_Status eCLD_WindowCoveringGetPercentagePosition(
  331.     uint8                       u8SourceEndPointId,
  332.     uint8                       *pu8PercentagePosition
  333. ) {
  334.     teZCL_Status eStatus;
  335.     tsZCL_EndPointDefinition *psEndPointDefinition;
  336.     tsZCL_ClusterInstance *psClusterInstance;
  337.     void *psCustomDataStructure;
  338.  
  339.     /* Find pointers to cluster */
  340.     eStatus = eZCL_FindCluster(
  341.                         CLOSURE_CLUSTER_ID_WINDOWCOVERING,
  342.                         u8SourceEndPointId,
  343.                         TRUE,
  344.                         &psEndPointDefinition,
  345.                         &psClusterInstance,
  346.                         (void*)&psCustomDataStructure);
  347.     if (eStatus != E_ZCL_SUCCESS) {
  348.         return eStatus;
  349.     }
  350.  
  351.     /* Get attribute state */
  352. #ifdef CLD_WINDOWCOVERING_ATTR_ID_CURRENT_POSITION_LIFT_PERCENTAGE
  353.     *pu8PercentagePosition = ((tsCLD_WindowCovering*)(psClusterInstance->pvEndPointSharedStructPtr))->u8CurrentPositionLiftPercentage;
  354. #endif /* CLD_WINDOWCOVERING_ATTR_ID_CURRENT_POSITION_LIFT_PERCENTAGE */
  355.  
  356. #ifdef CLD_WINDOWCOVERING_ATTR_ID_CURRENT_POSITION_TILT_PERCENTAGE
  357.     *pu8PercentagePosition = ((tsCLD_WindowCovering*)(psClusterInstance->pvEndPointSharedStructPtr))->u8CurrentPositionTiltPercentage;
  358. #endif /* CLD_WINDOWCOVERING_ATTR_ID_CURRENT_POSITION_TILT_PERCENTAGE */
  359.  
  360.     return E_ZCL_SUCCESS;
  361. }
  362.  
  363. #endif /* WINDOWCOVERING_SERVER */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement