You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/02/09 05:20:40 UTC
[3/3] incubator-mynewt-larva git commit: Convert nimble host from
console_printf to sys/log
Convert nimble host from console_printf to sys/log
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/edb63579
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/edb63579
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/edb63579
Branch: refs/heads/master
Commit: edb635795e8d0700fe37b1b74d8332b3f8e13e74
Parents: 071f317
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Feb 8 20:19:41 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Feb 8 20:20:28 2016 -0800
----------------------------------------------------------------------
net/nimble/host/egg.yml | 1 +
net/nimble/host/src/ble_hs.c | 7 ++
net/nimble/host/src/ble_hs_misc.c | 6 +-
net/nimble/host/src/ble_hs_priv.h | 5 ++
net/nimble/host/src/ble_l2cap_sig.c | 4 +-
net/nimble/host/src/host_dbg.c | 123 ++++++++++++++++---------------
net/nimble/host/src/host_hci.c | 14 ++--
net/nimble/host/src/host_hci_cmd.c | 4 +-
8 files changed, 90 insertions(+), 74 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/edb63579/net/nimble/host/egg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/egg.yml b/net/nimble/host/egg.yml
index 454eb09..74cf7aa 100644
--- a/net/nimble/host/egg.yml
+++ b/net/nimble/host/egg.yml
@@ -20,6 +20,7 @@
egg.name: net/nimble/host
egg.vers: 0.1
egg.deps:
+ - sys/log
- libs/os
- libs/util
- net/nimble
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/edb63579/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index 6f33430..15f2e07 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -42,6 +42,9 @@
#define BLE_HS_STACK_SIZE (176)
#endif
+static struct log_handler ble_hs_log_console_handler;
+struct log ble_hs_log;
+
static struct os_task ble_hs_task;
static os_stack_t ble_hs_stack[BLE_HS_STACK_SIZE] bssnz_t;
@@ -222,6 +225,10 @@ ble_hs_init(uint8_t prio, struct ble_hs_cfg *cfg)
ble_hs_cfg_init(cfg);
+ log_init();
+ log_console_handler_init(&ble_hs_log_console_handler);
+ log_register("ble_hs", &ble_hs_log, &ble_hs_log_console_handler);
+
os_task_init(&ble_hs_task, "ble_hs", ble_hs_task_handler, NULL, prio,
OS_WAIT_FOREVER, ble_hs_stack, BLE_HS_STACK_SIZE);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/edb63579/net/nimble/host/src/ble_hs_misc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_misc.c b/net/nimble/host/src/ble_hs_misc.c
index 9aeb586..8b4c676 100644
--- a/net/nimble/host/src/ble_hs_misc.c
+++ b/net/nimble/host/src/ble_hs_misc.c
@@ -53,9 +53,9 @@ ble_hs_misc_log_mbuf(struct os_mbuf *om)
for (i = 0; i < OS_MBUF_PKTLEN(om); i++) {
os_mbuf_copydata(om, i, 1, &u8);
- console_printf("0x%02x ", u8);
+ BLE_HS_LOG(DEBUG, "0x%02x ", u8);
}
- console_printf("\n");
+ BLE_HS_LOG(DEBUG, "\n");
}
void
@@ -66,7 +66,7 @@ ble_hs_misc_log_flat_buf(void *data, int len)
u8ptr = data;
for (i = 0; i < len; i++) {
- console_printf("0x%02x ", u8ptr[i]);
+ BLE_HS_LOG(DEBUG, "0x%02x ", u8ptr[i]);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/edb63579/net/nimble/host/src/ble_hs_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h
index 0163d53..5752d75 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -21,6 +21,7 @@
#define H_BLE_HS_PRIV_
#include <inttypes.h>
+#include "log/log.h"
#include "nimble/nimble_opt.h"
#include "host/ble_hs.h"
struct os_mbuf;
@@ -36,6 +37,8 @@ extern struct ble_hs_cfg ble_hs_cfg;
extern struct os_mbuf_pool ble_hs_mbuf_pool;
extern struct os_eventq ble_hs_evq;
+extern struct log ble_hs_log;
+
void ble_hs_process_tx_data_queue(void);
int ble_hs_rx_data(struct os_mbuf *om);
int ble_hs_tx_data(struct os_mbuf *om);
@@ -54,4 +57,6 @@ void ble_hs_misc_assert_no_locks(void);
struct os_mbuf *ble_hs_misc_pkthdr(void);
+#define BLE_HS_LOG(lvl, ...) LOG_ ## lvl(&ble_hs_log, 0, __VA_ARGS__)
+
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/edb63579/net/nimble/host/src/ble_l2cap_sig.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig.c b/net/nimble/host/src/ble_l2cap_sig.c
index bf5b25c..c66d91b 100644
--- a/net/nimble/host/src/ble_l2cap_sig.c
+++ b/net/nimble/host/src/ble_l2cap_sig.c
@@ -784,9 +784,9 @@ ble_l2cap_sig_rx(uint16_t conn_handle, struct os_mbuf **om)
struct ble_hs_conn *conn;
int rc;
- console_printf("L2CAP - rxed signalling msg: ");
+ BLE_HS_LOG(DEBUG, "L2CAP - rxed signalling msg: ");
ble_hs_misc_log_mbuf(*om);
- console_printf("\n");
+ BLE_HS_LOG(DEBUG, "\n");
*om = os_mbuf_pullup(*om, BLE_L2CAP_SIG_HDR_SZ);
if (*om == NULL) {
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/edb63579/net/nimble/host/src/host_dbg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_dbg.c b/net/nimble/host/src/host_dbg.c
index bf7a953..0598980 100644
--- a/net/nimble/host/src/host_dbg.c
+++ b/net/nimble/host/src/host_dbg.c
@@ -24,6 +24,7 @@
#include "console/console.h"
#include "nimble/hci_common.h"
#include "nimble/hci_transport.h"
+#include "ble_hs_priv.h"
void
host_hci_dbg_le_event_disp(uint8_t subev, uint8_t len, uint8_t *evdata)
@@ -41,26 +42,27 @@ host_hci_dbg_le_event_disp(uint8_t subev, uint8_t len, uint8_t *evdata)
case BLE_HCI_LE_SUBEV_CONN_COMPLETE:
status = evdata[0];
if (status == BLE_ERR_SUCCESS) {
- console_printf("LE connection complete. handle=%u role=%u "
- "paddrtype=%u addr=%x.%x.%x.%x.%x.%x itvl=%u "
- "latency=%u spvn_tmo=%u mca=%u\n",
- le16toh(evdata + 1), evdata[3], evdata[4],
- evdata[10], evdata[9], evdata[8], evdata[7],
- evdata[6], evdata[5], le16toh(evdata + 11),
- le16toh(evdata + 13), le16toh(evdata + 15),
- evdata[17]);
+ BLE_HS_LOG(DEBUG, "LE connection complete. handle=%u role=%u "
+ "paddrtype=%u addr=%x.%x.%x.%x.%x.%x itvl=%u "
+ "latency=%u spvn_tmo=%u mca=%u\n",
+ le16toh(evdata + 1), evdata[3], evdata[4],
+ evdata[10], evdata[9], evdata[8], evdata[7],
+ evdata[6], evdata[5], le16toh(evdata + 11),
+ le16toh(evdata + 13), le16toh(evdata + 15),
+ evdata[17]);
} else {
- console_printf("LE connection complete. FAIL (status=%u)\n",status);
+ BLE_HS_LOG(DEBUG, "LE connection complete. FAIL (status=%u)\n",
+ status);
}
break;
case BLE_HCI_LE_SUBEV_ADV_RPT:
advlen = evdata[9];
rssi = evdata[10 + advlen];
- console_printf("LE advertising report. len=%u num=%u evtype=%u "
- "addrtype=%u addr=%x.%x.%x.%x.%x.%x advlen=%u "
- "rssi=%d\n", len, evdata[0], evdata[1], evdata[2],
- evdata[8], evdata[7], evdata[6], evdata[5],
- evdata[4], evdata[3], advlen, rssi);
+ BLE_HS_LOG(DEBUG, "LE advertising report. len=%u num=%u evtype=%u "
+ "addrtype=%u addr=%x.%x.%x.%x.%x.%x advlen=%u "
+ "rssi=%d\n", len, evdata[0], evdata[1], evdata[2],
+ evdata[8], evdata[7], evdata[6], evdata[5],
+ evdata[4], evdata[3], advlen, rssi);
if (advlen) {
dptr = &evdata[10];
while (advlen > 0) {
@@ -76,55 +78,55 @@ host_hci_dbg_le_event_disp(uint8_t subev, uint8_t len, uint8_t *evdata)
++dptr;
}
advlen -= imax;
- console_printf("%s\n", adv_data_buf);
+ BLE_HS_LOG(DEBUG, "%s\n", adv_data_buf);
}
}
break;
case BLE_HCI_LE_SUBEV_CONN_UPD_COMPLETE:
status = evdata[0];
if (status == BLE_ERR_SUCCESS) {
- console_printf("LE Connection Update Complete. handle=%u "
- "itvl=%u latency=%u timeout=%u\n",
- le16toh(evdata + 1), le16toh(evdata + 3),
- le16toh(evdata + 5), le16toh(evdata + 7));
+ BLE_HS_LOG(DEBUG, "LE Connection Update Complete. handle=%u "
+ "itvl=%u latency=%u timeout=%u\n",
+ le16toh(evdata + 1), le16toh(evdata + 3),
+ le16toh(evdata + 5), le16toh(evdata + 7));
} else {
- console_printf("LE Connection Update Complete. FAIL (status=%u)\n",
- status);
+ BLE_HS_LOG(DEBUG, "LE Connection Update Complete. FAIL "
+ "(status=%u)\n", status);
}
break;
case BLE_HCI_LE_SUBEV_DATA_LEN_CHG:
- console_printf("LE Data Length Change. handle=%u max_tx_bytes=%u "
- "max_tx_time=%u max_rx_bytes=%u max_rx_time=%u\n",
- le16toh(evdata), le16toh(evdata + 2),
- le16toh(evdata + 4), le16toh(evdata + 6),
- le16toh(evdata + 8));
+ BLE_HS_LOG(DEBUG, "LE Data Length Change. handle=%u max_tx_bytes=%u "
+ "max_tx_time=%u max_rx_bytes=%u max_rx_time=%u\n",
+ le16toh(evdata), le16toh(evdata + 2),
+ le16toh(evdata + 4), le16toh(evdata + 6),
+ le16toh(evdata + 8));
break;
case BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ:
- console_printf("LE Remote Connection Parameter Request. handle=%u "
- "min_itvl=%u max_itvl=%u latency=%u timeout=%u\n",
- le16toh(evdata), le16toh(evdata + 2),
- le16toh(evdata + 4), le16toh(evdata + 6),
- le16toh(evdata + 8));
+ BLE_HS_LOG(DEBUG, "LE Remote Connection Parameter Request. handle=%u "
+ "min_itvl=%u max_itvl=%u latency=%u timeout=%u\n",
+ le16toh(evdata), le16toh(evdata + 2),
+ le16toh(evdata + 4), le16toh(evdata + 6),
+ le16toh(evdata + 8));
break;
case BLE_HCI_LE_SUBEV_RD_REM_USED_FEAT:
status = evdata[0];
if (status == BLE_ERR_SUCCESS) {
- console_printf("LE Remote Used Features. handle=%u feat=",
- le16toh(evdata + 1));
+ BLE_HS_LOG(DEBUG, "LE Remote Used Features. handle=%u feat=",
+ le16toh(evdata + 1));
for (i = 0; i < BLE_HCI_RD_LOC_SUPP_FEAT_RSPLEN; ++i) {
- console_printf("%02x ", evdata[3 + i]);
+ BLE_HS_LOG(DEBUG, "%02x ", evdata[3 + i]);
}
- console_printf("\n");
+ BLE_HS_LOG(DEBUG, "\n");
} else {
- console_printf("LE Remote Used Features. FAIL (status=%u)\n",
- status);
+ BLE_HS_LOG(DEBUG, "LE Remote Used Features. FAIL (status=%u)\n",
+ status);
}
break;
default:
- console_printf("\tUnknown LE event\n");
+ BLE_HS_LOG(DEBUG, "\tUnknown LE event\n");
break;
}
}
@@ -151,8 +153,8 @@ host_hci_dbg_disconn_comp_disp(uint8_t *evdata, uint8_t len)
} else {
reason = evdata[3];
}
- console_printf("Disconnection Complete: status=%u handle=%u reason=%u\n",
- status, handle, reason);
+ BLE_HS_LOG(DEBUG, "Disconnection Complete: status=%u handle=%u "
+ "reason=%u\n", status, handle, reason);
}
/**
@@ -164,10 +166,10 @@ host_hci_dbg_disconn_comp_disp(uint8_t *evdata, uint8_t len)
static void
host_hci_dbg_rd_rem_ver_disp(uint8_t *evdata, uint8_t len)
{
- console_printf("Remote Version Info: status=%u handle=%u vers_nr=%u "
- "compid=%u subver=%u\n",
- evdata[0], le16toh(evdata + 1), evdata[3],
- le16toh(evdata + 4), le16toh(evdata + 6));
+ BLE_HS_LOG(DEBUG, "Remote Version Info: status=%u handle=%u vers_nr=%u "
+ "compid=%u subver=%u\n",
+ evdata[0], le16toh(evdata + 1), evdata[3],
+ le16toh(evdata + 4), le16toh(evdata + 6));
}
/**
@@ -187,13 +189,14 @@ host_hci_dbg_num_comp_pkts_disp(uint8_t *evdata, uint8_t len)
handles = evdata[0];
if (len != ((handles * 4) + 1)) {
- console_printf("ERR: Number of Completed Packets bad length: "
- "num_handles=%u len=%u\n", handles, len);
+ BLE_HS_LOG(DEBUG, "ERR: Number of Completed Packets bad length: "
+ "num_handles=%u len=%u\n", handles, len);
return;
}
- console_printf("Number of Completed Packets: num_handles=%u\n", handles);
+ BLE_HS_LOG(DEBUG, "Number of Completed Packets: num_handles=%u\n",
+ handles);
if (handles) {
handle_ptr = evdata + 1;
pkt_ptr = handle_ptr + (2 * handles);
@@ -202,7 +205,7 @@ host_hci_dbg_num_comp_pkts_disp(uint8_t *evdata, uint8_t len)
handle_ptr += 2;
pkts = le16toh(pkt_ptr);
pkt_ptr += 2;
- console_printf("handle:%u pkts:%u\n", handle, pkts);
+ BLE_HS_LOG(DEBUG, "handle:%u pkts:%u\n", handle, pkts);
--handles;
}
}
@@ -219,14 +222,14 @@ host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
ogf = BLE_HCI_OGF(opcode);
ocf = BLE_HCI_OCF(opcode);
- console_printf("Command Complete: cmd_pkts=%u ocf=0x%x ogf=0x%x ",
- evdata[0], ocf, ogf);
+ BLE_HS_LOG(DEBUG, "Command Complete: cmd_pkts=%u ocf=0x%x ogf=0x%x ",
+ evdata[0], ocf, ogf);
/* Display parameters based on command. */
if (ogf == BLE_HCI_OGF_LE) {
switch (ocf) {
case BLE_HCI_OCF_LE_SET_ADV_DATA:
- console_printf("status=%u", evdata[3]);
+ BLE_HS_LOG(DEBUG, "status=%u", evdata[3]);
break;
default:
break;
@@ -234,19 +237,19 @@ host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
} else if (ogf == BLE_HCI_OGF_INFO_PARAMS) {
switch (ocf) {
case BLE_HCI_OCF_IP_RD_LOCAL_VER:
- console_printf("status=%u ", evdata[3]);
+ BLE_HS_LOG(DEBUG, "status=%u ", evdata[3]);
if (evdata[3] == BLE_ERR_SUCCESS) {
- console_printf("hci_ver=%u hci_rev=%u lmp_ver=%u mfrg=%u "
- "lmp_subver=%u", evdata[4], le16toh(evdata + 5),
- evdata[7], le16toh(evdata + 8),
- le16toh(evdata + 10));
+ BLE_HS_LOG(DEBUG, "hci_ver=%u hci_rev=%u lmp_ver=%u mfrg=%u "
+ "lmp_subver=%u",
+ evdata[4], le16toh(evdata + 5), evdata[7],
+ le16toh(evdata + 8), le16toh(evdata + 10));
}
break;
default:
break;
}
}
- console_printf("\n");
+ BLE_HS_LOG(DEBUG, "\n");
}
@@ -261,8 +264,8 @@ host_hci_dbg_cmd_status_disp(uint8_t *evdata, uint8_t len)
ogf = BLE_HCI_OGF(opcode);
ocf = BLE_HCI_OCF(opcode);
- console_printf("Command Status: status=%u cmd_pkts=%u ocf=0x%x ogf=0x%x\n",
- evdata[0], evdata[1], ocf, ogf);
+ BLE_HS_LOG(DEBUG, "Command Status: status=%u cmd_pkts=%u ocf=0x%x "
+ "ogf=0x%x\n", evdata[0], evdata[1], ocf, ogf);
}
void
@@ -296,7 +299,7 @@ host_hci_dbg_event_disp(uint8_t *evbuf)
host_hci_dbg_le_event_disp(evdata[0], len, evdata + 1);
break;
default:
- console_printf("Unknown event 0x%x len=%u\n", evcode, len);
+ BLE_HS_LOG(DEBUG, "Unknown event 0x%x len=%u\n", evcode, len);
break;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/edb63579/net/nimble/host/src/host_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci.c b/net/nimble/host/src/host_hci.c
index f455779..6da01b6 100644
--- a/net/nimble/host/src/host_hci.c
+++ b/net/nimble/host/src/host_hci.c
@@ -674,10 +674,10 @@ host_hci_data_rx(struct os_mbuf *om)
rc = host_hci_data_hdr_strip(om, &hci_hdr);
if (rc == 0) {
- console_printf("host_hci_data_rx(): handle=%u pb=%x len=%u data=",
- BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc),
- BLE_HCI_DATA_PB(hci_hdr.hdh_handle_pb_bc),
- hci_hdr.hdh_len);
+ BLE_HS_LOG(DEBUG, "host_hci_data_rx(): handle=%u pb=%x len=%u data=",
+ BLE_HCI_DATA_HANDLE(hci_hdr.hdh_handle_pb_bc),
+ BLE_HCI_DATA_PB(hci_hdr.hdh_handle_pb_bc),
+ hci_hdr.hdh_len);
ble_hs_misc_log_mbuf(om);
if (hci_hdr.hdh_len != OS_MBUF_PKTHDR(om)->omp_len) {
@@ -741,8 +741,8 @@ host_hci_data_hdr_prepend(struct os_mbuf *om, uint16_t handle, uint8_t pb_flag)
memcpy(om->om_data, &hci_hdr, sizeof hci_hdr);
- console_printf("host tx hci data; handle=%d length=%d\n", handle,
- le16toh(&hci_hdr.hdh_len));
+ BLE_HS_LOG(DEBUG, "host tx hci data; handle=%d length=%d\n", handle,
+ le16toh(&hci_hdr.hdh_len));
return om;
}
@@ -765,7 +765,7 @@ host_hci_data_tx(struct ble_hs_conn *connection, struct os_mbuf *om)
return BLE_HS_ENOMEM;
}
- console_printf("host_hci_data_tx(): ");
+ BLE_HS_LOG(DEBUG, "host_hci_data_tx(): ");
ble_hs_misc_log_mbuf(om);
rc = ble_hs_tx_data(om);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/edb63579/net/nimble/host/src/host_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci_cmd.c b/net/nimble/host/src/host_hci_cmd.c
index bcd5ed7..9946f04 100644
--- a/net/nimble/host/src/host_hci_cmd.c
+++ b/net/nimble/host/src/host_hci_cmd.c
@@ -66,8 +66,8 @@ host_hci_cmd_send(uint8_t ogf, uint8_t ocf, uint8_t len, void *cmddata)
memcpy(cmd + BLE_HCI_CMD_HDR_LEN, cmddata, len);
}
rc = host_hci_cmd_transport(cmd);
- console_printf("host_hci_cmd_send: ogf=0x%02x ocf=0x%02x len=%d\n",
- ogf, ocf, len);
+ BLE_HS_LOG(DEBUG, "host_hci_cmd_send: ogf=0x%02x ocf=0x%02x len=%d\n",
+ ogf, ocf, len);
if (rc == 0) {
host_hci_outstanding_opcode = opcode;
}