MS_scene_api.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. /**
  2. * \file MS_scene_api.h
  3. *
  4. * \brief This file defines the Mesh Scene 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_SCENE_API_
  12. #define _H_MS_SCENE_API_
  13. /* --------------------------------------------- Header File Inclusion */
  14. #include "MS_access_api.h"
  15. /* --------------------------------------------- Global Definitions */
  16. /**
  17. * \defgroup scene_module SCENE (Mesh Scene Model)
  18. * \{
  19. * This section describes the interfaces & APIs offered by the EtherMind
  20. * Mesh Scene Model (SCENE) module to the Application.
  21. */
  22. /** Scene Event Types */
  23. /** Scene Event - Store */
  24. #define MS_SCENE_EVENT_STORE 0x01
  25. /** Scene Event - Delete */
  26. #define MS_SCENE_EVENT_DELETE 0x02
  27. /** Scene Event - Recall Start */
  28. #define MS_SCENE_EVENT_RECALL_START 0x03
  29. /** Scene Event - Recall Complete */
  30. #define MS_SCENE_EVENT_RECALL_COMPLETE 0x04
  31. /** Scene Event - Recall Immediate */
  32. #define MS_SCENE_EVENT_RECALL_IMMEDIATE 0x05
  33. /* --------------------------------------------- Data Types/ Structures */
  34. /**
  35. * \defgroup scene_cb Application Callback
  36. * \{
  37. * This Section Describes the module Notification Callback interface offered
  38. * to the application
  39. */
  40. /**
  41. * Scene Server application Asynchronous Notification Callback.
  42. *
  43. * Scene Server calls the registered callback to indicate events occurred to the
  44. * application.
  45. *
  46. * \param [in] ctx Context of the message received for a specific model instance.
  47. * \param [in] msg_raw Uninterpreted/raw received message.
  48. * \param [in] req_type Requested message type.
  49. * \param [in] state_params Model specific state parameters.
  50. * \param [in] ext_params Additional parameters.
  51. *
  52. * TODO: Update
  53. */
  54. typedef void * (* MS_SCENE_SERVER_CB)
  55. (
  56. MS_ACCESS_MODEL_HANDLE * handle,
  57. UINT8 event_type,
  58. void * event_param,
  59. UINT16 event_length,
  60. void * context
  61. ) DECL_REENTRANT;
  62. /**
  63. * Scene Client application Asynchronous Notification Callback.
  64. *
  65. * Scene Client calls the registered callback to indicate events occurred to the
  66. * application.
  67. *
  68. * \param handle Model Handle.
  69. * \param opcode Opcode.
  70. * \param data_param Data associated with the event if any or NULL.
  71. * \param data_len Size of the event data. 0 if event data is NULL.
  72. */
  73. typedef API_RESULT (* MS_SCENE_CLIENT_CB)
  74. (
  75. MS_ACCESS_MODEL_HANDLE * handle,
  76. UINT32 opcode,
  77. UCHAR * data_param,
  78. UINT16 data_len
  79. ) DECL_REENTRANT;
  80. /** \} */
  81. /**
  82. * \defgroup scene_structures Structures
  83. * \{
  84. */
  85. /**
  86. * Scene Recall message parameters.
  87. */
  88. typedef struct MS_scene_recall_struct
  89. {
  90. /** The number of the scene to be recalled. */
  91. UINT16 scene_number;
  92. /** Transaction Identifier */
  93. UCHAR tid;
  94. /**
  95. * Transition Time is a 1-octet value that consists of two fields:
  96. * - a 2-bit bit field representing the step resolution
  97. * - a 6-bit bit field representing the number of transition steps.
  98. *
  99. * Field | Size (bits) | Description
  100. * ---------------------------|-------------|----------------
  101. * Transition Number of Steps | 6 | The number of Steps
  102. * Transition Step Resolution | 2 | The resolution of the Default Transition
  103. * | Number of Steps field
  104. */
  105. UCHAR transition_time;
  106. /** Message execution delay in 5 milliseconds steps */
  107. UCHAR delay;
  108. /** Flag: To represent if optional Transaction time and Delay fields are valid */
  109. UCHAR optional_fields_present;
  110. } MS_SCENE_RECALL_STRUCT;
  111. /**
  112. * Scene Status message parameters.
  113. */
  114. typedef struct MS_scene_status_struct
  115. {
  116. /** Status Code */
  117. UCHAR status_code;
  118. /** Scene Number of a current scene. */
  119. UINT16 current_scene;
  120. /** Scene Number of a target scene. (Optional) */
  121. UINT16 target_scene;
  122. /**
  123. * Remaining Time is a 1-octet value that consists of two fields:
  124. * - a 2-bit bit field representing the step resolution
  125. * - a 6-bit bit field representing the number of transition steps.
  126. *
  127. * Field | Size (bits) | Description
  128. * ---------------------------|-------------|----------------
  129. * Transition Number of Steps | 6 | The number of Steps
  130. * Transition Step Resolution | 2 | The resolution of the Default Transition
  131. * | Number of Steps field
  132. */
  133. UCHAR remaining_time;
  134. /** Flag: To represent if optional fields Target Scene and Remaining Time are valid */
  135. UCHAR optional_fields_present;
  136. } MS_SCENE_STATUS_STRUCT;
  137. /**
  138. * Scene Register Status message parameters.
  139. */
  140. typedef struct MS_scene_register_status_struct
  141. {
  142. /** Status Code */
  143. UCHAR status_code;
  144. /** Scene Number of a current scene */
  145. UINT16 current_scene;
  146. /** A list of scenes stored within an element */
  147. UCHAR *scenes;
  148. /** Number of Scenes */
  149. UINT16 scenes_len;
  150. } MS_SCENE_REGISTER_STATUS_STRUCT;
  151. /**
  152. * Scene Store message parameters.
  153. */
  154. typedef struct MS_scene_struct
  155. {
  156. /** The number of the scene to be stored. */
  157. UINT16 scene_number;
  158. } MS_SCENE_STRUCT;
  159. /** \} */
  160. /* --------------------------------------------- Function */
  161. /**
  162. * \defgroup scene_api_defs API Definitions
  163. * \{
  164. * This section describes the EtherMind Mesh Scene Model APIs.
  165. */
  166. /**
  167. * \defgroup scene_ser_api_defs Scene Server API Definitions
  168. * \{
  169. * This section describes the Scene Server APIs.
  170. */
  171. /**
  172. * \brief API to initialize Scene Server model
  173. *
  174. * \par Description
  175. * This is to initialize Scene Server model and to register with Acess layer.
  176. *
  177. * \param [in] element_handle
  178. * Element identifier to be associated with the model instance.
  179. *
  180. * \param [in, out] scene_model_handle
  181. * Model identifier associated with the Scene model instance on successful initialization.
  182. * After power cycle of an already provisioned node, the model handle will have
  183. * valid value and the same will be reused for registration.
  184. *
  185. * \param [in, out] scene_setup_model_handle
  186. * Model identifier associated with the Scene Setup model instance on successful initialization.
  187. * After power cycle of an already provisioned node, the model handle will have
  188. * valid value and the same will be reused for registration.
  189. *
  190. * \param [in] appl_cb Application Callback to be used by the Scene Server.
  191. *
  192. * \return API_SUCCESS or an error code indicating reason for failure
  193. */
  194. API_RESULT MS_scene_server_init
  195. (
  196. /* IN */ MS_ACCESS_ELEMENT_HANDLE element_handle,
  197. /* INOUT */ MS_ACCESS_MODEL_HANDLE * scene_model_handle,
  198. /* INOUT */ MS_ACCESS_MODEL_HANDLE * scene_setup_model_handle,
  199. /* IN */ MS_SCENE_SERVER_CB appl_cb
  200. );
  201. /**
  202. * \brief API to send reply or to update state change
  203. *
  204. * \par Description
  205. * This is to send reply for a request or to inform change in state.
  206. *
  207. * \param [in] ctx Context of the message.
  208. * \param [in] current_state_params Model specific current state parameters.
  209. * \param [in] target_state_params Model specific target state parameters (NULL: to be ignored).
  210. * \param [in] remaining_time Time from current state to target state (0: to be ignored).
  211. * \param [in] ext_params Additional parameters (NULL: to be ignored).
  212. *
  213. * \return API_SUCCESS or an error code indicating reason for failure
  214. */
  215. API_RESULT MS_scene_server_state_update
  216. (
  217. /* IN */ MS_ACCESS_MODEL_REQ_MSG_CONTEXT * ctx,
  218. /* IN */ MS_ACCESS_MODEL_STATE_PARAMS * current_state_params,
  219. /* IN */ MS_ACCESS_MODEL_STATE_PARAMS * target_state_params,
  220. /* IN */ UINT16 remaining_time,
  221. /* IN */ MS_ACCESS_MODEL_EXT_PARAMS * ext_params
  222. );
  223. /** \} */
  224. /**
  225. * \defgroup scene_cli_api_defs Scene Client API Definitions
  226. * \{
  227. * This section describes the Scene Client APIs.
  228. */
  229. /**
  230. * \brief API to initialize Scene Client model
  231. *
  232. * \par Description
  233. * This is to initialize Scene Client model and to register with Acess layer.
  234. *
  235. * \param [in] element_handle
  236. * Element identifier to be associated with the model instance.
  237. *
  238. * \param [in, out] model_handle
  239. * Model identifier associated with the model instance on successful initialization.
  240. * After power cycle of an already provisioned node, the model handle will have
  241. * valid value and the same will be reused for registration.
  242. *
  243. * \param [in] appl_cb Application Callback to be used by the Scene Client.
  244. *
  245. * \return API_SUCCESS or an error code indicating reason for failure
  246. */
  247. API_RESULT MS_scene_client_init
  248. (
  249. /* IN */ MS_ACCESS_ELEMENT_HANDLE element_handle,
  250. /* INOUT */ MS_ACCESS_MODEL_HANDLE * model_handle,
  251. /* IN */ MS_SCENE_CLIENT_CB appl_cb
  252. );
  253. /**
  254. * \brief API to get Scene client model handle
  255. *
  256. * \par Description
  257. * This is to get the handle of Scene client model.
  258. *
  259. * \param [out] model_handle Address of model handle to be filled/returned.
  260. *
  261. * \return API_SUCCESS or an error code indicating reason for failure
  262. */
  263. API_RESULT MS_scene_client_get_model_handle
  264. (
  265. /* OUT */ MS_ACCESS_MODEL_HANDLE * model_handle
  266. );
  267. /**
  268. * \brief API to send acknowledged commands
  269. *
  270. * \par Description
  271. * This is to initialize sending acknowledged commands.
  272. *
  273. * \param [in] req_opcode Request Opcode.
  274. * \param [in] param Parameter associated with Request Opcode.
  275. * \param [in] rsp_opcode Response Opcode.
  276. *
  277. * \return API_SUCCESS or an error code indicating reason for failure
  278. */
  279. API_RESULT MS_scene_client_send_reliable_pdu
  280. (
  281. /* IN */ UINT32 req_opcode,
  282. /* IN */ void * param,
  283. /* IN */ UINT32 rsp_opcode
  284. );
  285. /**
  286. * \brief API to get the current status of a currently active scene of an element.
  287. *
  288. * \par Description
  289. * Scene Get is an acknowledged message used to get the current status of a currently active scene of an element.
  290. * The response to the Scene Get message is a Scene Status message.
  291. * There are no parameters for this message.
  292. *
  293. * \return API_SUCCESS or an error code indicating reason for failure
  294. */
  295. #define MS_scene_get() \
  296. MS_scene_client_send_reliable_pdu \
  297. (\
  298. MS_ACCESS_SCENE_GET_OPCODE,\
  299. NULL,\
  300. MS_ACCESS_SCENE_STATUS_OPCODE\
  301. )
  302. /**
  303. * \brief API to ecall the current state of an element.
  304. *
  305. * \par Description
  306. * Scene Recall is an acknowledged message that is used to recall the current state of an element from a previously stored scene.
  307. * The response to the Scene Recall message is a Scene Status message.
  308. *
  309. * \param [in] param Scene Recall message
  310. *
  311. * \return API_SUCCESS or an error code indicating reason for failure
  312. */
  313. #define MS_scene_recall(param) \
  314. MS_scene_client_send_reliable_pdu \
  315. (\
  316. MS_ACCESS_SCENE_RECALL_OPCODE,\
  317. param,\
  318. MS_ACCESS_SCENE_STATUS_OPCODE\
  319. )
  320. /**
  321. * \brief API to ecall the current state of an element.
  322. *
  323. * \par Description
  324. * Scene Recall Unacknowledged is an unacknowledged message used to recall the current state of an element from a previously stored Scene.
  325. *
  326. * \param [in] param Scene Recall message
  327. *
  328. * \return API_SUCCESS or an error code indicating reason for failure
  329. */
  330. #define MS_scene_recall_unacknowledged(param) \
  331. MS_scene_client_send_reliable_pdu \
  332. (\
  333. MS_ACCESS_SCENE_RECALL_UNACKNOWLEDGED_OPCODE,\
  334. param,\
  335. 0xFFFFFFFF\
  336. )
  337. /**
  338. * \brief API to get the current status of the Scene Register of an element.
  339. *
  340. * \par Description
  341. * Scene Register Get is an acknowledged message used to get the current status of the Scene Register of an element.
  342. * The response to the Scene Register Get message is a Scene Register Status message.
  343. * There are no parameters for this message.
  344. *
  345. * \return API_SUCCESS or an error code indicating reason for failure
  346. */
  347. #define MS_scene_register_get() \
  348. MS_scene_client_send_reliable_pdu \
  349. (\
  350. MS_ACCESS_SCENE_REGISTER_GET_OPCODE,\
  351. NULL,\
  352. MS_ACCESS_SCENE_REGISTER_STATUS_OPCODE\
  353. )
  354. /**
  355. * \brief API to store the current state of an element as a Scene.
  356. *
  357. * \par Description
  358. * Scene Store is an acknowledged message used to store the current state of an element as a Scene, which can be recalled later.
  359. * The response to the Scene Store message is a Scene Register Status message.
  360. *
  361. * \param [in] param Scene Store message
  362. *
  363. * \return API_SUCCESS or an error code indicating reason for failure
  364. */
  365. #define MS_scene_store(param) \
  366. MS_scene_client_send_reliable_pdu \
  367. (\
  368. MS_ACCESS_SCENE_STORE_OPCODE,\
  369. param,\
  370. MS_ACCESS_SCENE_REGISTER_STATUS_OPCODE\
  371. )
  372. /**
  373. * \brief API to store the current state of an element as a Scene.
  374. *
  375. * \par Description
  376. * Scene Store Unacknowledged is an unacknowledged message used to store the current state of an element as a Scene, which can be recalled later.
  377. *
  378. * \param [in] param Scene Store message
  379. *
  380. * \return API_SUCCESS or an error code indicating reason for failure
  381. */
  382. #define MS_scene_store_unacknowledged(param) \
  383. MS_scene_client_send_reliable_pdu \
  384. (\
  385. MS_ACCESS_SCENE_STORE_UNACKNOWLEDGED_OPCODE,\
  386. param,\
  387. 0xFFFFFFFF\
  388. )
  389. /**
  390. * \brief API to delete a Scene from the Scene Register state of an element.
  391. *
  392. * \par Description
  393. * Scene Delete is an acknowledged message used to delete a Scene from the Scene Register state of an element.
  394. * The response to the Scene Delete message is a Scene Register Status message.
  395. *
  396. * \param [in] param Scene Delete parameter
  397. *
  398. * \return API_SUCCESS or an error code indicating reason for failure
  399. */
  400. #define MS_scene_delete(param) \
  401. MS_scene_client_send_reliable_pdu \
  402. (\
  403. MS_ACCESS_SCENE_DELETE_OPCODE,\
  404. param,\
  405. MS_ACCESS_SCENE_REGISTER_STATUS_OPCODE\
  406. )
  407. /**
  408. * \brief API to delete a Scene from the Scene Register state of an element.
  409. *
  410. * \par Description
  411. * Scene Delete Unacknowledged is an unacknowledged message used to delete a scene from the Scene Register state of an element.
  412. *
  413. * \param [in] param Scene Delete parameter
  414. *
  415. * \return API_SUCCESS or an error code indicating reason for failure
  416. */
  417. #define MS_scene_delete_unacknowledged(param) \
  418. MS_scene_client_send_reliable_pdu \
  419. (\
  420. MS_ACCESS_SCENE_DELETE_UNACKNOWLEDGED_OPCODE,\
  421. param,\
  422. 0xFFFFFFFF\
  423. )
  424. /** \} */
  425. /** \} */
  426. /** \} */
  427. #endif /*_H_MS_SCENE_API_ */