MeshX 0.4
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
meshXGenericLocationServerModel Class Reference

A template class for creating Generic Location Server models. More...

#include <meshx_model_location.hpp>

Inheritance diagram for meshXGenericLocationServerModel:
meshXServerModel< meshXBaseGenericServerModel, meshx_gen_location_send_params_t > meshXModel< meshXBaseGenericServerModel, meshx_gen_location_send_params_t > meshXModelIF

Public Member Functions

meshx_err_t model_send (meshx_gen_location_send_params_t *params) override
 Send a packet to the MeshX stack based on the given parameters.
meshx_err_t model_from_ble_cb (dev_struct_t *, control_task_msg_evt_t, meshx_ptr_t) override
 Callback function for handling BLE mesh events for Generic Location Server Model.
meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override
 Prepare message for element notification.
meshx_err_t element_state_change_handle (void) override
 Handle state change request from element.
 meshXGenericLocationServerModel (meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
 Constructor for Generic Location Server Model.
 ~meshXGenericLocationServerModel ()=default
Public Member Functions inherited from meshXServerModel< meshXBaseGenericServerModel, meshx_gen_location_send_params_t >
 meshXServerModel (MESHX_MODEL *p_plat_model, uint32_t model_id, meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
 Construct a new Server Model.
Public Member Functions inherited from meshXModel< meshXBaseGenericServerModel, meshx_gen_location_send_params_t >
void set_plat_model (MESHX_MODEL *p_model) override
 Set the platform-specific model instance.
meshx_err_t model_handle_from_ble_cb (dev_struct_t *p_dev, evt_model_id_t evt_model_id, meshx_ptr_t params)
 Handle upstream BLE Mesh events.
void on_baked (void) override
 Called when the model's parent element is baked.
virtual ~meshXModel ()
 Destructor for meshXModel.
meshx_err_t send_to_parent_element (meshx_ptr_t msg_ptr, size_t msg_size)
 Send message to parent element.
uint16_t get_model_func_id (void) const
 Get the model function identifier.
void set_model_func_id (uint16_t func_id)
 Set the model function identifier.
uint16_t get_model_id (void) const override
 Get the model identifier.
bool is_initialized (void) const override
 Check if the model is successfully initialized.
void set_model_id (uint16_t id)
 Set the model identifier.
meshx_err_t get_init_status (void) const
 Get the model initialization status.
meshXBaseGenericServerModelget_base_model (void) const
 Get the base model instance.
 meshXModel (MESHX_MODEL *p_plat_model, uint32_t model_id, meshXElementIF *parent_element=nullptr, uint16_t model_func_id=0)
 Constructs a new meshXModel instance.
Public Member Functions inherited from meshXModelIF
 meshXModelIF ()
 meshXModelIF (MESHX_MODEL *p_plat_model)
virtual ~meshXModelIF ()=default
MESHX_MODEL * get_plat_model (void) const
 Get the platform-specific model instance.
meshx_ptr_t get_pub_struct (void) const
 Get the publication structures.
meshx_ptr_t get_gen_struct (void) const
 Get the generic structures.
void set_pub_struct (meshx_ptr_t pub)
 Set the publication structures.
void set_gen_struct (meshx_ptr_t gen)
 Set the generic structures.
void set_parent_element (meshXElementIF *parent)
 Set the parent element for this model.
meshXElementIFget_parent_element (void) const
 Get the parent element of this model.
void set_parent_element_state (meshx_ptr_t state)
 Set the parent element state pointer.
meshx_ptr_t get_parent_element_state (void) const
 Get the parent element state pointer.

Private Member Functions

meshx_err_t plat_model_create (MESHX_MODEL *p_plat_model_ptr=nullptr) override
 Creates and initializes a server model instance for Generic Location Server.
meshx_err_t plat_model_delete (void) override
 Deletes the Generic Location Server model and its associated resources.

Private Attributes

meshx_gen_location_model_state_t model_state
meshx_location_srv_el_msg_t element_msg
bool element_msg_prepared = false

Additional Inherited Members

Protected Member Functions inherited from meshXServerModel< meshXBaseGenericServerModel, meshx_gen_location_send_params_t >
void update_element_state_change_header (meshx_err_t element_state_change, meshx_ptr_t msg_ptr) override
 Update element_state_change field in server message header.

Detailed Description

A template class for creating Generic Location Server models.

This class is derived from meshXServerModel and provides a convenient interface for creating Generic Location Server models. It handles the Generic Location state change notifications from the MeshX stack and publishes the state change event to the element layer.

Constructor & Destructor Documentation

◆ meshXGenericLocationServerModel()

meshXGenericLocationServerModel::meshXGenericLocationServerModel ( meshXElementIF * parent_element = nullptr,
meshx_ptr_t parent_element_state = nullptr,
uint16_t model_func_id = 0 )

Constructor for Generic Location Server Model.

Parameters
[in]parent_elementPointer to the parent element (meshXElementIF)
[in]parent_element_statePointer to the parent element's state structure.
[in]model_func_idFunctional ID for the model instance.
423{}
meshXElementIF * parent_element
Definition meshx_model_class.hpp:42
meshXServerModel(MESHX_MODEL *p_plat_model, uint32_t model_id, meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
Definition meshx_model_class.cpp:200
#define MESHX_MODEL_ID_GEN_LOCATION_SRV
Definition meshx_ble_mesh_cmn_def.h:84

◆ ~meshXGenericLocationServerModel()

meshXGenericLocationServerModel::~meshXGenericLocationServerModel ( )
default

Member Function Documentation

◆ element_state_change_handle()

meshx_err_t meshXGenericLocationServerModel::element_state_change_handle ( void )
overridevirtual

Handle state change request from element.

This function is called by the parent element when a state change request is received. It validates the request and returns a result to the element. Note: The actual state is maintained in the element layer, not the model layer.

Returns
  • MESHX_SUCCESS: State change handled successfully
  • MESHX_INVALID_ARG: Invalid parameter
  • MESHX_INVALID_STATE: No state change detected

Implements meshXModelIF.

384{
385 auto *el_state =
387
388 if (!el_state) {
389 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Invalid parameter in element_state_change_handle");
390 return MESHX_INVALID_ARG;
391 }
392
393 if(memcmp(&model_state, el_state, sizeof(meshx_gen_location_model_state_t)) != 0)
394 {
396 "Location state change request: global_lat=%d global_lon=%d local_lat=%d local_lon=%d",
397 el_state->global_latitude, el_state->global_longitude, el_state->local_latitude, el_state->local_longitude);
398 // Update the model state
399 *el_state = model_state;
400 }
401 else
402 {
403 return MESHX_INVALID_STATE;
404 }
405 return MESHX_SUCCESS;
406}
meshx_gen_location_model_state_t model_state
Definition meshx_model_location.hpp:143
meshx_ptr_t get_parent_element_state(void) const
Get the parent element state pointer.
Definition meshx_model_class.hpp:154
@ MESHX_INVALID_ARG
Definition meshx_err.h:46
@ MESHX_INVALID_STATE
Definition meshx_err.h:49
#define MESHX_LOGI(module_id, format,...)
Definition meshx_log.h:126
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:114
**This function is called by the parent element when a state change request *is received It validates the request and returns a result to the element not the model layer **return * MESHX_SUCCESS
Definition meshx_model_level.cpp:385
struct meshx_gen_location_model_state meshx_gen_location_model_state_t
Definition meshx_model_location.hpp:50
@ MODULE_ID_MODEL_SERVER
Definition module_id.h:34

◆ model_from_ble_cb()

meshx_err_t meshXGenericLocationServerModel::model_from_ble_cb ( dev_struct_t * p_dev,
control_task_msg_evt_t model_id,
meshx_ptr_t params )
overridevirtual

Callback function for handling BLE mesh events for Generic Location Server Model.

Parameters
[in]p_devPointer to the device structure
[in]model_idModel ID associated with the event
[in]paramsPointer to the event parameters
Returns
MESHX_SUCCESS if successful, error code otherwise

Implements meshXModel< meshXBaseGenericServerModel, meshx_gen_location_send_params_t >.

305{
306 if(!params || !p_dev)
307 {
308 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Invalid parameters");
309 return MESHX_INVALID_ARG;
310 }
312 {
313 /* Callback triggered not for this model */
314 return MESHX_SUCCESS;
315 }
316
317 auto *param = static_cast<meshx_gen_srv_cb_param_t *>(params);
318
319 // Store the message in member variable for later use by prepare_element_msg
320 element_msg = {
321 .header = {
322 .model = param->model,
323 .element_state_change = MESHX_SUCCESS,
324 },
325 .state = {
326 .global_latitude = param->state_change.loc_global_set.latitude,
327 .global_longitude = param->state_change.loc_global_set.longitude,
328 .global_altitude = param->state_change.loc_global_set.altitude,
329 .local_north = param->state_change.loc_local_set.north,
330 .local_east = param->state_change.loc_local_set.east,
331 .local_altitude = param->state_change.loc_local_set.altitude,
332 .floor_number = param->state_change.loc_local_set.floor_number,
333 .uncertainty = param->state_change.loc_local_set.uncertainty
334 }
335 };
336
338 return MESHX_SUCCESS;
339}
bool element_msg_prepared
Definition meshx_model_location.hpp:149
meshx_location_srv_el_msg_t element_msg
Definition meshx_model_location.hpp:146
struct meshx_gen_srv_cb_param meshx_gen_srv_cb_param_t

◆ model_send()

meshx_err_t meshXGenericLocationServerModel::model_send ( meshx_gen_location_send_params_t * params)
overridevirtual

Send a packet to the MeshX stack based on the given parameters.

This function takes a pointer to a meshx_gen_location_send_params_t structure as input and sends the corresponding packet to the MeshX stack for processing.

Parameters
[in]paramsPointer to the meshx_gen_location_send_params_t structure containing the parameters
Returns
MESHX_SUCCESS on success, or an error code on failure

Implements meshXModel< meshXBaseGenericServerModel, meshx_gen_location_send_params_t >.

267{
268if (!params|| !params->model || !params->ctx)
269 {
270 return MESHX_INVALID_ARG;
271 }
272 // For server, we need to determine which status to send based on context
273 // For simplicity, we'll send global location status
275 meshx_gen_srv_state_change_t state_change = {
276 .loc_global_set = {
277 .latitude = params->global_latitude,
278 .longitude = params->global_longitude,
279 .altitude = params->global_altitude
280 }
281 };
282 meshx_gen_server_send_params_t send_params = {
283 .p_model = params->model,
284 .p_ctx = params->ctx,
285 .state_change = state_change,
286 .data_len = sizeof(meshx_state_change_gen_loc_global_set_t)
287 };
288 return this->get_base_model()->plat_send_msg(&send_params);
289}
meshx_err_t plat_send_msg(meshx_gen_server_send_params_t *params) override
Sends a status message for the Generic Server model.
Definition meshx_base_model_generic.cpp:401
meshXBaseGenericServerModel * get_base_model(void) const
Definition meshx_model_class.hpp:315
struct meshx_gen_server_send_params { meshx_model_t *p_model; meshx_ctx_t *p_ctx; meshx_gen_srv_state_change_t state_change; size_t data_len; } meshx_gen_server_send_params_t
Definition meshx_base_model_generic.hpp:135
#define MESHX_MODEL_OP_GEN_LOC_GLOBAL_STATUS
Definition meshx_ble_mesh_cmn_def.h:294
uint32_t opcode
Definition meshx_ble_mesh_cmn.h:49
meshx_model_t * model
Definition meshx_model_location.hpp:57
meshx_ctx_t * ctx
Definition meshx_model_location.hpp:58

◆ plat_model_create()

meshx_err_t meshXGenericLocationServerModel::plat_model_create ( MESHX_MODEL * p_plat_model_ptr = nullptr)
overrideprivatevirtual

Creates and initializes a server model instance for Generic Location Server.

This function handles the platform-specific model creation process for Generic Location Server models. It initializes server-specific features and cannot be overridden by derived classes.

Returns
meshx_err_t Returns an error code indicating the result of the operation.
  • MESHX_SUCCESS on successful model creation and initialization
  • MESHX_ERR_NO_MEM if memory allocation fails
  • Other error codes for platform-specific failures
Note
This is a final function and cannot be overridden by derived classes.

Implements meshXModelIF.

441{
442 if (p_plat_model_ptr) {
443 this->set_plat_model(p_plat_model_ptr);
444 }
445 meshx_ptr_t p_pub = this->get_pub_struct();
446 meshx_ptr_t p_gen = this->get_gen_struct();
448
449 err = meshx_plat_location_gen_srv_create(this->get_plat_model(), &p_pub, &p_gen);
450 if(err)
451 {
452 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Failed to create Generic Location Server Model");
453 }
454 else
455 {
456 this->set_pub_struct(p_pub);
457 this->set_gen_struct(p_gen);
458 }
459 return err;
460}
meshx_ptr_t get_pub_struct(void) const
Get the publication structures.
Definition meshx_model_class.hpp:113
MESHX_MODEL * get_plat_model(void) const
Get the platform-specific model instance.
Definition meshx_model_class.hpp:107
void set_gen_struct(meshx_ptr_t gen)
Set the generic structures.
Definition meshx_model_class.hpp:131
meshx_ptr_t get_gen_struct(void) const
Get the generic structures.
Definition meshx_model_class.hpp:119
void set_pub_struct(meshx_ptr_t pub)
Set the publication structures.
Definition meshx_model_class.hpp:125
void set_plat_model(MESHX_MODEL *p_model) override
Definition meshx_model_class.cpp:92
void * meshx_ptr_t
Definition meshx_ble_mesh_cmn_def.h:636
meshx_err_t meshx_plat_location_gen_srv_create(void *p_model, void **p_pub, void **p_location_srv)
Creates a Generic Location Server model and its publication context.
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43

◆ plat_model_delete()

meshx_err_t meshXGenericLocationServerModel::plat_model_delete ( void )
overrideprivatevirtual

Deletes the Generic Location Server model and its associated resources.

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

Returns
  • MESHX_SUCCESS: Model and publication deleted successfully.
  • MESHX_FAIL: Failed to delete the model or publication.

Implements meshXModelIF.

476{
477 meshx_ptr_t p_pub = this->get_pub_struct();
478 meshx_ptr_t p_gen = this->get_gen_struct();
479
480 meshx_err_t err = meshx_plat_gen_srv_delete(&p_pub, &p_gen);
481 if (err)
482 {
483 MESHX_LOGE(MODULE_ID_MODEL_SERVER, "Failed to delete Generic Location Server Model");
484 }
485 else
486 {
487 this->set_pub_struct(nullptr);
488 this->set_gen_struct(nullptr);
489 }
490 return err;
491}
meshx_err_t meshx_plat_gen_srv_delete(void **p_pub, void **p_srv)
Deletes the Generic OnOff Server model and its associated resources.

◆ prepare_element_msg()

meshx_err_t meshXGenericLocationServerModel::prepare_element_msg ( meshx_ptr_t * msg_ptr,
size_t * msg_size )
overridevirtual

Prepare message for element notification.

Returns pointer to the stored element message if it has been prepared

Parameters
[out]msg_ptrPointer to message structure (output parameter)
[out]msg_sizeSize of the message structure (output parameter)
Returns
MESHX_SUCCESS if message prepared successfully, error code otherwise

Implements meshXModelIF.

352{
353 if (!msg_ptr || !msg_size)
354 {
355 return MESHX_INVALID_ARG;
356 }
357
359 {
360 return MESHX_NOT_SUPPORTED;
361 }
362
363 *msg_ptr = &element_msg;
364 *msg_size = sizeof(element_msg);
365
366 return MESHX_SUCCESS;
367}
@ MESHX_NOT_SUPPORTED
Definition meshx_err.h:51

Field Documentation

◆ element_msg

meshx_location_srv_el_msg_t meshXGenericLocationServerModel::element_msg
private

◆ element_msg_prepared

bool meshXGenericLocationServerModel::element_msg_prepared = false
private

◆ model_state

meshx_gen_location_model_state_t meshXGenericLocationServerModel::model_state
private

The documentation for this class was generated from the following files: