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

Header file for the Light CTL (Color Temperature Light) Client model. More...

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

Go to the source code of this file.

Data Structures

struct  meshx_ctl_el_state
 Structure to hold arguments for sending Light CTL messages. More...
 
struct  meshx_ctl_cli_el_msg
 Structure to hold the On/Off Server to element message. More...
 
struct  meshx_gen_ctl_send_params
 Structure to hold the parameters for sending a Generic Ctl message. More...
 

Macros

#define MESHX_LIGHT_CTL_CLI_MSG_SET   0
 
#define MESHX_LIGHT_CTL_CLI_MSG_GET   1
 
#define MESHX_LIGHT_CTL_CLI_MSG_ACK   1
 
#define MESHX_LIGHT_CTL_CLI_MSG_NO_ACK   0
 

Typedefs

typedef struct meshx_ctl_el_state meshx_ctl_el_state_t
 Structure to hold arguments for sending Light CTL messages.
 
typedef struct meshx_ctl_cli_el_msg meshx_ctl_cli_el_msg_t
 Structure to hold the On/Off Server to element message.
 
typedef meshx_model_interface_t meshx_light_ctl_client_model_t
 Structure representing the Light CTL (Color Temperature Lightness) client model in MeshX.
 
typedef struct meshx_gen_ctl_send_params meshx_gen_ctl_send_params_t
 Structure to hold the parameters for sending a Generic Ctl message.
 

Functions

meshx_err_t meshx_light_ctl_client_init ()
 Initialize the Light CTL Client model.
 
meshx_err_t meshx_light_ctl_client_create (meshx_light_ctl_client_model_t **p_model, void *p_sig_model)
 Creates and initializes a Generic Light Client model instance.
 
meshx_err_t meshx_light_ctl_client_delete (meshx_light_ctl_client_model_t **p_model)
 Delete the Light client model instance.
 
meshx_err_t meshx_light_ctl_client_send_msg (meshx_gen_ctl_send_params_t *params)
 Sends a Light CTL (Color Temperature Lightness) message from the Light CTL Client model.
 
meshx_err_t meshx_light_ctl_temperature_client_send_msg (meshx_gen_ctl_send_params_t *params)
 Sends a Light CTL Temperature message from the client model.
 
meshx_err_t meshx_light_ctl_temp_range_client_send_msg (meshx_gen_ctl_send_params_t *params)
 Sends a Light CTL Temperature Range message from the client model.
 
meshx_err_t meshx_light_ctl_state_change_handle (const meshx_ctl_cli_el_msg_t *param, meshx_ctl_el_state_t *p_ctl_prev_state, const meshx_ctl_el_state_t *p_ctl_next_state)
 Handles state changes for the Light CTL client element.
 

Detailed Description

Header file for the Light CTL (Color Temperature Light) Client model.

Copyright © 2024 - 2025 MeshX

This file contains the definitions and function declarations for the Light CTL Client model used in ESP32 BLE Mesh applications. The Light CTL Client model is responsible for sending messages to control the color temperature and lightness of a light.

The file includes necessary BLE Mesh headers and defines the event types, callback function types, and structures used for registering and handling Light CTL Client events.

Author
Pranjal Chanda

Definition in file meshx_light_ctl_client.h.

Macro Definition Documentation

◆ MESHX_LIGHT_CTL_CLI_MSG_ACK

#define MESHX_LIGHT_CTL_CLI_MSG_ACK   1

Definition at line 28 of file meshx_light_ctl_client.h.

◆ MESHX_LIGHT_CTL_CLI_MSG_GET

#define MESHX_LIGHT_CTL_CLI_MSG_GET   1

Definition at line 27 of file meshx_light_ctl_client.h.

◆ MESHX_LIGHT_CTL_CLI_MSG_NO_ACK

#define MESHX_LIGHT_CTL_CLI_MSG_NO_ACK   0

Definition at line 29 of file meshx_light_ctl_client.h.

◆ MESHX_LIGHT_CTL_CLI_MSG_SET

#define MESHX_LIGHT_CTL_CLI_MSG_SET   0

Definition at line 26 of file meshx_light_ctl_client.h.

Typedef Documentation

◆ meshx_ctl_cli_el_msg_t

Structure to hold the On/Off Server to element message.

◆ meshx_ctl_el_state_t

Structure to hold arguments for sending Light CTL messages.

◆ meshx_gen_ctl_send_params_t

Structure to hold the parameters for sending a Generic Ctl message.

◆ meshx_light_ctl_client_model_t

Structure representing the Light CTL (Color Temperature Lightness) client model in MeshX.

This structure holds pointers to the SIG model, publication structures, and generic structures associated with the Light CTL client functionality.

Definition at line 63 of file meshx_light_ctl_client.h.

Function Documentation

◆ meshx_light_ctl_client_create()

meshx_err_t meshx_light_ctl_client_create ( meshx_light_ctl_client_model_t ** p_model,
void * p_sig_model )

Creates and initializes a Generic Light Client model instance.

This function allocates and sets up a Generic Light Client model, associating it with the provided SIG model context.

Parameters
[out]p_modelPointer to a pointer where the created model instance will be stored.
[in]p_sig_modelPointer to the SIG model context to associate with the client model.
Returns
meshx_err_t Returns an error code indicating the result of the operation.
  • MESHX_OK on success
  • Appropriate error code otherwise

Definition at line 157 of file meshx_light_ctl_client.c.

158{
159 if (!p_model || !p_sig_model)
160 {
161 return MESHX_INVALID_ARG;
162 }
163
165 if (!*p_model)
166 {
167 return MESHX_NO_MEM;
168 }
169
171 p_sig_model,
172 &((*p_model)->meshx_pub),
173 &((*p_model)->meshx_gen));
174}
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.
#define MESHX_CALOC
Definition meshx_err.h:28
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
@ MESHX_NO_MEM
Definition meshx_err.h:44
meshx_model_interface_t meshx_light_ctl_client_model_t
Structure representing the Light CTL (Color Temperature Lightness) client model in MeshX.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_light_ctl_client_delete()

meshx_err_t meshx_light_ctl_client_delete ( meshx_light_ctl_client_model_t ** p_model)

Delete the Light client model instance.

This function deletes an instance of the Light client model, freeing associated resources and setting the model pointer to NULL.

Parameters
[in,out]p_modelDouble pointer to the Light client model instance to be deleted.
Returns
  • MESHX_SUCCESS: Successfully deleted the model.
  • MESHX_INVALID_ARG: Invalid argument provided.

Definition at line 188 of file meshx_light_ctl_client.c.

189{
190 if (p_model == NULL || *p_model == NULL)
191 {
192 return MESHX_INVALID_ARG;
193 }
194
196 &((*p_model)->meshx_pub),
197 &((*p_model)->meshx_gen)
198 );
199
200 MESHX_FREE(*p_model);
201 *p_model = NULL;
202
203 return MESHX_SUCCESS;
204}
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_SUCCESS
Definition meshx_err.h:40
#define MESHX_FREE
Definition meshx_err.h:32
Here is the call graph for this function:

◆ meshx_light_ctl_client_init()

meshx_err_t meshx_light_ctl_client_init ( )

Initialize the Light CTL Client model.

This function initializes the Light CTL Client model, setting up necessary resources and configurations.

Returns
  • MESHX_SUCCESS: Success
  • MESHX_NO_MEM: Out of memory
  • MESHX_FAIL: Other failures

This function initializes the Light CTL Client model by registering the Light Client callback with the BLE Mesh stack.

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

Definition at line 117 of file meshx_light_ctl_client.c.

118{
120
122 return MESHX_SUCCESS;
123
125
127 if (err)
128 {
129 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Failed to initialize meshx client");
130 }
131
135 );
136 if (err)
137 {
138 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Failed to register Light CTL Client callback: %d", err);
139 }
140
141 return err;
142}
#define MESHX_MODEL_ID_LIGHT_CTL_CLI
control_task_msg_handle_t meshx_gen_light_client_cb_t
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:39
static meshx_err_t meshx_handle_gen_light_msg(dev_struct_t *pdev, control_task_msg_evt_t model_id, meshx_gen_light_cli_cb_param_t *param)
Handle the Generic Light Client messages.
meshx_err_t meshx_gen_light_client_from_ble_reg_cb(uint16_t model_id, meshx_gen_light_client_cb_t cb)
Registers a callback function for getting Generic Light Client messages from BLE.
meshx_err_t meshx_gen_light_cli_init(void)
Initialize the meshxuction generic client.
#define LIGHT_CTL_CLIENT_INIT_MAGIC
static uint16_t light_ctl_client_init_flag
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:73
@ MODULE_ID_MODEL_CLIENT
Definition module_id.h:31
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_light_ctl_client_send_msg()

