pct.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296
  1. /**************************************************************************************************
  2. Filename: pct.c
  3. Revised: $Date: 2012-04-02 17:02:19 -0700 (Mon, 02 Apr 2012) $
  4. Revision: $Revision: 29996 $
  5. Description: This module implements the PCT functionality and contains the
  6. init and event loop functions
  7. Copyright 2009-2012 Texas Instruments Incorporated. All rights reserved.
  8. IMPORTANT: Your use of this Software is limited to those specific rights
  9. granted under the terms of a software license agreement between the user
  10. who downloaded the software, his/her employer (which must be your employer)
  11. and Texas Instruments Incorporated (the "License"). You may not use this
  12. Software unless you agree to abide by the terms of the License. The License
  13. limits your use, and you acknowledge, that the Software may not be modified,
  14. copied or distributed unless embedded on a Texas Instruments microcontroller
  15. or used solely and exclusively in conjunction with a Texas Instruments radio
  16. frequency transceiver, which is integrated into your product. Other than for
  17. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  18. works of, modify, distribute, perform, display or sell this Software and/or
  19. its documentation for any purpose.
  20. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  21. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  22. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  23. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  24. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  25. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  26. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  27. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  28. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  29. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  30. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  31. Should you have any questions regarding your right to use this Software,
  32. contact Texas Instruments Incorporated at www.TI.com.
  33. **************************************************************************************************/
  34. /*********************************************************************
  35. This application is designed for the test purpose of the SE profile which
  36. exploits the following clusters for a PCT configuration:
  37. General Basic
  38. General Alarms
  39. General Time
  40. General Key Establishment
  41. SE Demand Response and Load Control
  42. Key control:
  43. SW1: Join Network
  44. SW2: N/A
  45. SW3: N/A
  46. SW4: N/A
  47. *********************************************************************/
  48. /*********************************************************************
  49. * INCLUDES
  50. */
  51. #include "OSAL.h"
  52. #include "OSAL_Clock.h"
  53. #include "ZDApp.h"
  54. #include "ZDObject.h"
  55. #include "AddrMgr.h"
  56. #include "se.h"
  57. #include "pct.h"
  58. #include "zcl_general.h"
  59. #include "zcl_se.h"
  60. #include "zcl_key_establish.h"
  61. #include "onboard.h"
  62. /* HAL */
  63. #include "hal_lcd.h"
  64. #include "hal_led.h"
  65. #include "hal_key.h"
  66. /*********************************************************************
  67. * MACROS
  68. */
  69. // There is no attribute in the Mandatory Reportable Attribute list for now
  70. #define zcl_MandatoryReportableAttribute( a ) ( a == NULL )
  71. /*********************************************************************
  72. * CONSTANTS
  73. */
  74. #define pctNwkState devState
  75. /*********************************************************************
  76. * TYPEDEFS
  77. */
  78. /*********************************************************************
  79. * GLOBAL VARIABLES
  80. */
  81. /*********************************************************************
  82. * GLOBAL FUNCTIONS
  83. */
  84. /*********************************************************************
  85. * LOCAL VARIABLES
  86. */
  87. static uint8 pctTaskID; // osal task id for load control device
  88. static uint8 pctTransID; // transaction id
  89. static afAddrType_t ESPAddr; // ESP destination address
  90. #if SECURE
  91. static uint8 linkKeyStatus; // status variable from get link key function
  92. #endif
  93. static zclCCReportEventStatus_t rsp; // structure for report event status
  94. /*********************************************************************
  95. * LOCAL FUNCTIONS
  96. */
  97. static void pct_HandleKeys( uint8 shift, uint8 keys );
  98. #if SECURE
  99. static uint8 pct_KeyEstablish_ReturnLinkKey( uint16 shortAddr );
  100. #endif
  101. static void pct_ProcessIdentifyTimeChange( void );
  102. /*************************************************************************/
  103. /*** Application Callback Functions ***/
  104. /*************************************************************************/
  105. // Foundation Callback functions
  106. static uint8 pct_ValidateAttrDataCB( zclAttrRec_t *pAttr, zclWriteRec_t *pAttrInfo );
  107. // General Cluster Callback functions
  108. static void pct_BasicResetCB( void );
  109. static void pct_IdentifyCB( zclIdentify_t *pCmd );
  110. static void pct_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp );
  111. static void pct_AlarmCB( zclAlarm_t *pAlarm );
  112. #ifdef SE_UK_EXT
  113. static void pct_GetEventLogCB( uint8 srcEP, afAddrType_t *srcAddr,
  114. zclGetEventLog_t *pEventLog, uint8 seqNum );
  115. static void pct_PublishEventLogCB( afAddrType_t *srcAddr,
  116. zclPublishEventLog_t *pEventLog );
  117. #endif // SE_UK_EX
  118. // Function to process ZDO callback messages
  119. static void pct_ProcessZDOMsgs( zdoIncomingMsg_t *pMsg );
  120. // SE Callback functions
  121. static void pct_LoadControlEventCB( zclCCLoadControlEvent_t *pCmd,
  122. afAddrType_t *srcAddr, uint8 status, uint8 seqNum );
  123. static void pct_CancelLoadControlEventCB( zclCCCancelLoadControlEvent_t *pCmd,
  124. afAddrType_t *srcAddr, uint8 seqNum );
  125. static void pct_CancelAllLoadControlEventsCB( zclCCCancelAllLoadControlEvents_t *pCmd,
  126. afAddrType_t *srcAddr, uint8 seqNum );
  127. static void pct_ReportEventStatusCB( zclCCReportEventStatus_t *pCmd,
  128. afAddrType_t *srcAddr, uint8 seqNum );
  129. static void pct_GetScheduledEventCB( zclCCGetScheduledEvent_t *pCmd,
  130. afAddrType_t *srcAddr, uint8 seqNum );
  131. #if defined ( SE_UK_EXT )
  132. static void pct_GetPrepaySnapshotResponseCB( zclCCGetPrepaySnapshotResponse_t *pCmd,
  133. afAddrType_t *srcAddr, uint8 seqNum );
  134. static void pct_ChangePaymentModeResponseCB( zclCCChangePaymentModeResponse_t *pCmd,
  135. afAddrType_t *srcAddr, uint8 seqNum );
  136. static void pct_ConsumerTopupResponseCB( zclCCConsumerTopupResponse_t *pCmd,
  137. afAddrType_t *srcAddr, uint8 seqNum );
  138. static void pct_GetCommandsCB( uint8 prepayNotificationFlags,
  139. afAddrType_t *srcAddr, uint8 seqNum );
  140. static void pct_PublishTopupLogCB( zclCCPublishTopupLog_t *pCmd,
  141. afAddrType_t *srcAddr, uint8 seqNum );
  142. static void pct_PublishDebtLogCB( zclCCPublishDebtLog_t *pCmd,
  143. afAddrType_t *srcAddr, uint8 seqNum );
  144. #endif // SE_UK_EXT
  145. /************************************************************************/
  146. /*** Functions to process ZCL Foundation ***/
  147. /*** incoming Command/Response messages ***/
  148. /************************************************************************/
  149. static void pct_ProcessZCLMsg( zclIncomingMsg_t *msg );
  150. #if defined ( ZCL_READ )
  151. static uint8 pct_ProcessInReadRspCmd( zclIncomingMsg_t *pInMsg );
  152. #endif // ZCL_READ
  153. #if defined ( ZCL_WRITE )
  154. static uint8 pct_ProcessInWriteRspCmd( zclIncomingMsg_t *pInMsg );
  155. #endif // ZCL_WRITE
  156. static uint8 pct_ProcessInDefaultRspCmd( zclIncomingMsg_t *pInMsg );
  157. #if defined ( ZCL_DISCOVER )
  158. static uint8 pct_ProcessInDiscRspCmd( zclIncomingMsg_t *pInMsg );
  159. #endif // ZCL_DISCOVER
  160. /*********************************************************************
  161. * ZCL General Clusters Callback table
  162. */
  163. static zclGeneral_AppCallbacks_t pct_GenCmdCallbacks =
  164. {
  165. pct_BasicResetCB, // Basic Cluster Reset command
  166. pct_IdentifyCB, // Identify command
  167. pct_IdentifyQueryRspCB, // Identify Query Response command
  168. NULL, // On/Off cluster commands
  169. NULL, // Level Control Move to Level command
  170. NULL, // Level Control Move command
  171. NULL, // Level Control Step command
  172. NULL, // Level Control Stop command
  173. NULL, // Group Response commands
  174. NULL, // Scene Store Request command
  175. NULL, // Scene Recall Request command
  176. NULL, // Scene Response command
  177. pct_AlarmCB, // Alarm (Response) command
  178. #ifdef SE_UK_EXT
  179. pct_GetEventLogCB, // Get Event Log command
  180. pct_PublishEventLogCB, // Publish Event Log command
  181. #endif
  182. NULL, // RSSI Location command
  183. NULL // RSSI Location Response command
  184. };
  185. /*********************************************************************
  186. * ZCL SE Clusters Callback table
  187. */
  188. static zclSE_AppCallbacks_t pct_SECmdCallbacks =
  189. {
  190. NULL, // Publish Price
  191. NULL, // Publish Block Period
  192. #if defined ( SE_UK_EXT )
  193. NULL, // Publish Tariff Information
  194. NULL, // Publish Price Matrix
  195. NULL, // Publish Block Thresholds
  196. NULL, // Publish Conversion Factor
  197. NULL, // Publish Calorific Value
  198. NULL, // Publish CO2 Value
  199. NULL, // Publish CPP Event
  200. NULL, // Publish Billing Period
  201. NULL, // Publish Consolidated Bill
  202. NULL, // Publish Credit Payment Info
  203. #endif // SE_UK_EXT
  204. NULL, // Get Current Price
  205. NULL, // Get Scheduled Price
  206. NULL, // Price Acknowledgement
  207. NULL, // Get Block Period
  208. #if defined ( SE_UK_EXT )
  209. NULL, // Get Tariff Information
  210. NULL, // Get Price Matrix
  211. NULL, // Get Block Thresholds
  212. NULL, // Get Conversion Factor
  213. NULL, // Get Calorific Value
  214. NULL, // Get CO2 Value
  215. NULL, // Get Billing Period
  216. NULL, // Get Consolidated Bill
  217. NULL, // CPP Event Response
  218. #endif // SE_UK_EXT
  219. pct_LoadControlEventCB, // Load Control Event
  220. pct_CancelLoadControlEventCB, // Cancel Load Control Event
  221. pct_CancelAllLoadControlEventsCB, // Cancel All Load Control Events
  222. pct_ReportEventStatusCB, // Report Event Status
  223. pct_GetScheduledEventCB, // Get Scheduled Event
  224. NULL, // Get Profile Response
  225. NULL, // Request Mirror Command
  226. NULL, // Mirror Remove Command
  227. NULL, // Request Fast Poll Mode Response
  228. #if defined ( SE_UK_EXT )
  229. NULL, // Get Snapshot Response
  230. #endif // SE_UK_EXT
  231. NULL, // Get Profile Command
  232. NULL, // Request Mirror Response
  233. NULL, // Mirror Remove Response
  234. NULL, // Request Fast Poll Mode Command
  235. #if defined ( SE_UK_EXT )
  236. NULL, // Get Snapshot Command
  237. NULL, // Take Snapshot Command
  238. NULL, // Mirror Report Attribute Response
  239. #endif // SE_UK_EXT
  240. NULL, // Display Message Command
  241. NULL, // Cancel Message Command
  242. NULL, // Get Last Message Command
  243. NULL, // Message Confirmation
  244. NULL, // Request Tunnel Response
  245. NULL, // Transfer Data
  246. NULL, // Transfer Data Error
  247. NULL, // Ack Transfer Data
  248. NULL, // Ready Data
  249. #if defined ( SE_UK_EXT )
  250. NULL, // Supported Tunnel Protocols Response
  251. NULL, // Tunnel Closure Notification
  252. #endif // SE_UK_EXT
  253. NULL, // Request Tunnel
  254. NULL, // Close Tunnel
  255. #if defined ( SE_UK_EXT )
  256. NULL, // Get Supported Tunnel Protocols
  257. #endif // SE_UK_EXT
  258. NULL, // Supply Status Response
  259. #if defined ( SE_UK_EXT )
  260. pct_GetPrepaySnapshotResponseCB, // Get Prepay Snapshot Response
  261. pct_ChangePaymentModeResponseCB, // Change Payment Mode Response
  262. pct_ConsumerTopupResponseCB, // Consumer Topup Response
  263. pct_GetCommandsCB, // Get Commands
  264. pct_PublishTopupLogCB, // Publish Topup Log
  265. pct_PublishDebtLogCB, // Publish Debt Log
  266. #endif // SE_UK_EXT
  267. NULL, // Select Available Emergency Credit Command
  268. NULL, // Change Supply Command
  269. #if defined ( SE_UK_EXT )
  270. NULL, // Change Debt
  271. NULL, // Emergency Credit Setup
  272. NULL, // Consumer Topup
  273. NULL, // Credit Adjustment
  274. NULL, // Change PaymentMode
  275. NULL, // Get Prepay Snapshot
  276. NULL, // Get Topup Log
  277. NULL, // Set Low Credit Warning Level
  278. NULL, // Get Debt Repayment Log
  279. NULL, // Publish Calendar
  280. NULL, // Publish Day Profile
  281. NULL, // Publish Week Profile
  282. NULL, // Publish Seasons
  283. NULL, // Publish Special Days
  284. NULL, // Get Calendar
  285. NULL, // Get Day Profiles
  286. NULL, // Get Week Profiles
  287. NULL, // Get Seasons
  288. NULL, // Get Special Days
  289. NULL, // Publish Change Tenancy
  290. NULL, // Publish Change Supplier
  291. NULL, // Change Supply
  292. NULL, // Change Password
  293. NULL, // Local Change Supply
  294. NULL, // Get Change Tenancy
  295. NULL, // Get Change Supplier
  296. NULL, // Get Change Supply
  297. NULL, // Supply Status Response
  298. NULL, // Get Password
  299. #endif // SE_UK_EXT
  300. };
  301. /*********************************************************************
  302. * @fn pct_Init
  303. *
  304. * @brief Initialization function for the ZCL App Application.
  305. *
  306. * @param uint8 task_id - pct task id
  307. *
  308. * @return none
  309. */
  310. void pct_Init( uint8 task_id )
  311. {
  312. pctTaskID = task_id;
  313. // setup ESP destination address
  314. ESPAddr.addrMode = (afAddrMode_t)Addr16Bit;
  315. ESPAddr.endPoint = PCT_ENDPOINT;
  316. ESPAddr.addr.shortAddr = 0;
  317. // register SE endpoint
  318. zclSE_Init( &pctSimpleDesc );
  319. // Register the ZCL General Cluster Library callback functions
  320. zclGeneral_RegisterCmdCallbacks( PCT_ENDPOINT, &pct_GenCmdCallbacks );
  321. // Register the ZCL SE Cluster Library callback functions
  322. zclSE_RegisterCmdCallbacks( PCT_ENDPOINT, &pct_SECmdCallbacks );
  323. // Register the application's attribute list
  324. zcl_registerAttrList( PCT_ENDPOINT, PCT_MAX_ATTRIBUTES, pctAttrs );
  325. // Register the application's cluster option list
  326. zcl_registerClusterOptionList( PCT_ENDPOINT, PCT_MAX_OPTIONS, pctOptions );
  327. // Register the application's attribute data validation callback function
  328. zcl_registerValidateAttrData( pct_ValidateAttrDataCB );
  329. // Register the Application to receive the unprocessed Foundation command/response messages
  330. zcl_registerForMsg( pctTaskID );
  331. // Register for all key events - This app will handle all key events
  332. RegisterForKeys( pctTaskID );
  333. // Register with the ZDO to receive Match Descriptor Responses
  334. ZDO_RegisterForZDOMsg(task_id, Match_Desc_rsp);
  335. // Start the timer to sync LoadControl timer with the osal timer
  336. osal_start_timerEx( pctTaskID, PCT_UPDATE_TIME_EVT, PCT_UPDATE_TIME_PERIOD );
  337. }
  338. /*********************************************************************
  339. * @fn pct_event_loop
  340. *
  341. * @brief Event Loop Processor for PCT
  342. *
  343. * @param uint8 task_id - the osal task id
  344. * @param uint16 events - the event bitmask
  345. *
  346. * @return none
  347. */
  348. uint16 pct_event_loop( uint8 task_id, uint16 events )
  349. {
  350. afIncomingMSGPacket_t *MSGpkt;
  351. if ( events & SYS_EVENT_MSG )
  352. {
  353. while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( pctTaskID )) )
  354. {
  355. switch ( MSGpkt->hdr.event )
  356. {
  357. case ZDO_CB_MSG:
  358. pct_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt );
  359. break;
  360. case ZCL_INCOMING_MSG:
  361. // Incoming ZCL foundation command/response messages
  362. pct_ProcessZCLMsg( (zclIncomingMsg_t *)MSGpkt );
  363. break;
  364. case KEY_CHANGE:
  365. pct_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
  366. break;
  367. case ZDO_STATE_CHANGE:
  368. if (DEV_END_DEVICE == (devStates_t)(MSGpkt->hdr.status))
  369. {
  370. #if SECURE
  371. {
  372. // check to see if link key had already been established
  373. linkKeyStatus = pct_KeyEstablish_ReturnLinkKey(ESPAddr.addr.shortAddr);
  374. if (linkKeyStatus != ZSuccess)
  375. {
  376. cId_t cbkeCluster = ZCL_CLUSTER_ID_GEN_KEY_ESTABLISHMENT;
  377. zAddrType_t dstAddr;
  378. // Send out a match for the key establishment
  379. dstAddr.addrMode = AddrBroadcast;
  380. dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR;
  381. ZDP_MatchDescReq( &dstAddr, NWK_BROADCAST_SHORTADDR, ZCL_SE_PROFILE_ID,
  382. 1, &cbkeCluster, 0, NULL, FALSE );
  383. }
  384. }
  385. #endif
  386. // Per smart energy spec end device polling requirement of not to poll < 7.5 seconds.
  387. NLME_SetPollRate ( SE_DEVICE_POLL_RATE );
  388. }
  389. break;
  390. #if defined( ZCL_KEY_ESTABLISH )
  391. case ZCL_KEY_ESTABLISH_IND:
  392. if ((MSGpkt->hdr.status) == TermKeyStatus_Success)
  393. {
  394. ESPAddr.endPoint = PCT_ENDPOINT; // set destination endpoint back to application endpoint
  395. }
  396. break;
  397. #endif
  398. default:
  399. break;
  400. }
  401. // Release the memory
  402. osal_msg_deallocate( (uint8 *)MSGpkt );
  403. }
  404. // return unprocessed events
  405. return (events ^ SYS_EVENT_MSG);
  406. }
  407. // event to intiate key establishment request
  408. if ( events & PCT_KEY_ESTABLISHMENT_REQUEST_EVT )
  409. {
  410. zclGeneral_KeyEstablish_InitiateKeyEstablishment(pctTaskID, &ESPAddr, pctTransID);
  411. return ( events ^ PCT_KEY_ESTABLISHMENT_REQUEST_EVT );
  412. }
  413. // handle processing of identify timeout event triggered by an identify command
  414. if ( events & PCT_IDENTIFY_TIMEOUT_EVT )
  415. {
  416. if ( pctIdentifyTime > 0 )
  417. {
  418. pctIdentifyTime--;
  419. }
  420. pct_ProcessIdentifyTimeChange();
  421. return ( events ^ PCT_IDENTIFY_TIMEOUT_EVT );
  422. }
  423. // event to get current time
  424. if ( events & PCT_UPDATE_TIME_EVT )
  425. {
  426. pctTime = osal_getClock();
  427. osal_start_timerEx( pctTaskID, PCT_UPDATE_TIME_EVT, PCT_UPDATE_TIME_PERIOD );
  428. return ( events ^ PCT_UPDATE_TIME_EVT );
  429. }
  430. // event to handle pct load control complete event
  431. if ( events & PCT_LOAD_CTRL_EVT )
  432. {
  433. // pct load control evt completed
  434. // Send response back
  435. // DisableDefaultResponse is set to FALSE - it is recommended to turn on
  436. // default response since Report Event Status Command does not have
  437. // a response.
  438. rsp.eventStatus = EVENT_STATUS_LOAD_CONTROL_EVENT_COMPLETED;
  439. zclSE_LoadControl_Send_ReportEventStatus( PCT_ENDPOINT, &ESPAddr,
  440. &rsp, FALSE, pctTransID );
  441. HalLcdWriteString("PCT Evt Complete", HAL_LCD_LINE_3);
  442. HalLedSet(HAL_LED_4, HAL_LED_MODE_OFF);
  443. return ( events ^ PCT_LOAD_CTRL_EVT );
  444. }
  445. // Discard unknown events
  446. return 0;
  447. }
  448. /*********************************************************************
  449. * @fn pct_ProcessZDOMsgs
  450. *
  451. * @brief Called to process callbacks from the ZDO.
  452. *
  453. * @param none
  454. *
  455. * @return none
  456. */
  457. static void pct_ProcessZDOMsgs( zdoIncomingMsg_t *pMsg )
  458. {
  459. if (pMsg->clusterID == Match_Desc_rsp)
  460. {
  461. ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( pMsg );
  462. if (pRsp)
  463. {
  464. if (pRsp->cnt)
  465. {
  466. // Record the trust center
  467. ESPAddr.endPoint = pRsp->epList[0];
  468. ESPAddr.addr.shortAddr = pMsg->srcAddr.addr.shortAddr;
  469. // send out key establishment request
  470. osal_set_event( pctTaskID, PCT_KEY_ESTABLISHMENT_REQUEST_EVT);
  471. }
  472. osal_mem_free(pRsp);
  473. }
  474. }
  475. }
  476. /*********************************************************************
  477. * @fn pct_ProcessIdentifyTimeChange
  478. *
  479. * @brief Called to blink led for specified IdentifyTime attribute value
  480. *
  481. * @param none
  482. *
  483. * @return none
  484. */
  485. static void pct_ProcessIdentifyTimeChange( void )
  486. {
  487. if ( pctIdentifyTime > 0 )
  488. {
  489. osal_start_timerEx( pctTaskID, PCT_IDENTIFY_TIMEOUT_EVT, 1000 );
  490. HalLedBlink ( HAL_LED_4, 0xFF, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME );
  491. }
  492. else
  493. {
  494. HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
  495. osal_stop_timerEx( pctTaskID, PCT_IDENTIFY_TIMEOUT_EVT );
  496. }
  497. }
  498. #if SECURE
  499. /*********************************************************************
  500. * @fn pct_KeyEstablish_ReturnLinkKey
  501. *
  502. * @brief This function get the requested link key
  503. *
  504. * @param shortAddr - short address of the partner.
  505. *
  506. * @return none
  507. */
  508. static uint8 pct_KeyEstablish_ReturnLinkKey( uint16 shortAddr )
  509. {
  510. uint8 status = ZFailure;
  511. AddrMgrEntry_t entry;
  512. // Look up the long address of the device
  513. entry.user = ADDRMGR_USER_DEFAULT;
  514. entry.nwkAddr = shortAddr;
  515. if ( AddrMgrEntryLookupNwk( &entry ) )
  516. {
  517. // check if APS link key has been established
  518. if ( APSME_IsLinkKeyValid( entry.extAddr ) == TRUE )
  519. {
  520. status = ZSuccess;
  521. }
  522. }
  523. else
  524. {
  525. // It's an unknown device
  526. status = ZInvalidParameter;
  527. }
  528. return status;
  529. }
  530. #endif
  531. /*********************************************************************
  532. * @fn pct_HandleKeys
  533. *
  534. * @brief Handles all key events for this device.
  535. *
  536. * @param shift - true if in shift/alt.
  537. * @param keys - bit field for key events. Valid entries:
  538. * HAL_KEY_SW_4
  539. * HAL_KEY_SW_3
  540. * HAL_KEY_SW_2
  541. * HAL_KEY_SW_1
  542. *
  543. * @return none
  544. */
  545. static void pct_HandleKeys( uint8 shift, uint8 keys )
  546. {
  547. // Shift is used to make each button/switch dual purpose.
  548. if ( shift )
  549. {
  550. if ( keys & HAL_KEY_SW_1 )
  551. {
  552. }
  553. if ( keys & HAL_KEY_SW_2 )
  554. {
  555. }
  556. if ( keys & HAL_KEY_SW_3 )
  557. {
  558. }
  559. if ( keys & HAL_KEY_SW_4 )
  560. {
  561. }
  562. }
  563. else
  564. {
  565. if ( keys & HAL_KEY_SW_1 )
  566. {
  567. ZDOInitDevice(0); // join the network
  568. }
  569. if ( keys & HAL_KEY_SW_2 )
  570. {
  571. }
  572. if ( keys & HAL_KEY_SW_3 )
  573. {
  574. }
  575. if ( keys & HAL_KEY_SW_4 )
  576. {
  577. }
  578. }
  579. }
  580. /*********************************************************************
  581. * @fn pct_ValidateAttrDataCB
  582. *
  583. * @brief Check to see if the supplied value for the attribute data
  584. * is within the specified range of the attribute.
  585. *
  586. * @param pAttr - pointer to attribute
  587. * @param pAttrInfo - pointer to attribute info
  588. *
  589. * @return TRUE if data valid. FALSE otherwise.
  590. */
  591. static uint8 pct_ValidateAttrDataCB( zclAttrRec_t *pAttr, zclWriteRec_t *pAttrInfo )
  592. {
  593. uint8 valid = TRUE;
  594. switch ( pAttrInfo->dataType )
  595. {
  596. case ZCL_DATATYPE_BOOLEAN:
  597. if ( ( *(pAttrInfo->attrData) != 0 ) && ( *(pAttrInfo->attrData) != 1 ) )
  598. valid = FALSE;
  599. break;
  600. default:
  601. break;
  602. }
  603. return ( valid );
  604. }
  605. /*********************************************************************
  606. * @fn pct_BasicResetCB
  607. *
  608. * @brief Callback from the ZCL General Cluster Library to set all
  609. * the attributes of all the clusters to their factory defaults
  610. *
  611. * @param none
  612. *
  613. * @return none
  614. */
  615. static void pct_BasicResetCB( void )
  616. {
  617. // user should handle setting attributes to factory defaults here
  618. }
  619. /*********************************************************************
  620. * @fn pct_IdentifyCB
  621. *
  622. * @brief Callback from the ZCL General Cluster Library when
  623. * it received an Identity Command for this application.
  624. *
  625. * @param pCmd - pointer to structure for Identify command
  626. *
  627. * @return none
  628. */
  629. static void pct_IdentifyCB( zclIdentify_t *pCmd )
  630. {
  631. pctIdentifyTime = pCmd->identifyTime;
  632. pct_ProcessIdentifyTimeChange();
  633. }
  634. /*********************************************************************
  635. * @fn pct_IdentifyQueryRspCB
  636. *
  637. * @brief Callback from the ZCL General Cluster Library when
  638. * it received an Identity Query Response Command for this application.
  639. *
  640. * @param pRsp - pointer to structure for Identity Query Response command
  641. *
  642. * @return none
  643. */
  644. static void pct_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp )
  645. {
  646. // add user code here
  647. }
  648. /*********************************************************************
  649. * @fn pct_AlarmCB
  650. *
  651. * @brief Callback from the ZCL General Cluster Library when
  652. * it received an Alarm request or response command for
  653. * this application.
  654. *
  655. * @param pAlarm - pointer to structure for Alarm command
  656. *
  657. * @return none
  658. */
  659. static void pct_AlarmCB( zclAlarm_t *pAlarm )
  660. {
  661. // add user code here
  662. }
  663. #ifdef SE_UK_EXT
  664. /*********************************************************************
  665. * @fn pct_GetEventLogCB
  666. *
  667. * @brief Callback from the ZCL General Cluster Library when
  668. * it received a Get Event Log command for this
  669. * application.
  670. *
  671. * @param srcEP - source endpoint
  672. * @param srcAddr - pointer to source address
  673. * @param pEventLog - pointer to structure for Get Event Log command
  674. * @param seqNum - sequence number of this command
  675. *
  676. * @return none
  677. */
  678. static void pct_GetEventLogCB( uint8 srcEP, afAddrType_t *srcAddr,
  679. zclGetEventLog_t *pEventLog, uint8 seqNum )
  680. {
  681. // add user code here, which could fragment the event log payload if
  682. // the entire payload doesn't fit into one Publish Event Log Command.
  683. // Note: the Command Index starts at 0 and is incremented for each
  684. // fragment belonging to the same command.
  685. // There's no event log for now! The Metering Device will support
  686. // logging for all events configured to do so.
  687. }
  688. /*********************************************************************
  689. * @fn pct_PublishEventLogCB
  690. *
  691. * @brief Callback from the ZCL General Cluster Library when
  692. * it received a Publish Event Log command for this
  693. * application.
  694. *
  695. * @param srcAddr - pointer to source address
  696. * @param pEventLog - pointer to structure for Publish Event Log command
  697. *
  698. * @return none
  699. */
  700. static void pct_PublishEventLogCB( afAddrType_t *srcAddr, zclPublishEventLog_t *pEventLog )
  701. {
  702. // add user code here
  703. }
  704. #endif // SE_UK_EXT
  705. #if defined (ZCL_LOAD_CONTROL)
  706. /*********************************************************************
  707. * @fn pct_SendReportEventStatus
  708. *
  709. * @brief Callback from the ZCL SE Profile Message Cluster Library when
  710. * it received a Load Control Event Command for
  711. * this application.
  712. *
  713. * @param afAddrType_t *srcAddr - pointer to source address
  714. * @param uint8 seqNum - sequence number for this event
  715. * @param uint32 eventID - event ID for this event
  716. * @param uint32 startTime - start time for this event
  717. * @param uint8 eventStatus - status for this event
  718. * @param uint8 criticalityLevel - criticality level for this event
  719. * @param uint8 eventControl - event control for this event
  720. *
  721. * @return none
  722. */
  723. static void pct_SendReportEventStatus( afAddrType_t *srcAddr, uint8 seqNum,
  724. uint32 eventID, uint32 startTime,
  725. uint8 eventStatus, uint8 criticalityLevel,
  726. uint8 eventControl )
  727. {
  728. // Mandatory fields - use the incoming data
  729. rsp.issuerEventID = eventID;
  730. rsp.eventStartTime = startTime;
  731. rsp.criticalityLevelApplied = criticalityLevel;
  732. rsp.eventControl = eventControl;
  733. rsp.eventStatus = eventStatus;
  734. rsp.signatureType = SE_PROFILE_SIGNATURE_TYPE_ECDSA;
  735. // pct_Signature is a static array.
  736. // value can be changed in pct_data.c
  737. osal_memcpy( rsp.signature, pctSignature, SE_PROFILE_SIGNATURE_LENGTH );
  738. // Optional fields - fill in with non-used value by default
  739. rsp.coolingTemperatureSetPointApplied = SE_OPTIONAL_FIELD_TEMPERATURE_SET_POINT;
  740. rsp.heatingTemperatureSetPointApplied = SE_OPTIONAL_FIELD_TEMPERATURE_SET_POINT;
  741. rsp.averageLoadAdjustment = SE_OPTIONAL_FIELD_INT8;
  742. rsp.dutyCycleApplied = SE_OPTIONAL_FIELD_UINT8;
  743. // Send response back
  744. // DisableDefaultResponse is set to FALSE - it is recommended to turn on
  745. // default response since Report Event Status Command does not have
  746. // a response.
  747. zclSE_LoadControl_Send_ReportEventStatus( PCT_ENDPOINT, srcAddr,
  748. &rsp, FALSE, seqNum );
  749. }
  750. #endif // ZCL_LOAD_CONTROL
  751. /*********************************************************************
  752. * @fn pct_LoadControlEventCB
  753. *
  754. * @brief Callback from the ZCL SE Profile Load Contro Cluster Library when
  755. * it received a Load Control Event Command for
  756. * this application.
  757. *
  758. * @param pCmd - pointer to load control event command
  759. * @param srcAddr - pointer to source address
  760. * @param status - event status
  761. * @param seqNum - sequence number of this command
  762. *
  763. * @return none
  764. */
  765. static void pct_LoadControlEventCB( zclCCLoadControlEvent_t *pCmd,
  766. afAddrType_t *srcAddr, uint8 status,
  767. uint8 seqNum)
  768. {
  769. #if defined ( ZCL_LOAD_CONTROL )
  770. // According to the Smart Metering Specification, upon receipt
  771. // of the Load Control Event command, the receiving device shall
  772. // send Report Event Status command back.
  773. uint8 eventStatus;
  774. if ( status == ZCL_STATUS_INVALID_FIELD )
  775. {
  776. // If the incoming message has invalid fields in it
  777. // Send response back with status: rejected
  778. eventStatus = EVENT_STATUS_LOAD_CONTROL_EVENT_REJECTED;
  779. }
  780. else
  781. { // Send response back with status: received
  782. eventStatus = EVENT_STATUS_LOAD_CONTROL_EVENT_RECEIVED;
  783. }
  784. // Send response back
  785. pct_SendReportEventStatus( srcAddr, seqNum, pCmd->issuerEvent,
  786. pCmd->startTime, eventStatus,
  787. pCmd->criticalityLevel, pCmd->eventControl);
  788. if ( status != ZCL_STATUS_INVALID_FIELD )
  789. {
  790. // Start the Load Control Event
  791. if ( pCmd->issuerEvent == LOADCONTROL_EVENT_ID )
  792. {
  793. if ( pCmd->startTime == START_TIME_NOW ) // start time = NOW
  794. {
  795. // send back status event = load control event started
  796. eventStatus = EVENT_STATUS_LOAD_CONTROL_EVENT_STARTED;
  797. pct_SendReportEventStatus( srcAddr, seqNum, pCmd->issuerEvent,
  798. pCmd->startTime, eventStatus,
  799. pCmd->criticalityLevel, pCmd->eventControl);
  800. if ( pCmd->deviceGroupClass == ONOFF_LOAD_DEVICE_CLASS ) // is this one for residential on/off load?
  801. {
  802. HalLcdWriteString("Load Evt Started", HAL_LCD_LINE_3);
  803. }
  804. else if ( pCmd->deviceGroupClass == HVAC_DEVICE_CLASS ) // is this one for HVAC compressor/furnace?
  805. {
  806. HalLcdWriteString("PCT Evt Started", HAL_LCD_LINE_3);
  807. }
  808. HalLedBlink ( HAL_LED_4, 0, 50, 500 );
  809. osal_start_timerEx( pctTaskID, PCT_LOAD_CTRL_EVT,
  810. (PCT_LOAD_CTRL_PERIOD * (pCmd->durationInMinutes)) );
  811. }
  812. }
  813. }
  814. #endif // ZCL_LOAD_CONTROL
  815. }
  816. /*********************************************************************
  817. * @fn pct_CancelLoadControlEventCB
  818. *
  819. * @brief Callback from the ZCL SE Profile Load Control Cluster Library when
  820. * it received a Cancel Load Control Event Command for
  821. * this application.
  822. *
  823. * @param pCmd - pointer to structure for Cancel Load Control Event command
  824. * @param scrAddr - source address
  825. * @param seqNum - sequence number for this command
  826. *
  827. * @return none
  828. */
  829. static void pct_CancelLoadControlEventCB( zclCCCancelLoadControlEvent_t *pCmd,
  830. afAddrType_t *srcAddr, uint8 seqNum )
  831. {
  832. #if defined ( ZCL_LOAD_CONTROL )
  833. if ( 0 ) // User shall replace the if condition with "if the event exist"
  834. {
  835. // If the event exist, stop the event, and respond with status: cancelled
  836. // Cancel the event here
  837. // Use the following sample code to send response back.
  838. /*
  839. pct_SendReportEventStatus( srcAddr, seqNum, pCmd->issuerEventID,
  840. // startTime
  841. EVENT_STATUS_LOAD_CONTROL_EVENT_CANCELLED, // eventStatus
  842. // Criticality level
  843. // eventControl };
  844. */
  845. }
  846. else
  847. {
  848. // If the event does not exist, respond with status: rejected
  849. // The rest of the mandatory fields are not available, therefore,
  850. // set to optional value
  851. pct_SendReportEventStatus( srcAddr, seqNum, pCmd->issuerEventID,
  852. SE_OPTIONAL_FIELD_UINT32, // startTime
  853. EVENT_STATUS_LOAD_CONTROL_EVENT_RECEIVED, // eventStatus
  854. SE_OPTIONAL_FIELD_UINT8, // Criticality level
  855. SE_OPTIONAL_FIELD_UINT8 ); // eventControl
  856. }
  857. #endif // ZCL_LOAD_CONTROL
  858. }
  859. /*********************************************************************
  860. * @fn pct_CancelAllLoadControlEventsCB
  861. *
  862. * @brief Callback from the ZCL SE Profile Load Control Cluster Library when
  863. * it received a Cancel All Load Control Event Command for
  864. * this application.
  865. *
  866. * @param pCmd - pointer to structure for Cancel All Load Control Event command
  867. * @param scrAddr - source address
  868. * @param seqNum - sequence number for this command
  869. *
  870. * @return none
  871. */
  872. static void pct_CancelAllLoadControlEventsCB( zclCCCancelAllLoadControlEvents_t *pCmd,
  873. afAddrType_t *srcAddr, uint8 seqNum )
  874. {
  875. // Upon receipt of Cancel All Load Control Event Command,
  876. // the receiving device shall look up the table for all events
  877. // and send a seperate response for each event
  878. }
  879. /*********************************************************************
  880. * @fn pct_ReportEventStatusCB
  881. *
  882. * @brief Callback from the ZCL SE Profile Load Contro Cluster Library when
  883. * it received a Report Event Status Command for
  884. * this application.
  885. *
  886. * @param pCmd - pointer to structure for Report Event Status command
  887. * @param scrAddr - source address
  888. * @param seqNum - sequence number for this command
  889. *
  890. * @return none
  891. */
  892. static void pct_ReportEventStatusCB( zclCCReportEventStatus_t *pCmd,
  893. afAddrType_t *srcAddr, uint8 seqNum)
  894. {
  895. // add user code here
  896. }
  897. /*********************************************************************
  898. * @fn pct_GetScheduledEventCB
  899. *
  900. * @brief Callback from the ZCL SE Profile Load Control Cluster Library when
  901. * it received a Get Scheduled Event Command for
  902. * this application.
  903. *
  904. * @param pCmd - pointer to structure for Get Scheduled Event command
  905. * @param scrAddr - source address
  906. * @param seqNum - sequence number for this command
  907. *
  908. * @return none
  909. */
  910. static void pct_GetScheduledEventCB( zclCCGetScheduledEvent_t *pCmd,
  911. afAddrType_t *srcAddr, uint8 seqNum )
  912. {
  913. // add user code here
  914. }
  915. #if defined ( SE_UK_EXT )
  916. /*********************************************************************
  917. * @fn pct_GetPrepaySnapshotResponseCB
  918. *
  919. * @brief Callback from the ZCL SE Profile Prepayment Cluster Library when
  920. * it received a Get Prepay Snapshot Response for this application.
  921. *
  922. * @param pCmd - pointer to structure for Get Prepay Snapshot Response command
  923. * @param srcAddr - pointer to source address
  924. * @param seqNum - sequence number of this command
  925. *
  926. * @return none
  927. */
  928. static void pct_GetPrepaySnapshotResponseCB( zclCCGetPrepaySnapshotResponse_t *pCmd,
  929. afAddrType_t *srcAddr, uint8 seqNum )
  930. {
  931. // add user code here
  932. }
  933. /*********************************************************************
  934. * @fn pct_ChangePaymentModeResponseCB
  935. *
  936. * @brief Callback from the ZCL SE Profile Prepayment Cluster Library when
  937. * it received a Change Payment Mode Response for this application.
  938. *
  939. * @param pCmd - pointer to structure for Change Payment Mode Response command
  940. * @param srcAddr - pointer to source address
  941. * @param seqNum - sequence number of this command
  942. *
  943. * @return none
  944. */
  945. static void pct_ChangePaymentModeResponseCB( zclCCChangePaymentModeResponse_t *pCmd,
  946. afAddrType_t *srcAddr, uint8 seqNum )
  947. {
  948. // add user code here
  949. }
  950. /*********************************************************************
  951. * @fn pct_ConsumerTopupResponseCB
  952. *
  953. * @brief Callback from the ZCL SE Profile Prepayment Cluster Library when
  954. * it received a Consumer Topup Response for this application.
  955. *
  956. * @param pCmd - pointer to structure for Consumer Topup Response command
  957. * @param srcAddr - pointer to source address
  958. * @param seqNum - sequence number of this command
  959. *
  960. * @return none
  961. */
  962. static void pct_ConsumerTopupResponseCB( zclCCConsumerTopupResponse_t *pCmd,
  963. afAddrType_t *srcAddr, uint8 seqNum )
  964. {
  965. // add user code here
  966. }
  967. /*********************************************************************
  968. * @fn pct_GetCommandsCB
  969. *
  970. * @brief Callback from the ZCL SE Profile Prepayment Cluster Library when
  971. * it received a Get Commands for this application.
  972. *
  973. * @param prepayNotificationFlags - prepayment notification flags
  974. * @param srcAddr - pointer to source address
  975. * @param seqNum - sequence number of this command
  976. *
  977. * @return none
  978. */
  979. static void pct_GetCommandsCB( uint8 prepayNotificationFlags,
  980. afAddrType_t *srcAddr, uint8 seqNum )
  981. {
  982. // add user code here
  983. }
  984. /*********************************************************************
  985. * @fn pct_PublishTopupLogCB
  986. *
  987. * @brief Callback from the ZCL SE Profile Prepayment Cluster Library when
  988. * it received a Publish Topup Log for this application.
  989. *
  990. * @param pCmd - pointer to structure for Publish Topup Log command
  991. * @param srcAddr - pointer to source address
  992. * @param seqNum - sequence number of this command
  993. *
  994. * @return none
  995. */
  996. static void pct_PublishTopupLogCB( zclCCPublishTopupLog_t *pCmd,
  997. afAddrType_t *srcAddr, uint8 seqNum )
  998. {
  999. // add user code here
  1000. }
  1001. /*********************************************************************
  1002. * @fn pct_PublishDebtLogCB
  1003. *
  1004. * @brief Callback from the ZCL SE Profile Prepayment Cluster Library when
  1005. * it received a Publish Debt Log for this application.
  1006. *
  1007. * @param pCmd - pointer to structure for Publish Debt Log command
  1008. * @param srcAddr - pointer to source address
  1009. * @param seqNum - sequence number of this command
  1010. *
  1011. * @return none
  1012. */
  1013. static void pct_PublishDebtLogCB( zclCCPublishDebtLog_t *pCmd,
  1014. afAddrType_t *srcAddr, uint8 seqNum )
  1015. {
  1016. // add user code here
  1017. }
  1018. #endif // SE_UK_EXT
  1019. /******************************************************************************
  1020. *
  1021. * Functions for processing ZCL Foundation incoming Command/Response messages
  1022. *
  1023. *****************************************************************************/
  1024. /*********************************************************************
  1025. * @fn pct_ProcessZCLMsg
  1026. *
  1027. * @brief Process ZCL Foundation incoming message
  1028. *
  1029. * @param pInMsg - message to process
  1030. *
  1031. * @return none
  1032. */
  1033. static void pct_ProcessZCLMsg( zclIncomingMsg_t *pInMsg )
  1034. {
  1035. switch ( pInMsg->zclHdr.commandID )
  1036. {
  1037. #if defined ( ZCL_READ )
  1038. case ZCL_CMD_READ_RSP:
  1039. pct_ProcessInReadRspCmd( pInMsg );
  1040. break;
  1041. #endif // ZCL_READ
  1042. #if defined ( ZCL_WRITE )
  1043. case ZCL_CMD_WRITE_RSP:
  1044. pct_ProcessInWriteRspCmd( pInMsg );
  1045. break;
  1046. #endif // ZCL_WRITE
  1047. case ZCL_CMD_DEFAULT_RSP:
  1048. pct_ProcessInDefaultRspCmd( pInMsg );
  1049. break;
  1050. #if defined ( ZCL_DISCOVER )
  1051. case ZCL_CMD_DISCOVER_RSP:
  1052. pct_ProcessInDiscRspCmd( pInMsg );
  1053. break;
  1054. #endif // ZCL_DISCOVER
  1055. default:
  1056. break;
  1057. }
  1058. if ( pInMsg->attrCmd != NULL )
  1059. {
  1060. // free the parsed command
  1061. osal_mem_free( pInMsg->attrCmd );
  1062. pInMsg->attrCmd = NULL;
  1063. }
  1064. }
  1065. #if defined ( ZCL_READ )
  1066. /*********************************************************************
  1067. * @fn pct_ProcessInReadRspCmd
  1068. *
  1069. * @brief Process the "Profile" Read Response Command
  1070. *
  1071. * @param pInMsg - incoming message to process
  1072. *
  1073. * @return none
  1074. */
  1075. static uint8 pct_ProcessInReadRspCmd( zclIncomingMsg_t *pInMsg )
  1076. {
  1077. zclReadRspCmd_t *readRspCmd;
  1078. uint8 i;
  1079. readRspCmd = (zclReadRspCmd_t *)pInMsg->attrCmd;
  1080. for (i = 0; i < readRspCmd->numAttr; i++)
  1081. {
  1082. // Notify the originator of the results of the original read attributes
  1083. // attempt and, for each successfull request, the value of the requested
  1084. // attribute
  1085. }
  1086. return TRUE;
  1087. }
  1088. #endif // ZCL_READ
  1089. #if defined ( ZCL_WRITE )
  1090. /*********************************************************************
  1091. * @fn pct_ProcessInWriteRspCmd
  1092. *
  1093. * @brief Process the "Profile" Write Response Command
  1094. *
  1095. * @param pInMsg - incoming message to process
  1096. *
  1097. * @return none
  1098. */
  1099. static uint8 pct_ProcessInWriteRspCmd( zclIncomingMsg_t *pInMsg )
  1100. {
  1101. zclWriteRspCmd_t *writeRspCmd;
  1102. uint8 i;
  1103. writeRspCmd = (zclWriteRspCmd_t *)pInMsg->attrCmd;
  1104. for (i = 0; i < writeRspCmd->numAttr; i++)
  1105. {
  1106. // Notify the device of the results of the its original write attributes
  1107. // command.
  1108. }
  1109. return TRUE;
  1110. }
  1111. #endif // ZCL_WRITE
  1112. /*********************************************************************
  1113. * @fn pct_ProcessInDefaultRspCmd
  1114. *
  1115. * @brief Process the "Profile" Default Response Command
  1116. *
  1117. * @param pInMsg - incoming message to process
  1118. *
  1119. * @return none
  1120. */
  1121. static uint8 pct_ProcessInDefaultRspCmd( zclIncomingMsg_t *pInMsg )
  1122. {
  1123. // zclDefaultRspCmd_t *defaultRspCmd = (zclDefaultRspCmd_t *)pInMsg->attrCmd;
  1124. // Device is notified of the Default Response command.
  1125. return TRUE;
  1126. }
  1127. #if defined ( ZCL_DISCOVER )
  1128. /*********************************************************************
  1129. * @fn pct_ProcessInDiscRspCmd
  1130. *
  1131. * @brief Process the "Profile" Discover Response Command
  1132. *
  1133. * @param pInMsg - incoming message to process
  1134. *
  1135. * @return none
  1136. */
  1137. static uint8 pct_ProcessInDiscRspCmd( zclIncomingMsg_t *pInMsg )
  1138. {
  1139. zclDiscoverRspCmd_t *discoverRspCmd;
  1140. uint8 i;
  1141. discoverRspCmd = (zclDiscoverRspCmd_t *)pInMsg->attrCmd;
  1142. for ( i = 0; i < discoverRspCmd->numAttr; i++ )
  1143. {
  1144. // Device is notified of the result of its attribute discovery command.
  1145. }
  1146. return TRUE;
  1147. }
  1148. #endif // ZCL_DISCOVER
  1149. /****************************************************************************
  1150. ****************************************************************************/