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
esp_gen_light_cli_model.c File Reference

Implementation of the Generic Light Client model for BLE Mesh. This file contains the initialization, resource management, and message handling logic for the Generic Light Client model in the MeshX platform. More...

Include dependency graph for esp_gen_light_cli_model.c:

Go to the source code of this file.

Macros

#define MESHX_CLIENT_INIT_MAGIC_NO   0x3728
 

Functions

static void esp_ble_mesh_light_client_cb (MESHX_GEN_LIGHT_CLI_CB_EVT event, MESHX_GEN_LIGHT_CLI_CB_PARAM *param)
 Callback function for BLE Mesh Light Client events.
 
meshx_err_t meshx_plat_gen_light_client_init (void)
 Initialize the Generic Light Client Model. This function sets up the necessary parameters and resources for the Generic Light Client Model to operate correctly.
 
meshx_err_t meshx_plat_light_ctl_client_create (meshx_ptr_t p_model, meshx_ptr_t *p_pub, meshx_ptr_t *p_light_ctl_cli)
 Creates and initializes a Light CTL (Color Temperature Light) client model instance.
 
meshx_err_t meshx_plat_light_client_delete (meshx_ptr_t *p_pub, meshx_ptr_t *p_cli)
 Deletes the Light client instance and its associated publication context.
 
meshx_err_t meshx_plat_light_client_send_msg (meshx_ptr_t p_model, meshx_light_client_set_state_t *p_set, uint16_t opcode, uint16_t addr, uint16_t net_idx, uint16_t app_idx, bool is_get_opcode)
 Sends a Light Client message over BLE Mesh.
 

Variables

static uint16_t meshx_client_init = 0
 
static const char * client_state_str []
 Mapping of BLE Mesh client state events to string representations.
 

Detailed Description

Implementation of the Generic Light Client model for BLE Mesh. This file contains the initialization, resource management, and message handling logic for the Generic Light Client model in the MeshX platform.

Copyright (c) 2024 - 2025 MeshX

The Generic Light Client model is responsible for sending requests and receiving responses related to the light state of devices in a BLE Mesh network. It manages the client instance, publication context, and interacts with the MeshX BLE Mesh stack.

Author
Pranjal Chanda

Definition in file esp_gen_light_cli_model.c.

Macro Definition Documentation

◆ MESHX_CLIENT_INIT_MAGIC_NO

#define MESHX_CLIENT_INIT_MAGIC_NO   0x3728

Definition at line 27 of file esp_gen_light_cli_model.c.

Function Documentation

◆ esp_ble_mesh_light_client_cb()

static void esp_ble_mesh_light_client_cb ( MESHX_GEN_LIGHT_CLI_CB_EVT event,
MESHX_GEN_LIGHT_CLI_CB_PARAM * param )
static

Callback function for BLE Mesh Light Client events.

This function is invoked to handle events related to the Generic Light Client model in the BLE Mesh stack. It processes various client events and their associated parameters.

Parameters
eventThe event type received by the Light Client.
paramPointer to the structure containing event-specific parameters.

Definition at line 63 of file esp_gen_light_cli_model.c.

65{
67 MESHX_LOGD(MODULE_ID_MODEL_CLIENT, "%s, err|op|src|dst: %d|%04" PRIx32 "|%04x|%04x",
68 client_state_str[event], param->error_code,
69 param->params->ctx.recv_op, param->params->ctx.addr, param->params->ctx.recv_dst);
70
72 .ctx = {
73 .net_idx = param->params->ctx.net_idx,
74 .app_idx = param->params->ctx.app_idx,
75 .dst_addr = param->params->ctx.recv_dst,
76 .src_addr = param->params->ctx.addr,
77 .opcode = param->params->ctx.recv_op,
78 .p_ctx = &param->params->ctx
79 },
80 .model = {
81 .pub_addr = param->params->model->pub->publish_addr,
82 .model_id = param->params->model->model_id,
83 .el_id = param->params->model->element_idx,
84 .p_model = param->params->model
85 },
86 .evt = MESHX_BIT(event)
87 };
88
89 /* Copy the msg data from BLE Layer to MeshX Layer */
90 memcpy(&pub_param.status, &param->status_cb, sizeof(meshx_gen_light_client_status_cb_t));
91
92 /* Publish the event to the control task message queue */
95 pub_param.model.model_id,
96 &pub_param, sizeof(meshx_gen_light_cli_cb_param_t));
97 if (err != MESHX_SUCCESS)
98 {
99 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Failed to publish Generic Light Client event: %d", err);
100 }
101}
static const char * client_state_str[]
Mapping of BLE Mesh client state events to string representations.
#define MESHX_BIT(nr)
struct meshx_gen_light_cli_cb_param meshx_gen_light_cli_cb_param_t
Callback parameters for Generic Light Client Model events. This structure is used to pass information...
@ CONTROL_TASK_MSG_CODE_FRM_BLE
meshx_err_t control_task_msg_publish(control_task_msg_code_t msg_code, control_task_msg_evt_t msg_evt, const void *msg_evt_params, size_t sizeof_msg_evt_params)
Publish a control task message.
#define MESHX_UNUSED(x)
Definition meshx_err.h:15
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:39
@ MESHX_SUCCESS
Definition meshx_err.h:40
#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_light_client_status_cb_t status
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_plat_gen_light_client_init()

meshx_err_t meshx_plat_gen_light_client_init ( void )

Initialize the Generic Light Client Model. This function sets up the necessary parameters and resources for the Generic Light Client Model to operate correctly.

Returns
meshx_err_t Returns MESHX_SUCCESS on successful initialization, or an appropriate error code on failure.

Definition at line 114 of file esp_gen_light_cli_model.c.

