Initialize and load the MeshX configuration from the meshx_cfg partition.
If the loaded UUID is all zeros (or missing), the system should fall back to the legacy UUID generation method (e.g., based on device MAC).
90 {
95 }
96
100 }
101
105 }
106
110 }
111
112 if (header.schema_id != MESHX_SCHEMA_ID) {
114 header.schema_id, MESHX_SCHEMA_ID);
116 }
117
118
120 if (header.header_crc != expected_hdr_crc) {
123 }
124
126 uint8_t *payload = malloc(payload_len);
128
131 free(payload);
133 }
134
136 if (header.payload_crc != expected_pld_crc) {
137 MESHX_LOGE(
MODULE_ID_RO_CFG,
"Config payload CRC mismatch (calc: 0x%04X, exp: 0x%04X)", expected_pld_crc, header.payload_crc);
138 free(payload);
140 }
141
142 MeshXConfig config = MeshXConfig_init_zero;
146
147 pb_istream_t stream = pb_istream_from_buffer(payload, payload_len);
148
150
151 if (!pb_decode(&stream, MeshXConfig_fields, &config)) {
153 free(payload);
155 }
156
158
159 if (config.has_product) {
160 if (cid) *cid = config.product.cid;
161 if (pid) *pid = config.product.pid;
162 if (product_name) {
163 strncpy(product_name, config.product.name, name_max_len - 1);
164 product_name[name_max_len - 1] = '\0';
165 }
166 if (uuid && config.product.has_uuid) {
167 memcpy(uuid, config.product.uuid, 16);
169 }
171 config.product.cid, config.product.pid, config.product.name);
172 }
173
174 free(payload);
176}
void meshx_builder_commit(void)
Definition meshx_composition_builder.cpp:166
void meshx_builder_begin(void)
C-friendly builder lifecycle functions.
Definition meshx_composition_builder.cpp:161
@ MESHX_ERR_RO_CFG_VERSION
Definition meshx_err.h:58
@ MESHX_ERR_PLAT
Definition meshx_err.h:47
@ MESHX_NOT_FOUND
Definition meshx_err.h:50
@ MESHX_NO_MEM
Definition meshx_err.h:48
@ MESHX_ERR_RO_CFG_FORMAT
Definition meshx_err.h:57
@ MESHX_ERR_RO_CFG_CRC
Definition meshx_err.h:59
meshx_err_t meshx_fal_read(const meshx_fal_partition_t *part, uint32_t offset, void *buf, size_t len)
Read data from a flash partition.
meshx_err_t meshx_fal_find_partition(const char *name, meshx_fal_partition_t *part)
Find a flash partition by name.
#define MESHX_LOGI(module_id, format,...)
Definition meshx_log.h:126
#define MESHX_LOGE(module_id, format,...)
Definition meshx_log.h:114
#define MESHX_LOGD(module_id, format,...)
Definition meshx_log.h:132
**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
#define MODULE_ID_RO_CFG
Definition meshx_ro_cfg.c:18
static bool gpio_decode_cb(pb_istream_t *stream, const pb_field_iter_t *field, void **arg)
Definition meshx_ro_cfg.c:71
static uint16_t calc_crc16_ccitt(const uint8_t *data, size_t len)
Definition meshx_ro_cfg.c:45
static bool elements_decode_cb(pb_istream_t *stream, const pb_field_iter_t *field, void **arg)
Definition meshx_ro_cfg.c:61
static bool bindings_decode_cb(pb_istream_t *stream, const pb_field_iter_t *field, void **arg)
Definition meshx_ro_cfg.c:81
#define MESHX_HDR_SIZE
Definition meshx_ro_cfg.c:33
#define MESHX_CFG_MAGIC
Definition meshx_ro_cfg.c:31
#define MESHX_CFG_VERSION
Definition meshx_ro_cfg.c:32
Definition meshx_fal_interface.h:27