You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2018/12/05 09:31:22 UTC

[mynewt-core] branch master updated (fd4fbee -> f502582)

This is an automated email from the ASF dual-hosted git repository.

andk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git.


    from fd4fbee  adp5061: Make charge_control dependency optional
     new a72da36  sys/log: Simplify log dump
     new 885766f  sys/log: Add pretty-printing for CBOR log entries
     new d70b815  sys/log: Add option to dump only single log via cli
     new f502582  sys/log: Add option to list available logs via cli

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 sys/log/full/src/log.c       |   4 +-
 sys/log/full/src/log_shell.c | 167 +++++++++++++++++++++++++++++++++++++++----
 2 files changed, 157 insertions(+), 14 deletions(-)


[mynewt-core] 01/04: sys/log: Simplify log dump

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit a72da36ff12255511ee714a5b787cd44ea954628
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Dec 4 18:42:21 2018 +0100

    sys/log: Simplify log dump
    
    Make common start/end for each log entry (i.e. timestamp + newline) and
    also use console_write where possible to print simple strings instead of
    going through formatting code.
---
 sys/log/full/src/log_shell.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/sys/log/full/src/log_shell.c b/sys/log/full/src/log_shell.c
index c2b4608..2897039 100644
--- a/sys/log/full/src/log_shell.c
+++ b/sys/log/full/src/log_shell.c
@@ -58,26 +58,31 @@ shell_log_dump_entry(struct log *log, struct log_offset *log_offset,
     }
     data[rc] = 0;
 
+    console_printf("[%llu] ", ueh->ue_ts);
+
 #if MYNEWT_VAL(LOG_VERSION) <= 2
-    console_printf("[%llu] %s\n", ueh->ue_ts, data);
+    console_write(data, strlen(data));
 #else
     switch (ueh->ue_etype) {
     case LOG_ETYPE_STRING:
-        console_printf("[%llu] %s\n", ueh->ue_ts, data);
+        console_write(data, strlen(data));
         break;
     default:
-        console_printf("[%llu] ", ueh->ue_ts);
         for (off = 0; off < rc; off += blksz) {
             blksz = dlen - off;
             if (blksz > sizeof(tmp) >> 1) {
                 blksz = sizeof(tmp) >> 1;
             }
             hex_format(&data[off], blksz, tmp, sizeof(tmp));
-            console_printf("%s", tmp);
+            console_write(tmp, strlen(tmp));
+        }
+        if (rc < len) {
+            console_write("...", 3);
         }
-        console_printf("%s\n", rc < len ? "..." : "");
     }
 #endif
+
+    console_write("\n", 1);
     return 0;
 }
 


[mynewt-core] 02/04: sys/log: Add pretty-printing for CBOR log entries

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit 885766f3b8d6baee521fea2feef7c707ef1ccf2c
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Dec 4 16:52:36 2018 +0100

    sys/log: Add pretty-printing for CBOR log entries
---
 sys/log/full/src/log_shell.c | 130 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 126 insertions(+), 4 deletions(-)

diff --git a/sys/log/full/src/log_shell.c b/sys/log/full/src/log_shell.c
index 2897039..650d236 100644
--- a/sys/log/full/src/log_shell.c
+++ b/sys/log/full/src/log_shell.c
@@ -36,6 +36,115 @@
 #include "shell/shell.h"
 #include "console/console.h"
 #include "base64/hex.h"
