You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/12/19 13:02:14 UTC

[GitHub] andrzej-kaczmarek closed pull request #1150: log/shell: Add support for logging cbor logs in shell

andrzej-kaczmarek closed pull request #1150: log/shell: Add support for logging cbor logs in shell
URL: https://github.com/apache/mynewt-core/pull/1150
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/sys/log/full/src/log_shell.c b/sys/log/full/src/log_shell.c
index 6d482f9e19..1ab95652cf 100644
--- a/sys/log/full/src/log_shell.c
+++ b/sys/log/full/src/log_shell.c
@@ -35,6 +35,9 @@
 #endif
 #include "shell/shell.h"
 #include "console/console.h"
+#if MYNEWT_VAL(LOG_VERSION) > 2
+#include "tinycbor/cbor_mbuf_reader.h"
+#endif
 
 static int
 shell_log_dump_entry(struct log *log, struct log_offset *log_offset,
@@ -43,9 +46,47 @@ shell_log_dump_entry(struct log *log, struct log_offset *log_offset,
     char data[128];
     int dlen;
     int rc;
+#if MYNEWT_VAL(LOG_VERSION) > 2
+    struct cbor_mbuf_reader reader;
+    struct CborParser parser;
+    struct CborValue value;
+    struct os_mbuf *om;
+#endif
 
     dlen = min(len, 128);
 
+#if MYNEWT_VAL(LOG_VERSION) > 2
+    /* Type defined log */
+    switch (ueh.ue_etype) {
+    case LOG_ETYPE_STRING:
+        rc = log_read(log, dptr, data, sizeof(ueh), dlen);
+        if (rc < 0) {
+            return rc;
+        }
+
+        data[rc] = 0;
+
+        console_printf("[%llu] %s\n", ueh.ue_ts, data);
+
+        break;
+    case LOG_ETYPE_CBOR:
+        om = os_msys_get_pkthdr(0, 0);
+
+        log_read_mbuf(log, dptr, om, sizeof(ueh), dlen);
+        if (rc < 0) {
+            return rc;
+        }
+
+        cbor_mbuf_reader_init(&reader, om, 0);
+        cbor_parser_init(&reader.r, 0, &parser, &value);
+        cbor_value_to_pretty(stdout, &value);
+        console_printf("\n");
+        os_mbuf_free_chain(om);
+
+        break;
+    }
+#else
+    /* String type log */
     rc = log_read_body(log, dptr, data, 0, dlen);
     if (rc < 0) {
         return rc;
@@ -53,6 +94,7 @@ shell_log_dump_entry(struct log *log, struct log_offset *log_offset,
     data[rc] = 0;
 
     console_printf("[%llu] %s\n", ueh->ue_ts, data);
+#endif
 
     return 0;
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services