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
meshx_model_location.hpp
Go to the documentation of this file.
1/**
2 * @file meshx_model_location.hpp
3 * @brief Implementation of Generic Location Model for MeshX
4 *
5 * This file contains the implementation of the Generic Location model,
6 * which provides standard Location model functionality in the MeshX BLE mesh framework.
7 *
8 * Key Features:
9 * - Implements Bluetooth SIG-defined Generic Location model
10 * - Inherits from meshXClientModel, meshXServerModel templates
11 * - Provides standard Location control operations (Global/Local coordinates)
12 * - Integrates with MeshX transmission control
13 *
14 * @author Pranjal Chanda
15 * @date 2024-2025
16 * @copyright Copyright 2024 - 2025 MeshX
17 */
18
19#ifndef _MESHX_MODEL_LOCATION_HPP_
20#define _MESHX_MODEL_LOCATION_HPP_
21
22#include <meshx_model_class.hpp>
24
25#define MESHX_GEN_LOCATION_CLIENT_MODEL_TEMPLATE_PROTO
26#define MESHX_GEN_LOCATION_CLIENT_MODEL_TEMPLATE_PARAMS
27
28#define MESHX_GEN_LOCATION_SERVER_MODEL_TEMPLATE_PROTO
29#define MESHX_GEN_LOCATION_SERVER_MODEL_TEMPLATE_PARAMS
30
31#define MESHX_GEN_LOCATION_SETUP_SERVER_MODEL_TEMPLATE_PROTO
32#define MESHX_GEN_LOCATION_SETUP_SERVER_MODEL_TEMPLATE_PARAMS
33
34/**
35 * @brief Structure to hold the Location model state.
36 */
38{
39 // Global location data
40 int32_t global_latitude; /**< Global latitude (-90 to 90 degrees) */
41 int32_t global_longitude; /**< Global longitude (-180 to 180 degrees) */
42 int16_t global_altitude; /**< Global altitude (in meters) */
43 // Local location data
44 int16_t local_north; /**< Local North coordinate */
45 int16_t local_east; /**< Local East coordinate */
46 int16_t local_altitude; /**< Local altitude */
47 uint8_t floor_number; /**< Floor number */
48 uint16_t uncertainty; /**< Uncertainty of the location */
49};
51
52/**
53 * @brief Structure to hold the parameters for sending a Generic Location message.
54 */
56{
57 meshx_model_t *model; /**< Pointer to the Location client model. */
58 meshx_ctx_t *ctx; /**< The context of the message. */
59 uint8_t tid; /**< The transaction ID of the message. Only used by Client*/
60 meshx_gen_location_model_state_t state; /**< The state of the message. */
61};
62
64
65#if CONFIG_ENABLE_GEN_LOCATION_CLIENT
66/**
67 * @brief Structure to hold the Location Server to parent element message.
68 * The structure is used by the on_model_cb function to send the Location state
69 * change notification to the parent element.
70 */
72{
73 meshx_cli_model_send_param_header_t header; /**< Client model send param header */
74 meshx_gen_location_model_state_t state; /**< The state of the message. */
75};
76
78/**
79 * @class meshXGenericLocationClientModel
80 * @brief A template class for creating Generic Location Client models.
81 *
82 * This class is derived from meshXClientModel and provides a convenient interface for
83 * creating Generic Location Client models. It handles the Generic Location state change
84 * notifications from the MeshX stack and publishes the state change event to the
85 * element layer.
86 */
88class meshXGenericLocationClientModel : public meshXClientModel<meshXBaseGenericClientModel, meshx_gen_location_send_params_t>
89{
90private:
91 /* New or updated model state from BLE layer */
93
94 /* Message to be sent to parent element */
96
99
100public:
103 meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override;
104
107 meshx_ptr_t parent_element_state = nullptr,
108 uint16_t model_func_id = 0
109 );
111};
112
113#endif /* CONFIG_ENABLE_GEN_LOCATION_CLIENT */
114
115#if CONFIG_ENABLE_GEN_LOCATION_SERVER
116/**
117 * @brief Structure to hold the Location Server to parent element message.
118 * The structure is used by the on_model_cb function to send the Location state
119 * change notification to the parent element.
120 */
122{
123 meshx_srv_model_send_param_header_t header; /**< Server model send param header */
124 meshx_gen_location_model_state_t state; /**< The state of the message. */
125};
126
128
129/**
130 * @class meshXGenericLocationServerModel
131 * @brief A template class for creating Generic Location Server models.
132 *
133 * This class is derived from meshXServerModel and provides a convenient interface for
134 * creating Generic Location Server models. It handles the Generic Location state change
135 * notifications from the MeshX stack and publishes the state change event to the
136 * element layer.
137 */
139class meshXGenericLocationServerModel : public meshXServerModel<meshXBaseGenericServerModel, meshx_gen_location_send_params_t>
140{
141private:
142 /* New or updated model state from BLE layer */
144
145 /* Message to be sent to parent element */
147
148 /* Flag to indicate if element message has been prepared */
150
151 meshx_err_t plat_model_create (MESHX_MODEL* p_plat_model_ptr = nullptr) override;
152 meshx_err_t plat_model_delete (void) override;
153
154public:
157 meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override;
158
159 // Virtual method implementation from meshXModelIF
161
164 meshx_ptr_t parent_element_state = nullptr,
165 uint16_t model_func_id = 0
166 );
168};
169#endif /* CONFIG_ENABLE_GEN_LOCATION_SERVER */
170
171#if CONFIG_ENABLE_GEN_LOCATION_SETUP_SERVER
172/**
173 * @class meshXGenericLocationSetupServerModel
174 * @brief A template class for creating Generic Location Setup Server models.
175 *
176 * This class is derived from meshXServerModel and provides a convenient interface for
177 * creating Generic Location Setup Server models. It handles the Generic Location setup
178 * operations from the MeshX stack.
179 */
181class meshXGenericLocationSetupServerModel : public meshXServerModel<meshXBaseGenericServerModel, meshx_gen_location_send_params_t>
182{
183private:
184 /* Message to be sent to parent element */
186
187 /* Flag to indicate if element message has been prepared */
189
190public:
193 meshx_err_t prepare_element_msg (meshx_ptr_t *msg_ptr, size_t *msg_size) override;
194
197 meshx_ptr_t parent_element_state = nullptr,
198 uint16_t model_func_id = 0
199 );
201};
202#endif /* CONFIG_ENABLE_GEN_LOCATION_SETUP_SERVER */
203
204#endif /* CONFIG_ENABLE_GEN_LOCATION */
Interface class for MeshX elements.
Definition meshx_fwd_decl.hpp:82
meshx_err_t element_state_change_handle(void) override
Handle state change request from element.
Definition meshx_model_location.cpp:123
meshx_location_cli_el_msg_t element_msg
Definition meshx_model_location.hpp:95
meshx_err_t prepare_element_msg(meshx_ptr_t *msg_ptr, size_t *msg_size) override
Prepare message for element notification.
Definition meshx_model_location.cpp:96
meshx_err_t model_from_ble_cb(dev_struct_t *, control_task_msg_evt_t, meshx_ptr_t) override
Creates a meshXGenericLocationClientModel instance based on a BLE device.
Definition meshx_model_location.cpp:159
meshXGenericLocationClientModel(meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
A template class for creating Generic Location Client models.
Definition meshx_model_location.cpp:243
meshx_gen_location_model_state_t model_state
Definition meshx_model_location.hpp:92
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.
Definition meshx_model_location.cpp:192
meshx_err_t meshx_state_change_notify(const meshx_gen_cli_cb_param_t *param, uint8_t status)
Handle Generic Location state change notifications from the MeshX stack.
Definition meshx_model_location.cpp:38
bool element_msg_prepared
Definition meshx_model_location.hpp:149
meshx_err_t plat_model_delete(void) override
Deletes the Generic Location Server model and its associated resources.
Definition meshx_model_location.cpp:475
meshXGenericLocationServerModel(meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
Constructor for Generic Location Server Model.
Definition meshx_model_location.cpp:417
meshx_err_t element_state_change_handle(void) override
Handle state change request from element.
Definition meshx_model_location.cpp:383
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.
Definition meshx_model_location.cpp:440
meshx_gen_location_model_state_t model_state
Definition meshx_model_location.hpp:143
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.
Definition meshx_model_location.cpp:301
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.
Definition meshx_model_location.cpp:266
meshx_location_srv_el_msg_t element_msg
Definition meshx_model_location.hpp:146
meshx_err_t prepare_element_msg(meshx_ptr_t *msg_ptr, size_t *msg_size) override
Prepare message for element notification.
Definition meshx_model_location.cpp:351
bool element_msg_prepared
Definition meshx_model_location.hpp:188
meshx_location_srv_el_msg_t element_msg
Definition meshx_model_location.hpp:185
meshXGenericLocationSetupServerModel(meshXElementIF *parent_element=nullptr, meshx_ptr_t parent_element_state=nullptr, uint16_t model_func_id=0)
Constructor for Generic Location Setup Server Model.
Definition meshx_model_location.cpp:538
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 Setup Server Model.
Definition meshx_model_location.cpp:556
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.
Definition meshx_model_location.cpp:506
meshx_err_t prepare_element_msg(meshx_ptr_t *msg_ptr, size_t *msg_size) override
Prepare message for element notification.
Definition meshx_model_location.cpp:606
meshXElementIF * parent_element
Definition meshx_model_class.hpp:42
meshXClientModel(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:216
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
Header file for MeshX Generic Client and Server model declarations.
struct meshx_model meshx_model_t
struct meshx_ctx meshx_ctx_t
Structure to hold context information for BLE Mesh operations.
void * meshx_ptr_t
Definition meshx_ble_mesh_cmn_def.h:636
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...
struct dev_struct dev_struct_t
Structure representing the device composition and elements.
uint32_t control_task_msg_evt_t
Type definition for control task message event.
Definition meshx_control_task.h:81
meshx_err_t
MeshX Error Codes.
Definition meshx_err.h:43
Template declarations for MeshX model wrapper classes.
struct meshx_cli_model_send_param_header meshx_cli_model_send_param_header_t
Definition meshx_model_class.hpp:417
struct meshx_srv_model_send_param_header meshx_srv_model_send_param_header_t
Definition meshx_model_class.hpp:354
struct meshx_location_srv_el_msg meshx_location_srv_el_msg_t
Definition meshx_model_location.hpp:127
struct meshx_location_cli_el_msg meshx_location_cli_el_msg_t
Definition meshx_model_location.hpp:77
#define MESHX_GEN_LOCATION_CLIENT_MODEL_TEMPLATE_PROTO
Definition meshx_model_location.hpp:25
#define MESHX_GEN_LOCATION_SERVER_MODEL_TEMPLATE_PROTO
Definition meshx_model_location.hpp:28
struct meshx_gen_location_send_params meshx_gen_location_send_params_t
Definition meshx_model_location.hpp:63
#define MESHX_GEN_LOCATION_SETUP_SERVER_MODEL_TEMPLATE_PROTO
Definition meshx_model_location.hpp:31
struct meshx_gen_location_model_state meshx_gen_location_model_state_t
Definition meshx_model_location.hpp:50
Structure to hold the Location model state.
Definition meshx_model_location.hpp:38
int16_t global_altitude
Definition meshx_model_location.hpp:42
int32_t global_latitude
Definition meshx_model_location.hpp:40
int16_t local_north
Definition meshx_model_location.hpp:44
int32_t global_longitude
Definition meshx_model_location.hpp:41
uint8_t floor_number
Definition meshx_model_location.hpp:47
int16_t local_altitude
Definition meshx_model_location.hpp:46
uint16_t uncertainty
Definition meshx_model_location.hpp:48
int16_t local_east
Definition meshx_model_location.hpp:45
Structure to hold the parameters for sending a Generic Location message.
Definition meshx_model_location.hpp:56
uint8_t tid
Definition meshx_model_location.hpp:59
meshx_model_t * model
Definition meshx_model_location.hpp:57
meshx_ctx_t * ctx
Definition meshx_model_location.hpp:58
meshx_gen_location_model_state_t state
Definition meshx_model_location.hpp:60
Structure to hold the Location Server to parent element message. The structure is used by the on_mode...
Definition meshx_model_location.hpp:72
meshx_gen_location_model_state_t state
Definition meshx_model_location.hpp:74
meshx_cli_model_send_param_header_t header
Definition meshx_model_location.hpp:73
Structure to hold the Location Server to parent element message. The structure is used by the on_mode...
Definition meshx_model_location.hpp:122
meshx_gen_location_model_state_t state
Definition meshx_model_location.hpp:124
meshx_srv_model_send_param_header_t header
Definition meshx_model_location.hpp:123