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

Header file for the Light CTL Server module. More...

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

Go to the source code of this file.

Typedefs

typedef meshx_model_interface_t meshx_ctl_setup_server_model_t
 Structure representing the MeshX CTL (Color Temperature Lightness) Setup Server Model.
 
typedef meshx_model_interface_t meshx_ctl_server_model_t
 Structure representing the MeshX CTL (Color Temperature Lightness) server model.
 

Functions

meshx_err_t meshx_light_ctl_server_create (meshx_ctl_server_model_t **p_model, meshx_ptr_t p_sig_model)
 Create and initialize a new CTL server model instance.
 
meshx_err_t meshx_light_ctl_server_delete (meshx_ctl_server_model_t **p_model)
 Delete the CTL server model instance.
 
meshx_err_t meshx_light_ctl_srv_state_restore (meshx_ctl_server_model_t *p_model, meshx_light_ctl_srv_state_t ctl_state)
 Restore the CTL state for the generic server model.
 
meshx_err_t meshx_light_ctl_server_init (void)
 Initialize the CTL server model.
 
meshx_err_t meshx_get_ctl_setup_srv_model (meshx_ptr_t p_model)
 Retrieves the CTL (Color Temperature Lightness) Setup Server model instance.
 
meshx_err_t meshx_light_ctl_srv_status_send (meshx_model_t *p_model, meshx_ctx_t *ctx, int16_t delta_uv, uint16_t lightness, uint16_t temperature)
 Send the Light CTL status message.
 
meshx_err_t meshx_light_ctl_srv_send_pack_create (meshx_ptr_t p_model, uint16_t element_id, uint16_t net_idx, uint16_t app_idx, uint16_t pub_addr, meshx_light_ctl_srv_state_t ctl_state, meshx_lighting_server_cb_param_t *light_srv_send)
 Create a Light CTL Server send message packet.
 

Detailed Description

Header file for the Light CTL Server module.

Copyright © 2024 - 2025 MeshX

This file contains the function declarations and necessary includes for initializing and managing the Light CTL Server in the BLE mesh network.

Author
Pranjal Chanda

Definition in file meshx_light_ctl_srv.h.

Typedef Documentation

◆ meshx_ctl_server_model_t

Structure representing the MeshX CTL (Color Temperature Lightness) server model.

This structure encapsulates pointers to the CTL server SIG model, publication structures, and generic server structures used in the MeshX lighting control server implementation.

Definition at line 37 of file meshx_light_ctl_srv.h.

◆ meshx_ctl_setup_server_model_t

Structure representing the MeshX CTL (Color Temperature Lightness) Setup Server Model.

This structure encapsulates pointers to the SIG model, publication structures, and generic server structures required for the CTL setup server functionality.

Definition at line 29 of file meshx_light_ctl_srv.h.

Function Documentation

◆ meshx_get_ctl_setup_srv_model()

meshx_err_t meshx_get_ctl_setup_srv_model ( meshx_ptr_t p_model)

Retrieves the CTL (Color Temperature Lightness) Setup Server model instance.

This function is used to obtain a reference or handle to the CTL Setup Server model, which is responsible for managing color temperature and lightness control in a mesh network.

Parameters
[in]p_modelPointer to the model structure or context.
Returns
meshx_err_t Returns an error code indicating the result of the operation. Typically, MESHX_OK on success or an appropriate error code on failure.

Definition at line 289 of file meshx_light_ctl_srv.c.

290{
291 if (!p_model)
292 return MESHX_INVALID_ARG;
293
294 if (g_meshx_light_ctl_srv.ctl_setup_server.meshx_srv_model == NULL)
295 return MESHX_FAIL;
296
297 memcpy(p_model, &g_meshx_light_ctl_srv.ctl_setup_server.ctl_setup_srv_model, sizeof(MESHX_MODEL));
298 return MESHX_SUCCESS;
299}
@ MESHX_SUCCESS
Definition meshx_err.h:40
@ MESHX_INVALID_ARG
Definition meshx_err.h:42
@ MESHX_FAIL
Definition meshx_err.h:41
static struct @162134341120176320346270047367114065256252040066 g_meshx_light_ctl_srv
Structure to maintain the initialization and creation state of the MeshX Light CTL Server.
#define MESHX_MODEL

