Skip to content

Commit

Permalink
Merge branch 'refactor/size_t_formatter' into 'master'
Browse files Browse the repository at this point in the history
refactor: better formatters for logging in core

See merge request app-frameworks/esp-rainmaker!443
  • Loading branch information
shahpiyushv committed Jun 19, 2024
2 parents 20e4bba + e05ea20 commit e1fcc7c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion components/esp_rainmaker/src/core/esp_rmaker_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ esp_err_t esp_rmaker_change_node_id(char *node_id, size_t len)
if(esp_rmaker_priv_data) {
char *new_node_id = strndup(node_id, len);
if (!new_node_id) {
ESP_LOGE(TAG, "Failed to allocate %d bytes for new node_id.", len);
ESP_LOGE(TAG, "Failed to allocate %lu bytes for new node_id.", (unsigned long) len);
return ESP_ERR_NO_MEM;
}
if (esp_rmaker_priv_data->node_id) {
Expand Down
2 changes: 1 addition & 1 deletion components/esp_rainmaker/src/core/esp_rmaker_node_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ esp_err_t esp_rmaker_report_node_config()
}
char publish_topic[MQTT_TOPIC_BUFFER_SIZE];
esp_rmaker_create_mqtt_topic(publish_topic, MQTT_TOPIC_BUFFER_SIZE, NODE_CONFIG_TOPIC_SUFFIX, NODE_CONFIG_TOPIC_RULE);
ESP_LOGD(TAG, "Reporting Node Configuration of length %d bytes.", strlen(publish_payload));
ESP_LOGD(TAG, "Reporting Node Configuration of length %lu bytes.", (unsigned long) strlen(publish_payload));
ESP_LOGD(TAG, "%s", publish_payload);
esp_err_t ret = esp_rmaker_mqtt_publish(publish_topic, publish_payload, strlen(publish_payload),
RMAKER_MQTT_QOS1, NULL);
Expand Down
14 changes: 7 additions & 7 deletions components/esp_rainmaker/src/core/esp_rmaker_param.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ char *esp_rmaker_get_node_params(void)
req_size += RMAKER_PARAMS_SIZE_MARGIN;
char *node_params = MEM_CALLOC_EXTRAM(1, req_size);
if (!node_params) {
ESP_LOGE(TAG, "Failed to allocate %d bytes for Node params.", req_size);
ESP_LOGE(TAG, "Failed to allocate %lu bytes for Node params.", (unsigned long) req_size);
return NULL;
}
err = esp_rmaker_populate_params(node_params, &req_size, 0, false);
Expand All @@ -208,15 +208,15 @@ static char * esp_rmaker_param_get_buf(size_t size)
* we need to free existing buffer.
*/
if ((s_param_buf_size != 0) && (s_param_buf_size != size)) {
ESP_LOGD(TAG, "Freeing s_node_params_buf of size %d", s_param_buf_size);
ESP_LOGD(TAG, "Freeing s_node_params_buf of size %lu", (unsigned long) s_param_buf_size);
free(s_node_params_buf);
s_node_params_buf = NULL;
}
if (!s_node_params_buf) {
ESP_LOGD(TAG, "Allocating s_node_params_buf for size %d.", size);
ESP_LOGD(TAG, "Allocating s_node_params_buf for size %lu.", (unsigned long) size);
s_node_params_buf = MEM_CALLOC_EXTRAM(1, size);
if (!s_node_params_buf) {
ESP_LOGE(TAG, "Failed to allocate %d bytes for Node params.", size);
ESP_LOGE(TAG, "Failed to allocate %lu bytes for Node params.", (unsigned long) size);
s_param_buf_size = 0;
return NULL;
}
Expand All @@ -236,8 +236,8 @@ static esp_err_t esp_rmaker_allocate_and_populate_params(uint8_t flags, bool res
esp_err_t err = esp_rmaker_populate_params(node_params_buf, &req_size, flags, reset_flags);
/* If the max_node_params_size was insufficient, we will re-allocate new buffer */
if (err == ESP_ERR_NO_MEM) {
ESP_LOGW(TAG, "%d bytes not sufficient for Node params. Reallocating %d bytes.",
max_node_params_size, req_size + RMAKER_PARAMS_SIZE_MARGIN);
ESP_LOGW(TAG, "%lu bytes not sufficient for Node params. Reallocating %lu bytes.",
(unsigned long) max_node_params_size, (unsigned long) req_size + RMAKER_PARAMS_SIZE_MARGIN);
max_node_params_size = req_size + RMAKER_PARAMS_SIZE_MARGIN; /* Keeping some margin since paramater value size can change */
node_params_buf = esp_rmaker_param_get_buf(max_node_params_size);
if (!node_params_buf) {
Expand Down Expand Up @@ -393,7 +393,7 @@ static esp_err_t esp_rmaker_device_set_params(_esp_rmaker_device_t *device, jpar

esp_err_t esp_rmaker_handle_set_params(char *data, size_t data_len, esp_rmaker_req_src_t src)
{
ESP_LOGI(TAG, "Received params: %.*s", data_len, data);
ESP_LOGI(TAG, "Received params: %.*s", (int) data_len, data);
jparse_ctx_t jctx;
if (json_parse_start(&jctx, data, data_len) != 0) {
return ESP_FAIL;
Expand Down
6 changes: 3 additions & 3 deletions components/esp_rainmaker/src/core/esp_rmaker_scenes.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ static esp_err_t __esp_rmaker_scenes_get_params(char *buf, size_t *buf_size)
}

if (json_gen_end_array(&jstr) < 0) {
ESP_LOGE(TAG, "Buffer size %d not sufficient for reporting Scenes Params.", *buf_size);
ESP_LOGE(TAG, "Buffer size %lu not sufficient for reporting Scenes Params.", (unsigned long) *buf_size);
err = ESP_ERR_NO_MEM;
}
*buf_size = json_gen_str_end(&jstr);
Expand All @@ -469,7 +469,7 @@ static char *esp_rmaker_scenes_get_params(void)
}
char *data = MEM_CALLOC_EXTRAM(1, req_size);
if (!data) {
ESP_LOGE(TAG, "Failed to allocate %d bytes for scenes.", req_size);
ESP_LOGE(TAG, "Failed to allocate %lu bytes for scenes.", (unsigned long) req_size);
return NULL;
}
err = __esp_rmaker_scenes_get_params(data, &req_size);
Expand Down Expand Up @@ -503,7 +503,7 @@ static esp_err_t write_cb(const esp_rmaker_device_t *device, const esp_rmaker_pa
return ESP_ERR_INVALID_ARG;
}
if (strlen(val.val.s) <= 0) {
ESP_LOGI(TAG, "Invalid length for params: %d", strlen(val.val.s));
ESP_LOGI(TAG, "Invalid length for params: %lu", (unsigned long) strlen(val.val.s));
return ESP_ERR_INVALID_ARG;
}
bool report_params = false;
Expand Down
6 changes: 3 additions & 3 deletions components/esp_rainmaker/src/core/esp_rmaker_schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ static esp_err_t __esp_rmaker_schedule_get_params(char *buf, size_t *buf_size)
schedule = schedule->next;
}
if (json_gen_end_array(&jstr) < 0) {
ESP_LOGE(TAG, "Buffer size %d not sufficient for reporting Schedule Params.", *buf_size);
ESP_LOGE(TAG, "Buffer size %lu not sufficient for reporting Schedule Params.", (unsigned long) *buf_size);
err = ESP_ERR_NO_MEM;
}
*buf_size = json_gen_str_end(&jstr);
Expand All @@ -911,7 +911,7 @@ static char *esp_rmaker_schedule_get_params(void)
}
char *data = MEM_CALLOC_EXTRAM(1, req_size);
if (!data) {
ESP_LOGE(TAG, "Failed to allocate %d bytes for schedule.", req_size);
ESP_LOGE(TAG, "Failed to allocate %lu bytes for schedule.", (unsigned long) req_size);
return NULL;
}
err = __esp_rmaker_schedule_get_params(data, &req_size);
Expand Down Expand Up @@ -945,7 +945,7 @@ static esp_err_t write_cb(const esp_rmaker_device_t *device, const esp_rmaker_pa
return ESP_ERR_INVALID_ARG;
}
if (strlen(val.val.s) <= 0) {
ESP_LOGI(TAG, "Invalid length for params: %d", strlen(val.val.s));
ESP_LOGI(TAG, "Invalid length for params: %lu", (unsigned long) strlen(val.val.s));
return ESP_ERR_INVALID_ARG;
}
esp_rmaker_schedule_parse_json(val.val.s, strlen(val.val.s), ctx->src);
Expand Down

0 comments on commit e1fcc7c

Please sign in to comment.