kasjer commented on a change in pull request #2011: Change Reboot log from text
to CBOR encoded.
URL: https://github.com/apache/mynewt-core/pull/2011#discussion_r329244251
##########
File path: sys/reboot/src/log_reboot.c
##########
@@ -175,41 +184,93 @@ log_reboot_write(const struct log_reboot_info *info)
}
#endif
- rc = imgr_read_info(boot_current_slot, &ver, hash, NULL);
+ rc = imgr_read_info(boot_current_slot, &ver, hash, &flags);
if (rc != 0) {
return rc;
}
- off = 0;
- off += snprintf(buf + off, sizeof buf - off,
- "rsn:%s, cnt:%u, img:%u.%u.%u.%u, hash:",
- REBOOT_REASON_STR(info->reason), reboot_cnt, ver.iv_major,
- ver.iv_minor, ver.iv_revision,
- (unsigned int)ver.iv_build_num);
+ memset(cbor_enc_buf, 0, sizeof cbor_enc_buf);
+
+ cbor_buf_writer_init(&writer, cbor_enc_buf, sizeof cbor_enc_buf);
+ cbor_encoder_init(&enc, &writer.enc, 0);
+ rc = cbor_encoder_create_map(&enc, &map, CborIndefiniteLength);
+ if (rc != 0) {
+ return rc;
+ }
+
+ cbor_encode_text_stringz(&map, "rsn");
+ cbor_encode_text_stringz(&map, REBOOT_REASON_STR(info->reason));
+ cbor_encode_text_stringz(&map, "cnt");
+ cbor_encode_int(&map, reboot_cnt);
+
+ cbor_encode_text_stringz(&map, "img");
+ snprintf(buf, sizeof buf, "%u.%u.%u.%u",
+ ver.iv_major, ver.iv_minor, ver.iv_revision,
+ (unsigned int)ver.iv_build_num);
+ cbor_encode_text_stringz(&map, buf);
+
+ cbor_encode_text_stringz(&map, "hash");
+ memset(buf, 0, sizeof buf);
Review comment:
this is not really needed snprintf will work fine
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services