◆ meshx_light_ctl_server_create()

meshx_err_t meshx_light_ctl_server_create ( meshx_ctl_server_model_t ** p_model,
meshx_ptr_t p_sig_model )

Create and initialize a new CTL server model instance.

This function allocates memory for a new CTL server model and initializes it using the platform-specific creation function. It ensures that the model is properly set up for handling Generic OnOff messages in a BLE Mesh network.

Parameters
[in,out]p_modelPointer to a pointer where the newly created CTL server model instance will be stored.
[in,out]p_sig_modelPointer to a pointer where the offset of the model will be stored.
Returns
  • MESHX_SUCCESS: Successfully created and initialized the model.
  • MESHX_INVALID_ARG: The provided pointer is NULL.
  • MESHX_NO_MEM: Memory allocation failed.

Definition at line 357 of file meshx_light_ctl_srv.c.

358{
360 if (!p_model || !p_sig_model)
361 {
362 return MESHX_INVALID_ARG;
363 }
364
366 if (!*p_model)
367 {
368 return MESHX_NO_MEM;
369 }
370
372 p_sig_model,
373 &((*p_model)->meshx_pub),
374 &((*p_model)->meshx_gen));
375 if(err != MESHX_SUCCESS)
376 {
377 /* Tops down deinit for CTL server model */
379 return err;
380 }
381
382 if( g_meshx_light_ctl_srv.ctl_lighting_server_created == 0
383 && g_meshx_light_ctl_srv.ctl_setup_server.ctl_setup_server_init == 0)
384 {
385 MESHX_LOGI(MODULE_ID_MODEL_SERVER, "Creating CTL setup server model");
386 /* Create CTL setup server */
388 if(err != MESHX_SUCCESS)
389 {
390 /* Tops down deinit for CTL server model */
392 /* The code execution below is only possible if this is the very first model being created */
394 return err;
395 }
396 g_meshx_light_ctl_srv.ctl_setup_server.ctl_setup_server_init = MESHX_SERVER_INIT_MAGIC_NO;
397 }
398 else
399 {
400 g_meshx_light_ctl_srv.ctl_lighting_server_created++;
401 }
402
403 (*p_model)->meshx_sig = p_sig_model;
404
405 return err;
406}
meshx_err_t meshx_plat_light_ctl_srv_create(meshx_ptr_t p_model, meshx_ptr_t *p_pub, meshx_ptr_t *p_ctl_srv)
Create a Light CTL Server instance.
#define MESHX_CALOC
Definition meshx_err.h:28
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:39
@ MESHX_NO_MEM
Definition meshx_err.h:44
#define MESHX_SERVER_INIT_MAGIC_NO
static meshx_err_t meshx_light_ctl_setup_server_delete(void)
Deletes or deinitializes the Light CTL (Color Temperature Lightness) Setup Server instance.
static meshx_err_t meshx_light_ctl_setup_server_create(void)
Creates and initializes the Light CTL (Color Temperature Lightness) Setup Server.
meshx_err_t meshx_light_ctl_server_delete(meshx_ctl_server_model_t **p_model)
Delete the CTL server model instance.
meshx_model_interface_t meshx_ctl_server_model_t
Structure representing the MeshX CTL (Color Temperature Lightness) server model.
#define MESHX_LOGI(module_id, format,...)
Definition meshx_log.h:100
@ MODULE_ID_MODEL_SERVER
Definition module_id.h:30
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_light_ctl_server_delete()

meshx_err_t meshx_light_ctl_server_delete ( meshx_ctl_server_model_t ** p_model)

Delete the CTL server model instance.

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

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

Definition at line 420 of file meshx_light_ctl_srv.c.