+#if MYNEWT_VAL(LOG_VERSION) > 2
+#include "tinycbor/cbor.h"
+#endif
+
+#if MYNEWT_VAL(LOG_VERSION) > 2
+struct log_shell_cbor_reader {
+    struct cbor_decoder_reader r;
+    struct log *log;
+    void *dptr;
+};
+
+static uint8_t
+log_shell_cbor_reader_get8(struct cbor_decoder_reader *d, int offset)
+{
+    struct log_shell_cbor_reader *cbr = (struct log_shell_cbor_reader *)d;
+    uint8_t val = 0;
+
+    (void)log_read_body(cbr->log, cbr->dptr, &val, offset, sizeof(val));
+
+    return val;
+}
+
+static uint16_t
+log_shell_cbor_reader_get16(struct cbor_decoder_reader *d, int offset)
+{
+    struct log_shell_cbor_reader *cbr = (struct log_shell_cbor_reader *)d;
+    uint16_t val = 0;
+
+    (void)log_read_body(cbr->log, cbr->dptr, &val, offset, sizeof(val));
+
+    return val;
+}
+
+static uint32_t
+log_shell_cbor_reader_get32(struct cbor_decoder_reader *d, int offset)
+{
+    struct log_shell_cbor_reader *cbr = (struct log_shell_cbor_reader *)d;
+    uint8_t val = 0;
+
+    (void)log_read_body(cbr->log, cbr->dptr, &val, offset, sizeof(val));
+
+    return val;
+}
+
+static uint64_t
+log_shell_cbor_reader_get64(struct cbor_decoder_reader *d, int offset)
+{
+    struct log_shell_cbor_reader *cbr = (struct log_shell_cbor_reader *)d;
+    uint64_t val = 0;
+
+    (void)log_read_body(cbr->log, cbr->dptr, &val, offset, sizeof(val));
+
+    return val;
+}
+
+static uintptr_t
+log_shell_cbor_reader_cmp(struct cbor_decoder_reader *d, char *dst,
+                          int src_offset, size_t len)
+{
+    struct log_shell_cbor_reader *cbr = (struct log_shell_cbor_reader *)d;
+    uint8_t buf[16];
+    int chunk_len;
+    int offset;
+    int rc;
+
+    offset = 0;
+
+    while (offset < len) {
+        chunk_len = min(len - offset, sizeof(buf));
+
+        log_read_body(cbr->log, cbr->dptr, buf, src_offset + offset, chunk_len);
+
+        rc = memcmp(&dst[offset], buf, chunk_len);
+        if (rc) {
+            return rc;
+        }
+
+        offset += chunk_len;
+    }
+
+    return 0;
+}
+
+static uintptr_t
+log_shell_cbor_reader_cpy(struct cbor_decoder_reader *d, char *dst,
+                          int src_offset, size_t len)
+{
+    struct log_shell_cbor_reader *cbr = (struct log_shell_cbor_reader *)d;
+
+    log_read_body(cbr->log, cbr->dptr, dst, src_offset, len);
+
+    return (uintptr_t)dst;
+}
+
+static void
+log_shell_cbor_reader_init(struct log_shell_cbor_reader *cbr, struct log *log,
+                           void *dptr, uint16_t len)
+{
+    cbr->r.get8 = &log_shell_cbor_reader_get8;
+    cbr->r.get16 = &log_shell_cbor_reader_get16;
+    cbr->r.get32 = &log_shell_cbor_reader_get32;
+    cbr->r.get64 = &log_shell_cbor_reader_get64;
+    cbr->r.cmp = &log_shell_cbor_reader_cmp;
+    cbr->r.cpy = &log_shell_cbor_reader_cpy;
+    cbr->r.message_size = len;
+    cbr->log = log;
+    cbr->dptr = dptr;
+}
+#endif
 
 static int
 shell_log_dump_entry(struct log *log, struct log_offset *log_offset,
@@ -45,18 +154,26 @@ shell_log_dump_entry(struct log *log, struct log_offset *log_offset,
     int dlen;
     int rc;
 #if MYNEWT_VAL(LOG_VERSION) > 2
+    struct CborParser cbor_parser;
+    struct CborValue cbor_value;
+    struct log_shell_cbor_reader cbor_reader;
     char tmp[32 + 1];
     int off;
     int blksz;
+    bool read_data = ueh->ue_etype != LOG_ETYPE_CBOR;
+#else
+    bool read_data = true;
 #endif
 
     dlen = min(len, 128);
 
-    rc = log_read_body(log, dptr, data, 0, dlen);
-    if (rc < 0) {
-        return rc;
+    if (read_data) {
+        rc = log_read_body(log, dptr, data, 0, dlen);
+        if (rc < 0) {
+            return rc;
+        }
+        data[rc] = 0;
     }
-    data[rc] = 0;
 
     console_printf("[%llu] ", ueh->ue_ts);
 
@@ -67,6 +184,11 @@ shell_log_dump_entry(struct log *log, struct log_offset *log_offset,
     case LOG_ETYPE_STRING:
         console_write(data, strlen(data));
         break;
+    case LOG_ETYPE_CBOR:
+        log_shell_cbor_reader_init(&cbor_reader, log, dptr, len);
+        cbor_parser_init(&cbor_reader.r, 0, &cbor_parser, &cbor_value);
+        cbor_value_to_pretty(stdout, &cbor_value);
+        break;
     default:
         for (off = 0; off < rc; off += blksz) {
             blksz = dlen - off;


[mynewt-core] 04/04: sys/log: Add option to list available logs via cli

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit f5025829bbc414d17eb0d6958a3e42d22f41af01
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Dec 4 17:03:15 2018 +0100

    sys/log: Add option to list available logs via cli
    
    Use 'log -l' for this.
---
 sys/log/full/src/log_shell.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/sys/log/full/src/log_shell.c b/sys/log/full/src/log_shell.c
index 56812f3..0252552 100644
--- a/sys/log/full/src/log_shell.c
+++ b/sys/log/full/src/log_shell.c
@@ -214,8 +214,11 @@ shell_log_dump_cmd(int argc, char **argv)
     struct log *log;
     struct log_offset log_offset;
     bool last = false;
+    bool list_only;
     int rc;
 
+    list_only = ((argc > 1) && !strcmp(argv[1], "-l"));
+
     log = NULL;
     do {
         log = log_list_get_next(log);
@@ -227,6 +230,11 @@ shell_log_dump_cmd(int argc, char **argv)
             continue;
         }
 
+        if (list_only) {
+            console_printf("%s\n", log->l_name);
+            continue;
+        }
+
         if (argc > 1) {
             if (strcmp(log->l_name, argv[1])) {
                 continue;


[mynewt-core] 03/04: sys/log: Add option to dump only single log via cli

Posted by an...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit d70b815fea7aac7c96e095dd586d285636fe83d5
Author: Andrzej Kaczmarek <an...@codecoup.pl>
AuthorDate: Tue Dec 4 17:01:55 2018 +0100

    sys/log: Add option to dump only single log via cli
    
    Use 'log <logname>' for this.
---
 sys/log/full/src/log.c       |  4 ++--
 sys/log/full/src/log_shell.c | 14 +++++++++++---
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/sys/log/full/src/log.c b/sys/log/full/src/log.c
index c432bee..343cb42 100644
--- a/sys/log/full/src/log.c
+++ b/sys/log/full/src/log.c
@@ -40,10 +40,10 @@ static const char *g_log_module_list[ MYNEWT_VAL(LOG_MAX_USER_MODULES) ];
 static uint8_t log_written;
 
 #if MYNEWT_VAL(LOG_CLI)
-int shell_log_dump_all_cmd(int, char **);
+int shell_log_dump_cmd(int, char **);
 struct shell_cmd g_shell_log_cmd = {
     .sc_cmd = "log",
-    .sc_cmd_func = shell_log_dump_all_cmd
+    .sc_cmd_func = shell_log_dump_cmd
 };
 
 #if MYNEWT_VAL(LOG_FCB_SLOT1)
diff --git a/sys/log/full/src/log_shell.c b/sys/log/full/src/log_shell.c
index 650d236..56812f3 100644
--- a/sys/log/full/src/log_shell.c
+++ b/sys/log/full/src/log_shell.c
@@ -209,14 +209,15 @@ shell_log_dump_entry(struct log *log, struct log_offset *log_offset,
 }
 
 int
-shell_log_dump_all_cmd(int argc, char **argv)
+shell_log_dump_cmd(int argc, char **argv)
 {
     struct log *log;
     struct log_offset log_offset;
+    bool last = false;
     int rc;
 
     log = NULL;
-    while (1) {
+    do {
         log = log_list_get_next(log);
         if (log == NULL) {
             break;
@@ -226,6 +227,13 @@ shell_log_dump_all_cmd(int argc, char **argv)
             continue;
         }
 
+        if (argc > 1) {
+            if (strcmp(log->l_name, argv[1])) {
+                continue;
+            }
+            last = true;
+        }
+
         console_printf("Dumping log %s\n", log->l_name);
 
         log_offset.lo_arg = NULL;
@@ -237,7 +245,7 @@ shell_log_dump_all_cmd(int argc, char **argv)
         if (rc != 0) {
             goto err;
         }
-    }
+    } while (!last);
 
     return (0);
 err: