zcl_hvac.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /**************************************************************************************************
  2. Filename: zcl_hvac.c
  3. Revised: $Date: 2011-05-19 11:53:12 -0700 (Thu, 19 May 2011) $
  4. Revision: $Revision: 26031 $
  5. Description: Zigbee Cluster Library - HVAC
  6. Copyright 2006-2011 Texas Instruments Incorporated. All rights reserved.
  7. IMPORTANT: Your use of this Software is limited to those specific rights
  8. granted under the terms of a software license agreement between the user
  9. who downloaded the software, his/her employer (which must be your employer)
  10. and Texas Instruments Incorporated (the "License"). You may not use this
  11. Software unless you agree to abide by the terms of the License. The License
  12. limits your use, and you acknowledge, that the Software may not be modified,
  13. copied or distributed unless embedded on a Texas Instruments microcontroller
  14. or used solely and exclusively in conjunction with a Texas Instruments radio
  15. frequency transceiver, which is integrated into your product. Other than for
  16. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  17. works of, modify, distribute, perform, display or sell this Software and/or
  18. its documentation for any purpose.
  19. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  20. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  21. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  22. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  23. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  24. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  25. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  26. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  27. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  28. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  29. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  30. Should you have any questions regarding your right to use this Software,
  31. contact Texas Instruments Incorporated at www.TI.com.
  32. **************************************************************************************************/
  33. /*********************************************************************
  34. * INCLUDES
  35. */
  36. #include "ZComDef.h"
  37. #include "OSAL.h"
  38. #include "zcl.h"
  39. #include "zcl_general.h"
  40. #include "zcl_hvac.h"
  41. #if defined ( INTER_PAN )
  42. #include "stub_aps.h"
  43. #endif
  44. /*********************************************************************
  45. * MACROS
  46. */
  47. /*********************************************************************
  48. * CONSTANTS
  49. */
  50. /*********************************************************************
  51. * TYPEDEFS
  52. */
  53. typedef struct zclHVACCBRec
  54. {
  55. struct zclHVACCBRec *next;
  56. uint8 endpoint; // Used to link it into the endpoint descriptor
  57. zclHVAC_AppCallbacks_t *CBs; // Pointer to Callback function
  58. } zclHVACCBRec_t;
  59. /*********************************************************************
  60. * GLOBAL VARIABLES
  61. */
  62. /*********************************************************************
  63. * GLOBAL FUNCTIONS
  64. */
  65. /*********************************************************************
  66. * LOCAL VARIABLES
  67. */
  68. static zclHVACCBRec_t *zclHVACCBs = (zclHVACCBRec_t *)NULL;
  69. static uint8 zclHVACPluginRegisted = FALSE;
  70. /*********************************************************************
  71. * LOCAL FUNCTIONS
  72. */
  73. static ZStatus_t zclHVAC_HdlIncoming( zclIncoming_t *pInMsg );
  74. static ZStatus_t zclHVAC_HdlInSpecificCommands( zclIncoming_t *pInMsg );
  75. static zclHVAC_AppCallbacks_t *zclHVAC_FindCallbacks( uint8 endpoint );
  76. static ZStatus_t zclHVAC_ProcessInPumpCmds( zclIncoming_t *pInMsg );
  77. static ZStatus_t zclHVAC_ProcessInThermostatCmds( zclIncoming_t *pInMsg, zclHVAC_AppCallbacks_t *pCBs );
  78. /*********************************************************************
  79. * @fn zclHVAC_RegisterCmdCallbacks
  80. *
  81. * @brief Register an applications command callbacks
  82. *
  83. * @param endpoint - application's endpoint
  84. * @param callbacks - pointer to the callback record.
  85. *
  86. * @return ZMemError if not able to allocate
  87. */
  88. ZStatus_t zclHVAC_RegisterCmdCallbacks( uint8 endpoint, zclHVAC_AppCallbacks_t *callbacks )
  89. {
  90. zclHVACCBRec_t *pNewItem;
  91. zclHVACCBRec_t *pLoop;
  92. // Register as a ZCL Plugin
  93. if ( !zclHVACPluginRegisted )
  94. {
  95. zcl_registerPlugin( ZCL_CLUSTER_ID_HVAC_PUMP_CONFIG_CONTROL,
  96. ZCL_CLUSTER_ID_HAVC_USER_INTERFACE_CONFIG,
  97. zclHVAC_HdlIncoming );
  98. zclHVACPluginRegisted = TRUE;
  99. }
  100. // Fill in the new profile list
  101. pNewItem = osal_mem_alloc( sizeof( zclHVACCBRec_t ) );
  102. if ( pNewItem == NULL )
  103. return (ZMemError);
  104. pNewItem->next = (zclHVACCBRec_t *)NULL;
  105. pNewItem->endpoint = endpoint;
  106. pNewItem->CBs = callbacks;
  107. // Find spot in list
  108. if ( zclHVACCBs == NULL )
  109. {
  110. zclHVACCBs = pNewItem;
  111. }
  112. else
  113. {
  114. // Look for end of list
  115. pLoop = zclHVACCBs;
  116. while ( pLoop->next != NULL )
  117. pLoop = pLoop->next;
  118. // Put new item at end of list
  119. pLoop->next = pNewItem;
  120. }
  121. return ( ZSuccess );
  122. }
  123. /*********************************************************************
  124. * @fn zclHVAC_SendSetpointRaiseLower
  125. *
  126. * @brief Call to send out a Setpoint Raise/Lower Command
  127. *
  128. * @param srcEP - Sending application's endpoint
  129. * @param dstAddr - where you want the message to go
  130. * @param mode - which setpoint is to be configured
  131. * @param amount - amount setpoint(s) are to be increased (or decreased) by,
  132. * in steps of 0.1°C
  133. * @param seqNum - transaction sequence number
  134. *
  135. * @return ZStatus_t
  136. */
  137. ZStatus_t zclHVAC_SendSetpointRaiseLower( uint8 srcEP, afAddrType_t *dstAddr,
  138. uint8 mode, int8 amount,
  139. uint8 disableDefaultRsp, uint8 seqNum )
  140. {
  141. uint8 buf[2];
  142. buf[0] = mode;
  143. buf[1] = amount;
  144. return zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_HAVC_THERMOSTAT,
  145. COMMAND_THERMOSTAT_SETPOINT_RAISE_LOWER, TRUE,
  146. ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum, 2, buf );
  147. }
  148. /*********************************************************************
  149. * @fn zclHVAC_FindCallbacks
  150. *
  151. * @brief Find the callbacks for an endpoint
  152. *
  153. * @param endpoint
  154. *
  155. * @return pointer to the callbacks
  156. */
  157. static zclHVAC_AppCallbacks_t *zclHVAC_FindCallbacks( uint8 endpoint )
  158. {
  159. zclHVACCBRec_t *pCBs;
  160. pCBs = zclHVACCBs;
  161. while ( pCBs )
  162. {
  163. if ( pCBs->endpoint == endpoint )
  164. return ( pCBs->CBs );
  165. pCBs = pCBs->next;
  166. }
  167. return ( (zclHVAC_AppCallbacks_t *)NULL );
  168. }
  169. /*********************************************************************
  170. * @fn zclHVAC_HdlIncoming
  171. *
  172. * @brief Callback from ZCL to process incoming Commands specific
  173. * to this cluster library or Profile commands for attributes
  174. * that aren't in the attribute list
  175. *
  176. * @param pInMsg - pointer to the incoming message
  177. *
  178. * @return ZStatus_t
  179. */
  180. static ZStatus_t zclHVAC_HdlIncoming( zclIncoming_t *pInMsg )
  181. {
  182. ZStatus_t stat = ZSuccess;
  183. #if defined ( INTER_PAN )
  184. if ( StubAPS_InterPan( pInMsg->msg->srcAddr.panId, pInMsg->msg->srcAddr.endPoint ) )
  185. return ( stat ); // Cluster not supported thru Inter-PAN
  186. #endif
  187. if ( zcl_ClusterCmd( pInMsg->hdr.fc.type ) )
  188. {
  189. // Is this a manufacturer specific command?
  190. if ( pInMsg->hdr.fc.manuSpecific == 0 )
  191. {
  192. stat = zclHVAC_HdlInSpecificCommands( pInMsg );
  193. }
  194. else
  195. {
  196. // We don't support any manufacturer specific command -- ignore it.
  197. stat = ZFailure;
  198. }
  199. }
  200. else
  201. {
  202. // Handle all the normal (Read, Write...) commands -- should never get here
  203. stat = ZFailure;
  204. }
  205. return ( stat );
  206. }
  207. /*********************************************************************
  208. * @fn zclHVAC_HdlInSpecificCommands
  209. *
  210. * @brief Callback from ZCL to process incoming Commands specific
  211. * to this cluster library
  212. * @param pInMsg - pointer to the incoming message
  213. *
  214. * @return ZStatus_t
  215. */
  216. static ZStatus_t zclHVAC_HdlInSpecificCommands( zclIncoming_t *pInMsg )
  217. {
  218. ZStatus_t stat = ZSuccess;
  219. zclHVAC_AppCallbacks_t *pCBs;
  220. // make sure endpoint exists
  221. pCBs = (void*)zclHVAC_FindCallbacks( pInMsg->msg->endPoint );
  222. if ( pCBs == NULL )
  223. return ( ZFailure );
  224. switch ( pInMsg->msg->clusterId )
  225. {
  226. case ZCL_CLUSTER_ID_HVAC_PUMP_CONFIG_CONTROL:
  227. stat = zclHVAC_ProcessInPumpCmds( pInMsg );
  228. break;
  229. case ZCL_CLUSTER_ID_HAVC_THERMOSTAT:
  230. stat = zclHVAC_ProcessInThermostatCmds( pInMsg, pCBs );
  231. break;
  232. default:
  233. stat = ZFailure;
  234. break;
  235. }
  236. return ( stat );
  237. }
  238. /*********************************************************************
  239. * @fn zclHVAC_ProcessInPumpCmds
  240. *
  241. * @brief Callback from ZCL to process incoming Commands specific
  242. * to this cluster library on a command ID basis
  243. * @param pInMsg - pointer to the incoming message
  244. *
  245. * @return ZStatus_t
  246. */
  247. static ZStatus_t zclHVAC_ProcessInPumpCmds( zclIncoming_t *pInMsg )
  248. {
  249. ZStatus_t stat = ZFailure;
  250. // there are no specific command for this cluster yet.
  251. // instead of suppressing a compiler warnings( for a code porting reasons )
  252. // fake unused call here and keep the code skeleton intact
  253. (void)pInMsg;
  254. if ( stat != ZFailure )
  255. zclHVAC_FindCallbacks( 0 );
  256. return ( stat );
  257. }
  258. /*********************************************************************
  259. * @fn zclHVAC_ProcessInThermostatCmds
  260. *
  261. * @brief Callback from ZCL to process incoming Commands specific
  262. * to this cluster library on a command ID basis
  263. * @param pInMsg - pointer to the incoming message
  264. *
  265. * @return ZStatus_t
  266. */
  267. static ZStatus_t zclHVAC_ProcessInThermostatCmds( zclIncoming_t *pInMsg,
  268. zclHVAC_AppCallbacks_t *pCBs )
  269. {
  270. if ( pInMsg->hdr.commandID != COMMAND_THERMOSTAT_SETPOINT_RAISE_LOWER )
  271. return (ZFailure); // Error ignore the command
  272. if ( pCBs->pfnHVAC_SetpointRaiseLower )
  273. {
  274. zclCmdThermostatSetpointRaiseLowerPayload_t cmd;
  275. cmd.mode = pInMsg->pData[0];
  276. cmd.amount = pInMsg->pData[1];
  277. pCBs->pfnHVAC_SetpointRaiseLower( &cmd );
  278. }
  279. return ( ZSuccess );
  280. }
  281. /*********************************************************************
  282. * LOCAL VARIABLES
  283. */
  284. /*********************************************************************
  285. * LOCAL FUNCTIONS
  286. */
  287. /****************************************************************************
  288. ****************************************************************************/