MS_generic_battery_api.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /**
  2. * \file MS_generic_battery_api.h
  3. *
  4. * \brief This file defines the Mesh Generic Battery Model Application Interface
  5. * - includes Data Structures and Methods for both Server and Client.
  6. */
  7. /*
  8. * Copyright (C) 2017. Mindtree Ltd.
  9. * All rights reserved.
  10. */
  11. #ifndef _H_MS_GENERIC_BATTERY_API_
  12. #define _H_MS_GENERIC_BATTERY_API_
  13. /* --------------------------------------------- Header File Inclusion */
  14. #include "MS_access_api.h"
  15. /* --------------------------------------------- Global Definitions */
  16. /**
  17. * \defgroup generic_battery_module GENERIC_BATTERY (Mesh Generic Battery Model)
  18. * \{
  19. * This section describes the interfaces & APIs offered by the EtherMind
  20. * Mesh Generic OnOff Model (ONOFF) module to the Application.
  21. */
  22. /* --------------------------------------------- Data Types/ Structures */
  23. /**
  24. * \defgroup generic_battery_cb Application Callback
  25. * \{
  26. * This Section Describes the module Notification Callback interface offered
  27. * to the application
  28. */
  29. /**
  30. * Generic Battery Server application Asynchronous Notification Callback.
  31. *
  32. * Generic Battery Server calls the registered callback to indicate events occurred to the
  33. * application.
  34. *
  35. * \param [in] ctx Context of the message received for a specific model instance.
  36. * \param [in] msg_raw Uninterpreted/raw received message.
  37. * \param [in] req_type Requested message type.
  38. * \param [in] state_params Model specific state parameters.
  39. * \param [in] ext_params Additional parameters.
  40. */
  41. typedef API_RESULT (* MS_GENERIC_BATTERY_SERVER_CB)
  42. (
  43. MS_ACCESS_MODEL_REQ_MSG_CONTEXT * ctx,
  44. MS_ACCESS_MODEL_REQ_MSG_RAW * msg_raw,
  45. MS_ACCESS_MODEL_REQ_MSG_T * req_type,
  46. MS_ACCESS_MODEL_STATE_PARAMS * state_params,
  47. MS_ACCESS_MODEL_EXT_PARAMS * ext_params
  48. ) DECL_REENTRANT;
  49. /**
  50. * Generic Battery Client application Asynchronous Notification Callback.
  51. *
  52. * Generic Battery Client calls the registered callback to indicate events occurred to the
  53. * application.
  54. *
  55. * \param handle Model Handle.
  56. * \param opcode Opcode.
  57. * \param data_param Data associated with the event if any or NULL.
  58. * \param data_len Size of the event data. 0 if event data is NULL.
  59. */
  60. typedef API_RESULT (* MS_GENERIC_BATTERY_CLIENT_CB)
  61. (
  62. MS_ACCESS_MODEL_HANDLE * handle,
  63. UINT32 opcode,
  64. UCHAR * data_param,
  65. UINT16 data_len
  66. ) DECL_REENTRANT;
  67. /** \} */
  68. /**
  69. * \defgroup generic_battery_structures Structures
  70. * \{
  71. */
  72. /**
  73. * The Generic Battery state is a set of four values representing the state of a battery:
  74. * - a charge level (Generic Battery Level)
  75. * - remaining time to complete discharging (Generic Battery Time to Discharge)
  76. * - remaining time to complete charging (Generic Battery Time to Charge)
  77. * - flags bit field (Generic Battery Flags)
  78. */
  79. typedef struct MS_generic_battery_status_struct
  80. {
  81. /**
  82. * Generic Battery Level.
  83. * The Generic Battery Level state is a value ranging from 0 percent through 100 percent.
  84. *
  85. * Value | Description
  86. * ----------|------------
  87. * 0x00-0x64 | The percentage of the charge level. 100% represents fully charged. 0% represents fully discharged.
  88. * 0x65-0xFE | Prohibited
  89. * 0xFF | The percentage of the charge level is unknown.
  90. */
  91. UCHAR battery_level;
  92. /**
  93. * The Generic Battery Time to Discharge state is a 24-bit unsigned value ranging from 0 through 0xFFFFFF.
  94. *
  95. * Value | Description
  96. * ------------------|------------
  97. * 0x000000-0xFFFFFE | The remaining time (in minutes) of the discharging process
  98. * 0xFFFFFF | The remaining time of the discharging process is not known.
  99. */
  100. UINT32 time_to_discharge;
  101. /**
  102. * The Generic Battery Time to Charge state is a 24-bit unsigned value ranging from 0 through 0xFFFFFF.
  103. *
  104. * Value | Description
  105. * ------------------|------------
  106. * 0x000000-0xFFFFFE | The remaining time (in minutes) of the charging process
  107. * 0xFFFFFF | The remaining time of the charging process is not known.
  108. */
  109. UINT32 time_to_charge;
  110. /**
  111. * The Generic Battery Flags state is a concatenation of four 2-bit bit fields: Presence, Indicator, Charging, and Serviceability
  112. *
  113. * Bit | Description
  114. * -----|------------
  115. * 0-1 | Generic Battery Flags Presence
  116. * 2-3 | Generic Battery Flags Indicator
  117. * 4-5 | Generic Battery Flags Charging
  118. * 6-7 | Generic Battery Flags Serviceability
  119. */
  120. UCHAR flags;
  121. } MS_GENERIC_BATTERY_STATUS_STRUCT;
  122. /** \} */
  123. /* --------------------------------------------- Function */
  124. /**
  125. * \defgroup generic_battery_api_defs API Definitions
  126. * \{
  127. * This section describes the EtherMind Mesh Generic Battery Model APIs.
  128. */
  129. /**
  130. * \defgroup generic_battery_ser_api_defs Generic Battery Server API Definitions
  131. * \{
  132. * This section describes the Generic Battery Server APIs.
  133. */
  134. /**
  135. * \brief API to initialize Generic_Battery Server model
  136. *
  137. * \par Description
  138. * This is to initialize Generic_Battery Server model and to register with Acess layer.
  139. *
  140. * \param [in] element_handle
  141. * Element identifier to be associated with the model instance.
  142. *
  143. * \param [in, out] model_handle
  144. * Model identifier associated with the model instance on successful initialization.
  145. * After power cycle of an already provisioned node, the model handle will have
  146. * valid value and the same will be reused for registration.
  147. *
  148. * \param [in] appl_cb Application Callback to be used by the Generic_Battery Server.
  149. *
  150. * \return API_SUCCESS or an error code indicating reason for failure
  151. */
  152. API_RESULT MS_generic_battery_server_init
  153. (
  154. /* IN */ MS_ACCESS_ELEMENT_HANDLE element_handle,
  155. /* INOUT */ MS_ACCESS_MODEL_HANDLE * model_handle,
  156. /* IN */ MS_GENERIC_BATTERY_SERVER_CB appl_cb
  157. );
  158. /**
  159. * \brief API to send reply or to update state change
  160. *
  161. * \par Description
  162. * This is to send reply for a request or to inform change in state.
  163. *
  164. * \param [in] ctx Context of the message.
  165. * \param [in] current_state_params Model specific current state parameters.
  166. * \param [in] target_state_params Model specific target state parameters (NULL: to be ignored).
  167. * \param [in] remaining_time Time from current state to target state (0: to be ignored).
  168. * \param [in] ext_params Additional parameters (NULL: to be ignored).
  169. *
  170. * \return API_SUCCESS or an error code indicating reason for failure
  171. */
  172. API_RESULT MS_generic_battery_server_state_update
  173. (
  174. /* IN */ MS_ACCESS_MODEL_REQ_MSG_CONTEXT * ctx,
  175. /* IN */ MS_ACCESS_MODEL_STATE_PARAMS * current_state_params,
  176. /* IN */ MS_ACCESS_MODEL_STATE_PARAMS * target_state_params,
  177. /* IN */ UINT16 remaining_time,
  178. /* IN */ MS_ACCESS_MODEL_EXT_PARAMS * ext_params
  179. );
  180. /** \} */
  181. /**
  182. * \defgroup generic_battery_cli_api_defs Generic Battery Client API Definitions
  183. * \{
  184. * This section describes the Generic Battery Client APIs.
  185. */
  186. /**
  187. * \brief API to initialize Generic_Battery Client model
  188. *
  189. * \par Description
  190. * This is to initialize Generic_Battery Client model and to register with Acess layer.
  191. *
  192. * \param [in] element_handle
  193. * Element identifier to be associated with the model instance.
  194. *
  195. * \param [in, out] model_handle
  196. * Model identifier associated with the model instance on successful initialization.
  197. * After power cycle of an already provisioned node, the model handle will have
  198. * valid value and the same will be reused for registration.
  199. *
  200. * \param [in] appl_cb Application Callback to be used by the Generic_Battery Client.
  201. *
  202. * \return API_SUCCESS or an error code indicating reason for failure
  203. */
  204. API_RESULT MS_generic_battery_client_init
  205. (
  206. /* IN */ MS_ACCESS_ELEMENT_HANDLE element_handle,
  207. /* INOUT */ MS_ACCESS_MODEL_HANDLE * model_handle,
  208. /* IN */ MS_GENERIC_BATTERY_CLIENT_CB appl_cb
  209. );
  210. /**
  211. * \brief API to get Generic_Battery client model handle
  212. *
  213. * \par Description
  214. * This is to get the handle of Generic_Battery client model.
  215. *
  216. * \param [out] model_handle Address of model handle to be filled/returned.
  217. *
  218. * \return API_SUCCESS or an error code indicating reason for failure
  219. */
  220. API_RESULT MS_generic_battery_client_get_model_handle
  221. (
  222. /* OUT */ MS_ACCESS_MODEL_HANDLE * model_handle
  223. );
  224. /**
  225. * \brief API to send acknowledged commands
  226. *
  227. * \par Description
  228. * This is to initialize sending acknowledged commands.
  229. *
  230. * \param [in] req_opcode Request Opcode.
  231. * \param [in] param Parameter associated with Request Opcode.
  232. * \param [in] rsp_opcode Response Opcode.
  233. *
  234. * \return API_SUCCESS or an error code indicating reason for failure
  235. */
  236. API_RESULT MS_generic_battery_client_send_reliable_pdu
  237. (
  238. /* IN */ UINT32 req_opcode,
  239. /* IN */ void * param,
  240. /* IN */ UINT32 rsp_opcode
  241. );
  242. /**
  243. * \brief API to get the Generic Battery state of an element.
  244. *
  245. * \par Description
  246. * Generic Battery Get message is an acknowledged message used to get the Generic Battery state of an element.
  247. * The response to the Generic Battery Get message is a Generic Battery Status message.
  248. * There are no parameters for this message.
  249. *
  250. * \return API_SUCCESS or an error code indicating reason for failure
  251. */
  252. #define MS_generic_battery_get() \
  253. MS_generic_battery_client_send_reliable_pdu \
  254. (\
  255. MS_ACCESS_GENERIC_BATTERY_GET_OPCODE,\
  256. NULL,\
  257. MS_ACCESS_GENERIC_BATTERY_STATUS_OPCODE\
  258. )
  259. /** \} */
  260. /** \} */
  261. /** \} */
  262. #endif /*_H_MS_GENERIC_BATTERY_API_ */