zcl_lighting.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  1. /**************************************************************************************************
  2. Filename: zcl_lighting.c
  3. Revised: $Date: 2010-02-09 15:28:14 -0800 (Tue, 09 Feb 2010) $
  4. Revision: $Revision: 21679 $
  5. Description: Zigbee Cluster Library - Lighting
  6. Copyright 2006-2010 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_lighting.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 zclLightingCBRec
  54. {
  55. struct zclLightingCBRec *next;
  56. uint8 endpoint; // Used to link it into the endpoint descriptor
  57. zclLighting_AppCallbacks_t *CBs; // Pointer to Callback function
  58. } zclLightingCBRec_t;
  59. /*********************************************************************
  60. * GLOBAL VARIABLES
  61. */
  62. /*********************************************************************
  63. * GLOBAL FUNCTIONS
  64. */
  65. /*********************************************************************
  66. * LOCAL VARIABLES
  67. */
  68. static zclLightingCBRec_t *zclLightingCBs = (zclLightingCBRec_t *)NULL;
  69. static uint8 zclLightingPluginRegisted = FALSE;
  70. /*********************************************************************
  71. * LOCAL FUNCTIONS
  72. */
  73. static ZStatus_t zclLighting_HdlIncoming( zclIncoming_t *pInHdlrMsg );
  74. static ZStatus_t zclLighting_HdlInSpecificCommands( zclIncoming_t *pInMsg );
  75. static zclLighting_AppCallbacks_t *zclLighting_FindCallbacks( uint8 endpoint );
  76. static ZStatus_t zclLighting_ProcessInColorControlCmds( zclIncoming_t *pInMsg, zclLighting_AppCallbacks_t *pCBs );
  77. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveToHue( zclIncoming_t *pInMsg, zclLighting_AppCallbacks_t *pCBs );
  78. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveHue( zclIncoming_t *pInMsg, zclLighting_AppCallbacks_t *pCBs );
  79. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_StepHue( zclIncoming_t *pInMsg, zclLighting_AppCallbacks_t *pCBs );
  80. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveToSaturation( zclIncoming_t *pInMsg, zclLighting_AppCallbacks_t *pCBs );
  81. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveSaturation( zclIncoming_t *pInMsg, zclLighting_AppCallbacks_t *pCBs );
  82. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_StepSaturation( zclIncoming_t *pInMsg, zclLighting_AppCallbacks_t *pCBs );
  83. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveToHueAndSaturation( zclIncoming_t *pInMsg, zclLighting_AppCallbacks_t *pCBs );
  84. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveToColor( zclIncoming_t *pInMsg, zclLighting_AppCallbacks_t *pCBs );
  85. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveColor( zclIncoming_t *pInMsg, zclLighting_AppCallbacks_t *pCBs );
  86. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_StepColor( zclIncoming_t *pInMsg, zclLighting_AppCallbacks_t *pCBs );
  87. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveToColorTemperature( zclIncoming_t *pInMsg, zclLighting_AppCallbacks_t *pCBs );
  88. /*********************************************************************
  89. * @fn zclLighting_RegisterCmdCallbacks
  90. *
  91. * @brief Register an applications command callbacks
  92. *
  93. * @param endpoint - application's endpoint
  94. * @param callbacks - pointer to the callback record.
  95. *
  96. * @return ZMemError if not able to allocate
  97. */
  98. ZStatus_t zclLighting_RegisterCmdCallbacks( uint8 endpoint, zclLighting_AppCallbacks_t *callbacks )
  99. {
  100. zclLightingCBRec_t *pNewItem;
  101. zclLightingCBRec_t *pLoop;
  102. // Register as a ZCL Plugin
  103. if ( zclLightingPluginRegisted == FALSE )
  104. {
  105. zcl_registerPlugin( ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL,
  106. ZCL_CLUSTER_ID_LIGHTING_BALLAST_CONFIG,
  107. zclLighting_HdlIncoming );
  108. zclLightingPluginRegisted = TRUE;
  109. }
  110. // Fill in the new profile list
  111. pNewItem = osal_mem_alloc( sizeof( zclLightingCBRec_t ) );
  112. if ( pNewItem == NULL )
  113. return (ZMemError);
  114. pNewItem->next = (zclLightingCBRec_t *)NULL;
  115. pNewItem->endpoint = endpoint;
  116. pNewItem->CBs = callbacks;
  117. // Find spot in list
  118. if ( zclLightingCBs == NULL )
  119. {
  120. zclLightingCBs = pNewItem;
  121. }
  122. else
  123. {
  124. // Look for end of list
  125. pLoop = zclLightingCBs;
  126. while ( pLoop->next != NULL )
  127. pLoop = pLoop->next;
  128. // Put new item at end of list
  129. pLoop->next = pNewItem;
  130. }
  131. return ( ZSuccess );
  132. }
  133. /*********************************************************************
  134. * @fn zclLighting_ColorControl_Send_MoveToHueCmd
  135. *
  136. * @brief Call to send out a Move To Hue Command
  137. *
  138. * @param srcEP - Sending application's endpoint
  139. * @param dstAddr - where you want the message to go
  140. * @param hue - target hue value
  141. * @param direction - direction of hue change
  142. * @param transitionTime - tame taken to move to the target hue in 1/10 sec increments
  143. * @param disableDefaultRsp - whether to disable the Default Response command
  144. * @param seqNum - sequence number
  145. *
  146. * @return ZStatus_t
  147. */
  148. ZStatus_t zclLighting_ColorControl_Send_MoveToHueCmd( uint8 srcEP, afAddrType_t *dstAddr,
  149. uint8 hue, uint8 direction, uint16 transitionTime,
  150. uint8 disableDefaultRsp, uint8 seqNum )
  151. {
  152. uint8 buf[4];
  153. buf[0] = hue;
  154. buf[1] = direction;
  155. buf[2] = LO_UINT16( transitionTime );
  156. buf[3] = HI_UINT16( transitionTime );
  157. return zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL,
  158. COMMAND_LIGHTING_MOVE_TO_HUE, TRUE,
  159. ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum, 4, buf );
  160. }
  161. /*********************************************************************
  162. * @fn zclLighting_ColorControl_Send_MoveHueCmd
  163. *
  164. * @brief Call to send out a Move To Hue Command
  165. *
  166. * @param srcEP - Sending application's endpoint
  167. * @param dstAddr - where you want the message to go
  168. * @param moveMode - LIGHTING_MOVE_HUE_STOP, LIGHTING_MOVE_HUE_UP,
  169. * LIGHTING_MOVE_HUE_DOWN
  170. * @param rate - the movement in steps per second, where step is
  171. * a change in the device's hue of one unit
  172. * @param disableDefaultRsp - whether to disable the Default Response command
  173. * @param seqNum - sequence number
  174. *
  175. * @return ZStatus_t
  176. */
  177. ZStatus_t zclLighting_ColorControl_Send_MoveHueCmd( uint8 srcEP, afAddrType_t *dstAddr,
  178. uint8 moveMode, uint8 rate,
  179. uint8 disableDefaultRsp, uint8 seqNum )
  180. {
  181. uint8 buf[2];
  182. buf[0] = moveMode;
  183. buf[1] = rate;
  184. return zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL,
  185. COMMAND_LIGHTING_MOVE_HUE, TRUE,
  186. ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum, 2, buf );
  187. }
  188. /*********************************************************************
  189. * @fn zclLighting_ColorControl_Send_StepHueCmd
  190. *
  191. * @brief Call to send out a Step Hue Command
  192. *
  193. * @param srcEP - Sending application's endpoint
  194. * @param dstAddr - where you want the message to go
  195. * @param stepMode - LIGHTING_STEP_HUE_UP, LIGHTING_STEP_HUE_DOWN
  196. * @param stepSize - change to the current value of the device's hue
  197. * @param transitionTime - the movement in steps per 1/10 second
  198. * @param disableDefaultRsp - whether to disable the Default Response command
  199. * @param seqNum - sequence number
  200. *
  201. * @return ZStatus_t
  202. */
  203. ZStatus_t zclLighting_ColorControl_Send_StepHueCmd( uint8 srcEP, afAddrType_t *dstAddr,
  204. uint8 stepMode, uint8 stepSize, uint8 transitionTime,
  205. uint8 disableDefaultRsp, uint8 seqNum )
  206. {
  207. uint8 buf[3];
  208. buf[0] = stepMode;
  209. buf[1] = stepSize;
  210. buf[2] = transitionTime;
  211. return zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL,
  212. COMMAND_LIGHTING_STEP_HUE, TRUE,
  213. ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum, 3, buf );
  214. }
  215. /*********************************************************************
  216. * @fn zclLighting_ColorControl_Send_MoveToSaturationCmd
  217. *
  218. * @brief Call to send out a Move To Saturation Command
  219. *
  220. * @param srcEP - Sending application's endpoint
  221. * @param dstAddr - where you want the message to go
  222. * @param saturation - target saturation value
  223. * @param transitionTime - time taken move to the target saturation,
  224. * in 1/10 second units
  225. * @param disableDefaultRsp - whether to disable the Default Response command
  226. * @param seqNum - sequence number
  227. *
  228. * @return ZStatus_t
  229. */
  230. ZStatus_t zclLighting_ColorControl_Send_MoveToSaturationCmd( uint8 srcEP, afAddrType_t *dstAddr,
  231. uint8 saturation, uint16 transitionTime,
  232. uint8 disableDefaultRsp, uint8 seqNum )
  233. {
  234. uint8 buf[3];
  235. buf[0] = saturation;
  236. buf[1] = LO_UINT16( transitionTime );
  237. buf[2] = HI_UINT16( transitionTime );
  238. return zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL,
  239. COMMAND_LIGHTING_MOVE_TO_SATURATION, TRUE,
  240. ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum, 3, buf );
  241. }
  242. /*********************************************************************
  243. * @fn zclLighting_ColorControl_Send_MoveSaturationCmd
  244. *
  245. * @brief Call to send out a Move Saturation Command
  246. *
  247. * @param srcEP - Sending application's endpoint
  248. * @param dstAddr - where you want the message to go
  249. * @param moveMode - LIGHTING_MOVE_SATURATION_STOP, LIGHTING_MOVE_SATURATION_UP,
  250. * LIGHTING_MOVE_SATURATION_DOWN
  251. * @param rate - rate of movement in step/sec; step is the device's saturation of one unit
  252. * @param disableDefaultRsp - whether to disable the Default Response command
  253. * @param seqNum - sequence number
  254. *
  255. * @return ZStatus_t
  256. */
  257. ZStatus_t zclLighting_ColorControl_Send_MoveSaturationCmd( uint8 srcEP, afAddrType_t *dstAddr,
  258. uint8 moveMode, uint8 rate,
  259. uint8 disableDefaultRsp, uint8 seqNum )
  260. {
  261. uint8 buf[2];
  262. buf[0] = moveMode;
  263. buf[1] = rate;
  264. return zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL,
  265. COMMAND_LIGHTING_MOVE_SATURATION, TRUE,
  266. ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum, 2, buf );
  267. }
  268. /*********************************************************************
  269. * @fn zclLighting_ColorControl_Send_StepSaturationCmd
  270. *
  271. * @brief Call to send out a Step Saturation Command
  272. *
  273. * @param srcEP - Sending application's endpoint
  274. * @param dstAddr - where you want the message to go
  275. * @param stepMode - LIGHTING_STEP_SATURATION_UP, LIGHTING_STEP_SATURATION_DOWN
  276. * @param stepSize - change to the current value of the device's hue
  277. * @param transitionTime - time to perform a single step in 1/10 of second
  278. * @param disableDefaultRsp - whether to disable the Default Response command
  279. * @param seqNum - sequence number
  280. *
  281. * @return ZStatus_t
  282. */
  283. ZStatus_t zclLighting_ColorControl_Send_StepSaturationCmd( uint8 srcEP, afAddrType_t *dstAddr,
  284. uint8 stepMode, uint8 stepSize, uint8 transitionTime,
  285. uint8 disableDefaultRsp, uint8 seqNum )
  286. {
  287. uint8 buf[3];
  288. buf[0] = stepMode;
  289. buf[1] = stepSize;
  290. buf[2] = transitionTime;
  291. return zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL,
  292. COMMAND_LIGHTING_STEP_SATURATION, TRUE,
  293. ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum, 3, buf );
  294. }
  295. /*********************************************************************
  296. * @fn zclLighting_ColorControl_Send_MoveToHueAndSaturationCmd
  297. *
  298. * @brief Call to send out a Move To Hue And Saturation Command
  299. *
  300. * @param srcEP - Sending application's endpoint
  301. * @param dstAddr - where you want the message to go
  302. * @param hue - a target hue
  303. * @param saturation - a target saturation
  304. * @param transitionTime - time to move, equal of the value of the field in 1/10 seconds
  305. * @param disableDefaultRsp - whether to disable the Default Response command
  306. * @param seqNum - sequence number
  307. *
  308. * @return ZStatus_t
  309. */
  310. ZStatus_t zclLighting_ColorControl_Send_MoveToHueAndSaturationCmd( uint8 srcEP, afAddrType_t *dstAddr,
  311. uint8 hue, uint8 saturation, uint16 transitionTime,
  312. uint8 disableDefaultRsp, uint8 seqNum )
  313. {
  314. uint8 buf[4];
  315. buf[0] = hue;
  316. buf[1] = saturation;
  317. buf[2] = LO_UINT16( transitionTime );
  318. buf[3] = HI_UINT16( transitionTime );
  319. return zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL,
  320. COMMAND_LIGHTING_MOVE_TO_HUE_AND_SATURATION, TRUE,
  321. ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum, 4, buf );
  322. }
  323. /*********************************************************************
  324. * @fn zclLighting_ColorControl_Send_MoveToColorCmd
  325. *
  326. * @brief Call to send out a Move To Color Command
  327. *
  328. * @param srcEP - Sending application's endpoint
  329. * @param dstAddr - where you want the message to go
  330. * @param colorX - a target color X
  331. * @param colorY - a target color Y
  332. * @param transitionTime - time to move, equal of the value of the field in 1/10 seconds
  333. * @param disableDefaultRsp - whether to disable the Default Response command
  334. * @param seqNum - sequence number
  335. *
  336. * @return ZStatus_t
  337. */
  338. ZStatus_t zclLighting_ColorControl_Send_MoveToColorCmd( uint8 srcEP, afAddrType_t *dstAddr,
  339. uint16 colorX, uint16 colorY, uint16 transitionTime,
  340. uint8 disableDefaultRsp, uint8 seqNum )
  341. {
  342. uint8 buf[6];
  343. buf[0] = LO_UINT16( colorX );
  344. buf[1] = HI_UINT16( colorX );
  345. buf[2] = LO_UINT16( colorY );
  346. buf[3] = HI_UINT16( colorY );
  347. buf[4] = LO_UINT16( transitionTime );
  348. buf[5] = HI_UINT16( transitionTime );
  349. return zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL,
  350. COMMAND_LIGHTING_MOVE_TO_COLOR, TRUE,
  351. ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum, 6, buf );
  352. }
  353. /*********************************************************************
  354. * @fn zclLighting_ColorControl_Send_MoveColorCmd
  355. *
  356. * @brief Call to send out a Move Color Command
  357. *
  358. * @param srcEP - Sending application's endpoint
  359. * @param dstAddr - where you want the message to go
  360. * @param rateX - rate of movement in steps per second. A step is a change
  361. * in the device's CurrentX attribute of one unit.
  362. * @param rateY - rate of movement in steps per second. A step is a change
  363. * in the device's CurrentY attribute of one unit.
  364. * @param disableDefaultRsp - whether to disable the Default Response command
  365. * @param seqNum - sequence number
  366. *
  367. * @return ZStatus_t
  368. */
  369. ZStatus_t zclLighting_ColorControl_Send_MoveColorCmd( uint8 srcEP, afAddrType_t *dstAddr,
  370. int16 rateX, int16 rateY,
  371. uint8 disableDefaultRsp, uint8 seqNum )
  372. {
  373. uint8 buf[4];
  374. buf[0] = LO_UINT16( rateX );
  375. buf[1] = HI_UINT16( rateX );
  376. buf[2] = LO_UINT16( rateY );
  377. buf[3] = HI_UINT16( rateY );
  378. return zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL,
  379. COMMAND_LIGHTING_MOVE_COLOR, TRUE,
  380. ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum, 4, buf );
  381. }
  382. /*********************************************************************
  383. * @fn zclLighting_ColorControl_Send_StepColorCmd
  384. *
  385. * @brief Call to send out a Step Color Command
  386. *
  387. * @param srcEP - Sending application's endpoint
  388. * @param dstAddr - where you want the message to go
  389. * @param stepX - change to be added to the device's CurrentX attribute
  390. * @param stepY - change to be added to the device's CurrentY attribute
  391. * @param transitionTime - time to perform the color change, equal of
  392. * the value of the field in 1/10 seconds
  393. * @param disableDefaultRsp - whether to disable the Default Response command
  394. * @param seqNum - sequence number
  395. *
  396. * @return ZStatus_t
  397. */
  398. ZStatus_t zclLighting_ColorControl_Send_StepColorCmd( uint8 srcEP, afAddrType_t *dstAddr,
  399. int16 stepX, int16 stepY, uint16 transitionTime,
  400. uint8 disableDefaultRsp, uint8 seqNum )
  401. {
  402. uint8 buf[6];
  403. buf[0] = LO_UINT16( stepX );
  404. buf[1] = HI_UINT16( stepX );
  405. buf[2] = LO_UINT16( stepY );
  406. buf[3] = HI_UINT16( stepY );
  407. buf[4] = LO_UINT16( transitionTime );
  408. buf[5] = HI_UINT16( transitionTime );
  409. return zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL,
  410. COMMAND_LIGHTING_STEP_COLOR, TRUE,
  411. ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum, 6, buf );
  412. }
  413. /*********************************************************************
  414. * @fn zclLighting_ColorControl_Send_MoveToColorTemperatureCmd
  415. *
  416. * @brief Call to send out a Move To Color Temperature Command
  417. *
  418. * @param srcEP - Sending application's endpoint
  419. * @param dstAddr - where you want the message to go
  420. * @param colorTemperature - a target color temperature
  421. * @param transitionTime - time to perform the color change, equal of
  422. * the value of the field in 1/10 seconds
  423. * @param disableDefaultRsp - whether to disable the Default Response command
  424. * @param seqNum - sequence number
  425. *
  426. * @return ZStatus_t
  427. */
  428. ZStatus_t zclLighting_ColorControl_Send_MoveToColorTemperatureCmd( uint8 srcEP, afAddrType_t *dstAddr,
  429. uint16 colorTemperature, uint16 transitionTime,
  430. uint8 disableDefaultRsp, uint8 seqNum )
  431. {
  432. uint8 buf[4];
  433. buf[0] = LO_UINT16( colorTemperature );
  434. buf[1] = HI_UINT16( colorTemperature );
  435. buf[2] = LO_UINT16( transitionTime );
  436. buf[3] = HI_UINT16( transitionTime );
  437. return zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL,
  438. COMMAND_LIGHTING_MOVE_TO_COLOR_TEMPERATURE, TRUE,
  439. ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum, 4, buf );
  440. }
  441. /*********************************************************************
  442. * @fn zclLighting_FindCallbacks
  443. *
  444. * @brief Find the callbacks for an endpoint
  445. *
  446. * @param endpoint - endpoint to find the application callbacks for
  447. *
  448. * @return pointer to the callbacks
  449. */
  450. static zclLighting_AppCallbacks_t *zclLighting_FindCallbacks( uint8 endpoint )
  451. {
  452. zclLightingCBRec_t *pCBs;
  453. pCBs = zclLightingCBs;
  454. while ( pCBs != NULL )
  455. {
  456. if ( pCBs->endpoint == endpoint )
  457. return ( pCBs->CBs );
  458. pCBs = pCBs->next;
  459. }
  460. return ( (zclLighting_AppCallbacks_t *)NULL );
  461. }
  462. /*********************************************************************
  463. * @fn zclLighting_HdlIncoming
  464. *
  465. * @brief Callback from ZCL to process incoming Commands specific
  466. * to this cluster library or Profile commands for attributes
  467. * that aren't in the attribute list
  468. *
  469. * @param pInMsg - pointer to the incoming message
  470. *
  471. * @return ZStatus_t
  472. */
  473. static ZStatus_t zclLighting_HdlIncoming( zclIncoming_t *pInMsg )
  474. {
  475. ZStatus_t stat = ZSuccess;
  476. #if defined ( INTER_PAN )
  477. if ( StubAPS_InterPan( pInMsg->msg->srcAddr.panId, pInMsg->msg->srcAddr.endPoint ) )
  478. return ( stat ); // Cluster not supported thru Inter-PAN
  479. #endif
  480. if ( zcl_ClusterCmd( pInMsg->hdr.fc.type ) )
  481. {
  482. // Is this a manufacturer specific command?
  483. if ( pInMsg->hdr.fc.manuSpecific == 0 )
  484. {
  485. stat = zclLighting_HdlInSpecificCommands( pInMsg );
  486. }
  487. else
  488. {
  489. // We don't support any manufacturer specific command.
  490. stat = ZFailure;
  491. }
  492. }
  493. else
  494. {
  495. // Handle all the normal (Read, Write...) commands -- should never get here
  496. stat = ZFailure;
  497. }
  498. return ( stat );
  499. }
  500. /*********************************************************************
  501. * @fn zclLighting_HdlInSpecificCommands
  502. *
  503. * @brief Callback from ZCL to process incoming Commands specific
  504. * to this cluster library
  505. * @param pInMsg - pointer to the incoming message
  506. *
  507. * @return ZStatus_t
  508. */
  509. static ZStatus_t zclLighting_HdlInSpecificCommands( zclIncoming_t *pInMsg )
  510. {
  511. ZStatus_t stat = ZSuccess;
  512. zclLighting_AppCallbacks_t *pCBs;
  513. // make sure endpoint exists
  514. pCBs = zclLighting_FindCallbacks( pInMsg->msg->endPoint );
  515. if (pCBs == NULL )
  516. return ( ZFailure );
  517. switch ( pInMsg->msg->clusterId )
  518. {
  519. case ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL:
  520. stat = zclLighting_ProcessInColorControlCmds( pInMsg, pCBs );
  521. break;
  522. case ZCL_CLUSTER_ID_LIGHTING_BALLAST_CONFIG:
  523. // no commands
  524. default:
  525. stat = ZFailure;
  526. break;
  527. }
  528. return ( stat );
  529. }
  530. /*********************************************************************
  531. * @fn zclLighting_ProcessInColorControlCmds
  532. *
  533. * @brief Callback from ZCL to process incoming Commands specific
  534. * to this cluster library on a command ID basis
  535. * @param pInMsg - pointer to the incoming message
  536. * @param pCBs - pointer to the application callbacks
  537. *
  538. * @return ZStatus_t
  539. */
  540. static ZStatus_t zclLighting_ProcessInColorControlCmds( zclIncoming_t *pInMsg,
  541. zclLighting_AppCallbacks_t *pCBs )
  542. {
  543. ZStatus_t stat;
  544. switch ( pInMsg->hdr.commandID )
  545. {
  546. case COMMAND_LIGHTING_MOVE_TO_HUE:
  547. stat = zclLighting_ProcessInCmd_ColorControl_MoveToHue( pInMsg, pCBs );
  548. break;
  549. case COMMAND_LIGHTING_MOVE_HUE:
  550. stat = zclLighting_ProcessInCmd_ColorControl_MoveHue( pInMsg, pCBs );
  551. break;
  552. case COMMAND_LIGHTING_STEP_HUE:
  553. stat = zclLighting_ProcessInCmd_ColorControl_StepHue( pInMsg, pCBs );
  554. break;
  555. case COMMAND_LIGHTING_MOVE_TO_SATURATION:
  556. stat = zclLighting_ProcessInCmd_ColorControl_MoveToSaturation( pInMsg, pCBs );
  557. break;
  558. case COMMAND_LIGHTING_MOVE_SATURATION:
  559. stat = zclLighting_ProcessInCmd_ColorControl_MoveSaturation( pInMsg, pCBs );
  560. break;
  561. case COMMAND_LIGHTING_STEP_SATURATION:
  562. stat = zclLighting_ProcessInCmd_ColorControl_StepSaturation( pInMsg, pCBs );
  563. break;
  564. case COMMAND_LIGHTING_MOVE_TO_HUE_AND_SATURATION:
  565. stat = zclLighting_ProcessInCmd_ColorControl_MoveToHueAndSaturation( pInMsg, pCBs );
  566. break;
  567. case COMMAND_LIGHTING_MOVE_TO_COLOR:
  568. stat = zclLighting_ProcessInCmd_ColorControl_MoveToColor( pInMsg, pCBs );
  569. break;
  570. case COMMAND_LIGHTING_MOVE_COLOR:
  571. stat = zclLighting_ProcessInCmd_ColorControl_MoveColor( pInMsg, pCBs );
  572. break;
  573. case COMMAND_LIGHTING_STEP_COLOR:
  574. stat = zclLighting_ProcessInCmd_ColorControl_StepColor( pInMsg, pCBs );
  575. break;
  576. case COMMAND_LIGHTING_MOVE_TO_COLOR_TEMPERATURE:
  577. stat = zclLighting_ProcessInCmd_ColorControl_MoveToColorTemperature( pInMsg, pCBs );
  578. break;
  579. default:
  580. // Unknown command
  581. stat = ZFailure;
  582. break;
  583. }
  584. return ( stat );
  585. }
  586. /*********************************************************************
  587. * @fn zclLighting_ProcessInCmd_ColorControl_MoveToHue
  588. *
  589. * @brief Process in the received Move To Hue Command.
  590. *
  591. * @param pInMsg - pointer to the incoming message
  592. * @param pCBs - pointer to the application callbacks
  593. *
  594. * @return ZStatus_t
  595. */
  596. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveToHue( zclIncoming_t *pInMsg,
  597. zclLighting_AppCallbacks_t *pCBs )
  598. {
  599. if ( pCBs->pfnColorControl_MoveToHue )
  600. {
  601. zclCCMoveToHue_t cmd;
  602. cmd.hue = pInMsg->pData[0];
  603. cmd.direction = pInMsg->pData[1];
  604. cmd.transitionTime = BUILD_UINT16( pInMsg->pData[2], pInMsg->pData[3] );
  605. return ( pCBs->pfnColorControl_MoveToHue( &cmd ) );
  606. }
  607. return ( ZFailure );
  608. }
  609. /*********************************************************************
  610. * @fn zclLighting_ProcessInCmd_ColorControl_MoveHue
  611. *
  612. * @brief Process in the received Move Hue Command.
  613. *
  614. * @param pInMsg - pointer to the incoming message
  615. * @param pCBs - pointer to the application callbacks
  616. *
  617. * @return ZStatus_t
  618. */
  619. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveHue( zclIncoming_t *pInMsg,
  620. zclLighting_AppCallbacks_t *pCBs )
  621. {
  622. zclCCMoveHue_t cmd;
  623. cmd.moveMode = pInMsg->pData[0];
  624. cmd.rate = pInMsg->pData[1];
  625. // If the Rate field has a value of zero, the command has no effect and
  626. // a Default Response command is sent in response, with the status code
  627. // set to INVALID_FIELD.
  628. if ( cmd.rate == 0 )
  629. {
  630. zclDefaultRspCmd_t defaultRspCmd;
  631. defaultRspCmd.commandID = pInMsg->hdr.commandID;
  632. defaultRspCmd.statusCode = ZCL_STATUS_INVALID_FIELD;
  633. zcl_SendDefaultRspCmd( pInMsg->msg->endPoint, &(pInMsg->msg->srcAddr),
  634. pInMsg->msg->clusterId, &defaultRspCmd,
  635. ZCL_FRAME_SERVER_CLIENT_DIR, true, 0, pInMsg->hdr.transSeqNum );
  636. // Don't need the ZCL foundation to generate another Default Response command
  637. return ( ZCL_STATUS_CMD_HAS_RSP );
  638. }
  639. if ( pCBs->pfnColorControl_MoveHue )
  640. return ( pCBs->pfnColorControl_MoveHue( &cmd ) );
  641. return ( ZFailure );
  642. }
  643. /*********************************************************************
  644. * @fn zclLighting_ProcessInCmd_ColorControl_StepHue
  645. *
  646. * @brief Process in the received Step Hue Command.
  647. *
  648. * @param pInMsg - pointer to the incoming message
  649. * @param pCBs - pointer to the application callbacks
  650. *
  651. * @return ZStatus_t
  652. */
  653. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_StepHue( zclIncoming_t *pInMsg,
  654. zclLighting_AppCallbacks_t *pCBs )
  655. {
  656. if ( pCBs->pfnColorControl_StepHue )
  657. {
  658. zclCCStepHue_t cmd;
  659. cmd.stepMode = pInMsg->pData[0];
  660. cmd.stepSize = pInMsg->pData[1];
  661. cmd.transitionTime = pInMsg->pData[2];
  662. return ( pCBs->pfnColorControl_StepHue( &cmd ) );
  663. }
  664. return ( ZFailure );
  665. }
  666. /*********************************************************************
  667. * @fn zclLighting_ProcessInCmd_ColorControl_MoveToSaturation
  668. *
  669. * @brief Process in the received Move to Saturation Command.
  670. *
  671. * @param pInMsg - pointer to the incoming message
  672. * @param pCBs - pointer to the application callbacks
  673. *
  674. * @return ZStatus_t
  675. */
  676. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveToSaturation( zclIncoming_t *pInMsg,
  677. zclLighting_AppCallbacks_t *pCBs )
  678. {
  679. if ( pCBs->pfnColorControl_MoveToSaturation )
  680. {
  681. zclCCMoveToSaturation_t cmd;
  682. cmd.saturation = pInMsg->pData[0];
  683. cmd.transitionTime = BUILD_UINT16( pInMsg->pData[1], pInMsg->pData[2] );
  684. return ( pCBs->pfnColorControl_MoveToSaturation( &cmd ) );
  685. }
  686. return ( ZFailure );
  687. }
  688. /*********************************************************************
  689. * @fn zclLighting_ProcessInCmd_ColorControl_MoveSaturation
  690. *
  691. * @brief Process in the received Move Saturation Command.
  692. *
  693. * @param pInMsg - pointer to the incoming message
  694. * @param pCBs - pointer to the application callbacks
  695. *
  696. * @return ZStatus_t
  697. */
  698. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveSaturation( zclIncoming_t *pInMsg,
  699. zclLighting_AppCallbacks_t *pCBs )
  700. {
  701. zclCCMoveSaturation_t cmd;
  702. cmd.moveMode = pInMsg->pData[0];
  703. cmd.rate = pInMsg->pData[1];
  704. // If the Rate field has a value of zero, the command has no effect and
  705. // a Default Response command is sent in response, with the status code
  706. // set to INVALID_FIELD.
  707. if ( cmd.rate == 0 )
  708. {
  709. zclDefaultRspCmd_t defaultRspCmd;
  710. defaultRspCmd.commandID = pInMsg->hdr.commandID;
  711. defaultRspCmd.statusCode = ZCL_STATUS_INVALID_FIELD;
  712. zcl_SendDefaultRspCmd( pInMsg->msg->endPoint, &(pInMsg->msg->srcAddr),
  713. pInMsg->msg->clusterId, &defaultRspCmd,
  714. ZCL_FRAME_SERVER_CLIENT_DIR, true, 0, pInMsg->hdr.transSeqNum );
  715. // Don't need the ZCL foundation to generate another Default Response command
  716. return ( ZCL_STATUS_CMD_HAS_RSP );
  717. }
  718. if ( pCBs->pfnColorControl_MoveSaturation )
  719. return ( pCBs->pfnColorControl_MoveSaturation( &cmd ) );
  720. return ( ZFailure );
  721. }
  722. /*********************************************************************
  723. * @fn zclLighting_ProcessInCmd_ColorControl_StepSaturation
  724. *
  725. * @brief Process in the received Step Saturation Command.
  726. *
  727. * @param pInMsg - pointer to the incoming message
  728. * @param pCBs - pointer to the application callbacks
  729. *
  730. * @return ZStatus_t
  731. */
  732. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_StepSaturation( zclIncoming_t *pInMsg,
  733. zclLighting_AppCallbacks_t *pCBs )
  734. {
  735. if ( pCBs->pfnColorControl_StepSaturation )
  736. {
  737. zclCCStepSaturation_t cmd;
  738. cmd.stepMode = pInMsg->pData[0];
  739. cmd.stepSize = pInMsg->pData[1];
  740. cmd.transitionTime = pInMsg->pData[2];
  741. return ( pCBs->pfnColorControl_StepSaturation( &cmd ) );
  742. }
  743. return ( ZFailure );
  744. }
  745. /*********************************************************************
  746. * @fn zclLighting_ProcessInCmd_ColorControl_MoveToHueAndSaturation
  747. *
  748. * @brief Process in the received Move To Hue And Saturation Command.
  749. *
  750. * @param pInMsg - pointer to the incoming message
  751. * @param pCBs - pointer to the application callbacks
  752. *
  753. * @return ZStatus_t
  754. */
  755. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveToHueAndSaturation( zclIncoming_t *pInMsg,
  756. zclLighting_AppCallbacks_t *pCBs )
  757. {
  758. if ( pCBs->pfnColorControl_MoveToHueAndSaturation )
  759. {
  760. zclCCMoveToHueAndSaturation_t cmd;
  761. cmd.hue = pInMsg->pData[0];
  762. cmd.saturation = pInMsg->pData[1];
  763. cmd.transitionTime = BUILD_UINT16( pInMsg->pData[2], pInMsg->pData[3] );
  764. return ( pCBs->pfnColorControl_MoveToHueAndSaturation( &cmd ) );
  765. }
  766. return ( ZFailure );
  767. }
  768. /*********************************************************************
  769. * @fn zclLighting_ProcessInCmd_ColorControl_MoveToColor
  770. *
  771. * @brief Process in the received Move To Color Command.
  772. *
  773. * @param pInMsg - pointer to the incoming message
  774. * @param pCBs - pointer to the application callbacks
  775. *
  776. * @return ZStatus_t
  777. */
  778. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveToColor( zclIncoming_t *pInMsg,
  779. zclLighting_AppCallbacks_t *pCBs )
  780. {
  781. if ( pCBs->pfnColorControl_MoveToColor )
  782. {
  783. zclCCMoveToColor_t cmd;
  784. cmd.colorX = BUILD_UINT16( pInMsg->pData[0], pInMsg->pData[1] );
  785. cmd.colorY = BUILD_UINT16( pInMsg->pData[2], pInMsg->pData[3] );
  786. cmd.transitionTime = BUILD_UINT16( pInMsg->pData[4], pInMsg->pData[5] );
  787. return ( pCBs->pfnColorControl_MoveToColor( &cmd ) );
  788. }
  789. return ( ZFailure );
  790. }
  791. /*********************************************************************
  792. * @fn zclLighting_ProcessInCmd_ColorControl_MoveColor
  793. *
  794. * @brief Process in the received Move Color Command.
  795. *
  796. * @param pInMsg - pointer to the incoming message
  797. * @param pCBs - pointer to the application callbacks
  798. *
  799. * @return ZStatus_t
  800. */
  801. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveColor( zclIncoming_t *pInMsg,
  802. zclLighting_AppCallbacks_t *pCBs )
  803. {
  804. if ( pCBs->pfnColorControl_MoveColor )
  805. {
  806. zclCCMoveColor_t cmd;
  807. cmd.rateX = BUILD_UINT16( pInMsg->pData[0], pInMsg->pData[1] );
  808. cmd.rateY = BUILD_UINT16( pInMsg->pData[2], pInMsg->pData[3] );
  809. pCBs->pfnColorControl_MoveColor( &cmd );
  810. return ( ZSuccess );
  811. }
  812. return ( ZFailure );
  813. }
  814. /*********************************************************************
  815. * @fn zclLighting_ProcessInCmd_ColorControl_StepColor
  816. *
  817. * @brief Process in the received Step Color Command.
  818. *
  819. * @param pInMsg - pointer to the incoming message
  820. * @param pCBs - pointer to the application callbacks
  821. *
  822. * @return ZStatus_t
  823. */
  824. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_StepColor( zclIncoming_t *pInMsg,
  825. zclLighting_AppCallbacks_t *pCBs )
  826. {
  827. if ( pCBs->pfnColorControl_StepColor )
  828. {
  829. zclCCStepColor_t cmd;
  830. cmd.stepX = BUILD_UINT16( pInMsg->pData[0], pInMsg->pData[1] );
  831. cmd.stepY = BUILD_UINT16( pInMsg->pData[2], pInMsg->pData[3] );
  832. cmd.transitionTime = BUILD_UINT16( pInMsg->pData[4], pInMsg->pData[5] );
  833. return ( pCBs->pfnColorControl_StepColor( &cmd ) );
  834. }
  835. return ( ZFailure );
  836. }
  837. /*********************************************************************
  838. * @fn zclLighting_ProcessInCmd_ColorControl_MoveToColorTemperature
  839. *
  840. * @brief Process in the received Move to Color Temperature Command.
  841. *
  842. * @param pInMsg - pointer to the incoming message
  843. * @param pCBs - pointer to the application callbacks
  844. *
  845. * @return ZStatus_t
  846. */
  847. static ZStatus_t zclLighting_ProcessInCmd_ColorControl_MoveToColorTemperature( zclIncoming_t *pInMsg,
  848. zclLighting_AppCallbacks_t *pCBs )
  849. {
  850. if ( pCBs->pfnColorControl_MoveToColorTemperature )
  851. {
  852. zclCCMoveToColorTemperature_t cmd;
  853. cmd.colorTemperature = BUILD_UINT16( pInMsg->pData[0], pInMsg->pData[1] );
  854. cmd.transitionTime = BUILD_UINT16( pInMsg->pData[2], pInMsg->pData[3] );
  855. return ( pCBs->pfnColorControl_MoveToColorTemperature( &cmd ) );
  856. }
  857. return ( ZFailure );
  858. }
  859. /****************************************************************************
  860. ****************************************************************************/