MS_generic_level_api.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. /**
  2. * \file MS_generic_level_api.h
  3. *
  4. * \brief This file defines the Mesh Generic Level 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_LEVEL_API_
  12. #define _H_MS_GENERIC_LEVEL_API_
  13. /* --------------------------------------------- Header File Inclusion */
  14. #include "MS_access_api.h"
  15. /* --------------------------------------------- Global Definitions */
  16. /**
  17. * \defgroup generic_level_module GENERIC_LEVEL (Mesh Generic Level 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_level_cb Application Callback
  25. * \{
  26. * This Section Describes the module Notification Callback interface offered
  27. * to the application
  28. */
  29. /**
  30. * Generic Level Server application Asynchronous Notification Callback.
  31. *
  32. * Generic Level 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_LEVEL_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 Level Client application Asynchronous Notification Callback.
  51. *
  52. * Generic Level 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_LEVEL_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_level_structures Structures
  70. * \{
  71. */
  72. /**
  73. * Generic Level Set message parameters
  74. */
  75. typedef struct MS_generic_level_set_struct
  76. {
  77. /**
  78. * The target value of the Generic Level state.
  79. *
  80. * The Generic Level state is a 16-bit signed integer (2’s complement) representing
  81. * the state of an element.
  82. */
  83. UINT16 level;
  84. /** Transaction Identifier */
  85. UCHAR tid;
  86. /**
  87. * Transition Time is a 1-octet value that consists of two fields:
  88. * - a 2-bit bit field representing the step resolution
  89. * - a 6-bit bit field representing the number of transition steps.
  90. *
  91. * Field | Size (bits) | Description
  92. * ---------------------------|-------------|----------------
  93. * Transition Number of Steps | 6 | The number of Steps
  94. * Transition Step Resolution | 2 | The resolution of the Default Transition
  95. * | Number of Steps field
  96. */
  97. UCHAR transition_time;
  98. /** Message execution delay in 5 milliseconds steps */
  99. UCHAR delay;
  100. /** Flag: To represent if optional Transaction time and Delay fields are valid */
  101. UCHAR optional_fields_present;
  102. } MS_GENERIC_LEVEL_SET_STRUCT;
  103. /**
  104. * Generic Level Status message parameters
  105. */
  106. typedef struct MS_generic_level_status_struct
  107. {
  108. /** The present value of the Generic Level state. */
  109. UINT16 present_level;
  110. /** The target value of the Generic Level state */
  111. UINT16 target_level;
  112. /**
  113. * Remaining Time is a 1-octet value that consists of two fields:
  114. * - a 2-bit bit field representing the step resolution
  115. * - a 6-bit bit field representing the number of transition steps.
  116. *
  117. * Field | Size (bits) | Description
  118. * ---------------------------|-------------|----------------
  119. * Transition Number of Steps | 6 | The number of Steps
  120. * Transition Step Resolution | 2 | The resolution of the Default Transition
  121. * | Number of Steps field
  122. */
  123. UCHAR remaining_time;
  124. /** Flag: To represent if optional fields Target Level and Remaining Time are valid */
  125. UCHAR optional_fields_present;
  126. } MS_GENERIC_LEVEL_STATUS_STRUCT;
  127. /**
  128. * Generic Delta Set message parameters.
  129. */
  130. typedef struct MS_generic_delta_set_struct
  131. {
  132. /** The Delta change of the Generic Level state */
  133. UINT32 delta_level;
  134. /** Transaction Identifier */
  135. UCHAR tid;
  136. /**
  137. * Transition Time is a 1-octet value that consists of two fields:
  138. * - a 2-bit bit field representing the step resolution
  139. * - a 6-bit bit field representing the number of transition steps.
  140. *
  141. * Field | Size (bits) | Description
  142. * ---------------------------|-------------|----------------
  143. * Transition Number of Steps | 6 | The number of Steps
  144. * Transition Step Resolution | 2 | The resolution of the Default Transition
  145. * | Number of Steps field
  146. */
  147. UCHAR transition_time;
  148. /** Message execution delay in 5 milliseconds steps */
  149. UCHAR delay;
  150. /** Flag: To represent if optional Transaction time and Delay fields are valid */
  151. UCHAR optional_fields_present;
  152. } MS_GENERIC_DELTA_SET_STRUCT;
  153. /**
  154. * Generic Move Set message parameters.
  155. */
  156. typedef struct MS_generic_move_set_struct
  157. {
  158. /** The Delta Level step to calculate Move speed for the Generic Level state. */
  159. UINT16 delta_level;
  160. /** Transaction Identifier */
  161. UCHAR tid;
  162. /**
  163. * Transition Time is a 1-octet value that consists of two fields:
  164. * - a 2-bit bit field representing the step resolution
  165. * - a 6-bit bit field representing the number of transition steps.
  166. *
  167. * Field | Size (bits) | Description
  168. * ---------------------------|-------------|----------------
  169. * Transition Number of Steps | 6 | The number of Steps
  170. * Transition Step Resolution | 2 | The resolution of the Default Transition
  171. * | Number of Steps field
  172. */
  173. UCHAR transition_time;
  174. /** Message execution delay in 5 milliseconds steps */
  175. UCHAR delay;
  176. /** Flag: To represent if optional Transaction time and Delay fields are valid */
  177. UCHAR optional_fields_present;
  178. } MS_GENERIC_MOVE_SET_STRUCT;
  179. /** \} */
  180. /* --------------------------------------------- Function */
  181. /**
  182. * \defgroup generic_level_api_defs API Definitions
  183. * \{
  184. * This section describes the EtherMind Mesh Generic Level Model APIs.
  185. */
  186. /**
  187. * \defgroup generic_level_ser_api_defs Generic Level Server API Definitions
  188. * \{
  189. * This section describes the Generic Level Server APIs.
  190. */
  191. /**
  192. * \brief API to initialize Generic_Level Server model
  193. *
  194. * \par Description
  195. * This is to initialize Generic_Level Server model and to register with Acess layer.
  196. *
  197. * \param [in] element_handle
  198. * Element identifier to be associated with the model instance.
  199. *
  200. * \param [in, out] model_handle
  201. * Model identifier associated with the model instance on successful initialization.
  202. * After power cycle of an already provisioned node, the model handle will have
  203. * valid value and the same will be reused for registration.
  204. *
  205. * \param [in] appl_cb Application Callback to be used by the Generic_Level Server.
  206. *
  207. * \return API_SUCCESS or an error code indicating reason for failure
  208. */
  209. API_RESULT MS_generic_level_server_init
  210. (
  211. /* IN */ MS_ACCESS_ELEMENT_HANDLE element_handle,
  212. /* INOUT */ MS_ACCESS_MODEL_HANDLE * model_handle,
  213. /* IN */ MS_GENERIC_LEVEL_SERVER_CB appl_cb
  214. );
  215. /**
  216. * \brief API to send reply or to update state change
  217. *
  218. * \par Description
  219. * This is to send reply for a request or to inform change in state.
  220. *
  221. * \param [in] ctx Context of the message.
  222. * \param [in] current_state_params Model specific current state parameters.
  223. * \param [in] target_state_params Model specific target state parameters (NULL: to be ignored).
  224. * \param [in] remaining_time Time from current state to target state (0: to be ignored).
  225. * \param [in] ext_params Additional parameters (NULL: to be ignored).
  226. *
  227. * \return API_SUCCESS or an error code indicating reason for failure
  228. */
  229. API_RESULT MS_generic_level_server_state_update
  230. (
  231. /* IN */ MS_ACCESS_MODEL_REQ_MSG_CONTEXT * ctx,
  232. /* IN */ MS_ACCESS_MODEL_STATE_PARAMS * current_state_params,
  233. /* IN */ MS_ACCESS_MODEL_STATE_PARAMS * target_state_params,
  234. /* IN */ UINT16 remaining_time,
  235. /* IN */ MS_ACCESS_MODEL_EXT_PARAMS * ext_params
  236. );
  237. /** \} */
  238. /**
  239. * \defgroup generic_level_cli_api_defs Generic Level Client API Definitions
  240. * \{
  241. * This section describes the Generic Level Client APIs.
  242. */
  243. /**
  244. * \brief API to initialize Generic_Level Client model
  245. *
  246. * \par Description
  247. * This is to initialize Generic_Level Client model and to register with Acess layer.
  248. *
  249. * \param [in] element_handle
  250. * Element identifier to be associated with the model instance.
  251. *
  252. * \param [in, out] model_handle
  253. * Model identifier associated with the model instance on successful initialization.
  254. * After power cycle of an already provisioned node, the model handle will have
  255. * valid value and the same will be reused for registration.
  256. *
  257. * \param [in] appl_cb Application Callback to be used by the Generic_Level Client.
  258. *
  259. * \return API_SUCCESS or an error code indicating reason for failure
  260. */
  261. API_RESULT MS_generic_level_client_init
  262. (
  263. /* IN */ MS_ACCESS_ELEMENT_HANDLE element_handle,
  264. /* INOUT */ MS_ACCESS_MODEL_HANDLE * model_handle,
  265. /* IN */ MS_GENERIC_LEVEL_CLIENT_CB appl_cb
  266. );
  267. /**
  268. * \brief API to get Generic_Level client model handle
  269. *
  270. * \par Description
  271. * This is to get the handle of Generic_Level client model.
  272. *
  273. * \param [out] model_handle Address of model handle to be filled/returned.
  274. *
  275. * \return API_SUCCESS or an error code indicating reason for failure
  276. */
  277. API_RESULT MS_generic_level_client_get_model_handle
  278. (
  279. /* OUT */ MS_ACCESS_MODEL_HANDLE * model_handle
  280. );
  281. /**
  282. * \brief API to send acknowledged commands
  283. *
  284. * \par Description
  285. * This is to initialize sending acknowledged commands.
  286. *
  287. * \param [in] req_opcode Request Opcode.
  288. * \param [in] param Parameter associated with Request Opcode.
  289. * \param [in] rsp_opcode Response Opcode.
  290. *
  291. * \return API_SUCCESS or an error code indicating reason for failure
  292. */
  293. API_RESULT MS_generic_level_client_send_reliable_pdu
  294. (
  295. /* IN */ UINT32 req_opcode,
  296. /* IN */ void * param,
  297. /* IN */ UINT32 rsp_opcode
  298. );
  299. /**
  300. * \brief API to get the Generic Level state of an element.
  301. *
  302. * \par Description
  303. * Generic Level Get is an acknowledged message used to get the Generic Level state of an element.
  304. * The response to the Generic Level Get message is a Generic Level Status message.
  305. * There are no parameters for this message.
  306. *
  307. * \return API_SUCCESS or an error code indicating reason for failure
  308. */
  309. #define MS_generic_level_get() \
  310. MS_generic_level_client_send_reliable_pdu \
  311. (\
  312. MS_ACCESS_GENERIC_LEVEL_GET_OPCODE,\
  313. NULL,\
  314. MS_ACCESS_GENERIC_LEVEL_STATUS_OPCODE\
  315. )
  316. /**
  317. * \brief API to set the Generic Level state of an element to a new absolute value.
  318. *
  319. * \par Description
  320. * Generic Level Set is an acknowledged message used to set the Generic Level state of an element
  321. * to a new absolute value.
  322. * The response to the Generic Level Set message is a Generic Level Status message.
  323. *
  324. * \param [in] param Generic Level Set message
  325. *
  326. * \return API_SUCCESS or an error code indicating reason for failure
  327. */
  328. #define MS_generic_level_set(param) \
  329. MS_generic_level_client_send_reliable_pdu \
  330. (\
  331. MS_ACCESS_GENERIC_LEVEL_SET_OPCODE,\
  332. param,\
  333. MS_ACCESS_GENERIC_LEVEL_STATUS_OPCODE\
  334. )
  335. /**
  336. * \brief API to set the Generic Level state of an element to a new absolute value.
  337. *
  338. * \par Description
  339. * Generic Level Set Unacknowledged is an unacknowledged message used to set
  340. * the Generic Level state of an element to a new absolute value.
  341. *
  342. * \param [in] param Generic Level Set message
  343. *
  344. * \return API_SUCCESS or an error code indicating reason for failure
  345. */
  346. #define MS_generic_level_set_unacknowledged(param) \
  347. MS_generic_level_client_send_reliable_pdu \
  348. (\
  349. MS_ACCESS_GENERIC_LEVEL_SET_UNACKNOWLEDGED_OPCODE,\
  350. param,\
  351. 0xFFFFFFFF\
  352. )
  353. /**
  354. * \brief API to set the Generic Level state of an element by a relative value.
  355. *
  356. * \par Description
  357. * Generic Delta Set is an acknowledged message used to set the Generic Level state of an element
  358. * by a relative value. The message is transactional, it supports changing the state by a cumulative
  359. * value with a sequence of messages that are part of a transaction.
  360. * The response to the Generic Delta Set message is a Generic Level Status message.
  361. *
  362. * \param [in] param Generic Delta Set message
  363. *
  364. * \return API_SUCCESS or an error code indicating reason for failure
  365. */
  366. #define MS_generic_delta_set(param) \
  367. MS_generic_level_client_send_reliable_pdu \
  368. (\
  369. MS_ACCESS_GENERIC_DELTA_SET_OPCODE,\
  370. param,\
  371. MS_ACCESS_GENERIC_LEVEL_STATUS_OPCODE\
  372. )
  373. /**
  374. * \brief API to set the Generic Level state of an element by a relative value.
  375. *
  376. * \par Description
  377. * Generic Delta Set Unacknowledged is an unacknowledged message used to set the Generic Level state of an element
  378. * by a relative value.
  379. *
  380. * \param [in] param Generic Delta Set message
  381. *
  382. * \return API_SUCCESS or an error code indicating reason for failure
  383. */
  384. #define MS_generic_delta_set_unacknowledged(param) \
  385. MS_generic_level_client_send_reliable_pdu \
  386. (\
  387. MS_ACCESS_GENERIC_DELTA_SET_UNACKNOWLEDGED_OPCODE,\
  388. param,\
  389. 0xFFFFFFFF\
  390. )
  391. /**
  392. * \brief API to start a process of changing the Generic Level state of an element
  393. * with a defined transition speed.
  394. *
  395. * \par Description
  396. * Generic Move Set is an acknowledged message used to start a process of changing
  397. * the Generic Level state of an element with a defined transition speed.
  398. * The response to the Generic Move Set message is a Generic Level Status message.
  399. *
  400. * \param [in] param Generic Move Set message
  401. *
  402. * \return API_SUCCESS or an error code indicating reason for failure
  403. */
  404. #define MS_generic_move_set(param) \
  405. MS_generic_level_client_send_reliable_pdu \
  406. (\
  407. MS_ACCESS_GENERIC_MOVE_SET_OPCODE,\
  408. param,\
  409. MS_ACCESS_GENERIC_LEVEL_STATUS_OPCODE\
  410. )
  411. /**
  412. * \brief API to start a process of changing the Generic Level state of an element
  413. * with a defined transition speed.
  414. *
  415. * \par Description
  416. * Generic Move Set Unacknowledged is an unacknowledged message used to start a process
  417. * of changing the Generic Level state of an element with a defined transition speed.
  418. *
  419. * \param [in] param Generic Move Set message
  420. *
  421. * \return API_SUCCESS or an error code indicating reason for failure
  422. */
  423. #define MS_generic_move_set_unacknowledged(param) \
  424. MS_generic_level_client_send_reliable_pdu \
  425. (\
  426. MS_ACCESS_GENERIC_MOVE_SET_UNACKNOWLEDGED_OPCODE,\
  427. param,\
  428. 0xFFFFFFFF\
  429. )
  430. /** \} */
  431. /** \} */
  432. /** \} */
  433. #endif /*_H_MS_GENERIC_LEVEL_API_ */