MeshX 0.3
This repository provides an implementation for Bluetooth Low Energy (BLE) Mesh network nodes. The project allows you to create BLE mesh nodes that can communicate with each other, enabling the development of smart home solutions or other IoT-based applications.
Loading...
Searching...
No Matches
meshx_ble_mesh_gen_srv.h File Reference

Header file for Generic Server Models in MeshX BLE Mesh. More...

Include dependency graph for meshx_ble_mesh_gen_srv.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  meshx_state_change_gen_onoff_set_t
 
struct  meshx_state_change_gen_level_set_t
 
struct  meshx_state_change_gen_delta_set_t
 
struct  meshx_state_change_gen_move_set_t
 
struct  meshx_state_change_gen_def_trans_time_set_t
 
struct  meshx_state_change_gen_onpowerup_set_t
 
struct  meshx_state_change_gen_power_level_set_t
 
struct  meshx_state_change_gen_power_default_set_t
 
struct  meshx_state_change_gen_power_range_set_t
 
struct  meshx_state_change_gen_loc_global_set_t
 
struct  meshx_state_change_gen_loc_local_set_t
 
struct  meshx_state_change_gen_user_property_set_t
 
struct  meshx_state_change_gen_admin_property_set_t
 
struct  meshx_state_change_gen_manu_property_set_t
 
union  meshx_gen_srv_state_change_t
 
struct  meshx_gen_srv_cb_param
 

Typedefs

typedef struct meshx_gen_srv_cb_param meshx_gen_srv_cb_param_t
 
typedef control_task_msg_handle_t meshx_server_cb
 

Functions

meshx_err_t meshx_plat_on_off_gen_srv_create (void *p_model, void **p_pub, void **p_onoff_srv)
 Creates a Generic OnOff Server model and its publication context.
 
meshx_err_t meshx_plat_gen_srv_delete (void **p_pub, void **p_srv)
 Deletes the Generic OnOff Server model and its associated resources.
 
meshx_err_t meshx_plat_set_gen_srv_state (void *p_model, uint8_t on_off_state)
 Set the state of a generic server model.
 
meshx_err_t meshx_plat_gen_srv_init (void)
 Initialize the generic server model platform.
 
meshx_err_t meshx_plat_gen_on_off_srv_restore (void *p_model, uint8_t state)
 Restores the state of the Generic OnOff Server model.
 
meshx_err_t meshx_plat_gen_srv_send_status (meshx_model_t *p_model, meshx_ctx_t *p_ctx, meshx_ptr_t p_data, uint32_t data_len)
 Send a status message from the Generic Server model.
 

Detailed Description

Header file for Generic Server Models in MeshX BLE Mesh.

Copyright (c) 2024 - 2025 MeshX

This file defines the structures, types, and APIs for implementing Generic Server Models in the MeshX BLE Mesh stack. It includes definitions for various state change events, server callbacks, and functions to create, delete, and manage the state of Generic Server Models.

Author
Pranjal Chanda

Definition in file meshx_ble_mesh_gen_srv.h.

Typedef Documentation

◆ meshx_gen_srv_cb_param_t

◆ meshx_server_cb

Function Documentation

◆ meshx_plat_gen_on_off_srv_restore()

meshx_err_t meshx_plat_gen_on_off_srv_restore ( void * p_model,
uint8_t state )

Restores the state of the Generic OnOff Server model.

This function sets the user data of the specified model to the given state. It checks if the model pointer is valid before proceeding with the operation.

Parameters
[in]p_modelPointer to the model structure.
[in]stateThe state to be restored in the model.
Returns
  • MESHX_SUCCESS: State restored successfully.
  • MESHX_INVALID_ARG: Invalid model pointer.

Definition at line 247 of file esp_gen_srv_model.c.

248{
249 return meshx_plat_set_gen_srv_state (p_model, state);
250}
meshx_err_t meshx_plat_set_gen_srv_state(void *p_model, uint8_t on_off_state)
Set the state of a generic server model.
Here is the call graph for this function:

◆ meshx_plat_gen_srv_delete()

meshx_err_t meshx_plat_gen_srv_delete ( void ** p_pub,
void ** p_srv )

Deletes the Generic OnOff Server model and its associated resources.

This function frees the memory allocated for the Generic OnOff Server and sets the pointer to NULL. It also deletes the model publication resources associated with the server.

Parameters
[in,out]p_pubPointer to the publication structure to be deleted.
[in,out]p_srvPointer to the Generic Server structure to be freed.
Returns
  • MESHX_SUCCESS: Model and publication deleted successfully.
  • MESHX_FAIL: Failed to delete the model or publication.

Definition at line 236 of file esp_gen_srv_model.c.

237{
238 if(p_srv)
239 {
240 MESHX_FREE(*p_srv);
241 *p_srv = NULL;
242 }
243
244 return meshx_plat_del_model_pub(p_pub);
245}
meshx_err_t meshx_plat_del_model_pub(meshx_ptr_t *p_pub)
Deletes the model and publication objects.
#define MESHX_FREE
Definition meshx_err.h:32
Here is the call graph for this function:

◆ meshx_plat_gen_srv_init()

meshx_err_t meshx_plat_gen_srv_init ( void )

Initialize the generic server model platform.

Returns
MESHX_SUCCESS on success, or an appropriate error code on failure.

Initialize the generic server model platform.

This function sets up the necessary configurations and initializes the meshxuction generic server for the BLE mesh node.

Returns
  • MESHX_SUCCESS: Success
  • MESHX_FAIL: Failed to initialize the server

Definition at line 210 of file esp_gen_srv_model.c.

211{
213
214 /* Register the ESP Generic Server callback */
215 esp_err_t esp_err = esp_ble_mesh_register_generic_server_callback(
217 );
218 if(esp_err != ESP_OK)
219 err = MESHX_ERR_PLAT;
220
221 return err;
222}
static void esp_ble_mesh_generic_server_cb(MESHX_GEN_SRV_CB_EVT event, MESHX_GEN_SRV_CB_PARAM *param)
Callback function for BLE Mesh Generic Server events.
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:39
@ MESHX_SUCCESS
Definition meshx_err.h:40
@ MESHX_ERR_PLAT
Definition meshx_err.h:43
#define MESHX_GEN_SRV_CB
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_plat_gen_srv_send_status()

meshx_err_t meshx_plat_gen_srv_send_status ( meshx_model_t * p_model,
meshx_ctx_t * p_ctx,
meshx_ptr_t p_data,
uint32_t data_len )

Send a status message from the Generic Server model.

This function sends a status message to the specified context with the provided data.

Parameters
[in]p_modelPointer to the model instance.
[in]p_ctxPointer to the context structure containing destination address and other parameters.
[in]p_dataPointer to the data to be sent.
[in]data_lenLength of the data to be sent.
Returns
  • MESHX_SUCCESS: Message sent successfully.
  • MESHX_NO_MEM: Memory allocation failed.
  • MESHX_ERR_PLAT: Platform error occurred while sending the message.

Definition at line 142 of file esp_gen_srv_model.c.

148{
149 static esp_ble_mesh_msg_ctx_t ctx;
150 const esp_ble_mesh_msg_ctx_t *pctx = (esp_ble_mesh_msg_ctx_t *)p_ctx->p_ctx;
151 if(pctx != NULL)
152 {
153 memcpy(&ctx, pctx, sizeof(esp_ble_mesh_msg_ctx_t));
154 }
155
156 ctx.net_idx = p_ctx->net_idx;
157 ctx.app_idx = p_ctx->app_idx;
158 ctx.addr = p_ctx->dst_addr;
159 ctx.send_ttl = ESP_BLE_MESH_TTL_DEFAULT;
160 ctx.send_cred = 0;
161 ctx.send_tag = BIT1;
162
163 esp_err_t err = esp_ble_mesh_server_model_send_msg(p_model->p_model,
164 &ctx,
165 p_ctx->opcode,
166 (uint16_t)data_len,
167 (uint8_t*)p_data);
168 if(err)
169 {
170 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Mesh Model msg send failed (err: 0x%x)", err);
171 return MESHX_ERR_PLAT;
172 }
173 MESHX_LOGD(MODULE_ID_MODEL_SERVER, "Mesh Model msg sent (opcode: 0x%04x)", p_ctx->opcode);
174 return MESHX_SUCCESS;
175}
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:73
#define MESHX_LOGD(module_id, format,...)
Definition meshx_log.h:113
@ MODULE_ID_MODEL_SERVER
Definition module_id.h:30
meshx_ptr_t p_ctx
uint16_t dst_addr
meshx_ptr_t p_model
Here is the caller graph for this function:

◆ meshx_plat_on_off_gen_srv_create()

meshx_err_t meshx_plat_on_off_gen_srv_create ( void * p_model,
void ** p_pub,
void ** p_onoff_srv )

Creates a Generic OnOff Server model and its publication context.

This function initializes the Generic OnOff Server model, its publication context, and allocates memory for the server instance. It checks for invalid arguments and handles memory allocation failures.

Parameters
[out]p_modelPointer to the model structure to be created.
[out]p_pubPointer to the publication context to be created.
[out]p_onoff_srvPointer to the OnOff server instance to be allocated.
Returns
  • MESHX_SUCCESS: Successfully created the model and publication context.
  • MESHX_INVALID_ARG: One or more arguments are invalid.
  • MESHX_NO_MEM: Memory allocation failed.

Definition at line 224 of file esp_gen_srv_model.c.

225{
226 if(!p_model || !p_pub || !p_onoff_srv)
227 return MESHX_INVALID_ARG;
228
229 /* SIG ON OFF initialisation */
230 uint16_t model_id = ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV;
231 memcpy((meshx_ptr_t) &(((MESHX_MODEL*)p_model)->model_id), &model_id, sizeof(model_id));
232
233 return meshx_plat_gen_srv_create(p_model, p_pub, p_onoff_srv);
234}
static meshx_err_t meshx_plat_gen_srv_create(void *p_model, void **p_pub, void **p_srv)
Creates and initializes the Generic Server model platform resources.
void * meshx_ptr_t
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
#define MESHX_MODEL
Here is the call graph for this function:

◆ meshx_plat_set_gen_srv_state()

meshx_err_t meshx_plat_set_gen_srv_state ( void * p_model,
uint8_t on_off_state )

Set the state of a generic server model.

This function updates the on/off state of a specified generic server model.

Parameters
[in]p_modelPointer to the model whose state is to be set.
[in]on_off_stateThe desired on/off state to set for the model.
Returns
MESHX_SUCCESS on success, or an appropriate error code on failure.

Definition at line 187 of file esp_gen_srv_model.c.

188{
189 if(!p_model)
190 return MESHX_INVALID_ARG;
191
192 MESHX_MODEL * model = (MESHX_MODEL *)p_model;
193 MESHX_GEN_ONOFF_SRV *srv = (MESHX_GEN_ONOFF_SRV *)model->user_data;
194
195 srv->state.onoff = on_off_state;
196
197 return MESHX_SUCCESS;
198}
#define MESHX_GEN_ONOFF_SRV
Here is the caller graph for this function: