Skip to content

Commit

Permalink
porting: Remove dependency on Mynewt logging system
Browse files Browse the repository at this point in the history
Define NPL interface that can be used by ports to implement logging.
  • Loading branch information
sjanc committed Oct 6, 2023
1 parent e1f7546 commit da4e2f0
Show file tree
Hide file tree
Showing 56 changed files with 352 additions and 722 deletions.
2 changes: 0 additions & 2 deletions apps/blemesh_shell/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

#define MESH_LOG_MODULE BLE_MESH_LOG

#include <assert.h>
#include "os/mynewt.h"
#include "mesh/mesh.h"
Expand Down
22 changes: 10 additions & 12 deletions nimble/host/include/host/ble_hs_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
#ifndef H_BLE_HS_LOG_
#define H_BLE_HS_LOG_

#ifndef BLE_NPL_LOG_MODULE
#define BLE_NPL_LOG_MODULE BLE_HS_LOG
#endif

#include <nimble/nimble_npl_log.h>

/**
* @file ble_hs_log.h
*
Expand All @@ -33,14 +39,6 @@
* @{
*/

#include "modlog/modlog.h"
#include "log/log.h"

/* Only include the logcfg header if this version of newt can generate it. */
#if MYNEWT_VAL(NEWT_FEATURE_LOGCFG)
#include "logcfg/logcfg.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -57,7 +55,7 @@ struct os_mbuf;
* @param ... The format string and additional arguments for the log message.
*/
#define BLE_HS_LOG(lvl, ...) \
BLE_HS_LOG_ ## lvl(__VA_ARGS__)
BLE_NPL_LOG(lvl, __VA_ARGS__)

/**
* @brief Macro for logging a Bluetooth address at a specified log level.
Expand All @@ -69,9 +67,9 @@ struct os_mbuf;
* @param addr The Bluetooth address to be logged.
*/
#define BLE_HS_LOG_ADDR(lvl, addr) \
BLE_HS_LOG_ ## lvl("%02x:%02x:%02x:%02x:%02x:%02x", \
(addr)[5], (addr)[4], (addr)[3], \
(addr)[2], (addr)[1], (addr)[0])
BLE_NPL_LOG(lvl, "%02x:%02x:%02x:%02x:%02x:%02x", \
(addr)[5], (addr)[4], (addr)[3], \
(addr)[2], (addr)[1], (addr)[0])


/**
Expand Down
19 changes: 4 additions & 15 deletions nimble/host/mesh/include/mesh/glue.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include <errno.h>

#include "syscfg/syscfg.h"
#include "logcfg/logcfg.h"
#include "modlog/modlog.h"
#include "nimble/nimble_npl.h"

#include "os/os_mbuf.h"
Expand Down Expand Up @@ -182,19 +180,10 @@ extern "C" {
#define BT_GAP_ADV_SLOW_INT_MIN 0x0640 /* 1 s */
#define BT_GAP_ADV_SLOW_INT_MAX 0x0780 /* 1.2 s */

#ifndef MESH_LOG_MODULE
#define MESH_LOG_MODULE BLE_MESH_LOG
#endif

#define CAT(a, ...) PRIMITIVE_CAT(a, __VA_ARGS__)
#define PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__

#define BLE_MESH_LOG(lvl, ...) CAT(MESH_LOG_MODULE, CAT(_, lvl))(__VA_ARGS__)

#define BT_DBG(fmt, ...) BLE_MESH_LOG(DEBUG, "%s: " fmt "\n", __func__, ## __VA_ARGS__);
#define BT_INFO(fmt, ...) BLE_MESH_LOG(INFO, "%s: " fmt "\n", __func__, ## __VA_ARGS__);
#define BT_WARN(fmt, ...) BLE_MESH_LOG(WARN, "%s: " fmt "\n", __func__, ## __VA_ARGS__);
#define BT_ERR(fmt, ...) BLE_MESH_LOG(ERROR, "%s: " fmt "\n", __func__, ## __VA_ARGS__);
#define BT_DBG(fmt, ...) BLE_NPL_LOG(DEBUG, "%s: " fmt "\n", __func__, ## __VA_ARGS__);
#define BT_INFO(fmt, ...) BLE_NPL_LOG(INFO, "%s: " fmt "\n", __func__, ## __VA_ARGS__);
#define BT_WARN(fmt, ...) BLE_NPL_LOG(WARN, "%s: " fmt "\n", __func__, ## __VA_ARGS__);
#define BT_ERR(fmt, ...) BLE_NPL_LOG(ERROR, "%s: " fmt "\n", __func__, ## __VA_ARGS__);
#define BT_GATT_ERR(_att_err) (-(_att_err))

typedef ble_addr_t bt_addr_le_t;
Expand Down
4 changes: 3 additions & 1 deletion nimble/host/mesh/src/access.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_ACCESS_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_ACCESS_LOG
#include <nimble/nimble_npl_log.h>

#include <errno.h>
#include <stdlib.h>
Expand Down
3 changes: 2 additions & 1 deletion nimble/host/mesh/src/adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_ADV_LOG
#define BLE_NPL_LOG_MODULE BLE_MESH_ADV_LOG
#include <nimble/nimble_npl_log.h>

#include "mesh/mesh.h"
#include "host/ble_hs_adv.h"
Expand Down
4 changes: 2 additions & 2 deletions nimble/host/mesh/src/adv_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#define MESH_LOG_MODULE BLE_MESH_ADV_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_ADV_LOG
#include <nimble/nimble_npl_log.h>

#include "adv.h"
#include "net.h"
Expand Down
3 changes: 2 additions & 1 deletion nimble/host/mesh/src/adv_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#define MESH_LOG_MODULE BLE_MESH_ADV_LOG
#define BLE_NPL_LOG_MODULE BLE_MESH_ADV_LOG
#include <nimble/nimble_npl_log.h>

#include "adv.h"
#include "net.h"
Expand Down
4 changes: 3 additions & 1 deletion nimble/host/mesh/src/aes-ccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

#define BLE_NPL_LOG_MODULE BLE_MESH_LOG
#include <nimble/nimble_npl_log.h>

#include "crypto.h"
#define MESH_LOG_MODULE BLE_MESH_LOG

static inline void xor16(uint8_t *dst, const uint8_t *a, const uint8_t *b)
{
Expand Down
7 changes: 3 additions & 4 deletions nimble/host/mesh/src/app_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

#define BLE_NPL_LOG_MODULE BLE_MESH_LOG
#include <nimble/nimble_npl_log.h>

#include <string.h>
#include <stdlib.h>
#include "mesh/mesh.h"
Expand All @@ -21,10 +24,6 @@
#include "access.h"
#include "subnet.h"

#define MESH_LOG_MODULE BLE_MESH_LOG

#include "log/log.h"

/* Tracking of what storage changes are pending for App Keys. We track this in
* a separate array here instead of within the respective bt_mesh_app_key
* struct itselve, since once a key gets deleted its struct becomes invalid
Expand Down
5 changes: 4 additions & 1 deletion nimble/host/mesh/src/beacon.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_BEACON_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_BEACON_LOG
#include <nimble/nimble_npl_log.h>


#include <errno.h>
#include <assert.h>
Expand Down
5 changes: 3 additions & 2 deletions nimble/host/mesh/src/cdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

#define MESH_LOG_MODULE BLE_MESH_LOG
#include "log/log.h"
#define BLE_NPL_LOG_MODULE BLE_MESH_LOG
#include <nimble/nimble_npl_log.h>

#include <stdlib.h>

#include "cdb_priv.h"
Expand Down
6 changes: 3 additions & 3 deletions nimble/host/mesh/src/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

#define BLE_NPL_LOG_MODULE BLE_MESH_LOG
#include <nimble/nimble_npl_log.h>

#include "mesh/mesh.h"
#include "mesh_priv.h"
#include "net.h"
Expand All @@ -15,9 +18,6 @@
#include "cfg.h"
#include "mesh/glue.h"

#define MESH_LOG_MODULE BLE_MESH_LOG
#include "log/log.h"

/* Miscellaneous configuration server model states */
struct cfg_val {
uint8_t net_transmit;
Expand Down
5 changes: 4 additions & 1 deletion nimble/host/mesh/src/cfg_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_MODEL_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_MODEL_LOG
#include <nimble/nimble_npl_log.h>

#if MYNEWT_VAL(BLE_MESH_CFG_CLI)

#include "mesh/mesh.h"
Expand Down
4 changes: 3 additions & 1 deletion nimble/host/mesh/src/cfg_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_MODEL_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_MODEL_LOG
#include <nimble/nimble_npl_log.h>

#include <string.h>
#include <errno.h>
Expand Down
4 changes: 3 additions & 1 deletion nimble/host/mesh/src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_CRYPTO_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_CRYPTO_LOG
#include <nimble/nimble_npl_log.h>

#include <string.h>
#include <stdbool.h>
Expand Down
5 changes: 4 additions & 1 deletion nimble/host/mesh/src/friend.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_FRIEND_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_FRIEND_LOG
#include <nimble/nimble_npl_log.h>


#if MYNEWT_VAL(BLE_MESH_FRIEND)

Expand Down
4 changes: 3 additions & 1 deletion nimble/host/mesh/src/glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_LOG
#include <nimble/nimble_npl_log.h>

#include "mesh/glue.h"
#include "adv.h"
Expand Down
4 changes: 3 additions & 1 deletion nimble/host/mesh/src/health_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_MODEL_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_MODEL_LOG
#include <nimble/nimble_npl_log.h>

#include <string.h>
#include <errno.h>
Expand Down
4 changes: 3 additions & 1 deletion nimble/host/mesh/src/health_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_MODEL_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_MODEL_LOG
#include <nimble/nimble_npl_log.h>

#include <string.h>
#include <errno.h>
Expand Down
3 changes: 2 additions & 1 deletion nimble/host/mesh/src/heartbeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#define MESH_LOG_MODULE BLE_MESH_HEARTBEAT_LOG
#define BLE_NPL_LOG_MODULE BLE_MESH_HEARTBEAT_LOG
#include <nimble/nimble_npl_log.h>

#include "mesh_priv.h"
#include "net.h"
Expand Down
4 changes: 3 additions & 1 deletion nimble/host/mesh/src/lpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_LOW_POWER_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_LOW_POWER_LOG
#include <nimble/nimble_npl_log.h>

#if MYNEWT_VAL(BLE_MESH_LOW_POWER)

Expand Down
4 changes: 3 additions & 1 deletion nimble/host/mesh/src/mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_LOG
#include <nimble/nimble_npl_log.h>

#include <stdbool.h>
#include <errno.h>
Expand Down
4 changes: 3 additions & 1 deletion nimble/host/mesh/src/model_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_MODEL_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_MODEL_LOG
#include <nimble/nimble_npl_log.h>

#include "mesh/mesh.h"
#include "mesh/model_cli.h"
Expand Down
5 changes: 4 additions & 1 deletion nimble/host/mesh/src/model_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_MODEL_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_MODEL_LOG
#include <nimble/nimble_npl_log.h>


#include "mesh/mesh.h"
#include "mesh/model_srv.h"
Expand Down
4 changes: 3 additions & 1 deletion nimble/host/mesh/src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_NET_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_NET_LOG
#include <nimble/nimble_npl_log.h>

#include <string.h>
#include <errno.h>
Expand Down
4 changes: 3 additions & 1 deletion nimble/host/mesh/src/pb_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_PROV_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_PROV_LOG
#include <nimble/nimble_npl_log.h>

#include <stdint.h>
#include <string.h>
Expand Down
3 changes: 2 additions & 1 deletion nimble/host/mesh/src/pb_gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#define MESH_LOG_MODULE BLE_MESH_PROV_LOG
#define BLE_NPL_LOG_MODULE BLE_MESH_PROV_LOG
#include <nimble/nimble_npl_log.h>

#include "mesh/mesh.h"
#include "prov.h"
Expand Down
3 changes: 2 additions & 1 deletion nimble/host/mesh/src/pb_gatt_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#define MESH_LOG_MODULE BLE_MESH_PROV_LOG
#define BLE_NPL_LOG_MODULE BLE_MESH_PROV_LOG
#include <nimble/nimble_npl_log.h>

#include "mesh_priv.h"
#include "adv.h"
Expand Down
4 changes: 3 additions & 1 deletion nimble/host/mesh/src/prov.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
*/

#include "syscfg/syscfg.h"
#define MESH_LOG_MODULE BLE_MESH_PROV_LOG

#define BLE_NPL_LOG_MODULE BLE_MESH_PROV_LOG
#include <nimble/nimble_npl_log.h>

#include <errno.h>

Expand Down
Loading

0 comments on commit da4e2f0

Please sign in to comment.