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_cli.h File Reference

Header file for BLE Mesh Generic Client functionality in the MeshX framework. This file contains declarations and includes required for implementing BLE Mesh Generic Client operations. More...

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

Go to the source code of this file.

Data Structures

struct  meshx_gen_onoff_set_t
 
struct  meshx_gen_level_set_t
 
struct  meshx_gen_delta_set_t
 
struct  meshx_gen_move_set_t
 
struct  meshx_gen_def_trans_time_set_t
 
struct  meshx_gen_onpowerup_set_t
 
struct  meshx_gen_power_level_set_t
 
struct  meshx_gen_power_default_set_t
 
struct  meshx_gen_power_range_set_t
 
struct  meshx_gen_loc_global_set_t
 
struct  meshx_gen_loc_local_set_t
 
union  meshx_gen_cli_set_t
 Generic Client Model set message union. More...
 
struct  meshx_gen_onoff_status_cb_t
 
struct  meshx_gen_level_status_cb_t
 
struct  meshx_gen_def_trans_time_status_cb_t
 
struct  meshx_gen_onpowerup_status_cb_t
 
struct  meshx_gen_power_level_status_cb_t
 
struct  meshx_gen_power_last_status_cb_t
 
struct  meshx_gen_power_default_status_cb_t
 
struct  meshx_gen_power_range_status_cb_t
 
struct  meshx_gen_battery_status_cb_t
 
struct  meshx_gen_loc_global_status_cb_t
 
struct  meshx_gen_loc_local_status_cb_t
 
struct  meshx_gen_user_properties_status_cb_t
 
struct  meshx_gen_user_property_status_cb_t
 
struct  meshx_gen_admin_properties_status_cb_t
 
struct  meshx_gen_admin_property_status_cb_t
 
struct  meshx_gen_manufacturer_properties_status_cb_t
 
struct  meshx_gen_manufacturer_property_status_cb_t
 
struct  meshx_gen_client_properties_status_cb_t
 
union  meshx_gen_client_status_cb_t
 Generic Client Model received message union. More...
 
struct  meshx_gen_cli_cb_param
 Callback parameters for Generic Client Model events. This structure is used to pass information about the received messages and their context to the application. It includes the context, model pointer, event type, and status values. The status values are encapsulated in a union to handle different types of status messages that the Generic Client Model can receive. Each status type corresponds to a specific operation code (opcode) defined in the BLE Mesh specification, allowing the application to handle them appropriately. More...
 

Typedefs

typedef struct meshx_gen_cli_cb_param meshx_gen_cli_cb_param_t
 Callback parameters for Generic Client Model events. This structure is used to pass information about the received messages and their context to the application. It includes the context, model pointer, event type, and status values. The status values are encapsulated in a union to handle different types of status messages that the Generic Client Model can receive. Each status type corresponds to a specific operation code (opcode) defined in the BLE Mesh specification, allowing the application to handle them appropriately.
 
typedef control_task_msg_handle_t meshx_gen_client_cb_t
 

Enumerations

enum  meshx_gen_cli_evt_t {
  MESHX_GEN_CLI_EVT_GET = MESHX_BIT(0) ,
  MESHX_GEN_CLI_EVT_SET = MESHX_BIT(1) ,
  MESHX_GEN_CLI_PUBLISH = MESHX_BIT(2) ,
  MESHX_GEN_CLI_TIMEOUT = MESHX_BIT(3) ,
  MESHX_GEN_CLI_EVT_ALL
}
 

Functions

meshx_err_t meshx_plat_on_off_gen_cli_create (meshx_ptr_t p_model, meshx_ptr_t *p_pub, meshx_ptr_t *p_onoff_cli)
 Creates a Generic OnOff client model and its publication context.
 
meshx_err_t meshx_plat_gen_cli_delete (meshx_ptr_t *p_pub, meshx_ptr_t *p_cli)
 Deletes the Generic OnOff Client model and its associated resources.
 
