Skip to content

Commit 8028cff

Browse files
committed
cbor encoder: added callback support for additional meta collection
This callback is called from the top hierarchy map, `data` of the metadata.
1 parent 013328f commit 8028cff

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

components/esp_insights/src/esp_insights_cbor_encoder.c

+35
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,24 @@
2929
static CborEncoder s_encoder, s_result_map, s_diag_map, s_diag_data_map;
3030
static CborEncoder s_meta_encoder, s_meta_result_map, s_diag_meta_map, s_diag_meta_data_map;
3131

32+
#define CBOR_ENC_MAX_CBS 10
33+
static struct cbor_encoder_data {
34+
insights_cbor_encoder_cb_t cb[CBOR_ENC_MAX_CBS];
35+
int cb_cnt;
36+
} s_priv_data;
37+
3238
static inline void _cbor_encode_meta_hdr(CborEncoder *hdr_map, const rtc_store_meta_header_t *hdr);
3339

40+
esp_err_t esp_insights_cbor_encoder_register_meta_cb(insights_cbor_encoder_cb_t cb)
41+
{
42+
if (s_priv_data.cb_cnt == CBOR_ENC_MAX_CBS) {
43+
return ESP_ERR_NO_MEM;
44+
}
45+
ESP_LOGV(TAG, "Registering callback %p", cb);
46+
s_priv_data.cb[s_priv_data.cb_cnt++] = cb;
47+
return ESP_OK;
48+
}
49+
3450
void esp_insights_cbor_encode_diag_begin(void *data, size_t data_size, const char *version)
3551
{
3652
cbor_encoder_init(&s_encoder, data, data_size, 0);
@@ -681,6 +697,25 @@ void esp_insights_cbor_encode_meta_data_end(void)
681697
cbor_encoder_close_container(&s_diag_meta_map, &s_diag_meta_data_map);
682698
}
683699

700+
void esp_insights_cbor_encode_conf_meta_data_begin(void)
701+
{
702+
cbor_encode_text_stringz(&s_diag_meta_map, "data");
703+
cbor_encoder_create_map(&s_diag_meta_map, &s_diag_meta_data_map, CborIndefiniteLength);
704+
#ifdef NEW_META_STRUCT
705+
for (int i = 0; i < s_priv_data.cb_cnt; i++) {
706+
if (s_priv_data.cb[i]) {
707+
s_priv_data.cb[i] (&s_diag_meta_data_map, INSIGHTS_MSG_TYPE_META);
708+
}
709+
}
710+
#endif
711+
}
712+
713+
/** Vikram: remove? */
714+
void esp_insights_cbor_encode_conf_meta_data_end(void)
715+
{
716+
cbor_encoder_close_container(&s_diag_meta_map, &s_diag_meta_data_map);
717+
}
718+
684719
#if CONFIG_DIAG_ENABLE_METRICS
685720
static void encode_metrics_meta_element(CborEncoder *map, const esp_diag_metrics_meta_t *metrics)
686721
{

components/esp_insights/src/esp_insights_cbor_encoder.h

+22
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,28 @@
2020
#define NEW_META_STRUCT 1
2121
#endif
2222

23+
typedef enum {
24+
INSIGHTS_MSG_TYPE_META,
25+
INSIGHTS_MSG_TYPE_DATA
26+
} insights_msg_type_t;
27+
28+
/**
29+
* @brief cbor encoder callback
30+
*
31+
* @param map parent map to which new data will be encoded
32+
* @param type information type to be collected
33+
*/
34+
typedef void (*insights_cbor_encoder_cb_t) (CborEncoder *map, insights_msg_type_t type);
35+
36+
/**
37+
* @brief register a meta collection callback
38+
*
39+
* @param cb callback of type \ref insights_cbor_encoder_cb_t
40+
*
41+
* @return ESP_OK on success, appropriate error otherwise
42+
*/
43+
esp_err_t esp_insights_cbor_encoder_register_meta_cb(insights_cbor_encoder_cb_t cb);
44+
2345
void esp_insights_cbor_encode_diag_begin(void *data, size_t data_size, const char *version);
2446
void esp_insights_cbor_encode_diag_data_begin(void);
2547
void esp_insights_cbor_encode_diag_boot_info(esp_diag_device_info_t *device_info);

components/esp_insights/src/esp_insights_cmd_resp.c

+1
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ esp_err_t esp_insights_cmd_resp_enable(void)
537537
goto enable_err;
538538
}
539539

540+
esp_insights_cbor_encoder_register_meta_cb(&esp_insights_cbor_reboot_msg_cb);
540541
ESP_LOGI(TAG, "Enabling Command-Response Module.");
541542

542543
/* Register our config parsing command to cmd_resp module */

0 commit comments

Comments
 (0)