Skip to content

Commit 6a13a3b

Browse files
committed
main: clean up log outputs
1 parent fb1fb2d commit 6a13a3b

File tree

15 files changed

+173
-215
lines changed

15 files changed

+173
-215
lines changed

main/inc/user/ble_app.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
#ifndef INC_USER_BLE_APP_H_
99
#define INC_USER_BLE_APP_H_
1010

11-
#include "esp_gap_ble_api.h"
12-
13-
extern esp_ble_adv_params_t adv_params;
11+
extern void ble_gap_start_advertising(void);
1412

1513
extern void ble_app_init(void);
1614

main/inc/user/ble_gatts.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ typedef struct gatts_profile_inst {
3232
esp_bt_uuid_t descr_uuid;
3333
} gatts_profile_inst_t;
3434

35-
extern gatts_profile_inst_t gatts_profile_tbl[];
36-
37-
extern void gatts_ota_send_notification(const char *data, uint32_t len);
35+
extern gatts_profile_inst_t gatts_profile_tbl[PROFILE_IDX_MAX];
3836

3937
extern void ble_gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
4038

main/inc/user/bt_app_core.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,18 @@
1212

1313
#define BT_APP_SIG_WORK_DISPATCH (0x01)
1414

15-
/**
16-
* @brief handler for the dispatched work
17-
*/
1815
typedef void (*bt_app_cb_t)(uint16_t event, void *param);
1916

20-
/* message to be sent */
2117
typedef struct {
2218
uint16_t sig; /*!< signal to bt_app_task */
2319
uint16_t event; /*!< message event id */
2420
bt_app_cb_t cb; /*!< context switch callback */
2521
void *param; /*!< parameter area needs to be last */
2622
} bt_app_msg_t;
2723

28-
/**
29-
* @brief parameter deep-copy function to be customized
30-
*/
3124
typedef void (*bt_app_copy_cb_t)(bt_app_msg_t *msg, void *p_dest, void *p_src);
3225

33-
/**
34-
* @brief work dispatcher for the application task
35-
*/
36-
bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, int param_len, bt_app_copy_cb_t p_copy_cback);
37-
38-
void bt_app_task_start_up(void);
26+
extern bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, int param_len, bt_app_copy_cb_t p_copy_cback);
27+
extern void bt_app_task_start_up(void);
3928

4029
#endif /* INC_USER_BT_APP_CORE_H_ */

main/inc/user/bt_av.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,8 @@
1616
extern esp_bd_addr_t a2d_remote_bda;
1717
extern unsigned int a2d_sample_rate;
1818

19-
/**
20-
* @brief callback function for A2DP sink
21-
*/
22-
void bt_app_a2d_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param);
23-
24-
/**
25-
* @brief callback function for A2DP sink audio data stream
26-
*/
27-
void bt_app_a2d_data_cb(const uint8_t *data, uint32_t len);
28-
29-
/**
30-
* @brief callback function for AVRCP controller
31-
*/
32-
void bt_app_avrc_ct_cb(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param);
19+
extern void bt_app_avrc_ct_cb(esp_avrc_ct_cb_event_t event, esp_avrc_ct_cb_param_t *param);
20+
extern void bt_app_a2d_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param);
21+
extern void bt_app_a2d_data_cb(const uint8_t *data, uint32_t len);
3322

3423
#endif /* INC_USER_BT_AV_H_*/

main/src/board/ws2812.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void ws2812_init_board(void)
3737
led_strip_config_t strip_config = LED_STRIP_DEFAULT_CONFIG(WS2812_X * WS2812_Y, RMT_CHANNEL_0);
3838
strip = led_strip_new_rmt_ws2812(&strip_config);
3939
if (!strip) {
40-
ESP_LOGE(TAG, "initialization failed");
40+
ESP_LOGE(TAG, "initialization failed.");
4141
} else {
4242
ESP_LOGI(TAG, "initialized, din: %d", CONFIG_WS2812_DIN_PIN);
4343
}

main/src/user/audio_player.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static void audio_player_task(void *pvParameters)
9090
xEventGroupSetBits(user_event_group, AUDIO_PLAYER_IDLE_BIT);
9191
xEventGroupClearBits(user_event_group, AUDIO_PLAYER_RUN_BIT);
9292

93-
ESP_LOGE(TAG, "allocate memory failed.");
93+
ESP_LOGE(TAG, "failed to allocate memory");
9494

9595
playback_pending = false;
9696

@@ -142,7 +142,6 @@ static void audio_player_task(void *pvParameters)
142142
void audio_player_play_file(mp3_file_t idx)
143143
{
144144
if (idx >= sizeof(mp3_file_ptr) / sizeof(mp3_file_ptr[0])) {
145-
ESP_LOGE(TAG, "invalid file index");
146145
return;
147146
}
148147

main/src/user/audio_render.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ static void audio_render_task(void *pvParameter)
4747
if (remain >= FFT_BLOCK_SIZE) {
4848
delay = 0;
4949

50-
data = (uint8_t *)xRingbufferReceiveUpTo(audio_buff, &size, portMAX_DELAY, FFT_BLOCK_SIZE);
50+
data = xRingbufferReceiveUpTo(audio_buff, &size, portMAX_DELAY, FFT_BLOCK_SIZE);
5151
} else if (remain > 0) {
5252
delay = 0;
5353

54-
data = (uint8_t *)xRingbufferReceiveUpTo(audio_buff, &size, portMAX_DELAY, remain);
54+
data = xRingbufferReceiveUpTo(audio_buff, &size, portMAX_DELAY, remain);
5555
} else {
5656
if (++delay <= 10) {
5757
vTaskDelay(256000 / a2d_sample_rate / portTICK_RATE_MS);

main/src/user/ble_app.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define BLE_APP_TAG "ble_app"
2020
#define BLE_GAP_TAG "ble_gap"
2121

22-
esp_ble_adv_params_t adv_params = {
22+
static esp_ble_adv_params_t adv_params = {
2323
.adv_int_min = 0x20,
2424
.adv_int_max = 0x40,
2525
.adv_type = ADV_TYPE_IND,
@@ -35,14 +35,13 @@ static void ble_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_p
3535
esp_ble_gap_start_advertising(&adv_params);
3636
break;
3737
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT:
38-
// advertising start complete event to indicate advertising start successfully or failed
3938
if (param->adv_start_cmpl.status != ESP_BT_STATUS_SUCCESS) {
40-
ESP_LOGE(BLE_GAP_TAG, "advertising start failed");
39+
ESP_LOGE(BLE_GAP_TAG, "failed to start advertising");
4140
}
4241
break;
4342
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT:
4443
if (param->adv_stop_cmpl.status != ESP_BT_STATUS_SUCCESS) {
45-
ESP_LOGE(BLE_GAP_TAG, "advertising stop failed");
44+
ESP_LOGE(BLE_GAP_TAG, "failed to stop advertising");
4645
}
4746
break;
4847
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
@@ -54,7 +53,7 @@ static void ble_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_p
5453
}
5554
}
5655

57-
static void gap_config_adv_data(const char *name)
56+
static void ble_gap_config_adv_data(const char *name)
5857
{
5958
size_t len = strlen(name);
6059
uint8_t raw_adv_data[len + 5];
@@ -71,10 +70,15 @@ static void gap_config_adv_data(const char *name)
7170

7271
esp_err_t raw_adv_ret = esp_ble_gap_config_adv_data_raw(raw_adv_data, sizeof(raw_adv_data));
7372
if (raw_adv_ret) {
74-
ESP_LOGE(BLE_GAP_TAG, "config raw adv data failed, error code = 0x%x ", raw_adv_ret);
73+
ESP_LOGE(BLE_GAP_TAG, "failed to config raw adv data: %d", raw_adv_ret);
7574
}
7675
}
7776

77+
void ble_gap_start_advertising(void)
78+
{
79+
esp_ble_gap_start_advertising(&adv_params);
80+
}
81+
7882
void ble_app_init(void)
7983
{
8084
xEventGroupSetBits(user_event_group, BLE_GATTS_IDLE_BIT);
@@ -88,7 +92,7 @@ void ble_app_init(void)
8892

8993
ESP_ERROR_CHECK(esp_ble_gatt_set_local_mtu(ESP_GATT_MAX_MTU_SIZE));
9094

91-
gap_config_adv_data(CONFIG_BT_NAME);
95+
ble_gap_config_adv_data(CONFIG_BT_NAME);
9296

9397
ESP_LOGI(BLE_APP_TAG, "started.");
9498
}

main/src/user/ble_gatts.c

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,11 @@ static const char *s_gatts_conn_state_str[] = {"disconnected", "connected"};
4343
static void profile_ota_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
4444
static void profile_vfx_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param);
4545

46-
/* one gatt-based profile one app_id and one gatts_if, this array will store the gatts_if returned by ESP_GATTS_REG_EVT */
4746
gatts_profile_inst_t gatts_profile_tbl[PROFILE_IDX_MAX] = {
4847
[PROFILE_IDX_OTA] = { .gatts_cb = profile_ota_event_handler, .gatts_if = ESP_GATT_IF_NONE },
4948
[PROFILE_IDX_VFX] = { .gatts_cb = profile_vfx_event_handler, .gatts_if = ESP_GATT_IF_NONE }
5049
};
5150

52-
void gatts_ota_send_notification(const char *data, uint32_t len)
53-
{
54-
esp_ble_gatts_send_indicate(gatts_profile_tbl[PROFILE_IDX_OTA].gatts_if,
55-
gatts_profile_tbl[PROFILE_IDX_OTA].conn_id,
56-
gatts_profile_tbl[PROFILE_IDX_OTA].char_handle,
57-
len, (uint8_t *)data, false);
58-
}
59-
6051
static void profile_ota_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
6152
{
6253
switch (event) {
@@ -118,7 +109,7 @@ static void profile_ota_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t
118109
NULL,
119110
NULL);
120111
if (add_char_ret) {
121-
ESP_LOGE(GATTS_OTA_TAG, "add char failed, error code =%x", add_char_ret);
112+
ESP_LOGE(GATTS_OTA_TAG, "failed to add char: %d", add_char_ret);
122113
}
123114
break;
124115
case ESP_GATTS_ADD_INCL_SRVC_EVT:
@@ -134,7 +125,7 @@ static void profile_ota_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t
134125
NULL,
135126
NULL);
136127
if (add_descr_ret) {
137-
ESP_LOGE(GATTS_OTA_TAG, "add char descr failed, error code =%x", add_descr_ret);
128+
ESP_LOGE(GATTS_OTA_TAG, "failed to add char descr: %d", add_descr_ret);
138129
}
139130
break;
140131
case ESP_GATTS_ADD_CHAR_DESCR_EVT:
@@ -146,35 +137,37 @@ static void profile_ota_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t
146137
break;
147138
case ESP_GATTS_STOP_EVT:
148139
break;
149-
case ESP_GATTS_CONNECT_EVT: {
140+
case ESP_GATTS_CONNECT_EVT:
150141
xEventGroupClearBits(user_event_group, BLE_GATTS_IDLE_BIT);
151142

152143
esp_ble_gap_stop_advertising();
153144

154-
uint8_t *bda = param->connect.remote_bda;
155145
ESP_LOGI(GATTS_OTA_TAG, "GATTS connection state: %s, [%02x:%02x:%02x:%02x:%02x:%02x]",
156-
s_gatts_conn_state_str[1], bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
146+
s_gatts_conn_state_str[1],
147+
param->connect.remote_bda[0], param->connect.remote_bda[1],
148+
param->connect.remote_bda[2], param->connect.remote_bda[3],
149+
param->connect.remote_bda[4], param->connect.remote_bda[5]);
157150

158151
gatts_profile_tbl[PROFILE_IDX_OTA].conn_id = param->connect.conn_id;
159152

160153
break;
161-
}
162-
case ESP_GATTS_DISCONNECT_EVT: {
163-
uint8_t *bda = param->connect.remote_bda;
154+
case ESP_GATTS_DISCONNECT_EVT:
164155
ESP_LOGI(GATTS_OTA_TAG, "GATTS connection state: %s, [%02x:%02x:%02x:%02x:%02x:%02x]",
165-
s_gatts_conn_state_str[0], bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
156+
s_gatts_conn_state_str[0],
157+
param->connect.remote_bda[0], param->connect.remote_bda[1],
158+
param->connect.remote_bda[2], param->connect.remote_bda[3],
159+
param->connect.remote_bda[4], param->connect.remote_bda[5]);
166160

167161
ota_end();
168162

169163
EventBits_t uxBits = xEventGroupGetBits(user_event_group);
170164
if (!(uxBits & OS_PWR_RESET_BIT) && !(uxBits & OS_PWR_SLEEP_BIT)) {
171-
esp_ble_gap_start_advertising(&adv_params);
165+
ble_gap_start_advertising();
172166
}
173167

174168
xEventGroupSetBits(user_event_group, BLE_GATTS_IDLE_BIT);
175169

176170
break;
177-
}
178171
case ESP_GATTS_CONF_EVT:
179172
case ESP_GATTS_OPEN_EVT:
180173
case ESP_GATTS_CANCEL_OPEN_EVT:
@@ -285,7 +278,7 @@ static void profile_vfx_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t
285278
app_setenv("AIN_INIT_CFG", &ain_mode, sizeof(ain_mode_t));
286279
#endif
287280
} else {
288-
ESP_LOGE(GATTS_VFX_TAG, "command 0x%02X error", param->write.value[0]);
281+
ESP_LOGE(GATTS_VFX_TAG, "invalid command: 0x%02X", param->write.value[0]);
289282
}
290283
break;
291284
default:
@@ -320,7 +313,7 @@ static void profile_vfx_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t
320313
NULL,
321314
NULL);
322315
if (add_char_ret) {
323-
ESP_LOGE(GATTS_VFX_TAG, "add char failed, error code =%x", add_char_ret);
316+
ESP_LOGE(GATTS_VFX_TAG, "failed to add char: %d", add_char_ret);
324317
}
325318
break;
326319
case ESP_GATTS_ADD_INCL_SRVC_EVT:
@@ -336,7 +329,7 @@ static void profile_vfx_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t
336329
NULL,
337330
NULL);
338331
if (add_descr_ret) {
339-
ESP_LOGE(GATTS_VFX_TAG, "add char descr failed, error code =%x", add_descr_ret);
332+
ESP_LOGE(GATTS_VFX_TAG, "failed to add char descr: %d", add_descr_ret);
340333
}
341334
break;
342335
case ESP_GATTS_ADD_CHAR_DESCR_EVT:
@@ -348,22 +341,23 @@ static void profile_vfx_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t
348341
break;
349342
case ESP_GATTS_STOP_EVT:
350343
break;
351-
case ESP_GATTS_CONNECT_EVT: {
352-
uint8_t *bda = param->connect.remote_bda;
344+
case ESP_GATTS_CONNECT_EVT:
353345
ESP_LOGI(GATTS_VFX_TAG, "GATTS connection state: %s, [%02x:%02x:%02x:%02x:%02x:%02x]",
354-
s_gatts_conn_state_str[1], bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
346+
s_gatts_conn_state_str[1],
347+
param->connect.remote_bda[0], param->connect.remote_bda[1],
348+
param->connect.remote_bda[2], param->connect.remote_bda[3],
349+
param->connect.remote_bda[4], param->connect.remote_bda[5]);
355350

356351
gatts_profile_tbl[PROFILE_IDX_VFX].conn_id = param->connect.conn_id;
357352

358353
break;
359-
}
360-
case ESP_GATTS_DISCONNECT_EVT: {
361-
uint8_t *bda = param->connect.remote_bda;
354+
case ESP_GATTS_DISCONNECT_EVT:
362355
ESP_LOGI(GATTS_VFX_TAG, "GATTS connection state: %s, [%02x:%02x:%02x:%02x:%02x:%02x]",
363-
s_gatts_conn_state_str[0], bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
364-
356+
s_gatts_conn_state_str[0],
357+
param->connect.remote_bda[0], param->connect.remote_bda[1],
358+
param->connect.remote_bda[2], param->connect.remote_bda[3],
359+
param->connect.remote_bda[4], param->connect.remote_bda[5]);
365360
break;
366-
}
367361
case ESP_GATTS_CONF_EVT:
368362
case ESP_GATTS_OPEN_EVT:
369363
case ESP_GATTS_CANCEL_OPEN_EVT:
@@ -377,23 +371,17 @@ static void profile_vfx_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t
377371

