ipd.c 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834
  1. /**************************************************************************************************
  2. Filename: ipd.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 IPD 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 an IPD configuration:
  37. General Basic
  38. General Alarms
  39. General Time
  40. General Key Establishment
  41. SE Price
  42. SE Message
  43. Key control:
  44. SW1: Join Network
  45. SW2: Send INTER-PAN Get Current Price Message
  46. SW3: N/A
  47. SW4: N/A
  48. *********************************************************************/
  49. /*********************************************************************
  50. * INCLUDES
  51. */
  52. #include "OSAL.h"
  53. #include "OSAL_Clock.h"
  54. #include "ZDApp.h"
  55. #include "ZDObject.h"
  56. #include "AddrMgr.h"
  57. #include "se.h"
  58. #include "ipd.h"
  59. #include "zcl_general.h"
  60. #include "zcl_se.h"
  61. #include "zcl_key_establish.h"
  62. #if defined( INTER_PAN )
  63. #include "stub_aps.h"
  64. #endif
  65. #include "onboard.h"
  66. /* HAL */
  67. #include "hal_lcd.h"
  68. #include "hal_led.h"
  69. #include "hal_key.h"
  70. /*********************************************************************
  71. * MACROS
  72. */
  73. // There is no attribute in the Mandatory Reportable Attribute list for now
  74. #define zcl_MandatoryReportableAttribute( a ) ( a == NULL )
  75. /*********************************************************************
  76. * CONSTANTS
  77. */
  78. #define ipdNwkState devState
  79. // Request Fast Poll Mode parameters
  80. #define IPD_FAST_POLL_UPDATE_PERIOD 2 // in seconds
  81. #define IPD_FAST_POLL_DURATION 5 // in minutes
  82. /*********************************************************************
  83. * TYPEDEFS
  84. */
  85. /*********************************************************************
  86. * GLOBAL VARIABLES
  87. */
  88. /*********************************************************************
  89. * GLOBAL FUNCTIONS
  90. */
  91. /*********************************************************************
  92. * LOCAL VARIABLES
  93. */
  94. static uint8 ipdTaskID; // osal task id for IPD
  95. static uint8 ipdTransID; // transaction id
  96. static afAddrType_t ESPAddr; // ESP destination address
  97. #if SECURE
  98. static uint8 linkKeyStatus; // status variable returned from get link key function
  99. #endif
  100. static uint8 option; // tx options field
  101. #if defined (INTER_PAN)
  102. static uint8 rxOnIdle; // receiver on when idle flag
  103. // define endpoint structure to register with STUB APS for INTER-PAN support
  104. static endPointDesc_t ipdEp =
  105. {
  106. IPD_ENDPOINT,
  107. &ipdTaskID,
  108. (SimpleDescriptionFormat_t *)&ipdSimpleDesc,
  109. (afNetworkLatencyReq_t)0
  110. };
  111. #endif
  112. /*********************************************************************
  113. * LOCAL FUNCTIONS
  114. */
  115. static void ipd_HandleKeys( uint8 shift, uint8 keys );
  116. #if SECURE
  117. static uint8 ipd_KeyEstablish_ReturnLinkKey( uint16 shortAddr );
  118. #endif
  119. static void ipd_ProcessIdentifyTimeChange( void );
  120. /*************************************************************************/
  121. /*** Application Callback Functions ***/
  122. /*************************************************************************/
  123. // Foundation Callback functions
  124. static uint8 ipd_ValidateAttrDataCB( zclAttrRec_t *pAttr, zclWriteRec_t *pAttrInfo );
  125. // General Cluster Callback functions
  126. static void ipd_BasicResetCB( void );
  127. static void ipd_IdentifyCB( zclIdentify_t *pCmd );
  128. static void ipd_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp );
  129. static void ipd_AlarmCB( zclAlarm_t *pAlarm );
  130. #ifdef SE_UK_EXT
  131. static void ipd_GetEventLogCB( uint8 srcEP, afAddrType_t *srcAddr,
  132. zclGetEventLog_t *pEventLog, uint8 seqNum );
  133. static void ipd_PublishEventLogCB( afAddrType_t *srcAddr,
  134. zclPublishEventLog_t *pEventLog );
  135. #endif // SE_UK_EXT
  136. // Function to process ZDO callback messages
  137. static void ipd_ProcessZDOMsgs( zdoIncomingMsg_t *pMsg );
  138. // SE Callback functions
  139. static void ipd_GetCurrentPriceCB( zclCCGetCurrentPrice_t *pCmd,
  140. afAddrType_t *srcAddr, uint8 seqNum );
  141. static void ipd_GetScheduledPriceCB( zclCCGetScheduledPrice_t *pCmd,
  142. afAddrType_t *srcAddr, uint8 seqNum );
  143. static void ipd_PriceAcknowledgementCB( zclCCPriceAcknowledgement_t *pCmd,
  144. afAddrType_t *srcAddr, uint8 seqNum );
  145. static void ipd_GetBlockPeriodCB( zclCCGetBlockPeriod_t *pCmd,
  146. afAddrType_t *srcAddr, uint8 seqNum );
  147. static void ipd_PublishPriceCB( zclCCPublishPrice_t *pCmd,
  148. afAddrType_t *srcAddr, uint8 seqNum );
  149. static void ipd_PublishBlockPeriodCB( zclCCPublishBlockPeriod_t *pCmd,
  150. afAddrType_t *srcAddr, uint8 seqNum );
  151. static void ipd_DisplayMessageCB( zclCCDisplayMessage_t *pCmd,
  152. afAddrType_t *srcAddr, uint8 seqNum );
  153. static void ipd_CancelMessageCB( zclCCCancelMessage_t *pCmd,
  154. afAddrType_t *srcAddr, uint8 seqNum );
  155. static void ipd_GetLastMessageCB( afAddrType_t *srcAddr, uint8 seqNum );
  156. static void ipd_MessageConfirmationCB( zclCCMessageConfirmation_t *pCmd,
  157. afAddrType_t *srcAddr, uint8 seqNum );
  158. static void ipd_ReqFastPollModeCmdCB( zclCCReqFastPollModeCmd_t *pCmd,
  159. afAddrType_t *srcAddr, uint8 seqNum );
  160. static void ipd_ReqFastPollModeRspCB( zclCCReqFastPollModeRsp_t *pRsp,
  161. afAddrType_t *srcAddr, uint8 seqNum );
  162. static void ipd_SelAvailEmergencyCreditCmdCB( zclCCSelAvailEmergencyCredit_t *pCmd,
  163. afAddrType_t *srcAddr, uint8 seqNum );
  164. static void ipd_ChangeSupplyCmdCB( zclCCChangeSupply_t *pCmd,
  165. afAddrType_t *srcAddr, uint8 seqNum );
  166. static void ipd_SupplyStatusRspCB( zclCCSupplyStatusResponse_t *pCmd,
  167. afAddrType_t *srcAddr, uint8 seqNum );
  168. #if defined ( SE_UK_EXT )
  169. static void ipd_PublishTariffInformationCB( zclCCPublishTariffInformation_t *pCmd,
  170. afAddrType_t *srcAddr, uint8 seqNum );
  171. static void ipd_PublishPriceMatrixCB( zclCCPublishPriceMatrix_t *pCmd,
  172. afAddrType_t *srcAddr, uint8 seqNum );
  173. static void ipd_PublishBlockThresholdsCB( zclCCPublishBlockThresholds_t *pCmd,
  174. afAddrType_t *srcAddr, uint8 seqNum );
  175. static void ipd_PublishConversionFactorCB( zclCCPublishConversionFactor_t *pCmd,
  176. afAddrType_t *srcAddr, uint8 seqNum );
  177. static void ipd_PublishCalorificValueCB( zclCCPublishCalorificValue_t *pCmd,
  178. afAddrType_t *srcAddr, uint8 seqNum );
  179. static void ipd_PublishCO2ValueCB( zclCCPublishCO2Value_t *pCmd,
  180. afAddrType_t *srcAddr, uint8 seqNum );
  181. static void ipd_PublishCPPEventCB( zclCCPublishCPPEvent_t *pCmd,
  182. afAddrType_t *srcAddr, uint8 seqNum );
  183. static void ipd_PublishBillingPeriodCB( zclCCPublishBillingPeriod_t *pCmd,
  184. afAddrType_t *srcAddr, uint8 seqNum );
  185. static void ipd_PublishConsolidatedBillCB( zclCCPublishConsolidatedBill_t *pCmd,
  186. afAddrType_t *srcAddr, uint8 seqNum );
  187. static void ipd_PublishCreditPaymentInfoCB( zclCCPublishCreditPaymentInfo_t *pCmd,
  188. afAddrType_t *srcAddr, uint8 seqNum );
  189. static void ipd_GetPrepaySnapshotResponseCB( zclCCGetPrepaySnapshotResponse_t *pCmd,
  190. afAddrType_t *srcAddr, uint8 seqNum );
  191. static void ipd_ChangePaymentModeResponseCB( zclCCChangePaymentModeResponse_t *pCmd,
  192. afAddrType_t *srcAddr, uint8 seqNum );
  193. static void ipd_ConsumerTopupResponseCB( zclCCConsumerTopupResponse_t *pCmd,
  194. afAddrType_t *srcAddr, uint8 seqNum );
  195. static void ipd_GetCommandsCB( uint8 prepayNotificationFlags,
  196. afAddrType_t *srcAddr, uint8 seqNum );
  197. static void ipd_PublishTopupLogCB( zclCCPublishTopupLog_t *pCmd,
  198. afAddrType_t *srcAddr, uint8 seqNum );
  199. static void ipd_PublishDebtLogCB( zclCCPublishDebtLog_t *pCmd,
  200. afAddrType_t *srcAddr, uint8 seqNum );
  201. #endif // SE_UK_EXT
  202. /************************************************************************/
  203. /*** Functions to process ZCL Foundation ***/
  204. /*** incoming Command/Response messages ***/
  205. /************************************************************************/
  206. static void ipd_ProcessZCLMsg( zclIncomingMsg_t *msg );
  207. #if defined ( ZCL_READ )
  208. static uint8 ipd_ProcessInReadRspCmd( zclIncomingMsg_t *pInMsg );
  209. #endif // ZCL_READ
  210. #if defined ( ZCL_WRITE )
  211. static uint8 ipd_ProcessInWriteRspCmd( zclIncomingMsg_t *pInMsg );
  212. #endif // ZCL_WRITE
  213. static uint8 ipd_ProcessInDefaultRspCmd( zclIncomingMsg_t *pInMsg );
  214. #if defined ( ZCL_DISCOVER )
  215. static uint8 ipd_ProcessInDiscRspCmd( zclIncomingMsg_t *pInMsg );
  216. #endif // ZCL_DISCOVER
  217. /*********************************************************************
  218. * ZCL General Clusters Callback table
  219. */
  220. static zclGeneral_AppCallbacks_t ipd_GenCmdCallbacks =
  221. {
  222. ipd_BasicResetCB, // Basic Cluster Reset command
  223. ipd_IdentifyCB, // Identify command
  224. ipd_IdentifyQueryRspCB, // Identify Query Response command
  225. NULL, // On/Off cluster commands
  226. NULL, // Level Control Move to Level command
  227. NULL, // Level Control Move command
  228. NULL, // Level Control Step command
  229. NULL, // Level Control Stop command
  230. NULL, // Group Response commands
  231. NULL, // Scene Store Request command
  232. NULL, // Scene Recall Request command
  233. NULL, // Scene Response command
  234. ipd_AlarmCB, // Alarm (Response) command
  235. #ifdef SE_UK_EXT
  236. ipd_GetEventLogCB, // Get Event Log command
  237. ipd_PublishEventLogCB, // Publish Event Log command
  238. #endif
  239. NULL, // RSSI Location command
  240. NULL // RSSI Location Response command
  241. };
  242. /*********************************************************************
  243. * ZCL SE Clusters Callback table
  244. */
  245. static zclSE_AppCallbacks_t ipd_SECmdCallbacks =
  246. {
  247. ipd_PublishPriceCB, // Publish Price
  248. ipd_PublishBlockPeriodCB, // Publish Block Period
  249. #if defined ( SE_UK_EXT )
  250. ipd_PublishTariffInformationCB, // Publish Tariff Information
  251. ipd_PublishPriceMatrixCB, // Publish Price Matrix
  252. ipd_PublishBlockThresholdsCB, // Publish Block Thresholds
  253. ipd_PublishConversionFactorCB, // Publish Conversion Factor
  254. ipd_PublishCalorificValueCB, // Publish Calorific Value
  255. ipd_PublishCO2ValueCB, // Publish CO2 Value
  256. ipd_PublishCPPEventCB, // Publish CPP Event
  257. ipd_PublishBillingPeriodCB, // Publish Billing Period
  258. ipd_PublishConsolidatedBillCB, // Publish Consolidated Bill
  259. ipd_PublishCreditPaymentInfoCB, // Publish Credit Payment Info
  260. #endif // SE_UK_EXT
  261. ipd_GetCurrentPriceCB, // Get Current Price
  262. ipd_GetScheduledPriceCB, // Get Scheduled Price
  263. ipd_PriceAcknowledgementCB, // Price Acknowledgement
  264. ipd_GetBlockPeriodCB, // Get Block Period
  265. #if defined ( SE_UK_EXT )
  266. NULL, // Get Tariff Information
  267. NULL, // Get Price Matrix
  268. NULL, // Get Block Thresholds
  269. NULL, // Get Conversion Factor
  270. NULL, // Get Calorific Value
  271. NULL, // Get CO2 Value
  272. NULL, // Get Billing Period
  273. NULL, // Get Consolidated Bill
  274. NULL, // CPP Event Response
  275. #endif // SE_UK_EXT
  276. NULL, // Load Control Event
  277. NULL, // Cancel Load Control Event
  278. NULL, // Cancel All Load Control Events
  279. NULL, // Report Event Status
  280. NULL, // Get Scheduled Event
  281. NULL, // Get Profile Response
  282. NULL, // Request Mirror Command
  283. NULL, // Mirror Remove Command
  284. ipd_ReqFastPollModeRspCB, // Request Fast Poll Mode Response
  285. #if defined ( SE_UK_EXT )
  286. NULL, // Get Snapshot Response
  287. #endif // SE_UK_EXT
  288. NULL, // Get Profile Command
  289. NULL, // Request Mirror Response
  290. NULL, // Mirror Remove Response
  291. ipd_ReqFastPollModeCmdCB, // Request Fast Poll Mode Command
  292. #if defined ( SE_UK_EXT )
  293. NULL, // Get Snapshot Command
  294. NULL, // Take Snapshot Command
  295. NULL, // Mirror Report Attribute Response
  296. #endif // SE_UK_EXT
  297. ipd_DisplayMessageCB, // Display Message Command
  298. ipd_CancelMessageCB, // Cancel Message Command
  299. ipd_GetLastMessageCB, // Get Last Message Command
  300. ipd_MessageConfirmationCB, // Message Confirmation
  301. NULL, // Request Tunnel Response
  302. NULL, // Transfer Data
  303. NULL, // Transfer Data Error
  304. NULL, // Ack Transfer Data
  305. NULL, // Ready Data
  306. #if defined ( SE_UK_EXT )
  307. NULL, // Supported Tunnel Protocols Response
  308. NULL, // Tunnel Closure Notification
  309. #endif // SE_UK_EXT
  310. NULL, // Request Tunnel
  311. NULL, // Close Tunnel
  312. #if defined ( SE_UK_EXT )
  313. NULL, // Get Supported Tunnel Protocols
  314. #endif // SE_UK_EXT
  315. ipd_SupplyStatusRspCB, // Supply Status Response
  316. #if defined ( SE_UK_EXT )
  317. ipd_GetPrepaySnapshotResponseCB, // Get Prepay Snapshot Response
  318. ipd_ChangePaymentModeResponseCB, // Change Payment Mode Response
  319. ipd_ConsumerTopupResponseCB, // Consumer Topup Response
  320. ipd_GetCommandsCB, // Get Commands
  321. ipd_PublishTopupLogCB, // Publish Topup Log
  322. ipd_PublishDebtLogCB, // Publish Debt Log
  323. #endif // SE_UK_EXT
  324. ipd_SelAvailEmergencyCreditCmdCB, // Select Available Emergency Credit Command
  325. ipd_ChangeSupplyCmdCB, // Change Supply Command
  326. #if defined ( SE_UK_EXT )
  327. NULL, // Change Debt
  328. NULL, // Emergency Credit Setup
  329. NULL, // Consumer Topup
  330. NULL, // Credit Adjustment
  331. NULL, // Change PaymentMode
  332. NULL, // Get Prepay Snapshot
  333. NULL, // Get Topup Log
  334. NULL, // Set Low Credit Warning Level
  335. NULL, // Get Debt Repayment Log
  336. NULL, // Publish Calendar
  337. NULL, // Publish Day Profile
  338. NULL, // Publish Week Profile
  339. NULL, // Publish Seasons
  340. NULL, // Publish Special Days
  341. NULL, // Get Calendar
  342. NULL, // Get Day Profiles
  343. NULL, // Get Week Profiles
  344. NULL, // Get Seasons
  345. NULL, // Get Special Days
  346. NULL, // Publish Change Tenancy
  347. NULL, // Publish Change Supplier
  348. NULL, // Change Supply
  349. NULL, // Change Password
  350. NULL, // Local Change Supply
  351. NULL, // Get Change Tenancy
  352. NULL, // Get Change Supplier
  353. NULL, // Get Change Supply
  354. NULL, // Supply Status Response
  355. NULL, // Get Password
  356. #endif // SE_UK_EXT
  357. };
  358. /*********************************************************************
  359. * @fn ipd_Init
  360. *
  361. * @brief Initialization function for the ZCL App Application.
  362. *
  363. * @param uint8 task_id - ipd task id
  364. *
  365. * @return none
  366. */
  367. void ipd_Init( uint8 task_id )
  368. {
  369. ipdTaskID = task_id;
  370. ipdTransID = 0;
  371. // Device hardware initialization can be added here or in main() (Zmain.c).
  372. // If the hardware is application specific - add it here.
  373. // If the hardware is other parts of the device add it in main().
  374. // setup ESP destination address
  375. ESPAddr.addrMode = (afAddrMode_t)Addr16Bit;
  376. ESPAddr.endPoint = IPD_ENDPOINT;
  377. ESPAddr.addr.shortAddr = 0;
  378. // Register for SE endpoint
  379. zclSE_Init( &ipdSimpleDesc );
  380. // Register the ZCL General Cluster Library callback functions
  381. zclGeneral_RegisterCmdCallbacks( IPD_ENDPOINT, &ipd_GenCmdCallbacks );
  382. // Register the ZCL SE Cluster Library callback functions
  383. zclSE_RegisterCmdCallbacks( IPD_ENDPOINT, &ipd_SECmdCallbacks );
  384. // Register the application's attribute list
  385. zcl_registerAttrList( IPD_ENDPOINT, IPD_MAX_ATTRIBUTES, ipdAttrs );
  386. // Register the application's cluster option list
  387. zcl_registerClusterOptionList( IPD_ENDPOINT, IPD_MAX_OPTIONS, ipdOptions );
  388. // Register the application's attribute data validation callback function
  389. zcl_registerValidateAttrData( ipd_ValidateAttrDataCB );
  390. // Register the Application to receive the unprocessed Foundation command/response messages
  391. zcl_registerForMsg( ipdTaskID );
  392. // Register for all key events - This app will handle all key events
  393. RegisterForKeys( ipdTaskID );
  394. // Register with the ZDO to receive Match Descriptor Responses
  395. ZDO_RegisterForZDOMsg(task_id, Match_Desc_rsp);
  396. #if defined ( INTER_PAN )
  397. // Register with Stub APS
  398. StubAPS_RegisterApp( &ipdEp );
  399. #endif
  400. // Start the timer to sync IPD timer with the osal timer
  401. osal_start_timerEx( ipdTaskID, IPD_UPDATE_TIME_EVT, IPD_UPDATE_TIME_PERIOD );
  402. }
  403. /*********************************************************************
  404. * @fn ipd_event_loop
  405. *
  406. * @brief Event Loop Processor for ipd.
  407. *
  408. * @param uint8 task_id - ipd task id
  409. * @param uint16 events - event bitmask
  410. *
  411. * @return none
  412. */
  413. uint16 ipd_event_loop( uint8 task_id, uint16 events )
  414. {
  415. afIncomingMSGPacket_t *MSGpkt;
  416. if ( events & SYS_EVENT_MSG )
  417. {
  418. while ( (MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( ipdTaskID )) )
  419. {
  420. switch ( MSGpkt->hdr.event )
  421. {
  422. case ZDO_CB_MSG:
  423. ipd_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt );
  424. break;
  425. case ZCL_INCOMING_MSG:
  426. // Incoming ZCL foundation command/response messages
  427. ipd_ProcessZCLMsg( (zclIncomingMsg_t *)MSGpkt );
  428. break;
  429. case KEY_CHANGE:
  430. ipd_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
  431. break;
  432. case ZDO_STATE_CHANGE:
  433. if (DEV_END_DEVICE == (devStates_t)(MSGpkt->hdr.status))
  434. {
  435. #if SECURE
  436. {
  437. // check to see if link key had already been established
  438. linkKeyStatus = ipd_KeyEstablish_ReturnLinkKey(ESPAddr.addr.shortAddr);
  439. if (linkKeyStatus != ZSuccess)
  440. {
  441. cId_t cbkeCluster = ZCL_CLUSTER_ID_GEN_KEY_ESTABLISHMENT;
  442. zAddrType_t dstAddr;
  443. // Send out a match for the key establishment
  444. dstAddr.addrMode = AddrBroadcast;
  445. dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR;
  446. ZDP_MatchDescReq( &dstAddr, NWK_BROADCAST_SHORTADDR, ZCL_SE_PROFILE_ID,
  447. 1, &cbkeCluster, 0, NULL, FALSE );
  448. }
  449. else
  450. {
  451. #if !defined ( ZCL_PREPAYMENT ) && !defined ( FAST_POLL_TEST )
  452. // link key already established, resume sending reports
  453. osal_start_timerEx( ipdTaskID, IPD_GET_PRICING_INFO_EVT, IPD_GET_PRICING_INFO_PERIOD );
  454. #endif
  455. }
  456. }
  457. #else
  458. {
  459. #if !defined ( ZCL_PREPAYMENT ) && !defined ( FAST_POLL_TEST )
  460. osal_start_timerEx( ipdTaskID, IPD_GET_PRICING_INFO_EVT, IPD_GET_PRICING_INFO_PERIOD );
  461. #endif
  462. }
  463. #endif
  464. // Per smart energy spec end device polling requirement of not to poll < 7.5 seconds.
  465. NLME_SetPollRate ( SE_DEVICE_POLL_RATE );
  466. }
  467. break;
  468. #if defined( ZCL_KEY_ESTABLISH )
  469. case ZCL_KEY_ESTABLISH_IND:
  470. if ((MSGpkt->hdr.status) == TermKeyStatus_Success)
  471. {
  472. ESPAddr.endPoint = IPD_ENDPOINT; // set destination endpoint back to application endpoint
  473. #if !defined ( ZCL_PREPAYMENT ) && !defined ( FAST_POLL_TEST )
  474. osal_start_timerEx( ipdTaskID, IPD_GET_PRICING_INFO_EVT, IPD_GET_PRICING_INFO_PERIOD );
  475. #endif
  476. }
  477. break;
  478. #endif
  479. default:
  480. break;
  481. }
  482. // Release the memory
  483. osal_msg_deallocate( (uint8 *)MSGpkt );
  484. }
  485. // return unprocessed events
  486. return (events ^ SYS_EVENT_MSG);
  487. }
  488. // event to intiate key establishment request
  489. if ( events & IPD_KEY_ESTABLISHMENT_REQUEST_EVT )
  490. {
  491. zclGeneral_KeyEstablish_InitiateKeyEstablishment(ipdTaskID, &ESPAddr, ipdTransID);
  492. return ( events ^ IPD_KEY_ESTABLISHMENT_REQUEST_EVT );
  493. }
  494. // event to get current price
  495. if ( events & IPD_GET_PRICING_INFO_EVT )
  496. {
  497. #if defined( INTER_PAN )
  498. uint8 x = TRUE;
  499. ZMacGetReq( ZMacRxOnIdle, &rxOnIdle );
  500. ZMacSetReq( ZMacRxOnIdle, &x );
  501. #endif
  502. zclSE_Pricing_Send_GetCurrentPrice( IPD_ENDPOINT, &ESPAddr, option, TRUE, 0 );
  503. osal_start_timerEx( ipdTaskID, IPD_GET_PRICING_INFO_EVT, IPD_GET_PRICING_INFO_PERIOD );
  504. return ( events ^ IPD_GET_PRICING_INFO_EVT );
  505. }
  506. // handle processing of identify timeout event triggered by an identify command
  507. if ( events & IPD_IDENTIFY_TIMEOUT_EVT )
  508. {
  509. if ( ipdIdentifyTime > 0 )
  510. {
  511. ipdIdentifyTime--;
  512. }
  513. ipd_ProcessIdentifyTimeChange();
  514. return ( events ^ IPD_IDENTIFY_TIMEOUT_EVT );
  515. }
  516. // event to get current time
  517. if ( events & IPD_UPDATE_TIME_EVT )
  518. {
  519. ipdTime = osal_getClock();
  520. osal_start_timerEx( ipdTaskID, IPD_UPDATE_TIME_EVT, IPD_UPDATE_TIME_PERIOD );
  521. return ( events ^ IPD_UPDATE_TIME_EVT );
  522. }
  523. // Discard unknown events
  524. return 0;
  525. }
  526. /*********************************************************************
  527. * @fn ipd_ProcessZDOMsgs
  528. *
  529. * @brief Called to process callbacks from the ZDO.
  530. *
  531. * @param none
  532. *
  533. * @return none
  534. */
  535. static void ipd_ProcessZDOMsgs( zdoIncomingMsg_t *pMsg )
  536. {
  537. // make sure message comes from TC to initiate Key Establishment
  538. if ((pMsg->clusterID == Match_Desc_rsp) &&
  539. (pMsg->srcAddr.addr.shortAddr == zgTrustCenterAddr))
  540. {
  541. ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( pMsg );
  542. if (pRsp)
  543. {
  544. if (pRsp->cnt)
  545. {
  546. // Record the trust center
  547. ESPAddr.endPoint = pRsp->epList[0];
  548. ESPAddr.addr.shortAddr = pMsg->srcAddr.addr.shortAddr;
  549. // send out key establishment request
  550. osal_set_event( ipdTaskID, IPD_KEY_ESTABLISHMENT_REQUEST_EVT);
  551. }
  552. osal_mem_free(pRsp);
  553. }
  554. }
  555. }
  556. /*********************************************************************
  557. * @fn ipd_ProcessIdentifyTimeChange
  558. *
  559. * @brief Called to blink led for specified IdentifyTime attribute value
  560. *
  561. * @param none
  562. *
  563. * @return none
  564. */
  565. static void ipd_ProcessIdentifyTimeChange( void )
  566. {
  567. if ( ipdIdentifyTime > 0 )
  568. {
  569. osal_start_timerEx( ipdTaskID, IPD_IDENTIFY_TIMEOUT_EVT, 1000 );
  570. HalLedBlink ( HAL_LED_4, 0xFF, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME );
  571. }
  572. else
  573. {
  574. HalLedSet ( HAL_LED_4, HAL_LED_MODE_OFF );
  575. osal_stop_timerEx( ipdTaskID, IPD_IDENTIFY_TIMEOUT_EVT );
  576. }
  577. }
  578. #if SECURE
  579. /*********************************************************************
  580. * @fn ipd_KeyEstablish_ReturnLinkKey
  581. *
  582. * @brief This function get the requested link key
  583. *
  584. * @param shortAddr - short address of the partner.
  585. *
  586. * @return none
  587. */
  588. static uint8 ipd_KeyEstablish_ReturnLinkKey( uint16 shortAddr )
  589. {
  590. uint8 status = ZFailure;
  591. AddrMgrEntry_t entry;
  592. // Look up the long address of the device
  593. entry.user = ADDRMGR_USER_DEFAULT;
  594. entry.nwkAddr = shortAddr;
  595. if ( AddrMgrEntryLookupNwk( &entry ) )
  596. {
  597. // check if APS link key has been established
  598. if ( APSME_IsLinkKeyValid( entry.extAddr ) == TRUE )
  599. {
  600. status = ZSuccess;
  601. }
  602. }
  603. else
  604. {
  605. // It's an unknown device
  606. status = ZInvalidParameter;
  607. }
  608. return status;
  609. }
  610. #endif
  611. /*********************************************************************
  612. * @fn ipd_HandleKeys
  613. *
  614. * @brief Handles all key events for this device.
  615. *
  616. * @param shift - true if in shift/alt.
  617. * @param keys - bit field for key events. Valid entries:
  618. * HAL_KEY_SW_4
  619. * HAL_KEY_SW_3
  620. * HAL_KEY_SW_2
  621. * HAL_KEY_SW_1
  622. *
  623. * @return none
  624. */
  625. static void ipd_HandleKeys( uint8 shift, uint8 keys )
  626. {
  627. // Shift is used to make each button/switch dual purpose.
  628. if ( shift )
  629. {
  630. if ( keys & HAL_KEY_SW_1 )
  631. {
  632. }
  633. if ( keys & HAL_KEY_SW_2 )
  634. {
  635. }
  636. if ( keys & HAL_KEY_SW_3 )
  637. {
  638. }
  639. if ( keys & HAL_KEY_SW_4 )
  640. {
  641. }
  642. }
  643. else
  644. {
  645. if ( keys & HAL_KEY_SW_1 )
  646. {
  647. ZDOInitDevice(0); // join the network
  648. }
  649. if ( keys & HAL_KEY_SW_2 )
  650. {
  651. #if defined( INTER_PAN )
  652. uint8 x = TRUE;
  653. ZMacGetReq( ZMacRxOnIdle, &rxOnIdle );
  654. ZMacSetReq( ZMacRxOnIdle, &x );
  655. afAddrType_t dstAddr;
  656. uint8 option = 1;
  657. // Send a request for public pricing information using the INTERP-DATA SAP.
  658. // The request is sent as a broadcast to all PANs within the discovered
  659. // channel. Receiving devices that implement the INTRP-DATA SAP will process
  660. // it and, if any such device is able to respond, it will respond directly
  661. // to the requestor. After receiving at least one response the requestor may
  662. // store the PAN ID and device address of one or more responders so that it
  663. // may query them directly in future.
  664. dstAddr.addrMode = afAddrBroadcast;
  665. dstAddr.addr.shortAddr = NWK_BROADCAST_SHORTADDR_DEVALL;
  666. dstAddr.endPoint = STUBAPS_INTER_PAN_EP;
  667. dstAddr.panId = 0xFFFF;
  668. zclSE_Pricing_Send_GetCurrentPrice( IPD_ENDPOINT, &dstAddr, option, TRUE, 0 );
  669. #endif
  670. }
  671. if ( keys & HAL_KEY_SW_3 )
  672. {
  673. #if defined ( ZCL_PREPAYMENT )
  674. zclCCSelAvailEmergencyCredit_t cmd;
  675. uint8 siteIdLen = 4; // adjust this value if different label is set, test label "TEST"
  676. uint8 meterSerialNumLen = 6; // adjust this value if different label is set, test label "123456"
  677. osal_memset( &cmd, 0, sizeof( zclCCSelAvailEmergencyCredit_t ) );
  678. cmd.commandDateTime = osal_getClock();
  679. cmd.originatingDevice = SE_ORIG_DEV_INPREMISES_DISPLAY_DEV;
  680. cmd.siteId.pStr = (uint8 *)osal_mem_alloc(siteIdLen);
  681. if (cmd.siteId.pStr != NULL)
  682. {
  683. cmd.siteId.strLen = siteIdLen;
  684. osal_memcpy(cmd.siteId.pStr, "TEST", siteIdLen);
  685. }
  686. cmd.meterSerialNumber.pStr = (uint8 *)osal_mem_alloc(meterSerialNumLen);
  687. if (cmd.meterSerialNumber.pStr != NULL)
  688. {
  689. cmd.meterSerialNumber.strLen = meterSerialNumLen;
  690. osal_memcpy(cmd.meterSerialNumber.pStr, "123456", meterSerialNumLen);
  691. }
  692. zclSE_Prepayment_Send_SelAvailEmergencyCredit(IPD_ENDPOINT,
  693. &ESPAddr,
  694. &cmd, FALSE, 1 );
  695. if (cmd.siteId.pStr != NULL)
  696. {
  697. osal_mem_free(cmd.siteId.pStr);
  698. }
  699. if (cmd.meterSerialNumber.pStr != NULL)
  700. {
  701. osal_mem_free(cmd.meterSerialNumber.pStr);
  702. }
  703. #else // for regular IPD test
  704. #if defined ( FAST_POLL_TEST )
  705. zclCCReqFastPollModeCmd_t fastPollCmd;
  706. fastPollCmd.fastPollUpdatePeriod = IPD_FAST_POLL_UPDATE_PERIOD;
  707. fastPollCmd.duration = IPD_FAST_POLL_DURATION;
  708. // send out fast poll mode request
  709. zclSE_SimpleMetering_Send_ReqFastPollModeCmd( IPD_ENDPOINT, &ESPAddr,
  710. &fastPollCmd,
  711. TRUE, 1);
  712. #endif // FAST_POLL_TEST
  713. #endif // ZCL_PREPAYMENT
  714. }
  715. if ( keys & HAL_KEY_SW_4 )
  716. {
  717. #if defined ( ZCL_PREPAYMENT )
  718. #if !defined ( SE_UK_EXT )
  719. zclCCChangeSupply_t changeCmd;
  720. uint8 siteIdLen = 4; // adjust this value if different label is set, test label "TEST"
  721. uint8 meterSerialNumLen = 6; // adjust this value if different label is set, test label "123456"
  722. changeCmd.providerId = 0xbabeface;
  723. changeCmd.requestDateTime = osal_getClock();
  724. changeCmd.siteId.pStr = (uint8 *)osal_mem_alloc(siteIdLen);
  725. if (changeCmd.siteId.pStr != NULL)
  726. {
  727. changeCmd.siteId.strLen = siteIdLen;
  728. osal_memcpy(changeCmd.siteId.pStr, "TEST", siteIdLen);
  729. }
  730. changeCmd.meterSerialNumber.pStr = (uint8 *)osal_mem_alloc(meterSerialNumLen);
  731. if (changeCmd.meterSerialNumber.pStr != NULL)
  732. {
  733. changeCmd.meterSerialNumber.strLen = meterSerialNumLen;
  734. osal_memcpy(changeCmd.meterSerialNumber.pStr, "123456", meterSerialNumLen);
  735. }
  736. changeCmd.implementationDateTime = 0x00000000; // immediately
  737. changeCmd.proposedSupplyStatus = SE_SUPPLY_ON;
  738. changeCmd.origIdSupplyControlBits = ((SE_ORIG_DEV_INPREMISES_DISPLAY_DEV << 4) | SE_SUPPLY_CTRL_ACK_REQUIRED);
  739. zclSE_Prepayment_Send_ChangeSupply( IPD_ENDPOINT, &ESPAddr,
  740. &changeCmd, TRUE, 1);
  741. if (changeCmd.siteId.pStr != NULL)
  742. {
  743. osal_mem_free(changeCmd.siteId.pStr);
  744. }
  745. if (changeCmd.meterSerialNumber.pStr != NULL)
  746. {
  747. osal_mem_free(changeCmd.meterSerialNumber.pStr);
  748. }
  749. #endif // SE_UK_EXT
  750. #endif // ZCL_PREPAYMENT
  751. }
  752. }
  753. }
  754. /*********************************************************************
  755. * @fn ipd_ValidateAttrDataCB
  756. *
  757. * @brief Check to see if the supplied value for the attribute data
  758. * is within the specified range of the attribute.
  759. *
  760. * @param pAttr - pointer to attribute
  761. * @param pAttrInfo - pointer to attribute info
  762. *
  763. * @return TRUE if data valid. FALSE otherwise.
  764. */
  765. static uint8 ipd_ValidateAttrDataCB( zclAttrRec_t *pAttr, zclWriteRec_t *pAttrInfo )
  766. {
  767. uint8 valid = TRUE;
  768. switch ( pAttrInfo->dataType )
  769. {
  770. case ZCL_DATATYPE_BOOLEAN:
  771. if ( ( *(pAttrInfo->attrData) != 0 ) && ( *(pAttrInfo->attrData) != 1 ) )
  772. valid = FALSE;
  773. break;
  774. default:
  775. break;
  776. }
  777. return ( valid );
  778. }
  779. /*********************************************************************
  780. * @fn ipd_BasicResetCB
  781. *
  782. * @brief Callback from the ZCL General Cluster Library to set all
  783. * the attributes of all the clusters to their factory defaults
  784. *
  785. * @param none
  786. *
  787. * @return none
  788. */
  789. static void ipd_BasicResetCB( void )
  790. {
  791. // user should handle setting attributes to factory defaults here
  792. }
  793. /*********************************************************************
  794. * @fn ipd_IdentifyCB
  795. *
  796. * @brief Callback from the ZCL General Cluster Library when
  797. * it received an Identity Command for this application.
  798. *
  799. * @param pCmd - pointer to structure for Identify command
  800. *
  801. * @return none
  802. */
  803. static void ipd_IdentifyCB( zclIdentify_t *pCmd )
  804. {
  805. ipdIdentifyTime = pCmd->identifyTime;
  806. ipd_ProcessIdentifyTimeChange();
  807. }
  808. /*********************************************************************
  809. * @fn ipd_IdentifyQueryRspCB
  810. *
  811. * @brief Callback from the ZCL General Cluster Library when
  812. * it received an Identity Query Response Command for this application.
  813. *
  814. * @param pRsp - pointer to structure for Identity Query Response command
  815. *
  816. * @return none
  817. */
  818. static void ipd_IdentifyQueryRspCB( zclIdentifyQueryRsp_t *pRsp )
  819. {
  820. // add user code here
  821. }
  822. /*********************************************************************
  823. * @fn ipd_AlarmCB
  824. *
  825. * @brief Callback from the ZCL General Cluster Library when
  826. * it received an Alarm request or response command for
  827. * this application.
  828. *
  829. * @param pAlarm - pointer to structure for Alarm command
  830. *
  831. * @return none
  832. */
  833. static void ipd_AlarmCB( zclAlarm_t *pAlarm )
  834. {
  835. // add user code here
  836. }
  837. #ifdef SE_UK_EXT
  838. /*********************************************************************
  839. * @fn ipd_GetEventLogCB
  840. *
  841. * @brief Callback from the ZCL General Cluster Library when
  842. * it received a Get Event Log command for this
  843. * application.
  844. *
  845. * @param srcEP - source endpoint
  846. * @param srcAddr - pointer to source address
  847. * @param pEventLog - pointer to structure for Get Event Log command
  848. * @param seqNum - sequence number of this command
  849. *
  850. * @return none
  851. */
  852. static void ipd_GetEventLogCB( uint8 srcEP, afAddrType_t *srcAddr,
  853. zclGetEventLog_t *pEventLog, uint8 seqNum )
  854. {
  855. // add user code here, which could fragment the event log payload if
  856. // the entire payload doesn't fit into one Publish Event Log Command.
  857. // Note: the Command Index starts at 0 and is incremented for each
  858. // fragment belonging to the same command.
  859. // There's no event log for now! The Metering Device will support
  860. // logging for all events configured to do so.
  861. }
  862. /*********************************************************************
  863. * @fn ipd_PublishEventLogCB
  864. *
  865. * @brief Callback from the ZCL General Cluster Library when
  866. * it received a Publish Event Log command for this
  867. * application.
  868. *
  869. * @param srcAddr - pointer to source address
  870. * @param pEventLog - pointer to structure for Publish Event Log command
  871. *
  872. * @return none
  873. */
  874. static void ipd_PublishEventLogCB( afAddrType_t *srcAddr, zclPublishEventLog_t *pEventLog )
  875. {
  876. // add user code here
  877. }
  878. #endif // SE_UK_EXT
  879. /*********************************************************************
  880. * @fn ipd_GetCurrentPriceCB
  881. *
  882. * @brief Callback from the ZCL SE Profile Pricing Cluster Library when
  883. * it received a Get Current Price for
  884. * this application.
  885. *
  886. * @param pCmd - pointer to structure for Get Current Price command
  887. * @param srcAddr - pointer to source address
  888. * @param seqNum - sequence number for this command
  889. *
  890. * @return none
  891. */
  892. static void ipd_GetCurrentPriceCB( zclCCGetCurrentPrice_t *pCmd,
  893. afAddrType_t *srcAddr, uint8 seqNum )
  894. {
  895. #if defined ( ZCL_PRICING )
  896. // On receipt of Get Current Price command, the device shall send a
  897. // Publish Price command with the information for the current time.
  898. zclCCPublishPrice_t cmd;
  899. osal_memset( &cmd, 0, sizeof( zclCCPublishPrice_t ) );
  900. cmd.providerId = 0xbabeface;
  901. cmd.numberOfPriceTiers = 0xfe;
  902. zclSE_Pricing_Send_PublishPrice( IPD_ENDPOINT, srcAddr, &cmd, FALSE, seqNum );
  903. #endif // ZCL_PRICING
  904. }
  905. /*********************************************************************
  906. * @fn ipd_GetScheduledPriceCB
  907. *
  908. * @brief Callback from the ZCL SE Profile Pricing Cluster Library when
  909. * it received a Get Scheduled Price for
  910. * this application.
  911. *
  912. * @param pCmd - pointer to structure for Get Scheduled Price command
  913. * @param srcAddr - pointer to source address
  914. * @param seqNum - sequence number for this command
  915. *
  916. * @return none
  917. */
  918. static void ipd_GetScheduledPriceCB( zclCCGetScheduledPrice_t *pCmd,
  919. afAddrType_t *srcAddr, uint8 seqNum )
  920. {
  921. // On receipt of Get Scheduled Price command, the device shall send a
  922. // Publish Price command for all currently scheduled price events.
  923. // The sample code as follows only sends one.
  924. #if defined ( ZCL_PRICING )
  925. zclCCPublishPrice_t cmd;
  926. osal_memset( &cmd, 0, sizeof( zclCCPublishPrice_t ) );
  927. cmd.providerId = 0xbabeface;
  928. cmd.numberOfPriceTiers = 0xfe;
  929. zclSE_Pricing_Send_PublishPrice( IPD_ENDPOINT, srcAddr, &cmd, FALSE, seqNum );
  930. #endif // ZCL_PRICING
  931. }
  932. /*********************************************************************
  933. * @fn ipd_PriceAcknowledgementCB
  934. *
  935. * @brief Callback from the ZCL SE Profile Pricing Cluster Library when
  936. * it received a Price Acknowledgement for this application.
  937. *
  938. * @param pCmd - pointer to structure for Price Acknowledgement command
  939. * @param srcAddr - pointer to source address
  940. * @param seqNum - sequence number for this command
  941. *
  942. * @return none
  943. */
  944. void ipd_PriceAcknowledgementCB( zclCCPriceAcknowledgement_t *pCmd,
  945. afAddrType_t *srcAddr, uint8 seqNum )
  946. {
  947. // add user code here
  948. }
  949. /*********************************************************************
  950. * @fn ipd_GetBlockPeriodCB
  951. *
  952. * @brief Callback from the ZCL SE Profile Pricing Cluster Library when
  953. * it received a Get Block Period for this application.
  954. *
  955. * @param pCmd - pointer to structure for Get Block Period command
  956. * @param srcAddr - pointer to source address
  957. * @param seqNum - sequence number for this command
  958. *
  959. * @return none
  960. */
  961. static void ipd_GetBlockPeriodCB( zclCCGetBlockPeriod_t *pCmd,
  962. afAddrType_t *srcAddr, uint8 seqNum )
  963. {
  964. // add user code here
  965. }
  966. /*********************************************************************
  967. * @fn ipd_PublishPriceCB
  968. *
  969. * @brief Callback from the ZCL SE Profile Pricing Cluster Library when
  970. * it received a Publish Price for this application.
  971. *
  972. * @param pCmd - pointer to structure for Publish Price command
  973. * @param srcAddr - pointer to source address
  974. * @param seqNum - sequence number for this command
  975. *
  976. * @return none
  977. */
  978. static void ipd_PublishPriceCB( zclCCPublishPrice_t *pCmd,
  979. afAddrType_t *srcAddr, uint8 seqNum )
  980. {
  981. #if defined ( ZCL_PRICING )
  982. if ( pCmd )
  983. {
  984. // display Provider ID field
  985. HalLcdWriteString("Provider ID", HAL_LCD_LINE_1);
  986. HalLcdWriteValue( pCmd->providerId, 10, HAL_LCD_LINE_2 );
  987. }
  988. // Verify Price Control Options
  989. if ((pCmd->priceControl != SE_OPTIONAL_FIELD_UINT8) &&
  990. (pCmd->priceControl & SE_PROFILE_PRICEACK_REQUIRED_MASK))
  991. {
  992. zclCCPriceAcknowledgement_t cmd;
  993. cmd.providerId = pCmd->providerId;
  994. cmd.issuerEventId = pCmd->issuerEventId;
  995. cmd.priceAckTime = osal_getClock();
  996. cmd.control = pCmd->priceControl;
  997. zclSE_Pricing_Send_PriceAcknowledgement( IPD_ENDPOINT, srcAddr,
  998. &cmd, TRUE, seqNum );
  999. }
  1000. #if defined ( INTER_PAN )
  1001. ZMacSetReq( ZMacRxOnIdle, &rxOnIdle ); // set receiver on when idle flag to FALSE
  1002. // after getting publish price command via INTER-PAN
  1003. #endif // INTER_PAN
  1004. #endif // ZCL_PRICING
  1005. }
  1006. /*********************************************************************
  1007. * @fn ipd_PublishBlockPeriodCB
  1008. *
  1009. * @brief Callback from the ZCL SE Profile Pricing Cluster Library when
  1010. * it received a Publish Block Period for this application.
  1011. *
  1012. * @param pCmd - pointer to structure for Get Block Period command
  1013. * @param srcAddr - pointer to source address
  1014. * @param seqNum - sequence number for this command
  1015. *
  1016. * @return none
  1017. */
  1018. static void ipd_PublishBlockPeriodCB( zclCCPublishBlockPeriod_t *pCmd,
  1019. afAddrType_t *srcAddr, uint8 seqNum )
  1020. {
  1021. // add user code here
  1022. }
  1023. /*********************************************************************
  1024. * @fn ipd_DisplayMessageCB
  1025. *
  1026. * @brief Callback from the ZCL SE Profile Message Cluster Library when
  1027. * it received a Display Message Command for
  1028. * this application.
  1029. *
  1030. * @param pCmd - pointer to structure for Display Message command
  1031. * @param srcAddr - pointer to source address
  1032. * @param seqNum - sequence number for this command
  1033. *
  1034. * @return none
  1035. */
  1036. static void ipd_DisplayMessageCB( zclCCDisplayMessage_t *pCmd,
  1037. afAddrType_t *srcAddr, uint8 seqNum )
  1038. {
  1039. // Upon receipt of the Display Message Command, the device shall
  1040. // display the message. If the Message Confirmation bit indicates
  1041. // the message originator require a confirmation of receipt from
  1042. // a Utility Customer, the device should display the message or
  1043. // alert the user until it is either confirmed via a button or by
  1044. // selecting a confirmation option on the device. Confirmation is
  1045. // typically used when the Utility is sending down information
  1046. // such as a disconnection notice, or prepaid billing information.
  1047. // Message duration is ignored when confirmation is requested and
  1048. // the message is displayed until confirmed.
  1049. #if defined ( LCD_SUPPORTED )
  1050. // Allowing that strings have a non-printing '\0' terminator.
  1051. if (pCmd->msgString.strLen <= HAL_LCD_MAX_CHARS+1)
  1052. {
  1053. HalLcdWriteString((char*)pCmd->msgString.pStr, HAL_LCD_LINE_3);
  1054. }
  1055. else
  1056. {
  1057. // Allow 3 digit message remainder size and space; and the ellipse ("...") plus the plus ("+"):
  1058. const uint8 left = HAL_LCD_MAX_CHARS - 4 - 4;
  1059. uint8 buf[HAL_LCD_MAX_CHARS];
  1060. (void)osal_memcpy(buf, pCmd->msgString.pStr, left);
  1061. (void)osal_memcpy(buf+left, "...+\0", 5); // Copy the "end-of-string" delimiter.
  1062. HalLcdWriteStringValue((char *)buf, pCmd->msgString.strLen-left, 10, HAL_LCD_LINE_3);
  1063. }
  1064. #endif // LCD_SUPPORTED
  1065. }
  1066. /*********************************************************************
  1067. * @fn ipd_CancelMessageCB
  1068. *
  1069. * @brief Callback from the ZCL SE Profile Message Cluster Library when
  1070. * it received a Cancel Message Command for
  1071. * this application.
  1072. *
  1073. * @param pCmd - pointer to structure for Cancel Message command
  1074. * @param srcAddr - pointer to source address
  1075. * @param seqNum - sequence number for this command
  1076. *
  1077. * @return none
  1078. */
  1079. static void ipd_CancelMessageCB( zclCCCancelMessage_t *pCmd,
  1080. afAddrType_t *srcAddr, uint8 seqNum )
  1081. {
  1082. // add user code here
  1083. }
  1084. /*********************************************************************
  1085. * @fn ipd_GetLastMessageCB
  1086. *
  1087. * @brief Callback from the ZCL SE Profile Message Cluster Library when
  1088. * it received a Get Last Message Command for
  1089. * this application.
  1090. *
  1091. * @param pCmd - pointer to structure for Get Last Message command
  1092. * @param srcAddr - pointer to source address
  1093. * @param seqNum - sequence number for this command
  1094. *
  1095. * @return none
  1096. */
  1097. static void ipd_GetLastMessageCB( afAddrType_t *srcAddr, uint8 seqNum )
  1098. {
  1099. // On receipt of Get Last Message command, the device shall send a
  1100. // Display Message command back to the sender
  1101. #if defined ( ZCL_MESSAGE )
  1102. zclCCDisplayMessage_t cmd;
  1103. uint8 msg[10] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29 };
  1104. // Fill in the command with information for the last message
  1105. cmd.messageId = 0xaabbccdd;
  1106. cmd.messageCtrl.transmissionMode = 0;
  1107. cmd.messageCtrl.importance = 1;
  1108. cmd.messageCtrl.confirmationRequired = 1;
  1109. cmd.durationInMinutes = 60;
  1110. cmd.msgString.strLen = 10;
  1111. cmd.msgString.pStr = msg;
  1112. zclSE_Message_Send_DisplayMessage( IPD_ENDPOINT, srcAddr, &cmd,
  1113. FALSE, seqNum );
  1114. #endif // ZCL_MESSAGE
  1115. }
  1116. /*********************************************************************
  1117. * @fn ipd_MessageConfirmationCB
  1118. *
  1119. * @brief Callback from the ZCL SE Profile Message Cluster Library when
  1120. * it received a Message Confirmation Command for
  1121. * this application.
  1122. *
  1123. * @param pCmd - pointer to structure for Message Confirmation command
  1124. * @param srcAddr - pointer to source address
  1125. * @param seqNum - sequence number for this command
  1126. *
  1127. * @return none
  1128. */
  1129. static void ipd_MessageConfirmationCB( zclCCMessageConfirmation_t *pCmd,
  1130. afAddrType_t *srcAddr, uint8 seqNum )
  1131. {
  1132. // add user code here
  1133. }
  1134. /*********************************************************************
  1135. * @fn ipd_ReqFastPollModeCmdCB
  1136. *
  1137. * @brief Callback from the ZCL SE Profile Simple Metering Cluster Library when
  1138. * it received a Request Fast Poll Mode Command for this application.
  1139. *
  1140. * @param pCmd - pointer to structure for Request Fast Poll Mode command
  1141. * @param srcAddr - pointer to source address
  1142. * @param seqNum - sequence number of this command
  1143. *
  1144. * @return none
  1145. */
  1146. static void ipd_ReqFastPollModeCmdCB( zclCCReqFastPollModeCmd_t *pCmd,
  1147. afAddrType_t *srcAddr, uint8 seqNum )
  1148. {
  1149. // add user code here
  1150. }
  1151. /*********************************************************************
  1152. * @fn ipd_ReqFastPollModeRspCB
  1153. *
  1154. * @brief Callback from the ZCL SE Profile Simple Metering Cluster Library when
  1155. * it received a Request Fast Poll Mode Response for this application.
  1156. *
  1157. * @param pRsp - pointer to structure for Request Fast Poll Mode Response command
  1158. * @param srcAddr - pointer to source address
  1159. * @param seqNum - sequence number of this command
  1160. *
  1161. * @return none
  1162. */
  1163. static void ipd_ReqFastPollModeRspCB( zclCCReqFastPollModeRsp_t *pRsp,
  1164. afAddrType_t *srcAddr, uint8 seqNum )
  1165. {
  1166. #if defined ( ZCL_SIMPLE_METERING )
  1167. #if defined ( LCD_SUPPORTED )
  1168. HalLcdWriteString("Fast Polling", HAL_LCD_LINE_1 );
  1169. HalLcdWriteStringValue("App: ", pRsp->appliedUpdatePeriod, 10, HAL_LCD_LINE_2 );
  1170. HalLcdWriteStringValue("End 0x", pRsp->fastPollModeEndTime, 16, HAL_LCD_LINE_3 );
  1171. #endif // LCD_SUPPORTED
  1172. #endif // ZCL_SIMPLE_METERING
  1173. }
  1174. /*********************************************************************
  1175. * @fn ipd_SelAvailEmergencyCreditCmdCB
  1176. *
  1177. * @brief Callback from the ZCL SE Prepayment Cluster Library when it recieved
  1178. * Select Available Emergency Credit command in the application
  1179. *
  1180. *
  1181. * @param pCmd - pointer to structure for Select Available Emergency Credit command
  1182. * @param srcAddr - pointer to source address
  1183. * @param seqNum - Sequence no of the message
  1184. *
  1185. * @return none
  1186. */
  1187. static void ipd_SelAvailEmergencyCreditCmdCB( zclCCSelAvailEmergencyCredit_t *pCmd,
  1188. afAddrType_t *srcAddr, uint8 seqNum )
  1189. {
  1190. // add user code here
  1191. }
  1192. /*********************************************************************
  1193. * @fn ipd_ChangeSupplyCmdCB
  1194. *
  1195. * @brief Callback from the ZCL SE Prepayment Cluster Library when it recieved
  1196. * Change Supply command in the application
  1197. *
  1198. * @param pCmd - pointer to structure for Change Supply command
  1199. * @param srcAddr - pointer to source address
  1200. * @param seqNum - Sequence no of the message
  1201. *
  1202. * @return none
  1203. */
  1204. static void ipd_ChangeSupplyCmdCB( zclCCChangeSupply_t *pCmd,
  1205. afAddrType_t *srcAddr, uint8 seqNum )
  1206. {
  1207. // add user code here
  1208. }
  1209. /*********************************************************************
  1210. * @fn ipd_SupplyStatusRspCB
  1211. *
  1212. * @brief Callback from the ZCL SE Prepayment Cluster Library when it recieved
  1213. * Supply Status Response command in the application
  1214. *
  1215. * @param pCmd - pointer to structure for Supply Status Response command
  1216. * @param srcAddr - pointer to source address
  1217. * @param seqNum - Sequence no of the message
  1218. *
  1219. * @return none
  1220. */
  1221. static void ipd_SupplyStatusRspCB( zclCCSupplyStatusResponse_t *pCmd,
  1222. afAddrType_t *srcAddr, uint8 seqNum )
  1223. {
  1224. #if defined ( ZCL_PREPAYMENT )
  1225. #if ! defined ( SE_UK_EXT )
  1226. #if defined ( LCD_SUPPORTED )
  1227. if ( pCmd )
  1228. {
  1229. // display Provider ID field
  1230. HalLcdWriteString("SupplyStatusRsp", HAL_LCD_LINE_1 );
  1231. HalLcdWriteValue( pCmd->providerId, 10, HAL_LCD_LINE_2 );
  1232. HalLcdWriteStringValue("Status 0x", pCmd->supplyStatus, 16, HAL_LCD_LINE_3 );
  1233. }
  1234. #endif // LCD_SUPPORTED
  1235. #endif // SE_UK_EXT
  1236. #endif // ZCL_PREPAYMENT
  1237. }
  1238. #if defined ( SE_UK_EXT )
  1239. /*********************************************************************
  1240. * @fn ipd_PublishTariffInformationCB
  1241. *
  1242. * @brief Callback from the ZCL SE Profile Price Cluster Library when
  1243. * it received a Publish Tariff Information for this application.
  1244. *
  1245. * @param pCmd - pointer to structure for Publish Tariff Information command
  1246. * @param srcAddr - pointer to source address
  1247. * @param seqNum - sequence number of this command
  1248. *
  1249. * @return none
  1250. */
  1251. static void ipd_PublishTariffInformationCB( zclCCPublishTariffInformation_t *pCmd,
  1252. afAddrType_t *srcAddr, uint8 seqNum )
  1253. {
  1254. // add user code here
  1255. }
  1256. /*********************************************************************
  1257. * @fn ipd_PublishPriceMatrixCB
  1258. *
  1259. * @brief Callback from the ZCL SE Profile Price Cluster Library when
  1260. * it received a Publish Price Matrix for this application.
  1261. *
  1262. * @param pCmd - pointer to structure for Publish Price Matrix command
  1263. * @param srcAddr - pointer to source address
  1264. * @param seqNum - sequence number of this command
  1265. *
  1266. * @return none
  1267. */
  1268. static void ipd_PublishPriceMatrixCB( zclCCPublishPriceMatrix_t *pCmd,
  1269. afAddrType_t *srcAddr, uint8 seqNum )
  1270. {
  1271. // add user code here
  1272. }
  1273. /*********************************************************************
  1274. * @fn ipd_PublishBlockThresholdsCB
  1275. *
  1276. * @brief Callback from the ZCL SE Profile Price Cluster Library when
  1277. * it received a Publish Block Thresholds for this application.
  1278. *
  1279. * @param pCmd - pointer to structure for Publish Block Thresholds command
  1280. * @param srcAddr - pointer to source address
  1281. * @param seqNum - sequence number of this command
  1282. *
  1283. * @return none
  1284. */
  1285. static void ipd_PublishBlockThresholdsCB( zclCCPublishBlockThresholds_t *pCmd,
  1286. afAddrType_t *srcAddr, uint8 seqNum )
  1287. {
  1288. // add user code here
  1289. }
  1290. /*********************************************************************
  1291. * @fn ipd_PublishConversionFactorCB
  1292. *
  1293. * @brief Callback from the ZCL SE Profile Price Cluster Library when
  1294. * it received a Publish Conversion Factor for this application.
  1295. *
  1296. * @param pCmd - pointer to structure for Publish Conversion Factor command
  1297. * @param srcAddr - pointer to source address
  1298. * @param seqNum - sequence number of this command
  1299. *
  1300. * @return none
  1301. */
  1302. static void ipd_PublishConversionFactorCB( zclCCPublishConversionFactor_t *pCmd,
  1303. afAddrType_t *srcAddr, uint8 seqNum )
  1304. {
  1305. // add user code here
  1306. }
  1307. /*********************************************************************
  1308. * @fn ipd_PublishCalorificValueCB
  1309. *
  1310. * @brief Callback from the ZCL SE Profile Price Cluster Library when
  1311. * it received a Publish Calorific Value for this application.
  1312. *
  1313. * @param pCmd - pointer to structure for Publish Calorific Value command
  1314. * @param srcAddr - pointer to source address
  1315. * @param seqNum - sequence number of this command
  1316. *
  1317. * @return none
  1318. */
  1319. static void ipd_PublishCalorificValueCB( zclCCPublishCalorificValue_t *pCmd,
  1320. afAddrType_t *srcAddr, uint8 seqNum )
  1321. {
  1322. // add user code here
  1323. }
  1324. /*********************************************************************
  1325. * @fn ipd_PublishCO2ValueCB
  1326. *
  1327. * @brief Callback from the ZCL SE Profile Price Cluster Library when
  1328. * it received a Publish CO2 Value for this application.
  1329. *
  1330. * @param pCmd - pointer to structure for Publish CO2 Value command
  1331. * @param srcAddr - pointer to source address
  1332. * @param seqNum - sequence number of this command
  1333. *
  1334. * @return none
  1335. */
  1336. static void ipd_PublishCO2ValueCB( zclCCPublishCO2Value_t *pCmd,
  1337. afAddrType_t *srcAddr, uint8 seqNum )
  1338. {
  1339. // add user code here
  1340. }
  1341. /*********************************************************************
  1342. * @fn ipd_PublishCPPEventCB
  1343. *
  1344. * @brief Callback from the ZCL SE Profile Price Cluster Library when
  1345. * it received a Publish CPP Event for this application.
  1346. *
  1347. * @param pCmd - pointer to structure for Publish CPP Event command
  1348. * @param srcAddr - pointer to source address
  1349. * @param seqNum - sequence number of this command
  1350. *
  1351. * @return none
  1352. */
  1353. static void ipd_PublishCPPEventCB( zclCCPublishCPPEvent_t *pCmd,
  1354. afAddrType_t *srcAddr, uint8 seqNum )
  1355. {
  1356. // add user code here
  1357. }
  1358. /*********************************************************************
  1359. * @fn ipd_PublishBillingPeriodCB
  1360. *
  1361. * @brief Callback from the ZCL SE Profile Price Cluster Library when
  1362. * it received a Publish Billing Period for this application.
  1363. *
  1364. * @param pCmd - pointer to structure for Publish Billing Period command
  1365. * @param srcAddr - pointer to source address
  1366. * @param seqNum - sequence number of this command
  1367. *
  1368. * @return none
  1369. */
  1370. static void ipd_PublishBillingPeriodCB( zclCCPublishBillingPeriod_t *pCmd,
  1371. afAddrType_t *srcAddr, uint8 seqNum )
  1372. {
  1373. // add user code here
  1374. }
  1375. /*********************************************************************
  1376. * @fn ipd_PublishConsolidatedBillCB
  1377. *
  1378. * @brief Callback from the ZCL SE Profile Price Cluster Library when
  1379. * it received a Publish Consolidated Bill for this application.
  1380. *
  1381. * @param pCmd - pointer to structure for Publish Consolidated Bill command
  1382. * @param srcAddr - pointer to source address
  1383. * @param seqNum - sequence number of this command
  1384. *
  1385. * @return none
  1386. */
  1387. static void ipd_PublishConsolidatedBillCB( zclCCPublishConsolidatedBill_t *pCmd,
  1388. afAddrType_t *srcAddr, uint8 seqNum )
  1389. {
  1390. // add user code here
  1391. }
  1392. /*********************************************************************
  1393. * @fn ipd_PublishCreditPaymentInfoCB
  1394. *
  1395. * @brief Callback from the ZCL SE Profile Price Cluster Library when
  1396. * it received a Publish Credit Payment Info for this application.
  1397. *
  1398. * @param pCmd - pointer to structure for Publish Credit Payment Info command
  1399. * @param srcAddr - pointer to source address
  1400. * @param seqNum - sequence number of this command
  1401. *
  1402. * @return none
  1403. */
  1404. static void ipd_PublishCreditPaymentInfoCB( zclCCPublishCreditPaymentInfo_t *pCmd,
  1405. afAddrType_t *srcAddr, uint8 seqNum )
  1406. {
  1407. // add user code here
  1408. }
  1409. /*********************************************************************
  1410. * @fn ipd_GetPrepaySnapshotResponseCB
  1411. *
  1412. * @brief Callback from the ZCL SE Profile Prepayment Cluster Library when
  1413. * it received a Get Prepay Snapshot Response for this application.
  1414. *
  1415. * @param pCmd - pointer to structure for Get Prepay Snapshot Response command
  1416. * @param srcAddr - pointer to source address
  1417. * @param seqNum - sequence number of this command
  1418. *
  1419. * @return none
  1420. */
  1421. static void ipd_GetPrepaySnapshotResponseCB( zclCCGetPrepaySnapshotResponse_t *pCmd,
  1422. afAddrType_t *srcAddr, uint8 seqNum )
  1423. {
  1424. // add user code here
  1425. }
  1426. /*********************************************************************
  1427. * @fn ipd_ChangePaymentModeResponseCB
  1428. *
  1429. * @brief Callback from the ZCL SE Profile Prepayment Cluster Library when
  1430. * it received a Change Payment Mode Response for this application.
  1431. *
  1432. * @param pCmd - pointer to structure for Change Payment Mode Response command
  1433. * @param srcAddr - pointer to source address
  1434. * @param seqNum - sequence number of this command
  1435. *
  1436. * @return none
  1437. */
  1438. static void ipd_ChangePaymentModeResponseCB( zclCCChangePaymentModeResponse_t *pCmd,
  1439. afAddrType_t *srcAddr, uint8 seqNum )
  1440. {
  1441. // add user code here
  1442. }
  1443. /*********************************************************************
  1444. * @fn ipd_ConsumerTopupResponseCB
  1445. *
  1446. * @brief Callback from the ZCL SE Profile Prepayment Cluster Library when
  1447. * it received a Consumer Topup Response for this application.
  1448. *
  1449. * @param pCmd - pointer to structure for Consumer Topup Response command
  1450. * @param srcAddr - pointer to source address
  1451. * @param seqNum - sequence number of this command
  1452. *
  1453. * @return none
  1454. */
  1455. static void ipd_ConsumerTopupResponseCB( zclCCConsumerTopupResponse_t *pCmd,
  1456. afAddrType_t *srcAddr, uint8 seqNum )
  1457. {
  1458. // add user code here
  1459. }
  1460. /*********************************************************************
  1461. * @fn ipd_GetCommandsCB
  1462. *
  1463. * @brief Callback from the ZCL SE Profile Prepayment Cluster Library when
  1464. * it received a Get Commands for this application.
  1465. *
  1466. * @param prepayNotificationFlags - prepayment notification flags
  1467. * @param srcAddr - pointer to source address
  1468. * @param seqNum - sequence number of this command
  1469. *
  1470. * @return none
  1471. */
  1472. static void ipd_GetCommandsCB( uint8 prepayNotificationFlags,
  1473. afAddrType_t *srcAddr, uint8 seqNum )
  1474. {
  1475. // add user code here
  1476. }
  1477. /*********************************************************************
  1478. * @fn ipd_PublishTopupLogCB
  1479. *
  1480. * @brief Callback from the ZCL SE Profile Prepayment Cluster Library when
  1481. * it received a Publish Topup Log for this application.
  1482. *
  1483. * @param pCmd - pointer to structure for Publish Topup Log command
  1484. * @param srcAddr - pointer to source address
  1485. * @param seqNum - sequence number of this command
  1486. *
  1487. * @return none
  1488. */
  1489. static void ipd_PublishTopupLogCB( zclCCPublishTopupLog_t *pCmd,
  1490. afAddrType_t *srcAddr, uint8 seqNum )
  1491. {
  1492. // add user code here
  1493. }
  1494. /*********************************************************************
  1495. * @fn ipd_PublishDebtLogCB
  1496. *
  1497. * @brief Callback from the ZCL SE Profile Prepayment Cluster Library when
  1498. * it received a Publish Debt Log for this application.
  1499. *
  1500. * @param pCmd - pointer to structure for Publish Debt Log command
  1501. * @param srcAddr - pointer to source address
  1502. * @param seqNum - sequence number of this command
  1503. *
  1504. * @return none
  1505. */
  1506. static void ipd_PublishDebtLogCB( zclCCPublishDebtLog_t *pCmd,
  1507. afAddrType_t *srcAddr, uint8 seqNum )
  1508. {
  1509. // add user code here
  1510. }
  1511. #endif // SE_UK_EXT
  1512. /******************************************************************************
  1513. *
  1514. * Functions for processing ZCL Foundation incoming Command/Response messages
  1515. *
  1516. *****************************************************************************/
  1517. /*********************************************************************
  1518. * @fn ipd_ProcessZCLMsg
  1519. *
  1520. * @brief Process ZCL Foundation incoming message
  1521. *
  1522. * @param pInMsg - message to process
  1523. *
  1524. * @return none
  1525. */
  1526. static void ipd_ProcessZCLMsg( zclIncomingMsg_t *pInMsg )
  1527. {
  1528. switch ( pInMsg->zclHdr.commandID )
  1529. {
  1530. #if defined ( ZCL_READ )
  1531. case ZCL_CMD_READ_RSP:
  1532. ipd_ProcessInReadRspCmd( pInMsg );
  1533. break;
  1534. #endif // ZCL_READ
  1535. #if defined ( ZCL_WRITE )
  1536. case ZCL_CMD_WRITE_RSP:
  1537. ipd_ProcessInWriteRspCmd( pInMsg );
  1538. break;
  1539. #endif // ZCL_WRITE
  1540. case ZCL_CMD_DEFAULT_RSP:
  1541. ipd_ProcessInDefaultRspCmd( pInMsg );
  1542. break;
  1543. #if defined ( ZCL_DISCOVER )
  1544. case ZCL_CMD_DISCOVER_RSP:
  1545. ipd_ProcessInDiscRspCmd( pInMsg );
  1546. break;
  1547. #endif // ZCL_DISCOVER
  1548. default:
  1549. break;
  1550. }
  1551. if ( pInMsg->attrCmd != NULL )
  1552. {
  1553. // free the parsed command
  1554. osal_mem_free( pInMsg->attrCmd );
  1555. pInMsg->attrCmd = NULL;
  1556. }
  1557. }
  1558. #if defined ( ZCL_READ )
  1559. /*********************************************************************
  1560. * @fn ipd_ProcessInReadRspCmd
  1561. *
  1562. * @brief Process the "Profile" Read Response Command
  1563. *
  1564. * @param pInMsg - incoming message to process
  1565. *
  1566. * @return none
  1567. */
  1568. static uint8 ipd_ProcessInReadRspCmd( zclIncomingMsg_t *pInMsg )
  1569. {
  1570. zclReadRspCmd_t *readRspCmd;
  1571. uint8 i;
  1572. readRspCmd = (zclReadRspCmd_t *)pInMsg->attrCmd;
  1573. for (i = 0; i < readRspCmd->numAttr; i++)
  1574. {
  1575. // Notify the originator of the results of the original read attributes
  1576. // attempt and, for each successfull request, the value of the requested
  1577. // attribute
  1578. }
  1579. return TRUE;
  1580. }
  1581. #endif // ZCL_READ
  1582. #if defined ( ZCL_WRITE )
  1583. /*********************************************************************
  1584. * @fn ipd_ProcessInWriteRspCmd
  1585. *
  1586. * @brief Process the "Profile" Write Response Command
  1587. *
  1588. * @param pInMsg - incoming message to process
  1589. *
  1590. * @return none
  1591. */
  1592. static uint8 ipd_ProcessInWriteRspCmd( zclIncomingMsg_t *pInMsg )
  1593. {
  1594. zclWriteRspCmd_t *writeRspCmd;
  1595. uint8 i;
  1596. writeRspCmd = (zclWriteRspCmd_t *)pInMsg->attrCmd;
  1597. for (i = 0; i < writeRspCmd->numAttr; i++)
  1598. {
  1599. // Notify the device of the results of the its original write attributes
  1600. // command.
  1601. }
  1602. return TRUE;
  1603. }
  1604. #endif // ZCL_WRITE
  1605. /*********************************************************************
  1606. * @fn ipd_ProcessInDefaultRspCmd
  1607. *
  1608. * @brief Process the "Profile" Default Response Command
  1609. *
  1610. * @param pInMsg - incoming message to process
  1611. *
  1612. * @return none
  1613. */
  1614. static uint8 ipd_ProcessInDefaultRspCmd( zclIncomingMsg_t *pInMsg )
  1615. {
  1616. // zclDefaultRspCmd_t *defaultRspCmd = (zclDefaultRspCmd_t *)pInMsg->attrCmd;
  1617. // Device is notified of the Default Response command.
  1618. return TRUE;
  1619. }
  1620. #if defined ( ZCL_DISCOVER )
  1621. /*********************************************************************
  1622. * @fn ipd_ProcessInDiscRspCmd
  1623. *
  1624. * @brief Process the "Profile" Discover Response Command
  1625. *
  1626. * @param pInMsg - incoming message to process
  1627. *
  1628. * @return none
  1629. */
  1630. static uint8 ipd_ProcessInDiscRspCmd( zclIncomingMsg_t *pInMsg )
  1631. {
  1632. zclDiscoverRspCmd_t *discoverRspCmd;
  1633. uint8 i;
  1634. discoverRspCmd = (zclDiscoverRspCmd_t *)pInMsg->attrCmd;
  1635. for ( i = 0; i < discoverRspCmd->numAttr; i++ )
  1636. {
  1637. // Device is notified of the result of its attribute discovery command.
  1638. }
  1639. return TRUE;
  1640. }
  1641. #endif // ZCL_DISCOVER
  1642. /****************************************************************************
  1643. ****************************************************************************/