meshx_err_t meshx_plat_gen_cli_init (void)
 Initialize the meshxuction generic client.
 
meshx_err_t meshx_plat_gen_cli_send_msg (meshx_ptr_t p_model, meshx_gen_cli_set_t *p_set, uint16_t opcode, uint16_t addr, uint16_t net_idx, uint16_t app_idx, bool is_get_opcode)
 Sends a Generic Client message over BLE Mesh.
 

Detailed Description

Header file for BLE Mesh Generic Client functionality in the MeshX framework. This file contains declarations and includes required for implementing BLE Mesh Generic Client operations.

Copyright (c) 2024 - 2025 MeshX

Author
Pranjal Chanda

Definition in file meshx_ble_mesh_gen_cli.h.

Typedef Documentation

◆ meshx_gen_cli_cb_param_t

Callback parameters for Generic Client Model events. This structure is used to pass information about the received messages and their context to the application. It includes the context, model pointer, event type, and status values. The status values are encapsulated in a union to handle different types of status messages that the Generic Client Model can receive. Each status type corresponds to a specific operation code (opcode) defined in the BLE Mesh specification, allowing the application to handle them appropriately.

◆ meshx_gen_client_cb_t

Enumeration Type Documentation

◆ meshx_gen_cli_evt_t

Enumerator
MESHX_GEN_CLI_EVT_GET MESHX_BIT(0) 
MESHX_GEN_CLI_EVT_SET MESHX_BIT(1) 
MESHX_GEN_CLI_PUBLISH MESHX_BIT(2) 
MESHX_GEN_CLI_TIMEOUT MESHX_BIT(3) 
MESHX_GEN_CLI_EVT_ALL ( MESHX_GEN_CLI_EVT_GET | MESHX_GEN_CLI_EVT_SET | MESHX_GEN_CLI_PUBLISH | MESHX_GEN_CLI_TIMEOUT) 

Definition at line 18 of file meshx_ble_mesh_gen_cli.h.

Function Documentation

◆ meshx_plat_gen_cli_delete()

meshx_err_t meshx_plat_gen_cli_delete ( meshx_ptr_t * p_pub,
meshx_ptr_t * p_cli )

Deletes the Generic OnOff Client model and its associated resources.

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

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

Definition at line 187 of file esp_gen_cli_model.c.

188{
189 if (p_cli)
190 {
191 MESHX_FREE(*p_cli);
192 *p_cli = NULL;
193 }
194
195 return meshx_plat_del_model_pub(p_pub);
196}
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_cli_init()

meshx_err_t meshx_plat_gen_cli_init ( void )

Initialize the meshxuction generic client.

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

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

Definition at line 125 of file esp_gen_cli_model.c.

