ccollins476ad commented on a change in pull request #362: nimble: add monitor protocol/interface + improve logs URL: https://github.com/apache/incubator-mynewt-core/pull/362#discussion_r124883989
########## File path: net/nimble/host/src/ble_hs_log.c ########## @@ -45,3 +51,97 @@ ble_hs_log_flat_buf(const void *data, int len) BLE_HS_LOG(DEBUG, "0x%02x ", u8ptr[i]); } } + +const char * +ble_addr_str(const ble_addr_t *addr) +{ + static char bufs[2][27]; + static uint8_t cur; + char type[7]; + char *str; + + str = bufs[cur++]; + cur %= sizeof(bufs) / sizeof(bufs[0]); + + if (!addr) { + return "(none)"; + } + + switch (addr->type) { + case BLE_ADDR_PUBLIC: + strcpy(type, "public"); + break; + case BLE_ADDR_RANDOM: + strcpy(type, "random"); + break; + default: + snprintf(type, sizeof(type), "0x%02x", addr->type); + break; + } + + sprintf(str, "%02X:%02X:%02X:%02X:%02X:%02X (%s)", + addr->val[5], addr->val[4], addr->val[3], + addr->val[2], addr->val[1], addr->val[0], type); + + return str; +} + +static char * +get_buf(void) +{ + static char hexbufs[HEXBUF_COUNT][HEXBUF_LENGTH + 1]; Review comment: This allocates a fairly large buffer, even when logging is disabled entirely. The problem is that the log macros always evaluate their arguments even if output is disabled. I am not sure what the right solution is, but I don't think we want to allocate such a large buffer unconditionally. The old method of repeated calls to `ble_hs_log_flat_buf()` was clunky, but it did avoid allocating buffers upfront. One possible solution is to use something like `#if MYNEWT_VAL(LOG_LEVEL) <= LOG_LEVEL_CRITICAL` to stub out this function when logging is disabled. That is kind of a hack since it presumes this function would only be used for logging, and we still allocate the buffer when the log level is set to a low level. Maybe another syscfg setting controlling whether this gets enabled? If disabled, it could return "<ble hex dump disabled>" or something like that. That might be a pain in the neck for the user, but it least it gives him full control. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services