Skip to content

Commit 7226359

Browse files
committed
Merge branch 'bugfix/params_realloc' into 'master'
esp_rmaker_params: Fixes for buffer re-allocation and esp_rmaker_param_update_and_notify() See merge request app-frameworks/esp-rainmaker!269
2 parents d16eff0 + 252b47c commit 7226359

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

components/esp_rainmaker/src/core/esp_rmaker_param.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,6 @@ static esp_err_t esp_rmaker_populate_params(char *buf, size_t *buf_len, uint8_t
134134
device_added = true;
135135
}
136136
esp_rmaker_report_value(&param->val, param->name, &jstr);
137-
if (reset_flags) {
138-
param->flags &= ~flags;
139-
}
140137
}
141138
param = param->next;
142139
}
@@ -148,6 +145,23 @@ static esp_err_t esp_rmaker_populate_params(char *buf, size_t *buf_len, uint8_t
148145
if (json_gen_end_object(&jstr) < 0) {
149146
err = ESP_ERR_NO_MEM;
150147
}
148+
/* Resetting the flags after creating the JSON in order to handle cases wherein
149+
* memory has been insufficient and this same function would have to be called
150+
* again with a larger buffer.
151+
*/
152+
if (err == ESP_OK) {
153+
device = esp_rmaker_node_get_first_device(esp_rmaker_get_node());
154+
while (device) {
155+
_esp_rmaker_param_t *param = device->params;
156+
while (param) {
157+
if (reset_flags) {
158+
param->flags &= ~flags;
159+
}
160+
param = param->next;
161+
}
162+
device = device->next;
163+
}
164+
}
151165
*buf_len = json_gen_str_end(&jstr);
152166
return err;
153167
}
@@ -216,7 +230,7 @@ static esp_err_t esp_rmaker_allocate_and_populate_params(uint8_t flags, bool res
216230

217231
static esp_err_t esp_rmaker_report_param_internal(uint8_t flags)
218232
{
219-
esp_err_t err = esp_rmaker_allocate_and_populate_params(RMAKER_PARAM_FLAG_VALUE_CHANGE, true);
233+
esp_err_t err = esp_rmaker_allocate_and_populate_params(flags, true);
220234
if (err == ESP_OK) {
221235
/* Just checking if there are indeed any params to report by comparing with a decent enough
222236
* length as even the smallest possible data, Eg. '{"d":{"p":0}}' will be > 10 bytes.

0 commit comments

Comments
 (0)