meshx_err_t meshx_light_ctl_client_send_msg ( meshx_gen_ctl_send_params_t * params)

Sends a Light CTL (Color Temperature Lightness) message from the Light CTL Client model.

This function constructs and sends a Light CTL message to a specified destination address using the provided network and application indices. The message contains the desired lightness, temperature, and a transaction identifier (TID).

Parameters
[in]paramsPointer to a structure containing the message parameters.
Returns
meshx_err_t Returns the result of the message send operation.

Definition at line 217 of file meshx_light_ctl_client.c.

218{
220 if (!params || !params->model || !params->model->meshx_sig)
221 {
222 return MESHX_INVALID_ARG; // Invalid model pointer
223 }
225 .state = &set,
226 .addr = params->addr,
227 .opcode = params->opcode,
228 .app_idx = params->app_idx,
229 .net_idx = params->net_idx,
230 .model = params->model->meshx_sig,
231 };
232
234 {
236 }
237 else if (params->opcode == MESHX_MODEL_OP_LIGHT_CTL_SET ||
239 {
240 set.ctl_set.op_en = false;
241 set.ctl_set.tid = params->tid;
242 set.ctl_set.ctl_delta_uv = params->delta_uv;
243 set.ctl_set.ctl_lightness = params->lightness;
244 set.ctl_set.ctl_temperature = params->temperature;
245 }
246 else{
247 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Invalid opcode for Light CTL Client: %04x", params->opcode);
248 return MESHX_INVALID_ARG;
249 }
250 return meshx_gen_light_send_msg(&send_params);
251}
#define MESHX_MODEL_OP_LIGHT_CTL_SET
#define MESHX_MODEL_OP_LIGHT_CTL_SET_UNACK
#define MESHX_MODEL_OP_LIGHT_CTL_GET
#define MESHX_DO_NOTHING
Definition meshx_err.h:17
meshx_err_t meshx_gen_light_send_msg(const meshx_gen_light_client_send_params_t *params)
Send a message using the generic client model.
struct meshx_gen_light_client_send_params meshx_gen_light_client_send_params_t
Generic Light Client Model send parameters. This structure is used to pass parameters to the Generic ...
meshx_light_ctl_client_model_t * model
Lighting Client Model set message union.
Here is the call graph for this function:

◆ meshx_light_ctl_state_change_handle()

meshx_err_t meshx_light_ctl_state_change_handle ( const meshx_ctl_cli_el_msg_t * param,
meshx_ctl_el_state_t * p_ctl_prev_state,
const meshx_ctl_el_state_t * p_ctl_next_state )

Handles state changes for the Light CTL client element.

This function processes state change events for the Light CTL client element.

Parameters
[in]paramPointer to the message structure containing the state change parameters.
[in,out]p_ctl_prev_statePointer to the previous state structure.
[in,out]p_ctl_next_statePointer to the next state structure (currently unused).
Returns
meshx_err_t Returns an error code indicating the result of the handler execution.

Definition at line 357 of file meshx_light_ctl_client.c.

