simonratner 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_r124900025
 
 

 ##########
 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:
   Big ? on that idea, i feel like it will save some code space since every 
project rebuilds its own. 
   
   Glibc has a way to register custom printf handlers: 
https://www.gnu.org/software/libc/manual/html_node/Customizing-Printf.html#Customizing-Printf.
 I don't think we need to go that far, better a lightweight implementation that 
just does a couple of common things - `ble_addr_t`, `ble_uuid_t`, 
space-separated hex with a max width modifier - but the precedent is certainly 
there.
 
----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to