oic; add logging routines printing strings/hex data from mbuf.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/3ef9fa6e Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/3ef9fa6e Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/3ef9fa6e Branch: refs/heads/develop Commit: 3ef9fa6ea2e3b1e739acace5452f344a3e2689cf Parents: 9c3e986 Author: Marko Kiiskila <[email protected]> Authored: Fri Jan 6 11:26:35 2017 -0800 Committer: Marko Kiiskila <[email protected]> Committed: Fri Jan 6 15:03:00 2017 -0800 ---------------------------------------------------------------------- net/oic/include/oic/oc_log.h | 17 +++++++++++++++++ net/oic/src/port/mynewt/log.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3ef9fa6e/net/oic/include/oic/oc_log.h ---------------------------------------------------------------------- diff --git a/net/oic/include/oic/oc_log.h b/net/oic/include/oic/oc_log.h index 4ab711d..f97015c 100644 --- a/net/oic/include/oic/oc_log.h +++ b/net/oic/include/oic/oc_log.h @@ -38,6 +38,9 @@ extern struct log oc_log; struct oc_endpoint; void oc_log_endpoint(uint16_t lvl, struct oc_endpoint *); void oc_log_bytes(uint16_t lvl, void *addr, int len, int print_char); +struct os_mbuf; +void oc_log_bytes_mbuf(uint16_t lvl, struct os_mbuf *, int off, int len, + int print_char); #define OC_LOG_ENDPOINT(lvl, ep) \ do { \ @@ -53,6 +56,13 @@ void oc_log_bytes(uint16_t lvl, void *addr, int len, int print_char); } \ } while(0) +#define OC_LOG_STR_MBUF(lvl, m, off, len) \ + do { \ + if (MYNEWT_VAL(LOG_LEVEL) <= (lvl)) { \ + oc_log_bytes_mbuf(lvl, m, off, len, 1); \ + } \ + } while(0) + #define OC_LOG_HEX(lvl, addr, len) \ do { \ if (MYNEWT_VAL(LOG_LEVEL) <= (lvl)) { \ @@ -61,6 +71,13 @@ void oc_log_bytes(uint16_t lvl, void *addr, int len, int print_char); } while(0) #else +#define OC_LOG_HEX_MBUF(lvl, m, off, len) \ + do { \ + if (MYNEWT_VAL(LOG_LEVEL) <= (lvl)) { \ + oc_log_bytes_mbuf(lvl, m, off, len, 0); \ + } \ + } while(0) + #define OC_LOG_DEBUG(...) #define OC_LOG_INFO(...) #define OC_LOG_ERROR(...) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/3ef9fa6e/net/oic/src/port/mynewt/log.c ---------------------------------------------------------------------- diff --git a/net/oic/src/port/mynewt/log.c b/net/oic/src/port/mynewt/log.c index 85f7e5d..8d41ceb 100644 --- a/net/oic/src/port/mynewt/log.c +++ b/net/oic/src/port/mynewt/log.c @@ -83,3 +83,31 @@ oc_log_bytes(uint16_t lvl, void *addr, int len, int print_char) } log_printf(&oc_log, LOG_MODULE_IOTIVITY, lvl, "]\n"); } + +void +oc_log_bytes_mbuf(uint16_t lvl, struct os_mbuf *m, int off, int len, + int print_char) +{ + int i; + uint8_t tmp[4]; + int blen; + + log_printf(&oc_log, LOG_MODULE_IOTIVITY, lvl, "["); + while (len) { + blen = len; + if (blen > sizeof(tmp)) { + blen = sizeof(tmp); + } + os_mbuf_copydata(m, off, blen, tmp); + for (i = 0; i < blen; i++) { + if (print_char) { + log_printf(&oc_log, LOG_MODULE_IOTIVITY, lvl, "%c", tmp[i]); + } else { + log_printf(&oc_log, LOG_MODULE_IOTIVITY, lvl, "%02x", tmp[i]); + } + } + off += blen; + len -= blen; + } + log_printf(&oc_log, LOG_MODULE_IOTIVITY, lvl, "]\n"); +}