378372
void ble_gatts_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t *param)
379373
{
380-
/* if event is register event, store the gatts_if for each profile */
381374
if (event == ESP_GATTS_REG_EVT) {
382375
if (param->reg.status == ESP_GATT_OK) {
383376
gatts_profile_tbl[param->reg.app_id].gatts_if = gatts_if;
384377
} else {
385-
ESP_LOGE(BLE_GATTS_TAG, "reg app failed, app_id %04x, status %d",
386-
param->reg.app_id,
387-
param->reg.status);
378+
ESP_LOGE(BLE_GATTS_TAG, "reg app failed, app_id: %04x, status: %d", param->reg.app_id, param->reg.status);
388379
return;
389380
}
390381
}
391382

392-
/* if the gatts_if equal to profile A, call profile A cb handler,
393-
* so here call each profile's callback */
394383
for (int idx = 0; idx < PROFILE_IDX_MAX; idx++) {
395-
if (gatts_if == ESP_GATT_IF_NONE || /* ESP_GATT_IF_NONE, not specify a certain gatt_if, need to call every profile cb function */
396-
gatts_if == gatts_profile_tbl[idx].gatts_if) {
384+
if (gatts_if == ESP_GATT_IF_NONE || gatts_if == gatts_profile_tbl[idx].gatts_if) {
397385
if (gatts_profile_tbl[idx].gatts_cb) {
398386
gatts_profile_tbl[idx].gatts_cb(event, gatts_if, param);
399387
}

main/src/user/bt_app.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
esp_bd_addr_t last_remote_bda = {0};
2929

30-
/* event for handler "bt_app_hdl_stack_up */
3130
enum {
3231
BT_APP_EVT_STACK_UP = 0
3332
};
@@ -39,7 +38,7 @@ static void bt_app_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
3938
if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
4039
ESP_LOGI(BT_GAP_TAG, "authentication success: %s", param->auth_cmpl.device_name);
4140
} else {
42-
ESP_LOGE(BT_GAP_TAG, "authentication failed, status: %d", param->auth_cmpl.stat);
41+
ESP_LOGE(BT_GAP_TAG, "authentication failed: %d", param->auth_cmpl.stat);
4342
}
4443
break;
4544
default:
@@ -84,7 +83,7 @@ static void bt_app_hdl_stack_evt(uint16_t event, void *p_param)
8483

8584
break;
8685
default:
87-
ESP_LOGE(BT_APP_TAG, "%s unhandled evt %d", __func__, event);
86+
ESP_LOGW(BT_APP_TAG, "unhandled evt: %d", event);
8887
break;
8988
}
9089
}

0 commit comments

Comments
 (0)