362{
363 if (!p_ctl_prev_state || !param || !p_ctl_next_state)
364 return MESHX_INVALID_ARG;
365
366 /* Kept for future use */
367 MESHX_UNUSED(p_ctl_next_state);
368 bool state_change = false;
369 if(param->err_code == MESHX_SUCCESS)
370 {
372 {
373 if (p_ctl_prev_state->lightness != param->ctl_state.lightness
374 || p_ctl_prev_state->temperature != param->ctl_state.temperature
375 )
376 {
377 p_ctl_prev_state->lightness = param->ctl_state.lightness;
378 p_ctl_prev_state->temperature = param->ctl_state.temperature;
379 state_change = true;
380 }
381 }
383 {
384 if(p_ctl_prev_state->delta_uv != param->ctl_state.delta_uv
385 || p_ctl_prev_state->temperature != param->ctl_state.temperature)
386 {
387 p_ctl_prev_state->delta_uv = param->ctl_state.delta_uv;
388 p_ctl_prev_state->temperature = param->ctl_state.temperature;
389 state_change = true;
390 }
391 }
393 {
394 if (p_ctl_prev_state->temp_range_max != param->ctl_state.temp_range_max
395 || p_ctl_prev_state->temp_range_min != param->ctl_state.temp_range_min)
396 {
397 p_ctl_prev_state->temp_range_max = param->ctl_state.temp_range_max;
398 p_ctl_prev_state->temp_range_min = param->ctl_state.temp_range_min;
399 state_change = true;
400 }
401 }
403 {
405 }
406 else
407 {
408 /* Return as No CTL related OPCode were received */
410 }
411 }
412 else
413 {
414 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "CWWW Client Element Message: Error (%d)", param->err_code);
415 /* Retry sending the failed packet done by MeshX Light CTL Layer. Do not notify App */
417 }
418 return state_change ? MESHX_SUCCESS : MESHX_INVALID_STATE;
419}
#define MESHX_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS
#define MESHX_MODEL_OP_LIGHT_CTL_STATUS
#define MESHX_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS
#define MESHX_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS
#define MESHX_UNUSED(x)
Definition meshx_err.h:15
@ MESHX_INVALID_STATE
Definition meshx_err.h:45
meshx_ctl_el_state_t ctl_state

◆ meshx_light_ctl_temp_range_client_send_msg()

meshx_err_t meshx_light_ctl_temp_range_client_send_msg ( meshx_gen_ctl_send_params_t * params)

Sends a Light CTL Temperature Range message from the client model.

This function constructs and sends a Light CTL Temperature Range message to a specified address using the provided network and application indices. It allows the client to set or get the temperature range of a lighting element in a mesh network.

Parameters
[in]paramsPointer to a structure containing the message parameters.
Returns
meshx_err_t Result of the message send operation.

Definition at line 312 of file meshx_light_ctl_client.c.

313{
315 if (!params || !params->model || !params->model->meshx_sig)
316 {
317 return MESHX_INVALID_ARG; // Invalid model pointer
318 }
320 .state = &set,
321 .addr = params->addr,
322 .opcode = params->opcode,
323 .app_idx = params->app_idx,
324 .net_idx = params->net_idx,
325 .model = params->model->meshx_sig,
326 };
327
329 {
331 }
334 {
337 }
338 else{
339 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Invalid opcode for Light CTL Client: %04x", params->opcode);
340 return MESHX_INVALID_ARG;
341 }
342
343 return meshx_gen_light_send_msg(&send_params);
344}
#define MESHX_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET_UNACK
#define MESHX_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_GET
#define MESHX_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET
meshx_light_ctl_temperature_range_set_t ctl_temperature_range_set
Here is the call graph for this function:

◆ meshx_light_ctl_temperature_client_send_msg()

meshx_err_t meshx_light_ctl_temperature_client_send_msg ( meshx_gen_ctl_send_params_t * params)

Sends a Light CTL Temperature message from the client model.

This function constructs and sends a Light CTL Temperature message to a specified address using the provided network and application indices. It allows the client to control the color temperature and delta UV of a lighting element in a mesh network.

Parameters
[in]paramsPointer to a structure containing the message parameters.
Returns
meshx_err_t Result of the message send operation.

Definition at line 264 of file meshx_light_ctl_client.c.

265{
267 if (!params || !params->model || !params->model->meshx_sig)
268 {
269 return MESHX_INVALID_ARG; // Invalid model pointer
270 }
272 .state = &set,
273 .addr = params->addr,
274 .opcode = params->opcode,
275 .app_idx = params->app_idx,
276 .net_idx = params->net_idx,
277 .model = params->model->meshx_sig,
278 };
279
281 {
283 }
286 {
287 set.ctl_temperature_set.op_en = false;
288 set.ctl_temperature_set.tid = params->tid;
291
292 }
293 else{
294 MESHX_LOGE(MODULE_ID_MODEL_CLIENT, "Invalid opcode for Light CTL Client: %04x", params->opcode);
295 return MESHX_INVALID_ARG;
296 }
297
298 return meshx_gen_light_send_msg(&send_params);
299}
#define MESHX_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET
#define MESHX_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET_UNACK
#define MESHX_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET
meshx_light_ctl_temperature_set_t ctl_temperature_set
Here is the call graph for this function: