zcl_hvac.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /**************************************************************************************************
  2. Filename: zcl_hvac.c
  3. Revised: $Date: 2007-07-31 09:16:11 -0700 (Tue, 31 Jul 2007) $
  4. Revision: $Revision: 14985 $
  5. Description: Zigbee Cluster Library - HVAC
  6. Copyright 2006-2007 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. * @param seqNum - transaction sequence number
  133. *
  134. * @return ZStatus_t
  135. */
  136. ZStatus_t zclHVAC_SendSetpointRaiseLower( uint8 srcEP, afAddrType_t *dstAddr,
  137. uint8 mode, uint8 amount,
  138. uint8 disableDefaultRsp, uint8 seqNum )
  139. {
  140. uint8 buf[2];
  141. buf[0] = mode;
  142. buf[1] = amount;
  143. return zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_HAVC_THERMOSTAT,
  144. COMMAND_THERMOSTAT_SETPOINT_RAISE_LOWER, TRUE,
  145. ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum, 2, buf );
  146. }
  147. /*********************************************************************
  148. * @fn zclHVAC_FindCallbacks
  149. *
  150. * @brief Find the callbacks for an endpoint
  151. *
  152. * @param endpoint
  153. *
  154. * @return pointer to the callbacks
  155. */
  156. static zclHVAC_AppCallbacks_t *zclHVAC_FindCallbacks( uint8 endpoint )
  157. {
  158. zclHVACCBRec_t *pCBs;
  159. pCBs = zclHVACCBs;
  160. while ( pCBs )
  161. {
  162. if ( pCBs->endpoint == endpoint )
  163. return ( pCBs->CBs );
  164. pCBs = pCBs->next;
  165. }
  166. return ( (zclHVAC_AppCallbacks_t *)NULL );
  167. }
  168. /*********************************************************************
  169. * @fn zclHVAC_HdlIncoming
  170. *
  171. * @brief Callback from ZCL to process incoming Commands specific
  172. * to this cluster library or Profile commands for attributes
  173. * that aren't in the attribute list
  174. *
  175. * @param pInMsg - pointer to the incoming message
  176. *
  177. * @return ZStatus_t
  178. */
  179. static ZStatus_t zclHVAC_HdlIncoming( zclIncoming_t *pInMsg )
  180. {
  181. ZStatus_t stat = ZSuccess;
  182. #if defined ( INTER_PAN )
  183. if ( StubAPS_InterPan( pInMsg->msg->srcAddr.panId, pInMsg->msg->srcAddr.endPoint ) )
  184. return ( stat ); // Cluster not supported thru Inter-PAN
  185. #endif
  186. if ( zcl_ClusterCmd( pInMsg->hdr.fc.type ) )
  187. {
  188. // Is this a manufacturer specific command?
  189. if ( pInMsg->hdr.fc.manuSpecific == 0 )
  190. {
  191. stat = zclHVAC_HdlInSpecificCommands( pInMsg );
  192. }
  193. else
  194. {
  195. // We don't support any manufacturer specific command -- ignore it.
  196. stat = ZFailure;
  197. }
  198. }
  199. else
  200. {
  201. // Handle all the normal (Read, Write...) commands -- should never get here
  202. stat = ZFailure;
  203. }
  204. return ( stat );
  205. }
  206. /*********************************************************************
  207. * @fn zclHVAC_HdlInSpecificCommands
  208. *
  209. * @brief Callback from ZCL to process incoming Commands specific
  210. * to this cluster library
  211. * @param pInMsg - pointer to the incoming message
  212. *
  213. * @return ZStatus_t
  214. */
  215. static ZStatus_t zclHVAC_HdlInSpecificCommands( zclIncoming_t *pInMsg )
  216. {
  217. ZStatus_t stat = ZSuccess;
  218. zclHVAC_AppCallbacks_t *pCBs;
  219. // make sure endpoint exists
  220. pCBs = (void*)zclHVAC_FindCallbacks( pInMsg->msg->endPoint );
  221. if ( pCBs == NULL )
  222. return ( ZFailure );
  223. switch ( pInMsg->msg->clusterId )
  224. {
  225. case ZCL_CLUSTER_ID_HVAC_PUMP_CONFIG_CONTROL:
  226. stat = zclHVAC_ProcessInPumpCmds( pInMsg );
  227. break;
  228. case ZCL_CLUSTER_ID_HAVC_THERMOSTAT:
  229. stat = zclHVAC_ProcessInThermostatCmds( pInMsg, pCBs );
  230. break;
  231. default:
  232. stat = ZFailure;
  233. break;
  234. }
  235. return ( stat );
  236. }
  237. /*********************************************************************
  238. * @fn zclHVAC_ProcessInPumpCmds
  239. *
  240. * @brief Callback from ZCL to process incoming Commands specific
  241. * to this cluster library on a command ID basis
  242. * @param pInMsg - pointer to the incoming message
  243. *
  244. * @return ZStatus_t
  245. */
  246. static ZStatus_t zclHVAC_ProcessInPumpCmds( zclIncoming_t *pInMsg )
  247. {
  248. ZStatus_t stat = ZFailure;
  249. // there are no specific command for this cluster yet.
  250. // instead of suppressing a compiler warnings( for a code porting reasons )
  251. // fake unused call here and keep the code skeleton intact
  252. (void)pInMsg;
  253. if ( stat != ZFailure )
  254. zclHVAC_FindCallbacks( 0 );
  255. return ( stat );
  256. }
  257. /*********************************************************************
  258. * @fn zclHVAC_ProcessInThermostatCmds
  259. *
  260. * @brief Callback from ZCL to process incoming Commands specific
  261. * to this cluster library on a command ID basis
  262. * @param pInMsg - pointer to the incoming message
  263. *
  264. * @return ZStatus_t
  265. */
  266. static ZStatus_t zclHVAC_ProcessInThermostatCmds( zclIncoming_t *pInMsg,
  267. zclHVAC_AppCallbacks_t *pCBs )
  268. {
  269. if ( pInMsg->hdr.commandID != COMMAND_THERMOSTAT_SETPOINT_RAISE_LOWER )
  270. return (ZFailure); // Error ignore the command
  271. if ( pCBs->pfnHVAC_SetpointRaiseLower )
  272. {
  273. zclCmdThermostatSetpointRaiseLowerPayload_t cmd;
  274. cmd.mode = pInMsg->pData[0];
  275. cmd.amount = pInMsg->pData[1];
  276. pCBs->pfnHVAC_SetpointRaiseLower( &cmd );
  277. }
  278. return ( ZSuccess );
  279. }
  280. /*********************************************************************
  281. * LOCAL VARIABLES
  282. */
  283. /*********************************************************************
  284. * LOCAL FUNCTIONS
  285. */
  286. /****************************************************************************
  287. ****************************************************************************/