126{
127
130 {
131 return MESHX_SUCCESS; // Already initialized
132 }
134
135 // Register the callback for handling messages sent to the BLE layer
136 esp_err_t esp_err = esp_ble_mesh_register_generic_client_callback(
138 if (esp_err != ESP_OK)
139 err = MESHX_ERR_PLAT;
140
141 return err;
142}
static void esp_ble_mesh_generic_client_cb(MESHX_GEN_CLI_CB_EVT event, MESHX_GEN_CLI_CB_PARAM *param)
Callback function for handling BLE Mesh Generic Client 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_CLIENT_INIT_MAGIC_NO
uint16_t meshx_client_init
#define MESHX_GEN_CLI_CB
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_plat_gen_cli_send_msg()

meshx_err_t meshx_plat_gen_cli_send_msg ( meshx_ptr_t p_model,
meshx_gen_cli_set_t * p_set,
uint16_t opcode,
uint16_t addr,
uint16_t net_idx,
uint16_t app_idx,
bool is_get_opcode )

Sends a Generic Client message over BLE Mesh.

This function sends a message from a Generic Client model to a specified address within the BLE Mesh network, using the provided opcode and parameters.

Parameters
[in]p_modelPointer to the Generic Client model instance.
[in]p_setPointer to the structure containing the message parameters to set.
[in]opcodeOperation code specifying the type of message to send.
[in]addrDestination address within the BLE Mesh network.
[in]net_idxNetwork index identifying the subnet to use.
[in]app_idxApplication key index to encrypt the message.
[in]is_get_opcodeFlag indicating if the opcode is a GET request.
Returns
meshx_err_t Result of the operation. Returns MESHX_OK on success or an error code on failure.

Definition at line 214 of file esp_gen_cli_model.c.

220{
221 if (!p_model || !p_set)
222 {
223 return MESHX_INVALID_ARG; // Invalid arguments
224 }
225
226 esp_ble_mesh_client_common_param_t common = {0};
227 common.model = p_model;
228 common.opcode = opcode;
229 common.ctx.addr = addr;
230 common.ctx.net_idx = net_idx;
231 common.ctx.app_idx = app_idx;
232 common.ctx.send_ttl = BLE_MESH_TTL_DEFAULT;
233 common.msg_timeout = 0; /* 0 indicates that timeout value from menuconfig will be used */
234
235 esp_err_t err = ESP_OK;
236 if(!is_get_opcode)
237 {
238 p_set->onoff_set.trans_time = 0;
239 if(!(p_set->onoff_set.onoff == 0 || p_set->onoff_set.onoff == 1))
240 {
241 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Invalid OnOff value %d", p_set->onoff_set.onoff);
242 return MESHX_INVALID_ARG;
243 }
244 err = esp_ble_mesh_generic_client_set_state(
245 &common,
246 (esp_ble_mesh_generic_client_set_state_t *)p_set
247 );
248 if (err != ESP_OK)
249 {
250 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Send Generic OnOff failed: %d", err);
251 return MESHX_FAIL;
252 }
253 }
254 else
255 {
256 err = esp_ble_mesh_generic_client_get_state(
257 &common,
258 (esp_ble_mesh_generic_client_get_state_t *)p_set
259 );
260 if (err != ESP_OK)
261 {
262 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Send Generic OnOff Get failed: %d", err);
263 return MESHX_FAIL;
264 }
265 }
266 if (!err)
267 {
268 MESHX_LOGD(MODULE_ID_MODEL_CLIENT, "Client Send Success");
269 }
270
271 return MESHX_SUCCESS;
272}
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
@ MESHX_FAIL
Definition meshx_err.h:41
#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_CLIENT
Definition module_id.h:31
meshx_gen_onoff_set_t onoff_set
Here is the caller graph for this function:

◆ meshx_plat_on_off_gen_cli_create()

meshx_err_t meshx_plat_on_off_gen_cli_create ( meshx_ptr_t p_model,
meshx_ptr_t * p_pub,
meshx_ptr_t * p_onoff_cli )

Creates a Generic OnOff client model and its publication context.

This function initializes the Generic OnOff client model, its publication context, and allocates memory for the client 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_cliPointer to the OnOff client 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 160 of file esp_gen_cli_model.c.

161{
162 if (!p_model || !p_pub || !p_onoff_cli)
163 {
164 return MESHX_INVALID_ARG; // Invalid arguments
165 }
166 /* SIG On OFF Init */
167 uint16_t model_id = ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_CLI;
168 memcpy((meshx_ptr_t)&(((MESHX_MODEL *)p_model)->model_id), &model_id, sizeof(model_id));
169
170 return meshx_plat_client_create(p_model, p_pub, p_onoff_cli);
171}
meshx_err_t meshx_plat_client_create(meshx_ptr_t p_model, meshx_ptr_t *p_pub, meshx_ptr_t *p_cli)
Creates and initializes a generic client model for BLE Mesh.
void * meshx_ptr_t
#define MESHX_MODEL
Here is the call graph for this function: