• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2  *  @brief Bluetooth Mesh Health Server Model APIs.
3  */
4 
5 /*
6  * Copyright (c) 2017 Intel Corporation
7  *
8  * SPDX-License-Identifier: Apache-2.0
9  */
10 #ifndef __BT_MESH_HEALTH_SRV_H
11 #define __BT_MESH_HEALTH_SRV_H
12 
13 /**
14  * @brief Mesh Bluetooth Mesh Health Server Model
15  * @defgroup bt_mesh_health_srv
16  * @ingroup bt_mesh
17  * @{
18  */
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 struct bt_mesh_health_srv_cb {
25     /* Fetch current faults */
26     int (*fault_get_cur)(struct bt_mesh_model *model, u8_t *test_id,
27                          u16_t *company_id, u8_t *faults,
28                          u8_t *fault_count);
29 
30     /* Fetch registered faults */
31     int (*fault_get_reg)(struct bt_mesh_model *model, u16_t company_id,
32                          u8_t *test_id, u8_t *faults,
33                          u8_t *fault_count);
34 
35     /* Clear registered faults */
36     int (*fault_clear)(struct bt_mesh_model *model, u16_t company_id);
37 
38     /* Run a specific test */
39     int (*fault_test)(struct bt_mesh_model *model, u8_t test_id,
40                       u16_t company_id);
41 
42     /* Attention on */
43     void (*attn_on)(struct bt_mesh_model *model);
44 
45     /* Attention off */
46     void (*attn_off)(struct bt_mesh_model *model);
47 };
48 
49 /** @def BT_MESH_HEALTH_FAULT_MSG
50  *
51  *  A helper to define a health fault message.
52  *
53  *  @param max_faults Maximum number of faults the element can have.
54  *
55  *  @return a New net_buf_simple of the needed size.
56  */
57 #define BT_MESH_HEALTH_FAULT_MSG(max_faults) \
58     NET_BUF_SIMPLE(1 + 3 + (max_faults))
59 
60 /** Mesh Health Server Model Context */
61 struct bt_mesh_health_srv {
62     struct bt_mesh_model *model;
63 
64     /* Optional callback struct */
65     const struct bt_mesh_health_srv_cb *cb;
66 
67     /* Attention Timer state */
68     struct k_delayed_work attn_timer;
69 };
70 
71 int bt_mesh_fault_update(struct bt_mesh_elem *elem);
72 
73 extern const struct bt_mesh_model_op bt_mesh_health_srv_op[];
74 extern const struct bt_mesh_model_cb bt_mesh_health_srv_cb;
75 
76 /** @def BT_MESH_MODEL_HEALTH_SRV
77  *
78  *  Define a new health server model. Note that this API needs to be
79  *  repeated for each element that the application wants to have a
80  *  health server model on. Each instance also needs a unique
81  *  bt_mesh_health_srv and bt_mesh_model_pub context.
82  *
83  *  @param srv Pointer to a unique struct bt_mesh_health_srv.
84  *  @param pub Pointer to a unique struct bt_mesh_model_pub.
85  *
86  *  @return New mesh model instance.
87  */
88 #define BT_MESH_MODEL_HEALTH_SRV(srv, pub)                                     \
89     BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_HEALTH_SRV, bt_mesh_health_srv_op,   \
90              pub, srv, &bt_mesh_health_srv_cb)
91 
92 #ifdef __cplusplus
93 }
94 #endif
95 
96 /**
97  * @}
98  */
99 
100 #endif /* __BT_MESH_HEALTH_SRV_H */
101