MS_generic_onoff_api.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /**
  2. * \file MS_generic_onoff_api.h
  3. *
  4. * \brief This file defines the Mesh Generic Onoff 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_ONOFF_API_
  12. #define _H_MS_GENERIC_ONOFF_API_
  13. /* --------------------------------------------- Header File Inclusion */
  14. #include "MS_access_api.h"
  15. /* --------------------------------------------- Global Definitions */
  16. /**
  17. * \defgroup generic_onoff_module GENERIC_ONOFF (Mesh Generic Onoff 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_onoff_cb Application Callback
  25. * \{
  26. * This Section Describes the module Notification Callback interface offered
  27. * to the application
  28. */
  29. /**
  30. * Generic Onoff Server application Asynchronous Notification Callback.
  31. *
  32. * Generic Onoff 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_ONOFF_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 Onoff Client application Asynchronous Notification Callback.
  51. *
  52. * Generic Onoff 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_ONOFF_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_onoff_structures Structures
  70. * \{
  71. */
  72. /**
  73. * Generic OnOff Set message parameters.
  74. */
  75. typedef struct MS_generic_onoff_set_struct
  76. {
  77. /** The target value of the Generic OnOff state */
  78. UCHAR onoff;
  79. /** Transaction Identifier */
  80. UCHAR tid;
  81. /**
  82. * Transition Time is a 1-octet value that consists of two fields:
  83. * - a 2-bit bit field representing the step resolution
  84. * - a 6-bit bit field representing the number of transition steps.
  85. *
  86. * Field | Size (bits) | Description
  87. * ---------------------------|-------------|----------------
  88. * Transition Number of Steps | 6 | The number of Steps
  89. * Transition Step Resolution | 2 | The resolution of the Default Transition
  90. * | Number of Steps field
  91. */
  92. UCHAR transition_time;
  93. /** Message execution delay in 5 milliseconds steps */
  94. UCHAR delay;
  95. /** Flag: To represent if optional Transaction time and Delay fields are valid */
  96. UCHAR optional_fields_present;
  97. } MS_GENERIC_ONOFF_SET_STRUCT;
  98. /**
  99. * Generic OnOff Status message parameters.
  100. */
  101. typedef struct MS_generic_onoff_status_struct
  102. {
  103. /** The present value of the Generic OnOff state. */
  104. UCHAR present_onoff;
  105. /** The target value of the Generic OnOff state */
  106. UCHAR target_onoff;
  107. /**
  108. * Remaining Time is a 1-octet value that consists of two fields:
  109. * - a 2-bit bit field representing the step resolution
  110. * - a 6-bit bit field representing the number of transition steps.
  111. *
  112. * Field | Size (bits) | Description
  113. * ---------------------------|-------------|----------------
  114. * Transition Number of Steps | 6 | The number of Steps
  115. * Transition Step Resolution | 2 | The resolution of the Default Transition
  116. * | Number of Steps field
  117. */
  118. UCHAR remaining_time;
  119. /** Flag: To represent if optional fields Target OnOff and Remaining Time are valid */
  120. UCHAR optional_fields_present;
  121. } MS_GENERIC_ONOFF_STATUS_STRUCT;
  122. /** \} */
  123. /* --------------------------------------------- Function */
  124. /**
  125. * \defgroup generic_onoff_api_defs API Definitions
  126. * \{
  127. * This section describes the EtherMind Mesh Generic Onoff Model APIs.
  128. */
  129. /**
  130. * \defgroup generic_onoff_ser_api_defs Generic Onoff Server API Definitions
  131. * \{
  132. * This section describes the Generic Onoff Server APIs.
  133. */
  134. /**
  135. * \brief API to initialize Generic_Onoff Server model
  136. *
  137. * \par Description
  138. * This is to initialize Generic_Onoff 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_Onoff Server.
  149. *
  150. * \return API_SUCCESS or an error code indicating reason for failure
  151. */
  152. API_RESULT MS_generic_onoff_server_init
  153. (
  154. /* IN */ MS_ACCESS_ELEMENT_HANDLE element_handle,
  155. /* INOUT */ MS_ACCESS_MODEL_HANDLE * model_handle,
  156. /* IN */ MS_GENERIC_ONOFF_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_onoff_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_onoff_cli_api_defs Generic Onoff Client API Definitions
  183. * \{
  184. * This section describes the Generic Onoff Client APIs.
  185. */
  186. /**
  187. * \brief API to initialize Generic_Onoff Client model
  188. *
  189. * \par Description
  190. * This is to initialize Generic_Onoff 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_Onoff Client.
  201. *
  202. * \return API_SUCCESS or an error code indicating reason for failure
  203. */
  204. API_RESULT MS_generic_onoff_client_init
  205. (
  206. /* IN */ MS_ACCESS_ELEMENT_HANDLE element_handle,
  207. /* INOUT */ MS_ACCESS_MODEL_HANDLE * model_handle,
  208. /* IN */ MS_GENERIC_ONOFF_CLIENT_CB appl_cb
  209. );
  210. /**
  211. * \brief API to get Generic_Onoff client model handle
  212. *
  213. * \par Description
  214. * This is to get the handle of Generic_Onoff 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_onoff_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_onoff_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 Generic OnOff state
  244. *
  245. * \par Description
  246. * The Generic OnOff Get is an acknowledged message used to get the Generic OnOff
  247. * state of an element.
  248. *
  249. * \return API_SUCCESS or an error code indicating reason for failure
  250. */
  251. #define MS_generic_onoff_get() \
  252. MS_generic_onoff_client_send_reliable_pdu \
  253. (\
  254. MS_ACCESS_GENERIC_ONOFF_GET_OPCODE,\
  255. NULL,\
  256. MS_ACCESS_GENERIC_ONOFF_STATUS_OPCODE\
  257. )
  258. /**
  259. * \brief API to set Generic OnOff state
  260. *
  261. * \par Description
  262. * The Generic OnOff Set is an acknowledged message used to get the Generic OnOff
  263. * state of an element.
  264. *
  265. * \param [in] param
  266. * Pointer to the structure populated as in \ref MS_GENERIC_ONOFF_SET_STRUCT
  267. *
  268. * \return API_SUCCESS or an error code indicating reason for failure
  269. */
  270. #define MS_generic_onoff_set(param) \
  271. MS_generic_onoff_client_send_reliable_pdu \
  272. (\
  273. MS_ACCESS_GENERIC_ONOFF_SET_OPCODE,\
  274. param,\
  275. MS_ACCESS_GENERIC_ONOFF_STATUS_OPCODE\
  276. )
  277. /**
  278. * \brief API to set Generic OnOff state unacknowledged
  279. *
  280. * \par Description
  281. * The Generic OnOff Set is an unacknowledged message used to get the Generic OnOff
  282. * state of an element.
  283. *
  284. * \param [in] param
  285. * Pointer to the structure populated as in \ref MS_GENERIC_ONOFF_SET_STRUCT
  286. *
  287. * \return API_SUCCESS or an error code indicating reason for failure
  288. */
  289. #define MS_generic_onoff_set_unacknowledged(param) \
  290. MS_generic_onoff_client_send_reliable_pdu \
  291. (\
  292. MS_ACCESS_GENERIC_ONOFF_SET_UNACKNOWLEDGED_OPCODE,\
  293. param,\
  294. 0xFFFFFFFF\
  295. )
  296. /** \} */
  297. /** \} */
  298. /** \} */
  299. #endif /*_H_MS_GENERIC_ONOFF_API_ */