421{
422 if (p_model == NULL || *p_model == NULL)
423 {
424 return MESHX_INVALID_ARG;
425 }
426
428 &((*p_model)->meshx_pub),
429 &((*p_model)->meshx_gen));
430
431 MESHX_FREE(*p_model);
432 *p_model = NULL;
433 if (g_meshx_light_ctl_srv.ctl_lighting_server_created == 0)
434 {
435 MESHX_LOGW(MODULE_ID_MODEL_SERVER, "Deleting CTL setup server model");
436 /* Delete CTL setup server */
437 }
438 else
439 {
440 g_meshx_light_ctl_srv.ctl_lighting_server_created--;
441 }
442 return MESHX_SUCCESS;
443}
meshx_err_t meshx_plat_light_srv_delete(meshx_ptr_t *p_pub, meshx_ptr_t *p_ctl_srv)
Delete a Light CTL Server instance.
#define MESHX_FREE
Definition meshx_err.h:32
#define MESHX_LOGW(module_id, format,...)
Definition meshx_log.h:87
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_light_ctl_server_init()

meshx_err_t meshx_light_ctl_server_init ( void )

Initialize the CTL server model.

This function initializes the CTL server model for the BLE mesh node.

Returns
  • MESHX_SUCCESS: Success
  • MESHX_FAIL: Failure

Initialize the CTL server model.

This function initializes the Light CTL (Color Temperature Light) Server model for the BLE Mesh Node. It sets up the necessary configurations and state for the Light CTL Server to operate correctly.

Returns
  • MESHX_SUCCESS: Success
  • MESHX_FAIL: Failure

Definition at line 311 of file meshx_light_ctl_srv.c.

312{
314
315 if (g_meshx_light_ctl_srv.ctl_setup_server.ctl_setup_server_init == MESHX_SERVER_INIT_MAGIC_NO)
316 return MESHX_SUCCESS;
317
318 g_meshx_light_ctl_srv.ctl_setup_server.ctl_setup_server_init = MESHX_SERVER_INIT_MAGIC_NO;
319
321 if (err)
322 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Failed to initialize prod server");
323
327 );
328 if (err)
329 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Failed to initialize meshx_gen_srv_reg_cb (Err: %d)", err);
330
334 );
335 if (err)
336 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Failed to initialize meshx_gen_srv_reg_cb (Err: %d)", err);
337
338 return err;
339}
#define MESHX_MODEL_ID_LIGHT_CTL_SETUP_SRV
#define MESHX_MODEL_ID_LIGHT_CTL_SRV
static meshx_err_t meshx_handle_light_ctl_msg(const dev_struct_t *pdev, const control_task_msg_evt_t evt, meshx_lighting_server_cb_param_t *param)
Handle Light CTL messages for the lighting server model.
meshx_err_t meshx_lighting_srv_init(void)
Initialize the production lighting server.
control_task_msg_handle_t meshx_lighting_server_cb
meshx_err_t meshx_lighting_reg_cb(uint32_t model_id, meshx_lighting_server_cb cb)
Register a callback function for the lighting server model.
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:73
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_light_ctl_srv_send_pack_create()

meshx_err_t meshx_light_ctl_srv_send_pack_create ( meshx_ptr_t p_model,
uint16_t element_id,
uint16_t net_idx,
uint16_t app_idx,
uint16_t pub_addr,
meshx_light_ctl_srv_state_t ctl_state,
meshx_lighting_server_cb_param_t * light_srv_send )

Create a Light CTL Server send message packet.

This function creates a Light CTL Server send message packet with the provided parameters.

Parameters
[in]p_modelPointer to the MeshX model structure.
[in]element_idElement ID associated with the model.
[in]net_idxNetwork Index for the message.
[in]app_idxApplication Index for the message.
[in]pub_addrPublication address for the message.
[in]ctl_stateCurrent state of the Light CTL Server.
[out]light_srv_sendPointer to the structure where the created message packet will be stored.
Returns
  • MESHX_SUCCESS: Successfully created the message packet.
  • MESHX_INVALID_ARG: Invalid argument provided.

Definition at line 536 of file meshx_light_ctl_srv.c.

544{
545 if (!p_model || !light_srv_send)
546 {
547 return MESHX_INVALID_ARG;
548 }
549
550 memset(light_srv_send, 0, sizeof(meshx_lighting_server_cb_param_t));
551 light_srv_send->ctx.net_idx = net_idx;
552 light_srv_send->ctx.app_idx = app_idx;
553 light_srv_send->ctx.src_addr = element_id;
554 light_srv_send->ctx.dst_addr = pub_addr;
556 light_srv_send->ctx.p_ctx = NULL;
557
558 light_srv_send->model.el_id = element_id;
559 light_srv_send->model.p_model = p_model;
560
561 light_srv_send->state_change.ctl_set.delta_uv = ctl_state.delta_uv;
562 light_srv_send->state_change.ctl_set.lightness = ctl_state.lightness;
563 light_srv_send->state_change.ctl_set.temperature = ctl_state.temperature;
564
565 return MESHX_SUCCESS;
566}
#define MESHX_MODEL_OP_LIGHT_CTL_STATUS
struct meshx_lighting_server_cb_param meshx_lighting_server_cb_param_t
meshx_ptr_t p_ctx
uint16_t src_addr
uint16_t dst_addr
meshx_lighting_server_state_change_t state_change
meshx_ptr_t p_model
meshx_state_change_light_ctl_set_t ctl_set
Here is the caller graph for this function:

◆ meshx_light_ctl_srv_state_restore()

meshx_err_t meshx_light_ctl_srv_state_restore ( meshx_ctl_server_model_t * p_model,
meshx_light_ctl_srv_state_t ctl_state )

Restore the CTL state for the generic server model.

This function restores the CTL state of the specified server model using the provided state value. It checks for a valid model pointer before proceeding with the restoration.

Parameters
p_modelPointer to the CTL server model structure.
ctl_stateThe CTL state to be restored.
Returns
  • MESHX_INVALID_STATE: If the model pointer is NULL.
  • Result of the platform-specific restoration function.

Definition at line 459 of file meshx_light_ctl_srv.c.

460{
461 if (!p_model)
462 return MESHX_INVALID_STATE;
463
465 ctl_state.delta_uv,
466 ctl_state.lightness,
467 ctl_state.temperature,
468 ctl_state.temperature_range_max,
469 ctl_state.temperature_range_min);
470}
meshx_err_t meshx_plat_light_ctl_srv_restore(meshx_ptr_t p_model, uint16_t delta_uv, uint16_t lightness, uint16_t temperature, uint16_t temp_range_max, uint16_t temp_range_min)
Restore the state of the Light CTL Server.
@ MESHX_INVALID_STATE
Definition meshx_err.h:45
Here is the call graph for this function:
Here is the caller graph for this function:

◆ meshx_light_ctl_srv_status_send()

meshx_err_t meshx_light_ctl_srv_status_send ( meshx_model_t * p_model,
meshx_ctx_t * ctx,
int16_t delta_uv,
uint16_t lightness,
uint16_t temperature )

Send the Light CTL status message.

This function sends the Light CTL status message to the specified context.

Parameters
[in]p_modelPointer to the MeshX model structure.
[in]ctxContext structure containing the necessary parameters for sending the message.
[in]delta_uvThe Delta UV value to be included in the status message.
[in]lightnessThe Lightness value to be included in the status message.
[in]temperatureThe Temperature value to be included in the status message.
Returns
  • MESHX_SUCCESS: Successfully sent the status message.
  • Appropriate error code on failure.

Definition at line 486 of file meshx_light_ctl_srv.c.

491{
492 if (!p_model)
493 {
494 return MESHX_INVALID_ARG;
495 }
496
498 .ctl_set = {
499 .delta_uv = delta_uv,
500 .lightness = lightness,
501 .temperature = temperature
502 }
503 };
504
506 p_model,
507 ctx,
508 &state_change
509 );
510
511 if (err != MESHX_SUCCESS)
512 {
513 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Failed to send Light CTL status: %d", err);
514 }
515
516 return err;
517}
meshx_err_t meshx_gen_light_srv_status_send(meshx_model_t *p_model, meshx_ctx_t *ctx, meshx_lighting_server_state_change_t *state_change)
Sends a status message for the Lighting Server model.
Lighting Server Model state change value union.
Here is the call graph for this function:
Here is the caller graph for this function: