MT_UTIL.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /***************************************************************************************************
  2. Filename: MT_UTIL.c
  3. Revised: $Date: 2009-03-31 13:02:19 -0700 (Tue, 31 Mar 2009) $
  4. Revision: $Revision: 19612 $
  5. Description: MonitorTest Utility Functions
  6. Copyright 2007 - 2009 Texas Instruments Incorporated. All rights reserved.
  7. IMPORTANT: Your use of this Software is limited to those specific rights
  8. granted under the terms of a software license agreement between the user
  9. who downloaded the software, his/her employer (which must be your employer)
  10. and Texas Instruments Incorporated (the "License"). You may not use this
  11. Software unless you agree to abide by the terms of the License. The License
  12. limits your use, and you acknowledge, that the Software may not be modified,
  13. copied or distributed unless embedded on a Texas Instruments microcontroller
  14. or used solely and exclusively in conjunction with a Texas Instruments radio
  15. frequency transceiver, which is integrated into your product. Other than for
  16. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  17. works of, modify, distribute, perform, display or sell this Software and/or
  18. its documentation for any purpose.
  19. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  20. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  21. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  22. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  23. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  24. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  25. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  26. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  27. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  28. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  29. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  30. Should you have any questions regarding your right to use this Software,
  31. contact Texas Instruments Incorporated at www.TI.com.
  32. ***************************************************************************************************/
  33. /***************************************************************************************************
  34. * INCLUDES
  35. ***************************************************************************************************/
  36. #include "ZComDef.h"
  37. #include "OnBoard.h" /* This is here because of the key reading */
  38. #include "hal_key.h"
  39. #include "hal_led.h"
  40. #include "OSAL_Nv.h"
  41. #include "NLMEDE.h"
  42. #include "ZDApp.h"
  43. #include "MT.h"
  44. #include "MT_UTIL.h"
  45. #include "MT_ZDO.h"
  46. #include "MT_SAPI.h"
  47. #include "MT_NWK.h"
  48. #include "MT_AF.h"
  49. #include "MT_MAC.h"
  50. /***************************************************************************************************
  51. * CONSTANTS
  52. ***************************************************************************************************/
  53. #define MT_UTIL_DEVICE_INFO_RESPONSE_LEN 14
  54. /***************************************************************************************************
  55. * LOCAL FUNCTIONS
  56. ***************************************************************************************************/
  57. #if defined (MT_UTIL_FUNC)
  58. void MT_UtilGetDeviceInfo(void);
  59. void MT_UtilGetNvInfo(void);
  60. void MT_UtilSetPanID(uint8 *pBuf);
  61. void MT_UtilSetChannels(uint8 *pBuf);
  62. void MT_UtilSetSecLevel(uint8 *pBuf);
  63. void MT_UtilSetPreCfgKey(uint8 *pBuf);
  64. void MT_UtilCallbackSub(uint8 *pData);
  65. void MT_UtilKeyEvent(uint8 *pBuf);
  66. void MT_UtilHeartBeat(uint8 *pBuf);
  67. void MT_UtilTimeAlive(void);
  68. void MT_UtilLedControl(uint8 *pBuf);
  69. #endif /* MT_UTIL_FUNC */
  70. #if defined (MT_UTIL_FUNC)
  71. /***************************************************************************************************
  72. * @fn MT_UtilProcessing
  73. *
  74. * @brief Process all the DEBUG commands that are issued by test tool
  75. *
  76. * @param pBuf - pointer to received SPI data message
  77. *
  78. * @return status
  79. ***************************************************************************************************/
  80. uint8 MT_UtilCommandProcessing(uint8 *pBuf)
  81. {
  82. uint8 status = MT_RPC_SUCCESS;
  83. switch (pBuf[MT_RPC_POS_CMD1])
  84. {
  85. case MT_UTIL_GET_DEVICE_INFO:
  86. MT_UtilGetDeviceInfo();
  87. break;
  88. case MT_UTIL_GET_NV_INFO:
  89. MT_UtilGetNvInfo();
  90. break;
  91. case MT_UTIL_SET_PANID:
  92. MT_UtilSetPanID(pBuf);
  93. break;
  94. case MT_UTIL_SET_CHANNELS:
  95. MT_UtilSetChannels(pBuf);
  96. break;
  97. case MT_UTIL_SET_SECLEVEL:
  98. MT_UtilSetSecLevel(pBuf);
  99. break;
  100. case MT_UTIL_SET_PRECFGKEY:
  101. MT_UtilSetPreCfgKey(pBuf);
  102. break;
  103. case MT_UTIL_CALLBACK_SUB_CMD:
  104. MT_UtilCallbackSub(pBuf);
  105. break;
  106. case MT_UTIL_KEY_EVENT:
  107. #if (defined HAL_KEY) && (HAL_KEY == TRUE)
  108. MT_UtilKeyEvent(pBuf);
  109. #endif
  110. break;
  111. case MT_UTIL_LED_CONTROL:
  112. #if (defined HAL_LED) && (HAL_LED == TRUE)
  113. MT_UtilLedControl(pBuf);
  114. #endif
  115. break;
  116. case MT_UTIL_HEARTBEAT:
  117. MT_UtilHeartBeat(pBuf);
  118. break;
  119. case MT_UTIL_TIME_ALIVE:
  120. MT_UtilTimeAlive();
  121. break;
  122. default:
  123. status = MT_RPC_ERR_COMMAND_ID;
  124. break;
  125. }
  126. return status;
  127. }
  128. /***************************************************************************************************
  129. * @fn MT_UtilGetDeviceInfo
  130. *
  131. * @brief The Get Device Info serial message.
  132. *
  133. * @param void
  134. *
  135. * @return void
  136. ***************************************************************************************************/
  137. void MT_UtilGetDeviceInfo(void)
  138. {
  139. uint8 *buf;
  140. uint8 *pBuf;
  141. uint8 bufLen = MT_UTIL_DEVICE_INFO_RESPONSE_LEN;
  142. #if defined( RTR_NWK ) && !defined( NONWK )
  143. uint8 assocCnt = 0;
  144. #endif
  145. uint16 *assocList = NULL;
  146. #if defined( RTR_NWK ) && !defined( NONWK )
  147. assocList = AssocMakeList( &assocCnt );
  148. bufLen += (assocCnt * sizeof(uint16));
  149. #endif
  150. buf = osal_mem_alloc( bufLen );
  151. if ( buf )
  152. {
  153. pBuf = buf;
  154. *pBuf++ = ZSUCCESS; // Status
  155. osal_nv_read( ZCD_NV_EXTADDR, 0, Z_EXTADDR_LEN, pBuf );
  156. pBuf += Z_EXTADDR_LEN;
  157. #if defined( NONWK )
  158. // Skip past ZStack only parameters for NONWK
  159. *pBuf++ = 0;
  160. *pBuf++ = 0;
  161. *pBuf++ = 0;
  162. *pBuf++ = 0;
  163. *pBuf = 0;
  164. #else
  165. {
  166. uint16 shortAddr = NLME_GetShortAddr();
  167. *pBuf++ = LO_UINT16( shortAddr );
  168. *pBuf++ = HI_UINT16( shortAddr );
  169. }
  170. /* Return device type */
  171. *pBuf++ = ZSTACK_DEVICE_BUILD;
  172. /*Return device state */
  173. *pBuf++ = (uint8)devState;
  174. #if defined( RTR_NWK )
  175. *pBuf++ = assocCnt;
  176. if ( assocCnt )
  177. {
  178. uint8 x;
  179. uint16 *puint16 = assocList;
  180. for ( x = 0; x < assocCnt; x++, puint16++ )
  181. {
  182. *pBuf++ = LO_UINT16( *puint16 );
  183. *pBuf++ = HI_UINT16( *puint16 );
  184. }
  185. }
  186. #else
  187. *pBuf++ = 0;
  188. #endif
  189. #endif
  190. MT_BuildAndSendZToolResponse( ((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL),
  191. MT_UTIL_GET_DEVICE_INFO,
  192. bufLen, buf );
  193. osal_mem_free( buf );
  194. }
  195. if ( assocList )
  196. {
  197. osal_mem_free( assocList );
  198. }
  199. }
  200. /***************************************************************************************************
  201. * @fn MT_UtilGetNvInfo
  202. *
  203. * @brief The Get NV Info serial message.
  204. *
  205. * @param byte *msg - pointer to the data
  206. *
  207. * @return void
  208. ***************************************************************************************************/
  209. void MT_UtilGetNvInfo(void)
  210. {
  211. uint8 len;
  212. uint8 stat;
  213. uint8 *buf;
  214. uint8 *pBuf;
  215. uint16 tmp16;
  216. uint32 tmp32;
  217. /*
  218. Get required length of buffer
  219. Status + ExtAddr + ChanList + PanID + SecLevel + PreCfgKey
  220. */
  221. len = 1 + Z_EXTADDR_LEN + 4 + 2 + 1 + SEC_KEY_LEN;
  222. buf = osal_mem_alloc( len );
  223. if ( buf )
  224. {
  225. /* Assume NV not available */
  226. osal_memset( buf, 0xFF, len );
  227. /* Skip over status */
  228. pBuf = buf + 1;
  229. /* Start with 64-bit extended address */
  230. stat = osal_nv_read( ZCD_NV_EXTADDR, 0, Z_EXTADDR_LEN, pBuf );
  231. if ( stat ) stat = 0x01;
  232. pBuf += Z_EXTADDR_LEN;
  233. /* Scan channel list (bit mask) */
  234. if ( osal_nv_read( ZCD_NV_CHANLIST, 0, sizeof( tmp32 ), &tmp32 ) )
  235. stat |= 0x02;
  236. else
  237. {
  238. pBuf[0] = BREAK_UINT32( tmp32, 3 );
  239. pBuf[1] = BREAK_UINT32( tmp32, 2 );
  240. pBuf[2] = BREAK_UINT32( tmp32, 1 );
  241. pBuf[3] = BREAK_UINT32( tmp32, 0 );
  242. }
  243. pBuf += sizeof( tmp32 );
  244. /* ZigBee PanID */
  245. if ( osal_nv_read( ZCD_NV_PANID, 0, sizeof( tmp16 ), &tmp16 ) )
  246. stat |= 0x04;
  247. else
  248. {
  249. pBuf[0] = LO_UINT16( tmp16 );
  250. pBuf[1] = HI_UINT16( tmp16 );
  251. }
  252. pBuf += sizeof( tmp16 );
  253. /* Security level */
  254. if ( osal_nv_read( ZCD_NV_SECURITY_LEVEL, 0, sizeof( uint8 ), pBuf++ ) )
  255. stat |= 0x08;
  256. /* Pre-configured security key */
  257. if ( osal_nv_read( ZCD_NV_PRECFGKEY, 0, SEC_KEY_LEN, pBuf ) )
  258. stat |= 0x10;
  259. /* Status bit mask - bit=1 indicates failure */
  260. *buf = stat;
  261. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL), MT_UTIL_GET_NV_INFO,
  262. len, buf );
  263. osal_mem_free( buf );
  264. }
  265. }
  266. /***************************************************************************************************
  267. * @fn MT_UtilSetPanID
  268. *
  269. * @brief Set PanID message
  270. *
  271. * @param byte *msg - pointer to the data
  272. *
  273. * @return void
  274. ***************************************************************************************************/
  275. void MT_UtilSetPanID(uint8 *pBuf)
  276. {
  277. uint16 temp16;
  278. uint8 retValue = ZFailure;
  279. uint8 cmdId;
  280. /* parse header */
  281. cmdId = pBuf[MT_RPC_POS_CMD1];
  282. pBuf += MT_RPC_FRAME_HDR_SZ;
  283. temp16 = BUILD_UINT16(pBuf[0], pBuf[1]);
  284. pBuf += sizeof(uint16);
  285. retValue = osal_nv_write(ZCD_NV_PANID, 0, osal_nv_item_len( ZCD_NV_PANID ), &temp16);
  286. /* Build and send back the response */
  287. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL), cmdId, 1, &retValue);
  288. }
  289. /***************************************************************************************************
  290. * @fn MT_UtilSetChannels
  291. *
  292. * @brief Set Channels
  293. *
  294. * @param byte *msg - pointer to the data
  295. *
  296. * @return void
  297. ***************************************************************************************************/
  298. void MT_UtilSetChannels(uint8 *pBuf)
  299. {
  300. uint32 tmp32;
  301. uint8 retValue = ZFailure;
  302. uint8 cmdId;
  303. /* parse header */
  304. cmdId = pBuf[MT_RPC_POS_CMD1];
  305. pBuf += MT_RPC_FRAME_HDR_SZ;
  306. tmp32 = BUILD_UINT32(pBuf[0], pBuf[1], pBuf[2], pBuf[3]);
  307. retValue = osal_nv_write(ZCD_NV_CHANLIST, 0, osal_nv_item_len( ZCD_NV_CHANLIST ), &tmp32);
  308. /* Build and send back the response */
  309. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL), cmdId, 1, &retValue);
  310. }
  311. /***************************************************************************************************
  312. * @fn MT_UtilSetSecLevel
  313. *
  314. * @brief Set Sec Level
  315. *
  316. * @param byte *msg - pointer to the data
  317. *
  318. * @return void
  319. ***************************************************************************************************/
  320. void MT_UtilSetSecLevel(uint8 *pBuf)
  321. {
  322. uint8 retValue = ZFailure;
  323. uint8 cmdId;
  324. /* parse header */
  325. cmdId = pBuf[MT_RPC_POS_CMD1];
  326. pBuf += MT_RPC_FRAME_HDR_SZ;
  327. retValue = osal_nv_write( ZCD_NV_SECURITY_LEVEL, 0, osal_nv_item_len( ZCD_NV_SECURITY_LEVEL ), pBuf);
  328. /* Build and send back the response */
  329. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL), cmdId, 1, &retValue );
  330. }
  331. /***************************************************************************************************
  332. * @fn MT_UtilSetPreCfgKey
  333. *
  334. * @brief Set Pre Cfg Key
  335. *
  336. * @param byte *msg - pointer to the data
  337. *
  338. * @return void
  339. ***************************************************************************************************/
  340. void MT_UtilSetPreCfgKey(uint8 *pBuf)
  341. {
  342. uint8 retValue = ZFailure;
  343. uint8 cmdId;
  344. /* parse header */
  345. cmdId = pBuf[MT_RPC_POS_CMD1];
  346. pBuf += MT_RPC_FRAME_HDR_SZ;
  347. retValue = osal_nv_write( ZCD_NV_PRECFGKEY, 0, osal_nv_item_len( ZCD_NV_PRECFGKEY ), pBuf);
  348. /* Build and send back the response */
  349. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL), cmdId, 1, &retValue );
  350. }
  351. /***************************************************************************************************
  352. * @fn MT_UtilCallbackSub
  353. *
  354. * @brief The Callback subscribe.
  355. *
  356. * @param byte *msg - pointer to the data
  357. *
  358. * @return void
  359. ***************************************************************************************************/
  360. void MT_UtilCallbackSub(uint8 *pBuf)
  361. {
  362. uint8 cmdId = pBuf[MT_RPC_POS_CMD1];
  363. uint8 retValue = ZFailure;
  364. #if defined(MT_MAC_CB_FUNC) || defined(MT_NWK_CB_FUNC) || defined(MT_ZDO_CB_FUNC) || defined(MT_AF_CB_FUNC) || defined(MT_SAPI_CB_FUNC) || defined(MT_SAPI_CB_FUNC)
  365. uint8 subSystem;
  366. uint16 subscribed_command;
  367. // Move past header
  368. retValue = ZSuccess;
  369. pBuf += MT_RPC_FRAME_HDR_SZ;
  370. /* Command */
  371. subscribed_command = BUILD_UINT16(pBuf[0], pBuf[1]);
  372. pBuf += 2;
  373. /* Subsystem - 5 bits on the MSB of the command */
  374. subSystem = HI_UINT16(subscribed_command) & 0x1F ;
  375. /* What is the action - SUBSCRIBE or !SUBSCRIBE */
  376. if (*pBuf)
  377. {
  378. /* Turn ON */
  379. #if defined( MT_MAC_CB_FUNC )
  380. if ((subSystem == MT_RPC_SYS_MAC) || (subscribed_command == 0xFFFF))
  381. _macCallbackSub = 0xFFFF;
  382. #endif
  383. #if defined( MT_NWK_CB_FUNC )
  384. if ((subSystem == MT_RPC_SYS_NWK) || (subscribed_command == 0xFFFF))
  385. _nwkCallbackSub = 0xFFFF;
  386. #endif
  387. #if defined( MT_ZDO_CB_FUNC )
  388. if ((subSystem == MT_RPC_SYS_ZDO) || (subscribed_command == 0xFFFF))
  389. _zdoCallbackSub = 0xFFFFFFFF;
  390. #endif
  391. #if defined( MT_AF_CB_FUNC )
  392. if ((subSystem == MT_RPC_SYS_AF) || (subscribed_command == 0xFFFF))
  393. _afCallbackSub = 0xFFFF;
  394. #endif
  395. #if defined( MT_SAPI_CB_FUNC )
  396. if ((subSystem == MT_RPC_SYS_SAPI) || (subscribed_command == 0xFFFF))
  397. _sapiCallbackSub = 0xFFFF;
  398. #endif
  399. }
  400. else
  401. {
  402. /* Turn OFF */
  403. #if defined( MT_MAC_CB_FUNC )
  404. if ((subSystem == MT_RPC_SYS_MAC) || (subscribed_command == 0xFFFF))
  405. _macCallbackSub = 0x0000;
  406. #endif
  407. #if defined( MT_NWK_CB_FUNC )
  408. if ((subSystem == MT_RPC_SYS_NWK) || (subscribed_command == 0xFFFF))
  409. _nwkCallbackSub = 0x0000;
  410. #endif
  411. #if defined( MT_ZDO_CB_FUNC )
  412. if ((subSystem == MT_RPC_SYS_ZDO) || (subscribed_command == 0xFFFF))
  413. _zdoCallbackSub = 0x00000000;
  414. #endif
  415. #if defined( MT_AF_CB_FUNC )
  416. if ((subSystem == MT_RPC_SYS_AF) || (subscribed_command == 0xFFFF))
  417. _afCallbackSub = 0x0000;
  418. #endif
  419. #if defined( MT_SAPI_CB_FUNC )
  420. if ((subSystem == MT_RPC_SYS_SAPI) || (subscribed_command == 0xFFFF))
  421. _sapiCallbackSub = 0x0000;
  422. #endif
  423. }
  424. #endif // MT_MAC_CB_FUNC || MT_NWK_CB_FUNC || MT_ZDO_CB_FUNC || MT_AF_CB_FUNC || MT_SAPI_CB_FUNC || MT_SAPI_CB_FUNC
  425. /* Build and send back the response */
  426. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL), cmdId, 1, &retValue );
  427. }
  428. #if (defined HAL_KEY) && (HAL_KEY == TRUE)
  429. /***************************************************************************************************
  430. * @fn MT_UtilKeyEvent
  431. *
  432. * @brief Process Key Event
  433. *
  434. * @param byte *msg - pointer to the data
  435. *
  436. * @return void
  437. ***************************************************************************************************/
  438. void MT_UtilKeyEvent(uint8 *pBuf)
  439. {
  440. uint8 x = 0;
  441. uint8 retValue = ZFailure;
  442. uint8 cmdId;
  443. /* parse header */
  444. cmdId = pBuf[MT_RPC_POS_CMD1];
  445. pBuf += MT_RPC_FRAME_HDR_SZ;
  446. /* Translate between SPI values to device values */
  447. if ( *pBuf & 0x01 )
  448. x |= HAL_KEY_SW_1;
  449. if ( *pBuf & 0x02 )
  450. x |= HAL_KEY_SW_2;
  451. if ( *pBuf & 0x04 )
  452. x |= HAL_KEY_SW_3;
  453. if ( *pBuf & 0x08 )
  454. x |= HAL_KEY_SW_4;
  455. #if defined ( HAL_KEY_SW_5 )
  456. if ( *pBuf & 0x10 )
  457. x |= HAL_KEY_SW_5;
  458. #endif
  459. #if defined ( HAL_KEY_SW_6 )
  460. if ( *pBuf & 0x20 )
  461. x |= HAL_KEY_SW_6;
  462. #endif
  463. #if defined ( HAL_KEY_SW_7 )
  464. if ( *pBuf & 0x40 )
  465. x |= HAL_KEY_SW_7;
  466. #endif
  467. #if defined ( HAL_KEY_SW_8 )
  468. if ( *pBuf & 0x80 )
  469. x |= HAL_KEY_SW_8;
  470. #endif
  471. pBuf++;
  472. retValue = OnBoard_SendKeys(x, *pBuf);
  473. /* Build and send back the response */
  474. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL), cmdId, 1, &retValue );
  475. }
  476. #endif
  477. #if (defined HAL_LED) && (HAL_LED == TRUE)
  478. /***************************************************************************************************
  479. * @fn MT_UtilLedControl
  480. *
  481. * @brief Process the LED Control Message
  482. *
  483. * @param pBuf - pointer to the received data
  484. *
  485. * @return None
  486. ***************************************************************************************************/
  487. void MT_UtilLedControl(uint8 *pBuf)
  488. {
  489. uint8 iLed, Led, iMode, Mode, cmdId;
  490. uint8 retValue = ZFailure;
  491. /* parse header */
  492. cmdId = pBuf[MT_RPC_POS_CMD1];
  493. pBuf += MT_RPC_FRAME_HDR_SZ;
  494. /* LED and Mode */
  495. iLed = *pBuf++;
  496. iMode = *pBuf;
  497. if ( iLed == 1 )
  498. Led = HAL_LED_1;
  499. else if ( iLed == 2 )
  500. Led = HAL_LED_2;
  501. else if ( iLed == 3 )
  502. Led = HAL_LED_3;
  503. else if ( iLed == 4 )
  504. Led = HAL_LED_4;
  505. else if ( iLed == 0xFF )
  506. Led = HAL_LED_ALL;
  507. else
  508. Led = 0;
  509. if ( iMode == 0 )
  510. Mode = HAL_LED_MODE_OFF;
  511. else if ( iMode == 1 )
  512. Mode = HAL_LED_MODE_ON;
  513. else if ( iMode == 2 )
  514. Mode = HAL_LED_MODE_BLINK;
  515. else if ( iMode == 3 )
  516. Mode = HAL_LED_MODE_FLASH;
  517. else if ( iMode == 4 )
  518. Mode = HAL_LED_MODE_TOGGLE;
  519. else
  520. Led = 0;
  521. if ( Led != 0 )
  522. {
  523. HalLedSet (Led, Mode);
  524. retValue = ZSuccess;
  525. }
  526. /* Build and send back the response */
  527. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL), cmdId, 1, &retValue );
  528. }
  529. #endif /* HAL_LED */
  530. /***************************************************************************************************
  531. * @fn MT_UtilHeartBeat
  532. *
  533. * @brief Process the Heart Beat
  534. *
  535. * @param pBuf - pointer to the received data
  536. *
  537. * @return None
  538. ***************************************************************************************************/
  539. void MT_UtilHeartBeat(uint8 *pBuf)
  540. {
  541. //TBD
  542. (void)pBuf; // Remove this when heart beat function is established.
  543. }
  544. /***************************************************************************************************
  545. * @fn MT_UtilTimeAlive
  546. *
  547. * @brief Process Time Alive
  548. *
  549. * @param pBuf - pointer to the received data
  550. *
  551. * @return None
  552. ***************************************************************************************************/
  553. void MT_UtilTimeAlive(void)
  554. {
  555. uint8 timeAlive[4];
  556. uint32 tmp32;
  557. /* Time since last reset (seconds) */
  558. tmp32 = osal_GetSystemClock() / 1000;
  559. /* Convert to high byte first into temp buffer */
  560. timeAlive[0] = BREAK_UINT32(tmp32, 0);
  561. timeAlive[1] = BREAK_UINT32(tmp32, 1);
  562. timeAlive[2] = BREAK_UINT32(tmp32, 2);
  563. timeAlive[3] = BREAK_UINT32(tmp32, 3);
  564. /* Build and send back the response */
  565. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_UTIL), MT_UTIL_TIME_ALIVE,
  566. sizeof(tmp32), timeAlive );
  567. }
  568. #endif /* MT_UTIL_FUNC */
  569. /***************************************************************************************************
  570. ***************************************************************************************************/