zcl_sampleswota.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. /**************************************************************************************************
  2. Filename: zcl_sampleswota.c
  3. Revised: $Date: 2010-10-24 18:29:41 -0700 (Sun, 24 Oct 2010) $
  4. Revision: $Revision: 24191 $
  5. Description: Zigbee Cluster Library - sample device application.
  6. Copyright 2006-2009 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. This device will be like an On/Off Switch device. This application
  35. is not intended to be a On/Off Switch device, but will use the device
  36. description to implement this sample code.
  37. *********************************************************************/
  38. /*********************************************************************
  39. * INCLUDES
  40. */
  41. #include "ZComDef.h"
  42. #include "OSAL.h"
  43. #include "AF.h"
  44. #include "ZDApp.h"
  45. #include "ZDObject.h"
  46. #include "ZDProfile.h"
  47. #include "zcl.h"
  48. #include "zcl_general.h"
  49. #include "zcl_ha.h"
  50. #include "zcl_sampleswota.h"
  51. #include "onboard.h"
  52. /* HAL */
  53. #include "hal_lcd.h"
  54. #include "hal_led.h"
  55. #include "hal_key.h"
  56. #include "zcl_ota.h"
  57. #include "hal_ota.h"
  58. /*********************************************************************
  59. * MACROS
  60. */
  61. #define APP_DISC_ENDPOINT 0x08
  62. /*********************************************************************
  63. * CONSTANTS
  64. */
  65. /*********************************************************************
  66. * TYPEDEFS
  67. */
  68. typedef struct
  69. {
  70. uint16 addr;
  71. uint8 endpoint;
  72. } zclSampleSwOta_Server_t;
  73. /*********************************************************************
  74. * GLOBAL VARIABLES
  75. */
  76. #pragma location="PREAMBLE"
  77. const CODE preamble_t OTA_Preamble =
  78. {
  79. 0xFFFFFFFF, // Program Length
  80. OTA_MANUFACTURER_ID, // Manufacturer ID
  81. OTA_TYPE_ID, // Image Type
  82. 0x00000001, // Image Version
  83. };
  84. #pragma required=OTA_Preamble
  85. #pragma location="CRC"
  86. const CODE otaCrc_t OTA_CRC =
  87. {
  88. 0xFFFF, // CRC
  89. 0xFFFF, // CRC Shadow
  90. };
  91. #pragma required=OTA_CRC
  92. byte zclSampleSwOta_TaskID;
  93. static endPointDesc_t appDiscoveryEp =
  94. {
  95. APP_DISC_ENDPOINT,
  96. &zclSampleSwOta_TaskID,
  97. (SimpleDescriptionFormat_t *)&zclSampleSwOta_SimpleDesc,
  98. (afNetworkLatencyReq_t) 0
  99. };
  100. zclSampleSwOta_Server_t zclSampleSwOtaServerList[SAMPLESWOTA_OTA_MAX_SERVERS];
  101. /*********************************************************************
  102. * GLOBAL FUNCTIONS
  103. */
  104. /*********************************************************************
  105. * LOCAL VARIABLES
  106. */
  107. static afAddrType_t zclSampleSwOta_DstAddr;
  108. #define ZCLSAMPLESWOTA_BINDINGLIST 1
  109. static cId_t bindingOutClusters[ZCLSAMPLESWOTA_BINDINGLIST] =
  110. {
  111. ZCL_CLUSTER_ID_GEN_ON_OFF
  112. };
  113. // Test Endpoint to allow SYS_APP_MSGs
  114. static endPointDesc_t sampleSw_TestEp =
  115. {
  116. 20, // Test endpoint
  117. &zclSampleSwOta_TaskID,
  118. (SimpleDescriptionFormat_t *)NULL, // No Simple description for this test endpoint
  119. (afNetworkLatencyReq_t)0 // No Network Latency req
  120. };
  121. uint8 zclSampleSwOta_TransID; // This is the unique message ID (counter)
  122. /*********************************************************************
  123. * LOCAL FUNCTIONS
  124. */
  125. static void zclSampleSwOta_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg );
  126. static void zclSampleSwOta_HandleKeys( byte shift, byte keys );
  127. static void zclSampleSwOta_BasicResetCB( void );
  128. static void zclSampleSwOta_IdentifyCB( zclIdentify_t *pCmd );
  129. static void zclSampleSwOta_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp );
  130. static void zclSampleSwOta_ProcessIdentifyTimeChange( void );
  131. static void zclSampleSwOta_ProcessOTAMsgs( zclOTA_CallbackMsg_t* pMsg );
  132. // Functions to process ZCL Foundation incoming Command/Response messages
  133. static void zclSampleSwOta_ProcessIncomingMsg( zclIncomingMsg_t *msg );
  134. #ifdef ZCL_READ
  135. static uint8 zclSampleSwOta_ProcessInReadRspCmd( zclIncomingMsg_t *pInMsg );
  136. #endif
  137. #ifdef ZCL_WRITE
  138. static uint8 zclSampleSwOta_ProcessInWriteRspCmd( zclIncomingMsg_t *pInMsg );
  139. #endif
  140. static uint8 zclSampleSwOta_ProcessInDefaultRspCmd( zclIncomingMsg_t *pInMsg );
  141. #ifdef ZCL_DISCOVER
  142. static uint8 zclSampleSwOta_ProcessInDiscRspCmd( zclIncomingMsg_t *pInMsg );
  143. #endif
  144. /*********************************************************************
  145. * ZCL General Profile Callback table
  146. */
  147. static zclGeneral_AppCallbacks_t zclSampleSwOta_CmdCallbacks =
  148. {
  149. zclSampleSwOta_BasicResetCB, // Basic Cluster Reset command
  150. zclSampleSwOta_IdentifyCB, // Identify command
  151. zclSampleSwOta_IdentifyQueryRspCB, // Identify Query Response command
  152. NULL, // On / Off cluster command - not needed.
  153. NULL, // Level Control Move to Level command
  154. NULL, // Level Control Move command
  155. NULL, // Level Control Step command
  156. NULL, // Group Response commands
  157. NULL, // Scene Store Request command
  158. NULL, // Scene Recall Request command
  159. NULL, // Scene Response commands
  160. NULL, // Alarm (Response) commands
  161. NULL, // RSSI Location commands
  162. NULL, // RSSI Location Response commands
  163. };
  164. /*********************************************************************
  165. * @fn zclSampleSwOta_Init
  166. *
  167. * @brief Initialization function for the zclGeneral layer.
  168. *
  169. * @param none
  170. *
  171. * @return none
  172. */
  173. void zclSampleSwOta_Init( byte task_id )
  174. {
  175. OTA_ImageHeader_t header;
  176. preamble_t preamble;
  177. zclSampleSwOta_TaskID = task_id;
  178. char lcdBuf[20];
  179. #if HAL_OTA_XNV_IS_SPI
  180. XNV_SPI_INIT();
  181. #endif
  182. // Set destination address to indirect
  183. zclSampleSwOta_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent;
  184. zclSampleSwOta_DstAddr.endPoint = 0;
  185. zclSampleSwOta_DstAddr.addr.shortAddr = 0;
  186. // Read the OTA File Header
  187. HalOTARead(0, (uint8 *)&header, sizeof(OTA_ImageHeader_t), HAL_OTA_DL);
  188. if (header.magicNumber == OTA_HDR_MAGIC_NUMBER)
  189. {
  190. zclOTA_DownloadedFileVersion = header.fileId.version;
  191. zclOTA_DownloadedZigBeeStackVersion = header.stackVersion;
  192. }
  193. // Load the OTA Attributes from the constant values in NV
  194. HalOTARead(PREAMBLE_OFFSET, (uint8 *)&preamble, sizeof(preamble_t), HAL_OTA_RC);
  195. zclOTA_ManufacturerId = preamble.manufacturerId;
  196. zclOTA_ImageType = preamble.imageType;
  197. zclOTA_CurrentFileVersion = preamble.imageVersion;
  198. // This app is part of the Home Automation Profile
  199. zclHA_Init( &zclSampleSwOta_SimpleDesc );
  200. // Register the ZCL General Cluster Library callback functions
  201. zclGeneral_RegisterCmdCallbacks( SAMPLESWOTA_ENDPOINT, &zclSampleSwOta_CmdCallbacks );
  202. // Register the application's attribute list
  203. zcl_registerAttrList( SAMPLESWOTA_ENDPOINT, SAMPLESWOTA_MAX_ATTRIBUTES, zclSampleSwOta_Attrs );
  204. // Register the Application to receive the unprocessed Foundation command/response messages
  205. zcl_registerForMsg( zclSampleSwOta_TaskID );
  206. // Register for all key events - This app will handle all key events
  207. RegisterForKeys( zclSampleSwOta_TaskID );
  208. // Register for callback events from the ZCL OTA
  209. zclOTA_Register(zclSampleSwOta_TaskID);
  210. // Register for a test endpoint
  211. afRegister( &sampleSw_TestEp );
  212. // Register for a test endpoint
  213. afRegister( &appDiscoveryEp );
  214. // Indicate teh current image version on LCD
  215. osal_memset(lcdBuf, ' ', sizeof(lcdBuf));
  216. lcdBuf[19] = '\0';
  217. osal_memcpy(lcdBuf, "Ver: 0x", 7);
  218. _ltoa(zclOTA_CurrentFileVersion, (uint8*)&lcdBuf[7], 16);
  219. HalLcdWriteString(lcdBuf, HAL_LCD_LINE_3);
  220. ZDO_RegisterForZDOMsg( zclSampleSwOta_TaskID, End_Device_Bind_rsp );
  221. ZDO_RegisterForZDOMsg( zclSampleSwOta_TaskID, Match_Desc_rsp );
  222. }
  223. /*********************************************************************
  224. * @fn zclSample_event_loop
  225. *
  226. * @brief Event Loop Processor for zclGeneral.
  227. *
  228. * @param none
  229. *
  230. * @return none
  231. */
  232. uint16 zclSampleSwOta_event_loop( uint8 task_id, uint16 events )
  233. {
  234. afIncomingMSGPacket_t *MSGpkt;
  235. (void)task_id; // Intentionally unreferenced parameter
  236. if ( events & SYS_EVENT_MSG )
  237. {
  238. while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( zclSampleSwOta_TaskID )) )
  239. {
  240. switch ( MSGpkt->hdr.event )
  241. {
  242. case ZCL_OTA_CALLBACK_IND:
  243. zclSampleSwOta_ProcessOTAMsgs( (zclOTA_CallbackMsg_t*)MSGpkt );
  244. break;
  245. case ZCL_INCOMING_MSG:
  246. // Incoming ZCL Foundation command/response messages
  247. zclSampleSwOta_ProcessIncomingMsg( (zclIncomingMsg_t *)MSGpkt );
  248. break;
  249. case ZDO_CB_MSG:
  250. zclSampleSwOta_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt );
  251. break;
  252. case KEY_CHANGE:
  253. zclSampleSwOta_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
  254. break;
  255. default:
  256. break;
  257. }
  258. // Release the memory
  259. osal_msg_deallocate( (uint8 *)MSGpkt );
  260. }
  261. // return unprocessed events
  262. return (events ^ SYS_EVENT_MSG);
  263. }
  264. if ( events & SAMPLESWOTA_IDENTIFY_TIMEOUT_EVT )
  265. {
  266. zclSampleSwOta_IdentifyTime = 10;
  267. zclSampleSwOta_ProcessIdentifyTimeChange();
  268. return ( events ^ SAMPLESWOTA_IDENTIFY_TIMEOUT_EVT );
  269. }
  270. // Discard unknown events
  271. return 0;
  272. }
  273. /*********************************************************************
  274. * @fn zclSampleSwOta_ProcessZDOMsgs()
  275. *
  276. * @brief Process response messages
  277. *
  278. * @param none
  279. *
  280. * @return none
  281. */
  282. void zclSampleSwOta_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg )
  283. {
  284. switch ( inMsg->clusterID )
  285. {
  286. case End_Device_Bind_rsp:
  287. if ( ZDO_ParseBindRsp( inMsg ) == ZSuccess )
  288. {
  289. // Light LED
  290. HalLedSet( HAL_LED_4, HAL_LED_MODE_ON );
  291. }
  292. #if defined(BLINK_LEDS)
  293. else
  294. {
  295. // Flash LED to show failure
  296. HalLedSet ( HAL_LED_4, HAL_LED_MODE_FLASH );
  297. }
  298. #endif
  299. break;
  300. case Match_Desc_rsp:
  301. {
  302. ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( inMsg );
  303. if ( pRsp )
  304. {
  305. if ( pRsp->status == ZSuccess && pRsp->cnt )
  306. {
  307. zclSampleSwOta_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
  308. zclSampleSwOta_DstAddr.addr.shortAddr = pRsp->nwkAddr;
  309. // Take the first endpoint, Can be changed to search through endpoints
  310. zclSampleSwOta_DstAddr.endPoint = pRsp->epList[0];
  311. // Light LED
  312. HalLedSet( HAL_LED_4, HAL_LED_MODE_ON );
  313. }
  314. osal_mem_free( pRsp );
  315. }
  316. }
  317. break;
  318. }
  319. }
  320. /*********************************************************************
  321. * @fn zclSampleSwOta_HandleKeys
  322. *
  323. * @brief Handles all key events for this device.
  324. *
  325. * @param shift - true if in shift/alt.
  326. * @param keys - bit field for key events. Valid entries:
  327. * HAL_KEY_SW_4
  328. * HAL_KEY_SW_3
  329. * HAL_KEY_SW_2
  330. * HAL_KEY_SW_1
  331. *
  332. * @return none
  333. */
  334. static void zclSampleSwOta_HandleKeys( byte shift, byte keys )
  335. {
  336. zAddrType_t dstAddr;
  337. (void)shift; // Intentionally unreferenced parameter
  338. if ( keys & HAL_KEY_SW_1 )
  339. {
  340. // Using this as the "Light Switch"
  341. #ifdef ZCL_ON_OFF
  342. zclGeneral_SendOnOff_CmdToggle( SAMPLESWOTA_ENDPOINT, &zclSampleSwOta_DstAddr, false, 0 );
  343. #endif
  344. }
  345. if ( keys & HAL_KEY_SW_2 )
  346. {
  347. HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
  348. // Initiate an End Device Bind Request, this bind request will
  349. // only use a cluster list that is important to binding.
  350. dstAddr.addrMode = afAddr16Bit;
  351. dstAddr.addr.shortAddr = 0; // Coordinator makes the match
  352. ZDP_EndDeviceBindReq( &dstAddr, NLME_GetShortAddr(),
  353. SAMPLESWOTA_ENDPOINT,
  354. ZCL_HA_PROFILE_ID,
  355. 0, NULL, // No incoming clusters to bind
  356. ZCLSAMPLESWOTA_BINDINGLIST, bindingOutClusters,
  357. TRUE );
  358. }
  359. if ( keys & HAL_KEY_SW_3 )
  360. {
  361. }
  362. if ( keys & HAL_KEY_SW_4 )
  363. {
  364. HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
  365. // Initiate a Match Description Request (Service Discovery)
  366. dstAddr.addrMode = AddrBroadcast;
  367. dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR;
  368. ZDP_MatchDescReq( &dstAddr, NWK_BROADCAST_SHORTADDR,
  369. ZCL_HA_PROFILE_ID,
  370. ZCLSAMPLESWOTA_BINDINGLIST, bindingOutClusters,
  371. 0, NULL, // No incoming clusters to bind
  372. FALSE );
  373. }
  374. }
  375. /*********************************************************************
  376. * @fn zclSampleSwOta_ProcessIdentifyTimeChange
  377. *
  378. * @brief Called to process any change to the IdentifyTime attribute.
  379. *
  380. * @param none
  381. *
  382. * @return none
  383. */
  384. static void zclSampleSwOta_ProcessIdentifyTimeChange( void )
  385. {
  386. if ( zclSampleSwOta_IdentifyTime > 0 )
  387. {
  388. osal_start_timerEx( zclSampleSwOta_TaskID, SAMPLESWOTA_IDENTIFY_TIMEOUT_EVT, 1000 );
  389. HalLedBlink ( HAL_LED_4, 0xFF, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME );
  390. }
  391. else
  392. {
  393. if ( zclSampleSwOta_OnOff )
  394. HalLedSet ( HAL_LED_4, HAL_LED_MODE_ON );
  395. else
  396. HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
  397. osal_stop_timerEx( zclSampleSwOta_TaskID, SAMPLESWOTA_IDENTIFY_TIMEOUT_EVT );
  398. }
  399. }
  400. /*********************************************************************
  401. * @fn zclSampleSwOta_BasicResetCB
  402. *
  403. * @brief Callback from the ZCL General Cluster Library
  404. * to set all the Basic Cluster attributes to default values.
  405. *
  406. * @param none
  407. *
  408. * @return none
  409. */
  410. static void zclSampleSwOta_BasicResetCB( void )
  411. {
  412. }
  413. /*********************************************************************
  414. * @fn zclSampleSwOta_IdentifyCB
  415. *
  416. * @brief Callback from the ZCL General Cluster Library when
  417. * it received an Identity Command for this application.
  418. *
  419. * @param srcAddr - source address and endpoint of the response message
  420. * @param identifyTime - the number of seconds to identify yourself
  421. *
  422. * @return none
  423. */
  424. static void zclSampleSwOta_IdentifyCB( zclIdentify_t *pCmd )
  425. {
  426. zclSampleSwOta_IdentifyTime = pCmd->identifyTime;
  427. zclSampleSwOta_ProcessIdentifyTimeChange();
  428. }
  429. /*********************************************************************
  430. * @fn zclSampleSwOta_IdentifyQueryRspCB
  431. *
  432. * @brief Callback from the ZCL General Cluster Library when
  433. * it received an Identity Query Response Command for this application.
  434. *
  435. * @param srcAddr - source address
  436. * @param timeout - number of seconds to identify yourself (valid for query response)
  437. *
  438. * @return none
  439. */
  440. static void zclSampleSwOta_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp )
  441. {
  442. // Query Response (with timeout value)
  443. (void)pRsp;
  444. }
  445. /******************************************************************************
  446. *
  447. * Functions for processing ZCL Foundation incoming Command/Response messages
  448. *
  449. *****************************************************************************/
  450. /*********************************************************************
  451. * @fn zclSampleSwOta_ProcessIncomingMsg
  452. *
  453. * @brief Process ZCL Foundation incoming message
  454. *
  455. * @param pInMsg - pointer to the received message
  456. *
  457. * @return none
  458. */
  459. static void zclSampleSwOta_ProcessIncomingMsg( zclIncomingMsg_t *pInMsg )
  460. {
  461. switch ( pInMsg->zclHdr.commandID )
  462. {
  463. #ifdef ZCL_READ
  464. case ZCL_CMD_READ_RSP:
  465. zclSampleSwOta_ProcessInReadRspCmd( pInMsg );
  466. break;
  467. #endif
  468. #ifdef ZCL_WRITE
  469. case ZCL_CMD_WRITE_RSP:
  470. zclSampleSwOta_ProcessInWriteRspCmd( pInMsg );
  471. break;
  472. #endif
  473. #ifdef ZCL_REPORT
  474. // See ZCL Test Applicaiton (zcl_testapp.c) for sample code on Attribute Reporting
  475. case ZCL_CMD_CONFIG_REPORT:
  476. //zclSampleSwOta_ProcessInConfigReportCmd( pInMsg );
  477. break;
  478. case ZCL_CMD_CONFIG_REPORT_RSP:
  479. //zclSampleSwOta_ProcessInConfigReportRspCmd( pInMsg );
  480. break;
  481. case ZCL_CMD_READ_REPORT_CFG:
  482. //zclSampleSwOta_ProcessInReadReportCfgCmd( pInMsg );
  483. break;
  484. case ZCL_CMD_READ_REPORT_CFG_RSP:
  485. //zclSampleSwOta_ProcessInReadReportCfgRspCmd( pInMsg );
  486. break;
  487. case ZCL_CMD_REPORT:
  488. //zclSampleSwOta_ProcessInReportCmd( pInMsg );
  489. break;
  490. #endif
  491. case ZCL_CMD_DEFAULT_RSP:
  492. zclSampleSwOta_ProcessInDefaultRspCmd( pInMsg );
  493. break;
  494. #ifdef ZCL_DISCOVER
  495. case ZCL_CMD_DISCOVER_RSP:
  496. zclSampleSwOta_ProcessInDiscRspCmd( pInMsg );
  497. break;
  498. #endif
  499. default:
  500. break;
  501. }
  502. if ( pInMsg->attrCmd )
  503. osal_mem_free( pInMsg->attrCmd );
  504. }
  505. #ifdef ZCL_READ
  506. /*********************************************************************
  507. * @fn zclSampleSwOta_ProcessInReadRspCmd
  508. *
  509. * @brief Process the "Profile" Read Response Command
  510. *
  511. * @param pInMsg - incoming message to process
  512. *
  513. * @return none
  514. */
  515. static uint8 zclSampleSwOta_ProcessInReadRspCmd( zclIncomingMsg_t *pInMsg )
  516. {
  517. zclReadRspCmd_t *readRspCmd;
  518. uint8 i;
  519. readRspCmd = (zclReadRspCmd_t *)pInMsg->attrCmd;
  520. for (i = 0; i < readRspCmd->numAttr; i++)
  521. {
  522. // Notify the originator of the results of the original read attributes
  523. // attempt and, for each successfull request, the value of the requested
  524. // attribute
  525. }
  526. return TRUE;
  527. }
  528. #endif // ZCL_READ
  529. #ifdef ZCL_WRITE
  530. /*********************************************************************
  531. * @fn zclSampleSwOta_ProcessInWriteRspCmd
  532. *
  533. * @brief Process the "Profile" Write Response Command
  534. *
  535. * @param pInMsg - incoming message to process
  536. *
  537. * @return none
  538. */
  539. static uint8 zclSampleSwOta_ProcessInWriteRspCmd( zclIncomingMsg_t *pInMsg )
  540. {
  541. zclWriteRspCmd_t *writeRspCmd;
  542. uint8 i;
  543. writeRspCmd = (zclWriteRspCmd_t *)pInMsg->attrCmd;
  544. for (i = 0; i < writeRspCmd->numAttr; i++)
  545. {
  546. // Notify the device of the results of the its original write attributes
  547. // command.
  548. }
  549. return TRUE;
  550. }
  551. #endif // ZCL_WRITE
  552. /*********************************************************************
  553. * @fn zclSampleSwOta_ProcessInDefaultRspCmd
  554. *
  555. * @brief Process the "Profile" Default Response Command
  556. *
  557. * @param pInMsg - incoming message to process
  558. *
  559. * @return none
  560. */
  561. static uint8 zclSampleSwOta_ProcessInDefaultRspCmd( zclIncomingMsg_t *pInMsg )
  562. {
  563. // zclDefaultRspCmd_t *defaultRspCmd = (zclDefaultRspCmd_t *)pInMsg->attrCmd;
  564. // Device is notified of the Default Response command.
  565. (void)pInMsg;
  566. return TRUE;
  567. }
  568. #ifdef ZCL_DISCOVER
  569. /*********************************************************************
  570. * @fn zclSampleSwOta_ProcessInDiscRspCmd
  571. *
  572. * @brief Process the "Profile" Discover Response Command
  573. *
  574. * @param pInMsg - incoming message to process
  575. *
  576. * @return none
  577. */
  578. static uint8 zclSampleSwOta_ProcessInDiscRspCmd( zclIncomingMsg_t *pInMsg )
  579. {
  580. zclDiscoverRspCmd_t *discoverRspCmd;
  581. uint8 i;
  582. discoverRspCmd = (zclDiscoverRspCmd_t *)pInMsg->attrCmd;
  583. for ( i = 0; i < discoverRspCmd->numAttr; i++ )
  584. {
  585. // Device is notified of the result of its attribute discovery command.
  586. }
  587. return TRUE;
  588. }
  589. #endif // ZCL_DISCOVER
  590. /*********************************************************************
  591. * @fn zclSampleSwOta_ProcessOTAMsgs
  592. *
  593. * @brief Called to process callbacks from the ZCL OTA.
  594. *
  595. * @param none
  596. *
  597. * @return none
  598. */
  599. static void zclSampleSwOta_ProcessOTAMsgs( zclOTA_CallbackMsg_t* pMsg )
  600. {
  601. uint8 RxOnIdle;
  602. switch(pMsg->ota_event)
  603. {
  604. case ZCL_OTA_START_CALLBACK:
  605. if (pMsg->hdr.status == ZSuccess)
  606. {
  607. // Speed up the poll rate
  608. RxOnIdle = TRUE;
  609. ZMacSetReq( ZMacRxOnIdle, &RxOnIdle );
  610. NLME_SetPollRate( 2000 );
  611. }
  612. break;
  613. case ZCL_OTA_DL_COMPLETE_CALLBACK:
  614. if (pMsg->hdr.status == ZSuccess)
  615. {
  616. // Reset the CRC Shadow and reboot. The bootloader will see the
  617. // CRC shadow has been cleared and switch to the new image
  618. HalOTAInvRC();
  619. SystemReset();
  620. }
  621. else
  622. {
  623. // slow the poll rate back down.
  624. RxOnIdle = FALSE;
  625. ZMacSetReq( ZMacRxOnIdle, &RxOnIdle );
  626. NLME_SetPollRate(DEVICE_POLL_RATE);
  627. }
  628. break;
  629. default:
  630. break;
  631. }
  632. }
  633. /****************************************************************************
  634. ****************************************************************************/