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 Bluetooth Mesh Health Server Model 15 * @defgroup bt_mesh_health_srv Bluetooth Mesh Health Server Model 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 /** @def BT_MESH_HEALTH_PUB_DEFINE 61 * 62 * A helper to define a health publication context 63 * 64 * @param _name Name given to the publication context variable. 65 * @param _max_faults Maximum number of faults the element can have. 66 */ 67 #define BT_MESH_HEALTH_PUB_DEFINE(_name, _max_faults) \ 68 BT_MESH_MODEL_PUB_DEFINE(_name, NULL, (1 + 3 + (_max_faults))) 69 70 71 /** Mesh Health Server Model Context */ 72 struct bt_mesh_health_srv { 73 struct bt_mesh_model *model; 74 75 /* Optional callback struct */ 76 const struct bt_mesh_health_srv_cb *cb; 77 78 /* Attention Timer state */ 79 struct k_delayed_work attn_timer; 80 }; 81 82 int bt_mesh_fault_update(struct bt_mesh_elem *elem); 83 84 extern const struct bt_mesh_model_op bt_mesh_health_srv_op[]; 85 86 /** @def BT_MESH_MODEL_HEALTH_SRV 87 * 88 * Define a new health server model. Note that this API needs to be 89 * repeated for each element that the application wants to have a 90 * health server model on. Each instance also needs a unique 91 * bt_mesh_health_srv and bt_mesh_model_pub context. 92 * 93 * @param srv Pointer to a unique struct bt_mesh_health_srv. 94 * @param pub Pointer to a unique struct bt_mesh_model_pub. 95 * 96 * @return New mesh model instance. 97 */ 98 99 extern struct bt_mesh_health_srv g_health_srv; 100 extern struct bt_mesh_model_pub g_health_pub; 101 102 103 104 #define BT_MESH_MODEL_HEALTH_SRV(srv, pub) \ 105 BT_MESH_MODEL(BT_MESH_MODEL_ID_HEALTH_SRV, \ 106 bt_mesh_health_srv_op, pub, srv) 107 108 #define MESH_MODEL_HEALTH_SRV_NULL() BT_MESH_MODEL_HEALTH_SRV(&g_health_srv, &g_health_pub) 109 110 #ifdef __cplusplus 111 } 112 #endif 113 114 /** 115 * @} 116 */ 117 118 #endif /* __BT_MESH_HEALTH_SRV_H */ 119