115{
118 {
119 return MESHX_SUCCESS; // Already initialized
120 }
122
123 // Register the callback for handling messages sent to the BLE layer
124 esp_err_t esp_err = esp_ble_mesh_register_light_client_callback(
126 if (esp_err != ESP_OK)
127 err = MESHX_ERR_PLAT;
128 return err;
129}
static void esp_ble_mesh_light_client_cb(MESHX_GEN_LIGHT_CLI_CB_EVT event, MESHX_GEN_LIGHT_CLI_CB_PARAM *param)
Callback function for BLE Mesh Light Client events.
@ MESHX_ERR_PLAT
Definition meshx_err.h:43
#define MESHX_CLIENT_INIT_MAGIC_NO
uint16_t meshx_client_init
#define MESHX_GEN_LIGHT_CLI_CB
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_plat_light_client_delete()

meshx_err_t meshx_plat_light_client_delete ( meshx_ptr_t * p_pub,
meshx_ptr_t * p_cli )

Deletes the Light client instance and its associated publication context.

This function is responsible for cleaning up and freeing resources associated with the Light client model, including its publication context.

Parameters
[in]p_pubPointer to the publication context to be deleted.
[in]p_cliPointer to the client instance to be deleted.
Returns
meshx_err_t Returns an error code indicating the result of the delete operation.

Definition at line 168 of file esp_gen_light_cli_model.c.

169{
170 if (p_cli)
171 {
172 MESHX_FREE(*p_cli);
173 *p_cli = NULL;
174 }
175
176 return meshx_plat_del_model_pub(p_pub);
177}
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:
Here is the caller graph for this function:

◆ meshx_plat_light_client_send_msg()

meshx_err_t meshx_plat_light_client_send_msg ( meshx_ptr_t p_model,
meshx_light_client_set_state_t * p_set,
uint16_t opcode,
uint16_t addr,
uint16_t net_idx,
uint16_t app_idx,
bool is_get_opcode )

Sends a Light Client message over BLE Mesh.

This function constructs and sends a Light Client message using the specified model, set state parameters, opcode, destination address, network index, and application index.

Parameters
[in]p_modelPointer to the BLE Mesh model instance.
[in]p_setPointer to the structure containing the light client set state parameters.
[in]opcodeOpcode of the message to be sent.
[in]addrDestination address for the message.
[in]net_idxNetwork index to be used for sending the message.
[in]app_idxApplication index to be used for sending the message.
[in]is_get_opcodeIndicates whether the opcode is a GET type (true) or SET type (false).
Returns
meshx_err_t Result of the message send operation.

Definition at line 195 of file esp_gen_light_cli_model.c.

201{
202 if (!p_model || !p_set)
203 {
204 return MESHX_INVALID_ARG;
205 }
206
207 esp_ble_mesh_client_common_param_t common = {0};
208 common.model = p_model;
209 common.opcode = opcode;
210 common.ctx.addr = addr;
211 common.ctx.net_idx = net_idx;
212 common.ctx.app_idx = app_idx;
213 common.ctx.send_ttl = BLE_MESH_TTL_DEFAULT;
214 common.msg_timeout = 0; /* 0 indicates that timeout value from menuconfig will be used */
215
216 // Send the message using the appropriate BLE Mesh API
217 if (!is_get_opcode)
218 {
219 esp_err_t esp_err = esp_ble_mesh_light_client_set_state(
220 &common,
221 (esp_ble_mesh_light_client_set_state_t *)p_set
222 );
223 if (esp_err != ESP_OK)
224 {
225 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Failed to send Light Client message: %d", esp_err);
226 return MESHX_ERR_PLAT;
227 }
228 }
229 else
230 {
231 esp_err_t esp_err = esp_ble_mesh_light_client_get_state(
232 &common,
233 (esp_ble_mesh_light_client_get_state_t *)p_set
234 );
235 if (esp_err != ESP_OK)
236 {
237 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Failed to send Light Client GET message: %d", esp_err);
238 return MESHX_ERR_PLAT;
239 }
240 }
241 return MESHX_SUCCESS;
242}
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
Here is the caller graph for this function:

◆ meshx_plat_light_ctl_client_create()

meshx_err_t meshx_plat_light_ctl_client_create ( meshx_ptr_t p_model,
meshx_ptr_t * p_pub,
meshx_ptr_t * p_light_ctl_cli )

Creates and initializes a Light CTL (Color Temperature Light) client model instance.

This function sets up the Light CTL client model for use in the BLE Mesh network. It associates the client model with the provided model pointer and optionally sets up publication and client context pointers.

Parameters
[in]p_modelPointer to the mesh model structure to associate with the Light CTL client.
[out]p_pubPointer to a publication context pointer to be initialized (can be NULL if not used).
[out]p_light_ctl_cliPointer to a Light CTL client context pointer to be initialized.
Returns
meshx_err_t Returns MESHX_OK on success, or an appropriate error code on failure.

Definition at line 144 of file esp_gen_light_cli_model.c.

145{
146 if (!p_model || !p_pub || !p_light_ctl_cli)
147 {
148 return MESHX_INVALID_ARG; // Invalid arguments
149 }
150 /* SIG Light CTL Init */
151 uint16_t model_id = ESP_BLE_MESH_MODEL_ID_LIGHT_CTL_CLI;
152 memcpy((meshx_ptr_t)&(((MESHX_MODEL *)p_model)->model_id), &model_id, sizeof(model_id));
153
154 return meshx_plat_client_create(p_model, p_pub, p_light_ctl_cli);
155}
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:
Here is the caller graph for this function:

Variable Documentation

◆ client_state_str

const char* client_state_str[]
static
Initial value:
=
{
[ESP_BLE_MESH_LIGHT_CLIENT_PUBLISH_EVT] = "PUBLISH_EVT",
[ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT] = "TIMEOUT_EVT",
[ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT] = "GET_STATE_EVT",
[ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT] = "SET_STATE_EVT",
}

Mapping of BLE Mesh client state events to string representations.

Definition at line 37 of file esp_gen_light_cli_model.c.

38{
39 [ESP_BLE_MESH_LIGHT_CLIENT_PUBLISH_EVT] = "PUBLISH_EVT",
40 [ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT] = "TIMEOUT_EVT",
41 [ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT] = "GET_STATE_EVT",
42 [ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT] = "SET_STATE_EVT",
43};

◆ meshx_client_init

uint16_t meshx_client_init = 0
static

Definition at line 32 of file esp_gen_light_cli_model.c.