Advertisement
tranthudo

BasicComandHandler

Jun 4th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 14.91 KB | None | 0 0
  1. /****************************************************************************
  2.  *
  3.  * MODULE:             Basic Cluster
  4.  *
  5.  * COMPONENT:          $RCSfile $
  6.  *
  7.  * AUTHOR:             Lee Mitchell
  8.  *
  9.  * $HeadURL: https://www.collabnet.nxp.com/svn/lprf_sware/Projects/Components/ZCL/Trunk/Clusters/General/Source/BasicCommandHandler.c $
  10.  *
  11.  * REVISION:           $Revision: 65575 $
  12.  *
  13.  * DATED:              $Date: 2014-11-14 12:35:30 +0100 (Fri, 14 Nov 2014) $
  14.  *
  15.  * $LastChangedDate: 2014-11-14 12:35:30 +0100 (Fri, 14 Nov 2014) $
  16.  *
  17.  * $Id: BasicCommandHandler.c 65575 2014-11-14 11:35:30Z nxp57621 $
  18.  *
  19.  * DESCRIPTION:
  20.  * Message event handler functions
  21.  *
  22.  * LAST MODIFIED BY:   $Author: nxp57621 $
  23.  *                     $Modtime: $
  24.  *
  25.  ****************************************************************************
  26.  *
  27.  * This software is owned by NXP B.V. and/or its supplier and is protected
  28.  * under applicable copyright laws. All rights are reserved. We grant You,
  29.  * and any third parties, a license to use this software solely and
  30.  * exclusively on NXP products [NXP Microcontrollers such as JN5168, JN5164,
  31.  * JN5161, JN5148, JN5142, JN5139].
  32.  * You, and any third parties must reproduce the copyright and warranty notice
  33.  * and any other legend of ownership on each  copy or partial copy of the software.
  34.  *
  35.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  36.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  37.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  38.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  39.  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  40.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  41.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  42.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  43.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  44.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  45.  * POSSIBILITY OF SUCH DAMAGE.
  46.  *
  47.  * Copyright NXP B.V. 2012. All rights reserved
  48.  *
  49.  ****************************************************************************/
  50.  
  51. /****************************************************************************/
  52. /***        Include files                                                 ***/
  53. /****************************************************************************/
  54.  
  55. #include <jendefs.h>
  56. #include <string.h>
  57.  
  58. #include "zcl.h"
  59. #include "zcl_customcommand.h"
  60.  
  61. #include "Basic.h"
  62. #include "Basic_internal.h"
  63.  
  64. #include "zcl_options.h"
  65.  
  66. #include "dbg.h"
  67.  
  68. #ifdef DEBUG_CLD_BASIC
  69. #define TRACE_BASIC    TRUE
  70. #else
  71. #define TRACE_BASIC    FALSE
  72. #endif
  73.  
  74. /****************************************************************************/
  75. /***        Macro Definitions                                             ***/
  76. /****************************************************************************/
  77.  
  78. /****************************************************************************/
  79. /***        Type Definitions                                              ***/
  80. /****************************************************************************/
  81.  
  82. /****************************************************************************/
  83. /***        Local Function Prototypes                                     ***/
  84. /****************************************************************************/
  85. #ifdef BASIC_SERVER
  86. #ifdef CLD_BAS_CMD_RESET_TO_FACTORY_DEFAULTS
  87. PRIVATE teZCL_Status eCLD_BasicHandleResetToFactoryDefaultsCommand(
  88.                             ZPS_tsAfEvent               *pZPSevent,
  89.                             tsZCL_EndPointDefinition    *psEndPointDefinition,
  90.                             tsZCL_ClusterInstance       *psClusterInstance);
  91. #endif
  92.  
  93. #ifdef CLD_BAS_CMD_MAN_SPEC_SET_LED_INTENSITY
  94. PRIVATE teZCL_Status eCLD_BasicHandleSetLedIntensityCommand(
  95.                             ZPS_tsAfEvent               *pZPSevent,
  96.                             tsZCL_EndPointDefinition    *psEndPointDefinition,
  97.                             tsZCL_ClusterInstance       *psClusterInstance);
  98. #endif
  99.  
  100. #ifdef CLD_BAS_CMD_MAN_SPEC_SET_VIBRATION_INTENSITY
  101. PRIVATE teZCL_Status eCLD_BasicHandleSetVibrationIntensityCommand(
  102.                             ZPS_tsAfEvent               *pZPSevent,
  103.                             tsZCL_EndPointDefinition    *psEndPointDefinition,
  104.                             tsZCL_ClusterInstance       *psClusterInstance);
  105. #endif
  106.  
  107. #endif
  108.  
  109. /****************************************************************************/
  110. /***        Exported Variables                                            ***/
  111. /****************************************************************************/
  112.  
  113. /****************************************************************************/
  114. /***        Local Variables                                               ***/
  115. /****************************************************************************/
  116.  
  117. /****************************************************************************/
  118. /***        Public Functions                                              ***/
  119. /****************************************************************************/
  120.  
  121. /****************************************************************************
  122.  **
  123.  ** NAME:       eCLD_BasicCommandHandler
  124.  **
  125.  ** DESCRIPTION:
  126.  ** Handles Message Cluster custom commands
  127.  **
  128.  ** PARAMETERS:               Name                      Usage
  129.  ** ZPS_tsAfEvent            *pZPSevent                 Zigbee stack event structure
  130.  ** tsZCL_EndPointDefinition *psEndPointDefinition      EP structure
  131.  ** tsZCL_ClusterInstance    *psClusterInstance         Cluster structure
  132.  **
  133.  ** RETURN:
  134.  ** teZCL_Status
  135.  **
  136.  ****************************************************************************/
  137.  
  138. PUBLIC teZCL_Status eCLD_BasicCommandHandler(
  139.                     ZPS_tsAfEvent               *pZPSevent,
  140.                     tsZCL_EndPointDefinition    *psEndPointDefinition,
  141.                     tsZCL_ClusterInstance       *psClusterInstance)
  142. {
  143.     teZCL_Status eReturnStatus = E_ZCL_SUCCESS;
  144. #ifdef BASIC_SERVER
  145.  
  146.     tsZCL_HeaderParams sZCL_HeaderParams;
  147.     // further error checking can only be done once we have interrogated the ZCL payload
  148.     u16ZCL_ReadCommandHeader(pZPSevent->uEvent.sApsDataIndEvent.hAPduInst,
  149.                              &sZCL_HeaderParams);
  150.  
  151.     // We don't handle messages as a client, so exit
  152.     if(psClusterInstance->bIsServer == FALSE)
  153.     {
  154.         return(E_ZCL_FAIL);
  155.     }
  156.  
  157.     /*
  158.      * The command is successfully qualified for all the errors , now take action
  159.      */
  160.     // get EP mutex
  161.     #ifndef COOPERATIVE
  162.         eZCL_GetMutex(psEndPointDefinition);
  163.     #endif
  164.  
  165.  
  166.     // SERVER
  167.     switch(sZCL_HeaderParams.u8CommandIdentifier)
  168.     {
  169.         #ifdef CLD_BAS_CMD_RESET_TO_FACTORY_DEFAULTS
  170.             case(E_CLD_BASIC_CMD_RESET_TO_FACTORY_DEFAULTS):
  171.             {
  172.                 eCLD_BasicHandleResetToFactoryDefaultsCommand(pZPSevent, psEndPointDefinition, psClusterInstance);
  173.                 eReturnStatus = E_ZCL_SUCCESS;
  174.                 break;
  175.             }
  176.         #endif
  177.  
  178.         #ifdef CLD_BAS_CMD_MAN_SPEC_SET_LED_INTENSITY
  179.             case E_CLD_BASIC_CMD_MAN_SPEC_SET_LED_INTENSITY:
  180.             {
  181.                 eCLD_BasicHandleSetLedIntensityCommand(pZPSevent, psEndPointDefinition, psClusterInstance);
  182.                 eReturnStatus = E_ZCL_SUCCESS;
  183.                 break;
  184.             }
  185.         #endif
  186.  
  187.         #ifdef CLD_BAS_CMD_MAN_SPEC_SET_VIBRATION_INTENSITY
  188.             case E_CLD_BASIC_CMD_MAN_SPEC_SET_VIBRATION_INTENSITY:
  189.             {
  190.                 eCLD_BasicHandleSetVibrationIntensityCommand(pZPSevent, psEndPointDefinition, psClusterInstance);
  191.                 eReturnStatus = E_ZCL_SUCCESS;
  192.                 break;
  193.             }
  194.         #endif
  195.  
  196.  
  197.             default:
  198.             {
  199.                 eReturnStatus = E_ZCL_ERR_CUSTOM_COMMAND_HANDLER_NULL_OR_RETURNED_ERROR;
  200.                 break;
  201.             }
  202.     }
  203.  
  204.     // unlock and return
  205.     #ifndef COOPERATIVE
  206.         eZCL_ReleaseMutex(psEndPointDefinition);
  207.     #endif
  208.  
  209.  
  210. #endif
  211.  
  212.     // delete the i/p buffer on return
  213.     return(eReturnStatus);
  214.  
  215. }
  216.  
  217. /****************************************************************************/
  218. /***        Private Functions                                             ***/
  219. /****************************************************************************/
  220. #ifdef BASIC_SERVER
  221. /****************************************************************************
  222.  **
  223.  ** NAME:       eCLD_BasicHandleResetToFactoryDefaultsCommand
  224.  **
  225.  ** DESCRIPTION:
  226.  ** Handles Reset To Factory Defaults Command
  227.  **
  228.  ** PARAMETERS:               Name                      Usage
  229.  ** ZPS_tsAfEvent            *pZPSevent                 Zigbee stack event structure
  230.  ** tsZCL_EndPointDefinition *psEndPointDefinition      EP structure
  231.  ** tsZCL_ClusterInstance    *psClusterInstance         Cluster structure
  232.  **
  233.  ** RETURN:
  234.  ** teZCL_Status
  235.  **
  236.  ****************************************************************************/
  237. #ifdef CLD_BAS_CMD_RESET_TO_FACTORY_DEFAULTS
  238. PRIVATE teZCL_Status eCLD_BasicHandleResetToFactoryDefaultsCommand(
  239.                             ZPS_tsAfEvent               *pZPSevent,
  240.                             tsZCL_EndPointDefinition    *psEndPointDefinition,
  241.                             tsZCL_ClusterInstance       *psClusterInstance)
  242. {
  243.  
  244.     teZCL_Status eStatus;
  245.     uint8   u8TransactionSequenceNumber;
  246.  
  247.     tsZCL_CallBackEvent sBasicCustomCallBackEvent;
  248.     tsCLD_BasicCallBackMessage sBasicCallBackMessage;
  249.  
  250.     /* Receive the command */
  251.     eStatus = eCLD_BasicCommandResetToFactoryDefaultsReceive(
  252.                                             pZPSevent,
  253.                                             &u8TransactionSequenceNumber);
  254.     if(eStatus != E_ZCL_SUCCESS)
  255.     {
  256.         return eStatus;
  257.     }
  258.  
  259.     // fill in callback event structure
  260.     eZCL_SetCustomCallBackEvent(&sBasicCustomCallBackEvent, pZPSevent, u8TransactionSequenceNumber, psEndPointDefinition->u8EndPointNumber);
  261.     sBasicCustomCallBackEvent.eEventType = E_ZCL_CBET_CLUSTER_CUSTOM;
  262.     sBasicCustomCallBackEvent.uMessage.sClusterCustomMessage.u16ClusterId = psClusterInstance->psClusterDefinition->u16ClusterEnum;
  263.     sBasicCustomCallBackEvent.uMessage.sClusterCustomMessage.pvCustomData = (void *)&sBasicCallBackMessage;
  264.     sBasicCustomCallBackEvent.psClusterInstance = psClusterInstance;
  265.  
  266.     /* Fill in message */
  267.     sBasicCallBackMessage.u8CommandId = E_CLD_BASIC_CMD_RESET_TO_FACTORY_DEFAULTS;
  268.  
  269.     // call callback
  270.     psEndPointDefinition->pCallBackFunctions(&sBasicCustomCallBackEvent);
  271.  
  272.     return E_ZCL_SUCCESS;
  273. }
  274. #endif
  275.  
  276. #ifdef CLD_BAS_CMD_MAN_SPEC_SET_LED_INTENSITY
  277. PRIVATE teZCL_Status eCLD_BasicHandleSetLedIntensityCommand(
  278.                             ZPS_tsAfEvent               *pZPSevent,
  279.                             tsZCL_EndPointDefinition    *psEndPointDefinition,
  280.                             tsZCL_ClusterInstance       *psClusterInstance)
  281. {
  282.  
  283.     teZCL_Status eStatus;
  284.     uint8   u8TransactionSequenceNumber;
  285.     tsCLD_Basic_SetLedIntensityPayload sPayload = {0};
  286.     tsCLD_Basic *psSharedStruct = (tsCLD_Basic *)psClusterInstance->pvEndPointSharedStructPtr;
  287.  
  288.     tsZCL_CallBackEvent sBasicCustomCallBackEvent;
  289.     tsCLD_BasicCallBackMessage sBasicCallBackMessage;
  290.  
  291.     /* Receive the command */
  292.     eStatus = eCLD_BasicCommandSetLedIntensityReceive(
  293.                                             pZPSevent,
  294.                                             &u8TransactionSequenceNumber,
  295.                                             &sPayload);
  296.     if(eStatus != E_ZCL_SUCCESS)
  297.     {
  298.         return eStatus;
  299.     }
  300.  
  301.     /* Set LED intensity level */
  302. #ifdef CLD_BAS_ATTR_MAN_SPEC_LED_INTENSITY
  303.     psSharedStruct->u8LedIntensity = sPayload.u8IntensityLevel;
  304. #endif
  305.  
  306.     // fill in callback event structure
  307.     eZCL_SetCustomCallBackEvent(&sBasicCustomCallBackEvent, pZPSevent, u8TransactionSequenceNumber, psEndPointDefinition->u8EndPointNumber);
  308.     sBasicCustomCallBackEvent.eEventType = E_ZCL_CBET_CLUSTER_CUSTOM;
  309.     sBasicCustomCallBackEvent.uMessage.sClusterCustomMessage.u16ClusterId = psClusterInstance->psClusterDefinition->u16ClusterEnum;
  310.     sBasicCustomCallBackEvent.uMessage.sClusterCustomMessage.pvCustomData = (void *)&sBasicCallBackMessage;
  311.     sBasicCustomCallBackEvent.psClusterInstance = psClusterInstance;
  312.  
  313.     /* Fill in message */
  314.     sBasicCallBackMessage.u8CommandId = E_CLD_BASIC_CMD_MAN_SPEC_SET_LED_INTENSITY;
  315.  
  316.     // call callback
  317.     psEndPointDefinition->pCallBackFunctions(&sBasicCustomCallBackEvent);
  318.  
  319.     return E_ZCL_SUCCESS;
  320. }
  321. #endif
  322.  
  323. #ifdef CLD_BAS_CMD_MAN_SPEC_SET_VIBRATION_INTENSITY
  324. PRIVATE teZCL_Status eCLD_BasicHandleSetVibrationIntensityCommand(
  325.                             ZPS_tsAfEvent               *pZPSevent,
  326.                             tsZCL_EndPointDefinition    *psEndPointDefinition,
  327.                             tsZCL_ClusterInstance       *psClusterInstance)
  328. {
  329.  
  330.     teZCL_Status eStatus;
  331.     uint8   u8TransactionSequenceNumber;
  332.     tsCLD_Basic_SetVibrationIntensityPayload sPayload = {0};
  333.     tsCLD_Basic *psSharedStruct = (tsCLD_Basic *)psClusterInstance->pvEndPointSharedStructPtr;
  334.  
  335.     tsZCL_CallBackEvent sBasicCustomCallBackEvent;
  336.     tsCLD_BasicCallBackMessage sBasicCallBackMessage;
  337.  
  338.     /* Receive the command */
  339.     eStatus = eCLD_BasicCommandSetVibrationIntensityReceive(
  340.                                             pZPSevent,
  341.                                             &u8TransactionSequenceNumber,
  342.                                             &sPayload);
  343.     if(eStatus != E_ZCL_SUCCESS)
  344.     {
  345.         return eStatus;
  346.     }
  347.  
  348.     /* Set LED intensity level */
  349. #ifdef CLD_BAS_ATTR_MAN_SPEC_VIBRATION_INTENSITY
  350.     psSharedStruct->u8VibrationIntensity = sPayload.u8IntensityLevel;
  351. #endif
  352.  
  353.     // fill in callback event structure
  354.     eZCL_SetCustomCallBackEvent(&sBasicCustomCallBackEvent, pZPSevent, u8TransactionSequenceNumber, psEndPointDefinition->u8EndPointNumber);
  355.     sBasicCustomCallBackEvent.eEventType = E_ZCL_CBET_CLUSTER_CUSTOM;
  356.     sBasicCustomCallBackEvent.uMessage.sClusterCustomMessage.u16ClusterId = psClusterInstance->psClusterDefinition->u16ClusterEnum;
  357.     sBasicCustomCallBackEvent.uMessage.sClusterCustomMessage.pvCustomData = (void *)&sBasicCallBackMessage;
  358.     sBasicCustomCallBackEvent.psClusterInstance = psClusterInstance;
  359.  
  360.     /* Fill in message */
  361.     sBasicCallBackMessage.u8CommandId = E_CLD_BASIC_CMD_MAN_SPEC_SET_VIBRATION_INTENSITY;
  362.  
  363.     // call callback
  364.     psEndPointDefinition->pCallBackFunctions(&sBasicCustomCallBackEvent);
  365.  
  366.     return E_ZCL_SUCCESS;
  367. }
  368. #endif
  369.  
  370. #endif
  371. /****************************************************************************/
  372. /***        END OF FILE                                                   ***/
  373. /****************************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement