simplemeter.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. /**************************************************************************************************
  2. Filename: simplemeter.c
  3. Revised: $Date: 2007-08-02 09:20:10 -0700 (Thu,02 Aug 2007) $
  4. Revision: $Revision: 15001 $
  5. Description: This module implements the Simple Meter functionality and
  6. contains the init and event loop functions
  7. Copyright 2009 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 Simple Metering configuration:
  37. General Basic
  38. General Alarms
  39. General Time
  40. General Key Establishment
  41. SE Simple Metering
  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 "AddrMgr.h"
  55. #include "se.h"
  56. #include "simplemeter.h"
  57. #include "zcl_general.h"
  58. #include "zcl_se.h"
  59. #include "zcl_key_establish.h"
  60. #include "onboard.h"
  61. /* HAL */
  62. #include "hal_lcd.h"
  63. #include "hal_led.h"
  64. #include "hal_key.h"
  65. /*********************************************************************
  66. * MACROS
  67. */
  68. // There is no attribute in the Mandatory Reportable Attribute list for now
  69. #define zcl_MandatoryReportableAttribute( a ) ( a == NULL )
  70. /*********************************************************************
  71. * CONSTANTS
  72. */
  73. #define SIMPLEMETER_MIN_REPORTING_INTERVAL 5
  74. /*********************************************************************
  75. * TYPEDEFS
  76. */
  77. /*********************************************************************
  78. * GLOBAL VARIABLES
  79. */
  80. /*********************************************************************
  81. * GLOBAL FUNCTIONS
  82. */
  83. /*********************************************************************
  84. * LOCAL VARIABLES
  85. */
  86. static uint8 simpleMeterTaskID; // osal task id of simple meter
  87. static uint8 simpleMeterTransID; // transaction id
  88. static devStates_t simpleMeterNwkState; // network state variable
  89. static afAddrType_t ESPAddr; // esp destination address
  90. static zclReportCmd_t *pReportCmd; // report command structure
  91. static uint8 numAttr = 1; // number of attributes in report
  92. extern uint8 simpleMeterCurrentSummationDelivered[]; // defined in simplemeter_data.c
  93. static uint8 linkKeyStatus; // status return from get link key routine
  94. /*********************************************************************
  95. * LOCAL FUNCTIONS
  96. */
  97. static void simplemeter_HandleKeys( uint8 shift, uint8 keys );
  98. #if defined (ZCL_KEY_ESTABLISH)
  99. static uint8 simplemeter_KeyEstablish_ReturnLinkKey( uint16 shortAddr );
  100. #endif // ZCL_KEY_ESTABLISH
  101. #if defined ( ZCL_ALARMS )
  102. static void simplemeter_ProcessAlarmCmd( uint8 srcEP, afAddrType_t *dstAddr,
  103. uint16 clusterID, zclFrameHdr_t *hdr, uint8 len, uint8 *data );
  104. #endif // ZCL_ALARMS
  105. static void simplemeter_ProcessIdentifyTimeChange( void );
  106. /*************************************************************************/
  107. /*** Application Callback Functions ***/
  108. /*************************************************************************/
  109. // Foundation Callback functions
  110. static uint8 simplemeter_ValidateAttrDataCB( zclAttrRec_t *pAttr, zclWriteRec_t *pAttrInfo );
  111. // General Cluster Callback functions
  112. static void simplemeter_BasicResetCB( void );
  113. static void simplemeter_IdentifyCB( zclIdentify_t *pCmd );
  114. static void simplemeter_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp );
  115. static void simplemeter_AlarmCB( zclAlarm_t *pAlarm );
  116. // SE Callback functions
  117. static void simplemeter_GetProfileCmdCB( zclCCGetProfileCmd_t *pCmd,
  118. afAddrType_t *srcAddr, uint8 seqNum );
  119. static void simplemeter_GetProfileRspCB( zclCCGetProfileRsp_t *pCmd,
  120. afAddrType_t *srcAddr, uint8 seqNum );
  121. static void simplemeter_ReqMirrorCmdCB( afAddrType_t *srcAddr, uint8 seqNum );
  122. static void simplemeter_ReqMirrorRspCB( zclCCReqMirrorRsp_t *pCmd,
  123. afAddrType_t *srcAddr, uint8 seqNum );
  124. static void simplemeter_MirrorRemCmdCB( afAddrType_t *srcAddr, uint8 seqNum );
  125. static void simplemeter_MirrorRemRspCB( zclCCMirrorRemRsp_t *pCmd,
  126. afAddrType_t *srcAddr, uint8 seqNum );
  127. /************************************************************************/
  128. /*** Functions to process ZCL Foundation ***/
  129. /*** incoming Command/Response messages ***/
  130. /************************************************************************/
  131. static void simplemeter_ProcessZCLMsg( zclIncomingMsg_t *msg );
  132. #if defined ( ZCL_READ )
  133. static uint8 simplemeter_ProcessInReadRspCmd( zclIncomingMsg_t *pInMsg );
  134. #endif // ZCL_READ
  135. #if defined ( ZCL_WRITE )
  136. static uint8 simplemeter_ProcessInWriteRspCmd( zclIncomingMsg_t *pInMsg );
  137. #endif // ZCL_WRITE
  138. #if defined ( ZCL_REPORT )
  139. static uint8 simplemeter_ProcessInConfigReportCmd( zclIncomingMsg_t *pInMsg );
  140. static uint8 simplemeter_ProcessInConfigReportRspCmd( zclIncomingMsg_t *pInMsg );
  141. static uint8 simplemeter_ProcessInReadReportCfgCmd( zclIncomingMsg_t *pInMsg );
  142. static uint8 simplemeter_ProcessInReadReportCfgRspCmd( zclIncomingMsg_t *pInMsg );
  143. static uint8 simplemeter_ProcessInReportCmd( zclIncomingMsg_t *pInMsg );
  144. #endif // ZCL_REPORT
  145. static uint8 simplemeter_ProcessInDefaultRspCmd( zclIncomingMsg_t *pInMsg );
  146. #if defined ( ZCL_DISCOVER )
  147. static uint8 simplemeter_ProcessInDiscRspCmd( zclIncomingMsg_t *pInMsg );
  148. #endif // ZCL_DISCOVER
  149. /*********************************************************************
  150. * ZCL General Clusters Callback table
  151. */
  152. static zclGeneral_AppCallbacks_t simplemeter_GenCmdCallbacks =
  153. {
  154. simplemeter_BasicResetCB, // Basic Cluster Reset command
  155. simplemeter_IdentifyCB, // Identify command
  156. simplemeter_IdentifyQueryRspCB, // Identify Query Response command
  157. NULL, // On/Off cluster commands
  158. NULL, // Level Control Move to Level command
  159. NULL, // Level Control Move command
  160. NULL, // Level Control Step command
  161. NULL, // Level Control Stop command
  162. NULL, // Group Response commands
  163. NULL, // Scene Store Request command
  164. NULL, // Scene Recall Request command
  165. NULL, // Scene Response command
  166. simplemeter_AlarmCB, // Alarm (Response) command
  167. NULL, // RSSI Location command
  168. NULL, // RSSI Location Response command
  169. };
  170. /*********************************************************************
  171. * ZCL SE Clusters Callback table
  172. */
  173. static zclSE_AppCallbacks_t simplemeter_SECmdCallbacks =
  174. {
  175. simplemeter_GetProfileCmdCB, // Get Profile Command
  176. simplemeter_GetProfileRspCB, // Get Profile Response
  177. simplemeter_ReqMirrorCmdCB, // Request Mirror Command
  178. simplemeter_ReqMirrorRspCB, // Request Mirror Response
  179. simplemeter_MirrorRemCmdCB, // Mirror Remove Command
  180. simplemeter_MirrorRemRspCB, // Mirror Remove Response
  181. NULL, // Get Current Price
  182. NULL, // Get Scheduled Price
  183. NULL, // Publish Price
  184. NULL, // Display Message Command
  185. NULL, // Cancel Message Command
  186. NULL, // Get Last Message Command
  187. NULL, // Message Confirmation
  188. NULL, // Load Control Event
  189. NULL, // Cancel Load Control Event
  190. NULL, // Cancel All Load Control Events
  191. NULL, // Report Event Status
  192. NULL, // Get Scheduled Event
  193. };
  194. /*********************************************************************
  195. * @fn simplemeter_Init
  196. *
  197. * @brief Initialization function for the ZCL App Application.
  198. *
  199. * @param uint8 task_id - simple meter task id
  200. *
  201. * @return none
  202. */
  203. void simplemeter_Init( uint8 task_id )
  204. {
  205. simpleMeterTaskID = task_id;
  206. simpleMeterNwkState = DEV_INIT;
  207. simpleMeterTransID = 0;
  208. // Device hardware initialization can be added here or in main() (Zmain.c).
  209. // If the hardware is application specific - add it here.
  210. // If the hardware is other parts of the device add it in main().
  211. // ESP destination address init
  212. ESPAddr.addrMode = (afAddrMode_t)Addr16Bit;
  213. ESPAddr.endPoint = SIMPLEMETER_ENDPOINT;
  214. ESPAddr.addr.shortAddr = 0;
  215. // register for SE endpoint
  216. zclSE_Init( &simpleMeterSimpleDesc );
  217. // Register the ZCL General Cluster Library callback functions
  218. zclGeneral_RegisterCmdCallbacks( SIMPLEMETER_ENDPOINT, &simplemeter_GenCmdCallbacks );
  219. // Register the ZCL SE Cluster Library callback functions
  220. zclSE_RegisterCmdCallbacks( SIMPLEMETER_ENDPOINT, &simplemeter_SECmdCallbacks );
  221. // Register the application's attribute list
  222. zcl_registerAttrList( SIMPLEMETER_ENDPOINT, SIMPLEMETER_MAX_ATTRIBUTES, simpleMeterAttrs );
  223. // Register the application's cluster option list
  224. zcl_registerClusterOptionList( SIMPLEMETER_ENDPOINT, SIMPLEMETER_MAX_OPTIONS, simpleMeterOptions );
  225. // Register the application's attribute data validation callback function
  226. zcl_registerValidateAttrData( simplemeter_ValidateAttrDataCB );
  227. // Register the Application to receive the unprocessed Foundation command/response messages
  228. zcl_registerForMsg( simpleMeterTaskID );
  229. // Register for all key events - This app will handle all key events
  230. RegisterForKeys( simpleMeterTaskID );
  231. // Start the timer to sync SimpleMeter timer with the osal timer
  232. osal_start_timerEx( simpleMeterTaskID, SIMPLEMETER_UPDATE_TIME_EVT, SIMPLEMETER_UPDATE_TIME_PERIOD );
  233. // setup attribute IDs of interest for Simple Meter
  234. pReportCmd = (zclReportCmd_t *)osal_mem_alloc( sizeof( zclReportCmd_t ) + ( numAttr * sizeof( zclReport_t ) ) );
  235. if ( pReportCmd != NULL )
  236. {
  237. pReportCmd->numAttr = numAttr;
  238. // Set up the first attribute
  239. pReportCmd->attrList[0].attrID = ATTRID_SE_CURRENT_SUMMATION_DELIVERED;
  240. pReportCmd->attrList[0].dataType = ZCL_DATATYPE_UINT48;
  241. pReportCmd->attrList[0].attrData = simpleMeterCurrentSummationDelivered;
  242. // Set up the remaining attributes
  243. }
  244. }
  245. /*********************************************************************
  246. * @fn simplemeter_event_loop
  247. *
  248. * @brief Event Loop Processor for the simple meter.
  249. *
  250. * @param uint8 task_id - the osal task id
  251. * @param uint16 events - the event bitmask
  252. *
  253. * @return none
  254. */
  255. uint16 simplemeter_event_loop( uint8 task_id, uint16 events )
  256. {
  257. afIncomingMSGPacket_t *MSGpkt;
  258. if ( events & SYS_EVENT_MSG )
  259. {
  260. while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( simpleMeterTaskID )) )
  261. {
  262. switch ( MSGpkt->hdr.event )
  263. {
  264. case ZCL_INCOMING_MSG:
  265. // Incoming ZCL foundation command/response messages
  266. simplemeter_ProcessZCLMsg( (zclIncomingMsg_t *)MSGpkt );
  267. break;
  268. case KEY_CHANGE:
  269. simplemeter_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
  270. break;
  271. case ZDO_STATE_CHANGE:
  272. simpleMeterNwkState = (devStates_t)(MSGpkt->hdr.status);
  273. if (ZG_SECURE_ENABLED)
  274. {
  275. if ( (simpleMeterNwkState == DEV_ROUTER) || (simpleMeterNwkState == DEV_END_DEVICE) )
  276. {
  277. // check to see if link key had already been established
  278. linkKeyStatus = simplemeter_KeyEstablish_ReturnLinkKey(ESPAddr.addr.shortAddr);
  279. if (linkKeyStatus != ZSuccess)
  280. {
  281. // send out key establishment request
  282. osal_set_event( simpleMeterTaskID, SIMPLEMETER_KEY_ESTABLISHMENT_REQUEST_EVT);
  283. }
  284. else
  285. {
  286. // link key already established, resume sending reports
  287. osal_start_timerEx( simpleMeterTaskID, SIMPLEMETER_REPORT_ATTRIBUTE_EVT, SIMPLEMETER_REPORT_PERIOD );
  288. }
  289. }
  290. }
  291. else
  292. {
  293. osal_start_timerEx( simpleMeterTaskID, SIMPLEMETER_REPORT_ATTRIBUTE_EVT, SIMPLEMETER_REPORT_PERIOD );
  294. }
  295. NLME_SetPollRate ( SE_DEVICE_POLL_RATE ); // per smart energy spec end device polling requirement of not to poll < 7.5 seconds
  296. break;
  297. #if defined( ZCL_KEY_ESTABLISH )
  298. case ZCL_KEY_ESTABLISH_IND:
  299. osal_start_timerEx( simpleMeterTaskID, SIMPLEMETER_REPORT_ATTRIBUTE_EVT, SIMPLEMETER_REPORT_PERIOD );
  300. break;
  301. #endif
  302. default:
  303. break;
  304. }
  305. // Release the memory
  306. osal_msg_deallocate( (uint8 *)MSGpkt );
  307. }
  308. // return unprocessed events
  309. return (events ^ SYS_EVENT_MSG);
  310. }
  311. // event to intiate key establishment request
  312. if ( events & SIMPLEMETER_KEY_ESTABLISHMENT_REQUEST_EVT )
  313. {
  314. zclGeneral_KeyEstablish_InitiateKeyEstablishment(simpleMeterTaskID, &ESPAddr, simpleMeterTransID);
  315. return ( events ^ SIMPLEMETER_KEY_ESTABLISHMENT_REQUEST_EVT );
  316. }
  317. // event to send report attribute
  318. if ( events & SIMPLEMETER_REPORT_ATTRIBUTE_EVT )
  319. {
  320. if ( pReportCmd != NULL )
  321. {
  322. zcl_SendReportCmd( SIMPLEMETER_ENDPOINT, &ESPAddr,
  323. ZCL_CLUSTER_ID_SE_SIMPLE_METERING, pReportCmd,
  324. ZCL_FRAME_SERVER_CLIENT_DIR, 1, 0 );
  325. osal_start_timerEx( simpleMeterTaskID, SIMPLEMETER_REPORT_ATTRIBUTE_EVT, SIMPLEMETER_REPORT_PERIOD );
  326. }
  327. return ( events ^ SIMPLEMETER_REPORT_ATTRIBUTE_EVT );
  328. }
  329. // handle processing of identify timeout event triggered by an identify command
  330. if ( events & SIMPLEMETER_IDENTIFY_TIMEOUT_EVT )
  331. {
  332. if ( simpleMeterIdentifyTime > 0 )
  333. {
  334. simpleMeterIdentifyTime--;
  335. }
  336. simplemeter_ProcessIdentifyTimeChange();
  337. return ( events ^ SIMPLEMETER_IDENTIFY_TIMEOUT_EVT );
  338. }
  339. // event to get current time
  340. if ( events & SIMPLEMETER_UPDATE_TIME_EVT )
  341. {
  342. simpleMeterTime = osal_getClock();
  343. osal_start_timerEx( simpleMeterTaskID, SIMPLEMETER_UPDATE_TIME_EVT, SIMPLEMETER_UPDATE_TIME_PERIOD );
  344. return ( events ^ SIMPLEMETER_UPDATE_TIME_EVT );
  345. }
  346. // Discard unknown events
  347. return 0;
  348. }
  349. /*********************************************************************
  350. * @fn simplemeter_ProcessIdentifyTimeChange
  351. *
  352. * @brief Called to blink led for specified IdentifyTime attribute value
  353. *
  354. * @param none
  355. *
  356. * @return none
  357. */
  358. static void simplemeter_ProcessIdentifyTimeChange( void )
  359. {
  360. if ( simpleMeterIdentifyTime > 0 )
  361. {
  362. osal_start_timerEx( simpleMeterTaskID, SIMPLEMETER_IDENTIFY_TIMEOUT_EVT, 1000 );
  363. HalLedBlink ( HAL_LED_4, 0xFF, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME );
  364. }
  365. else
  366. {
  367. HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
  368. osal_stop_timerEx( simpleMeterTaskID, SIMPLEMETER_IDENTIFY_TIMEOUT_EVT );
  369. }
  370. }
  371. #if defined ( ZCL_KEY_ESTABLISH )
  372. /*********************************************************************
  373. * @fn simplemeter_KeyEstablish_ReturnLinkKey
  374. *
  375. * @brief This function get the requested link key
  376. *
  377. * @param shortAddr - short address of the partner.
  378. *
  379. * @return none
  380. */
  381. static uint8 simplemeter_KeyEstablish_ReturnLinkKey( uint16 shortAddr )
  382. {
  383. APSME_LinkKeyData_t* keyData;
  384. uint8 status = ZFailure;
  385. AddrMgrEntry_t entry;
  386. // Look up the long address of the device
  387. entry.user = ADDRMGR_USER_DEFAULT;
  388. entry.nwkAddr = shortAddr;
  389. if ( AddrMgrEntryLookupNwk( &entry ) )
  390. {
  391. // check for APS link key data
  392. APSME_LinkKeyDataGet( entry.extAddr, &keyData );
  393. if ( (keyData != NULL) && (keyData->key != NULL) )
  394. {
  395. status = ZSuccess;
  396. }
  397. }
  398. else
  399. {
  400. // It's an unknown device
  401. status = ZInvalidParameter;
  402. }
  403. return status;
  404. }
  405. #endif // ZCL_KEY_ESTABLISH
  406. /*********************************************************************
  407. * @fn simplemeter_HandleKeys
  408. *
  409. * @brief Handles all key events for this device.
  410. *
  411. * @param shift - true if in shift/alt.
  412. * @param keys - bit field for key events. Valid entries:
  413. * HAL_KEY_SW_4
  414. * HAL_KEY_SW_3
  415. * HAL_KEY_SW_2
  416. * HAL_KEY_SW_1
  417. *
  418. * @return none
  419. */
  420. static void simplemeter_HandleKeys( uint8 shift, uint8 keys )
  421. {
  422. // Shift is used to make each button/switch dual purpose.
  423. if ( shift )
  424. {
  425. if ( keys & HAL_KEY_SW_1 )
  426. {
  427. }
  428. if ( keys & HAL_KEY_SW_2 )
  429. {
  430. }
  431. if ( keys & HAL_KEY_SW_3 )
  432. {
  433. }
  434. if ( keys & HAL_KEY_SW_4 )
  435. {
  436. }
  437. }
  438. else
  439. {
  440. if ( keys & HAL_KEY_SW_1 )
  441. {
  442. ZDOInitDevice(0); // join the network
  443. }
  444. if ( keys & HAL_KEY_SW_2 )
  445. {
  446. }
  447. if ( keys & HAL_KEY_SW_3 )
  448. {
  449. }
  450. if ( keys & HAL_KEY_SW_4 )
  451. {
  452. }
  453. }
  454. }
  455. /*********************************************************************
  456. * @fn simplemeter_ValidateAttrDataCB
  457. *
  458. * @brief Check to see if the supplied value for the attribute data
  459. * is within the specified range of the attribute.
  460. *
  461. * @param pAttr - pointer to attribute
  462. * @param pAttrInfo - pointer to attribute info
  463. *
  464. * @return TRUE if data valid. FALSE otherwise.
  465. */
  466. static uint8 simplemeter_ValidateAttrDataCB( zclAttrRec_t *pAttr, zclWriteRec_t *pAttrInfo )
  467. {
  468. uint8 valid = TRUE;
  469. switch ( pAttrInfo->dataType )
  470. {
  471. case ZCL_DATATYPE_BOOLEAN:
  472. if ( ( *(pAttrInfo->attrData) != 0 ) && ( *(pAttrInfo->attrData) != 1 ) )
  473. valid = FALSE;
  474. break;
  475. default:
  476. break;
  477. }
  478. return ( valid );
  479. }
  480. /*********************************************************************
  481. * @fn simplemeter_BasicResetCB
  482. *
  483. * @brief Callback from the ZCL General Cluster Library to set all
  484. * the attributes of all the clusters to their factory defaults
  485. *
  486. * @param none
  487. *
  488. * @return none
  489. */
  490. static void simplemeter_BasicResetCB( void )
  491. {
  492. // user should handle setting attributes to factory defaults here
  493. }
  494. /*********************************************************************
  495. * @fn simplemeter_IdentifyCB
  496. *
  497. * @brief Callback from the ZCL General Cluster Library when
  498. * it received an Identity Command for this application.
  499. *
  500. * @param pCmd - pointer to structure for identify command
  501. *
  502. * @return none
  503. */
  504. static void simplemeter_IdentifyCB( zclIdentify_t *pCmd )
  505. {
  506. simpleMeterIdentifyTime = pCmd->identifyTime;
  507. simplemeter_ProcessIdentifyTimeChange();
  508. }
  509. /*********************************************************************
  510. * @fn simplemeter_IdentifyQueryRspCB
  511. *
  512. * @brief Callback from the ZCL General Cluster Library when
  513. * it received an Identity Query Response Command for this application.
  514. *
  515. * @param pRsp - pointer to structure for identify query response
  516. *
  517. * @return none
  518. */
  519. static void simplemeter_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp )
  520. {
  521. // add user code here
  522. }
  523. /*********************************************************************
  524. * @fn simplemeter_AlarmCB
  525. *
  526. * @brief Callback from the ZCL General Cluster Library when
  527. * it received an Alarm request or response command for
  528. * this application.
  529. *
  530. * @param pAlarm - pointer to structure for alarm command
  531. *
  532. * @return none
  533. */
  534. static void simplemeter_AlarmCB( zclAlarm_t *pAlarm )
  535. {
  536. // add user code here
  537. }
  538. /*********************************************************************
  539. * @fn simplemeter_GetProfileCmdCB
  540. *
  541. * @brief Callback from the ZCL SE Profile Simple Metering Cluster Library when
  542. * it received a Get Profile Command for
  543. * this application.
  544. *
  545. * @param pCmd - pointer to get profile command structure
  546. * @param srcAddr - pointer to source address
  547. * @param seqNum - sequence number of this command
  548. *
  549. * @return none
  550. */
  551. static void simplemeter_GetProfileCmdCB( zclCCGetProfileCmd_t *pCmd, afAddrType_t *srcAddr, uint8 seqNum )
  552. {
  553. #if defined ( ZCL_SIMPLE_METERING )
  554. // Upon receipt of the Get Profile Command, the metering device shall send
  555. // Get Profile Response back.
  556. // Variables in the following are initialized to arbitrary value for test purpose
  557. // In real application, user shall look up the interval data captured during
  558. // the period specified in the pCmd->endTime and return corresponding data.
  559. uint32 endTime;
  560. uint8 status = zclSE_SimpleMeter_GetProfileRsp_Status_Success;
  561. uint8 profileIntervalPeriod = PROFILE_INTERVAL_PERIOD_60MIN;
  562. uint8 numberOfPeriodDelivered = 5;
  563. uint24 intervals[] = {0xa00001, 0xa00002, 0xa00003, 0xa00004, 0xa00005};
  564. // endTime: 32 bit value (in UTC) representing the end time of the most
  565. // chronologically recent interval being requested.
  566. // Example: Data collected from 2:00 PM to 3:00 PM would be specified as a
  567. // 3:00 PM interval (end time).
  568. // The Intervals block returned shall be the most recent block with
  569. // its EndTime equal or older to the one in the request (pCmd->endTime).
  570. // Requested End Time with value 0xFFFFFFFF indicats the most recent
  571. // Intervals block is requested.
  572. // Sample Code - assuming the end time of the requested block is the same as
  573. // it in the request.
  574. endTime = pCmd->endTime;
  575. // Send Get Profile Response Command back
  576. zclSE_SimpleMetering_Send_GetProfileRsp( SIMPLEMETER_ENDPOINT, srcAddr, endTime,
  577. status,
  578. profileIntervalPeriod,
  579. numberOfPeriodDelivered, intervals,
  580. false, seqNum );
  581. #endif // ZCL_SIMPLE_METERING
  582. }
  583. /*********************************************************************
  584. * @fn simplemeter_GetProfileRspCB
  585. *
  586. * @brief Callback from the ZCL SE Profile Simple Metering Cluster Library when
  587. * it received a Get Profile Response for
  588. * this application.
  589. *
  590. * @param pCmd - pointer to get profile response structure
  591. * @param srcAddr - pointer to source address
  592. * @param seqNum - sequence number of this command
  593. *
  594. * @return none
  595. */
  596. static void simplemeter_GetProfileRspCB( zclCCGetProfileRsp_t *pCmd, afAddrType_t *srcAddr, uint8 seqNum )
  597. {
  598. // add user code here
  599. }
  600. /*********************************************************************
  601. * @fn simplemeter_ReqMirrorCmdCB
  602. *
  603. * @brief Callback from the ZCL SE Profile Simple Metering Cluster Library when
  604. * it received a Request Mirror Command for
  605. * this application.
  606. *
  607. * @param srcAddr - pointer to source address
  608. * @param seqNum - sequence number of this command
  609. *
  610. * @return none
  611. */
  612. static void simplemeter_ReqMirrorCmdCB( afAddrType_t *srcAddr, uint8 seqNum )
  613. {
  614. // add user code here
  615. }
  616. /*********************************************************************
  617. * @fn simplemeter_ReqMirrorRspCB
  618. *
  619. * @brief Callback from the ZCL SE Profile Simple Metering Cluster Library when
  620. * it received a Request Mirror Response for
  621. * this application.
  622. *
  623. * @param pRsp - pointer to request mirror response structure
  624. * @param srcAddr - pointer to source address
  625. * @param seqNum - sequence number of this command
  626. *
  627. * @return none
  628. */
  629. static void simplemeter_ReqMirrorRspCB( zclCCReqMirrorRsp_t *pRsp, afAddrType_t *srcAddr, uint8 seqNum )
  630. {
  631. // add user code here
  632. }
  633. /*********************************************************************
  634. * @fn simplemeter_MirrorRemCmdCB
  635. *
  636. * @brief Callback from the ZCL SE Profile Simple Metering Cluster Library when
  637. * it received a Mirror Remove Command for
  638. * this application.
  639. *
  640. * @param srcAddr - pointer to source address
  641. * @param seqNum - sequence number of this command
  642. *
  643. * @return none
  644. */
  645. static void simplemeter_MirrorRemCmdCB( afAddrType_t *srcAddr, uint8 seqNum )
  646. {
  647. // add user code here
  648. }
  649. /*********************************************************************
  650. * @fn simplemeter_MirrorRemRspCB
  651. *
  652. * @brief Callback from the ZCL SE Profile Simple Metering Cluster Library when
  653. * it received a Mirror Remove Response for
  654. * this application.
  655. *
  656. * @param pCmd - pointer to mirror remove response structure
  657. * @param srcAddr - pointer to source address
  658. * @param seqNum - sequence number of this command
  659. *
  660. * @return none
  661. */
  662. static void simplemeter_MirrorRemRspCB( zclCCMirrorRemRsp_t *pCmd, afAddrType_t *srcAddr, uint8 seqNum )
  663. {
  664. // add user code here
  665. }
  666. /******************************************************************************
  667. *
  668. * Functions for processing ZCL Foundation incoming Command/Response messages
  669. *
  670. *****************************************************************************/
  671. /*********************************************************************
  672. * @fn simplemeter_ProcessZCLMsg
  673. *
  674. * @brief Process ZCL Foundation incoming message
  675. *
  676. * @param pInMsg - message to process
  677. *
  678. * @return none
  679. */
  680. static void simplemeter_ProcessZCLMsg( zclIncomingMsg_t *pInMsg )
  681. {
  682. switch ( pInMsg->zclHdr.commandID )
  683. {
  684. #if defined ( ZCL_READ )
  685. case ZCL_CMD_READ_RSP:
  686. simplemeter_ProcessInReadRspCmd( pInMsg );
  687. break;
  688. #endif // ZCL_READ
  689. #if defined ( ZCL_WRITE )
  690. case ZCL_CMD_WRITE_RSP:
  691. simplemeter_ProcessInWriteRspCmd( pInMsg );
  692. break;
  693. #endif // ZCL_READ
  694. #if defined ( ZCL_REPORT )
  695. case ZCL_CMD_CONFIG_REPORT:
  696. simplemeter_ProcessInConfigReportCmd( pInMsg );
  697. break;
  698. case ZCL_CMD_CONFIG_REPORT_RSP:
  699. simplemeter_ProcessInConfigReportRspCmd( pInMsg );
  700. break;
  701. case ZCL_CMD_READ_REPORT_CFG:
  702. simplemeter_ProcessInReadReportCfgCmd( pInMsg );
  703. break;
  704. case ZCL_CMD_READ_REPORT_CFG_RSP:
  705. simplemeter_ProcessInReadReportCfgRspCmd( pInMsg );
  706. break;
  707. case ZCL_CMD_REPORT:
  708. simplemeter_ProcessInReportCmd( pInMsg );
  709. break;
  710. #endif // ZCL_REPORT
  711. case ZCL_CMD_DEFAULT_RSP:
  712. simplemeter_ProcessInDefaultRspCmd( pInMsg );
  713. break;
  714. #if defined ( ZCL_DISCOVER )
  715. case ZCL_CMD_DISCOVER_RSP:
  716. simplemeter_ProcessInDiscRspCmd( pInMsg );
  717. break;
  718. #endif // ZCL_DISCOVER
  719. default:
  720. break;
  721. }
  722. if ( pInMsg->attrCmd != NULL )
  723. {
  724. // free the parsed command
  725. osal_mem_free( pInMsg->attrCmd );
  726. pInMsg->attrCmd = NULL;
  727. }
  728. }
  729. #if defined ( ZCL_READ )
  730. /*********************************************************************
  731. * @fn simplemeter_ProcessInReadRspCmd
  732. *
  733. * @brief Process the "Profile" Read Response Command
  734. *
  735. * @param pInMsg - incoming message to process
  736. *
  737. * @return none
  738. */
  739. static uint8 simplemeter_ProcessInReadRspCmd( zclIncomingMsg_t *pInMsg )
  740. {
  741. zclReadRspCmd_t *readRspCmd;
  742. uint8 i;
  743. readRspCmd = (zclReadRspCmd_t *)pInMsg->attrCmd;
  744. for (i = 0; i < readRspCmd->numAttr; i++)
  745. {
  746. // Notify the originator of the results of the original read attributes
  747. // attempt and, for each successfull request, the value of the requested
  748. // attribute
  749. }
  750. return TRUE;
  751. }
  752. #endif // ZCL_READ
  753. #if defined ( ZCL_WRITE )
  754. /*********************************************************************
  755. * @fn simplemeter_ProcessInWriteRspCmd
  756. *
  757. * @brief Process the "Profile" Write Response Command
  758. *
  759. * @param pInMsg - incoming message to process
  760. *
  761. * @return none
  762. */
  763. static uint8 simplemeter_ProcessInWriteRspCmd( zclIncomingMsg_t *pInMsg )
  764. {
  765. zclWriteRspCmd_t *writeRspCmd;
  766. uint8 i;
  767. writeRspCmd = (zclWriteRspCmd_t *)pInMsg->attrCmd;
  768. for (i = 0; i < writeRspCmd->numAttr; i++)
  769. {
  770. // Notify the device of the results of the its original write attributes
  771. // command.
  772. }
  773. return TRUE;
  774. }
  775. #endif // ZCL_WRITE
  776. #if defined ( ZCL_REPORT )
  777. /*********************************************************************
  778. * @fn simplemeter_ProcessInConfigReportCmd
  779. *
  780. * @brief Process the "Profile" Configure Reporting Command
  781. *
  782. * @param pInMsg - incoming message to process
  783. *
  784. * @return TRUE if attribute was found in the Attribute list,
  785. * FALSE if not
  786. */
  787. static uint8 simplemeter_ProcessInConfigReportCmd( zclIncomingMsg_t *pInMsg )
  788. {
  789. zclCfgReportCmd_t *cfgReportCmd;
  790. zclCfgReportRec_t *reportRec;
  791. zclCfgReportRspCmd_t *cfgReportRspCmd;
  792. zclAttrRec_t attrRec;
  793. uint8 status;
  794. uint8 i, j = 0;
  795. cfgReportCmd = (zclCfgReportCmd_t *)pInMsg->attrCmd;
  796. // Allocate space for the response command
  797. cfgReportRspCmd = (zclCfgReportRspCmd_t *)osal_mem_alloc( sizeof ( zclCfgReportRspCmd_t ) + \
  798. sizeof ( zclCfgReportStatus_t) * cfgReportCmd->numAttr );
  799. if ( cfgReportRspCmd == NULL )
  800. return FALSE; // EMBEDDED RETURN
  801. // Process each Attribute Reporting Configuration record
  802. for ( i = 0; i < cfgReportCmd->numAttr; i++ )
  803. {
  804. reportRec = &(cfgReportCmd->attrList[i]);
  805. status = ZCL_STATUS_SUCCESS;
  806. if ( zclFindAttrRec( SIMPLEMETER_ENDPOINT, pInMsg->clusterId, reportRec->attrID, &attrRec ) )
  807. {
  808. if ( reportRec->direction == ZCL_SEND_ATTR_REPORTS )
  809. {
  810. if ( reportRec->dataType == attrRec.attr.dataType )
  811. {
  812. // This the attribute that is to be reported
  813. if ( zcl_MandatoryReportableAttribute( &attrRec ) == TRUE )
  814. {
  815. if ( reportRec->minReportInt < SIMPLEMETER_MIN_REPORTING_INTERVAL ||
  816. ( reportRec->maxReportInt != 0 &&
  817. reportRec->maxReportInt < reportRec->minReportInt ) )
  818. {
  819. // Invalid fields
  820. status = ZCL_STATUS_INVALID_VALUE;
  821. }
  822. else
  823. {
  824. // Set the Min and Max Reporting Intervals and Reportable Change
  825. //status = zclSetAttrReportInterval( pAttr, cfgReportCmd );
  826. status = ZCL_STATUS_UNREPORTABLE_ATTRIBUTE; // for now
  827. }
  828. }
  829. else
  830. {
  831. // Attribute cannot be reported
  832. status = ZCL_STATUS_UNREPORTABLE_ATTRIBUTE;
  833. }
  834. }
  835. else
  836. {
  837. // Attribute data type is incorrect
  838. status = ZCL_STATUS_INVALID_DATA_TYPE;
  839. }
  840. }
  841. else
  842. {
  843. // We shall expect reports of values of this attribute
  844. if ( zcl_MandatoryReportableAttribute( &attrRec ) == TRUE )
  845. {
  846. // Set the Timeout Period
  847. //status = zclSetAttrTimeoutPeriod( pAttr, cfgReportCmd );
  848. status = ZCL_STATUS_UNSUPPORTED_ATTRIBUTE; // for now
  849. }
  850. else
  851. {
  852. // Reports of attribute cannot be received
  853. status = ZCL_STATUS_UNSUPPORTED_ATTRIBUTE;
  854. }
  855. }
  856. }
  857. else
  858. {
  859. // Attribute is not supported
  860. status = ZCL_STATUS_UNSUPPORTED_ATTRIBUTE;
  861. }
  862. // If not successful then record the status
  863. if ( status != ZCL_STATUS_SUCCESS )
  864. {
  865. cfgReportRspCmd->attrList[j].status = status;
  866. cfgReportRspCmd->attrList[j++].attrID = reportRec->attrID;
  867. }
  868. } // for loop
  869. if ( j == 0 )
  870. {
  871. // Since all attributes were configured successfully, include a single
  872. // attribute status record in the response command with the status field
  873. // set to SUCCESS and the attribute ID field omitted.
  874. cfgReportRspCmd->attrList[0].status = ZCL_STATUS_SUCCESS;
  875. cfgReportRspCmd->numAttr = 1;
  876. }
  877. else
  878. {
  879. cfgReportRspCmd->numAttr = j;
  880. }
  881. // Send the response back
  882. zcl_SendConfigReportRspCmd( SIMPLEMETER_ENDPOINT, &(pInMsg->srcAddr),
  883. pInMsg->clusterId, cfgReportRspCmd, ZCL_FRAME_SERVER_CLIENT_DIR,
  884. true, pInMsg->zclHdr.transSeqNum );
  885. osal_mem_free( cfgReportRspCmd );
  886. return TRUE ;
  887. }
  888. /*********************************************************************
  889. * @fn simplemeter_ProcessInConfigReportRspCmd
  890. *
  891. * @brief Process the "Profile" Configure Reporting Response Command
  892. *
  893. * @param pInMsg - incoming message to process
  894. *
  895. * @return none
  896. */
  897. static uint8 simplemeter_ProcessInConfigReportRspCmd( zclIncomingMsg_t *pInMsg )
  898. {
  899. zclCfgReportRspCmd_t *cfgReportRspCmd;
  900. zclAttrRec_t attrRec;
  901. uint8 i;
  902. cfgReportRspCmd = (zclCfgReportRspCmd_t *)pInMsg->attrCmd;
  903. for (i = 0; i < cfgReportRspCmd->numAttr; i++)
  904. {
  905. if ( zclFindAttrRec( SIMPLEMETER_ENDPOINT, pInMsg->clusterId,
  906. cfgReportRspCmd->attrList[i].attrID, &attrRec ) )
  907. {
  908. // Notify the device of success (or otherwise) of the its original configure
  909. // reporting command, for each attribute.
  910. }
  911. }
  912. return TRUE;
  913. }
  914. /*********************************************************************
  915. * @fn simplemeter_ProcessInReadReportCfgCmd
  916. *
  917. * @brief Process the "Profile" Read Reporting Configuration Command
  918. *
  919. * @param pInMsg - incoming message to process
  920. *
  921. * @return none
  922. */
  923. static uint8 simplemeter_ProcessInReadReportCfgCmd( zclIncomingMsg_t *pInMsg )
  924. {
  925. zclReadReportCfgCmd_t *readReportCfgCmd;
  926. zclReadReportCfgRspCmd_t *readReportCfgRspCmd;
  927. zclReportCfgRspRec_t *reportRspRec;
  928. zclAttrRec_t attrRec;
  929. uint8 reportChangeLen;
  930. uint8 *dataPtr;
  931. uint8 hdrLen;
  932. uint8 dataLen = 0;
  933. uint8 status;
  934. uint8 i;
  935. readReportCfgCmd = (zclReadReportCfgCmd_t *)pInMsg->attrCmd;
  936. // Find out the response length (Reportable Change field is of variable length)
  937. for ( i = 0; i < readReportCfgCmd->numAttr; i++ )
  938. {
  939. // For supported attributes with 'analog' data type, find out the length of
  940. // the Reportable Change field
  941. if ( zclFindAttrRec( SIMPLEMETER_ENDPOINT, pInMsg->clusterId,
  942. readReportCfgCmd->attrList[i].attrID, &attrRec ) )
  943. {
  944. if ( zclAnalogDataType( attrRec.attr.dataType ) )
  945. {
  946. reportChangeLen = zclGetDataTypeLength( attrRec.attr.dataType );
  947. // add padding if neede
  948. if ( PADDING_NEEDED( reportChangeLen ) )
  949. reportChangeLen++;
  950. dataLen += reportChangeLen;
  951. }
  952. }
  953. }
  954. hdrLen = sizeof( zclReadReportCfgRspCmd_t ) + ( readReportCfgCmd->numAttr * sizeof( zclReportCfgRspRec_t ) );
  955. // Allocate space for the response command
  956. readReportCfgRspCmd = (zclReadReportCfgRspCmd_t *)osal_mem_alloc( hdrLen + dataLen );
  957. if ( readReportCfgRspCmd == NULL )
  958. return FALSE; // EMBEDDED RETURN
  959. dataPtr = (uint8 *)( (uint8 *)readReportCfgRspCmd + hdrLen );
  960. readReportCfgRspCmd->numAttr = readReportCfgCmd->numAttr;
  961. for (i = 0; i < readReportCfgCmd->numAttr; i++)
  962. {
  963. reportRspRec = &(readReportCfgRspCmd->attrList[i]);
  964. if ( zclFindAttrRec( SIMPLEMETER_ENDPOINT, pInMsg->clusterId,
  965. readReportCfgCmd->attrList[i].attrID, &attrRec ) )
  966. {
  967. if ( zcl_MandatoryReportableAttribute( &attrRec ) == TRUE )
  968. {
  969. // Get the Reporting Configuration
  970. // status = zclReadReportCfg( readReportCfgCmd->attrID[i], reportRspRec );
  971. status = ZCL_STATUS_UNREPORTABLE_ATTRIBUTE; // for now
  972. if ( status == ZCL_STATUS_SUCCESS && zclAnalogDataType( attrRec.attr.dataType ) )
  973. {
  974. reportChangeLen = zclGetDataTypeLength( attrRec.attr.dataType );
  975. //osal_memcpy( dataPtr, pBuf, reportChangeLen );
  976. reportRspRec->reportableChange = dataPtr;
  977. // add padding if needed
  978. if ( PADDING_NEEDED( reportChangeLen ) )
  979. reportChangeLen++;
  980. dataPtr += reportChangeLen;
  981. }
  982. }
  983. else
  984. {
  985. // Attribute not in the Mandatory Reportable Attribute list
  986. status = ZCL_STATUS_UNREPORTABLE_ATTRIBUTE;
  987. }
  988. }
  989. else
  990. {
  991. // Attribute not found
  992. status = ZCL_STATUS_UNSUPPORTED_ATTRIBUTE;
  993. }
  994. reportRspRec->status = status;
  995. reportRspRec->attrID = readReportCfgCmd->attrList[i].attrID;
  996. }
  997. // Send the response back
  998. zcl_SendReadReportCfgRspCmd( SIMPLEMETER_ENDPOINT, &(pInMsg->srcAddr),
  999. pInMsg->clusterId, readReportCfgRspCmd, ZCL_FRAME_SERVER_CLIENT_DIR,
  1000. true, pInMsg->zclHdr.transSeqNum );
  1001. osal_mem_free( readReportCfgRspCmd );
  1002. return TRUE;
  1003. }
  1004. /*********************************************************************
  1005. * @fn simplemeter_ProcessInReadReportCfgRspCmd
  1006. *
  1007. * @brief Process the "Profile" Read Reporting Configuration Response Command
  1008. *
  1009. * @param pInMsg - incoming message to process
  1010. *
  1011. * @return none
  1012. */
  1013. static uint8 simplemeter_ProcessInReadReportCfgRspCmd( zclIncomingMsg_t *pInMsg )
  1014. {
  1015. zclReadReportCfgRspCmd_t *readReportCfgRspCmd;
  1016. zclReportCfgRspRec_t *reportRspRec;
  1017. uint8 i;
  1018. readReportCfgRspCmd = (zclReadReportCfgRspCmd_t *)pInMsg->attrCmd;
  1019. for ( i = 0; i < readReportCfgRspCmd->numAttr; i++ )
  1020. {
  1021. reportRspRec = &(readReportCfgRspCmd->attrList[i]);
  1022. // Notify the device of the results of the its original read reporting
  1023. // configuration command.
  1024. if ( reportRspRec->status == ZCL_STATUS_SUCCESS )
  1025. {
  1026. if ( reportRspRec->direction == ZCL_SEND_ATTR_REPORTS )
  1027. {
  1028. // add user code here
  1029. }
  1030. else
  1031. {
  1032. // expecting attribute reports
  1033. }
  1034. }
  1035. }
  1036. return TRUE;
  1037. }
  1038. /*********************************************************************
  1039. * @fn simplemeter_ProcessInReportCmd
  1040. *
  1041. * @brief Process the "Profile" Report Command
  1042. *
  1043. * @param pInMsg - incoming message to process
  1044. *
  1045. * @return none
  1046. */
  1047. static uint8 simplemeter_ProcessInReportCmd( zclIncomingMsg_t *pInMsg )
  1048. {
  1049. zclReportCmd_t *reportCmd;
  1050. uint8 i;
  1051. reportCmd = (zclReportCmd_t *)pInMsg->attrCmd;
  1052. for (i = 0; i < reportCmd->numAttr; i++)
  1053. {
  1054. // add user code here
  1055. }
  1056. return TRUE;
  1057. }
  1058. #endif // ZCL_REPORT
  1059. /*********************************************************************
  1060. * @fn simplemeter_ProcessInDefaultRspCmd
  1061. *
  1062. * @brief Process the "Profile" Default Response Command
  1063. *
  1064. * @param pInMsg - incoming message to process
  1065. *
  1066. * @return none
  1067. */
  1068. static uint8 simplemeter_ProcessInDefaultRspCmd( zclIncomingMsg_t *pInMsg )
  1069. {
  1070. // zclDefaultRspCmd_t *defaultRspCmd = (zclDefaultRspCmd_t *)pInMsg->attrCmd;
  1071. // Device is notified of the Default Response command.
  1072. return TRUE;
  1073. }
  1074. #if defined ( ZCL_DISCOVER )
  1075. /*********************************************************************
  1076. * @fn simplemeter_ProcessInDiscRspCmd
  1077. *
  1078. * @brief Process the "Profile" Discover Response Command
  1079. *
  1080. * @param pInMsg - incoming message to process
  1081. *
  1082. * @return none
  1083. */
  1084. static uint8 simplemeter_ProcessInDiscRspCmd( zclIncomingMsg_t *pInMsg )
  1085. {
  1086. zclDiscoverRspCmd_t *discoverRspCmd;
  1087. uint8 i;
  1088. discoverRspCmd = (zclDiscoverRspCmd_t *)pInMsg->attrCmd;
  1089. for ( i = 0; i < discoverRspCmd->numAttr; i++ )
  1090. {
  1091. // Device is notified of the result of its attribute discovery command.
  1092. }
  1093. return TRUE;
  1094. }
  1095. #endif // ZCL_DISCOVER
  1096. /****************************************************************************
  1097. ****************************************************************************/