Skip to content

Commit bc06174

Browse files
author
Victor Tchistiak
committed
20190916 - cleanup: remove static vars, add/use constants, fix typos
1 parent dcefa81 commit bc06174

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

libraries/BluetoothSerial/src/BluetoothSerial.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,11 @@ static EventGroupHandle_t _spp_event_group = NULL;
5353
static boolean secondConnectionAttempt;
5454
static esp_spp_cb_t * custom_spp_callback = NULL;
5555

56-
#define SPP_TAG "BluetoothSerial"
57-
static const esp_spp_sec_t sec_mask = ESP_SPP_SEC_AUTHENTICATE;
58-
static const esp_spp_role_t role_master = ESP_SPP_ROLE_MASTER;
56+
#define INQ_LEN 30;
57+
#define INQ_NUM_RSPS 0;
5958
static esp_bd_addr_t _peer_bd_addr;
60-
static uint8_t peer_bdname_len;
61-
static char peer_bdname[ESP_BT_GAP_MAX_BDNAME_LEN + 1];
62-
static const esp_bt_inq_mode_t inq_mode = ESP_BT_INQ_MODE_GENERAL_INQUIRY;
63-
static const uint8_t inq_len = 30;
64-
static const uint8_t inq_num_rsps = 0;
6559
static char _remote_name[ESP_BT_GAP_MAX_BDNAME_LEN + 1];
6660
static bool _isRemoteAddressSet;
67-
static esp_bd_addr_t _remote_address;
6861
static bool _isMaster;
6962
static esp_bt_pin_code_t _pin_code;
7063
static int _pin_len;
@@ -295,7 +288,7 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
295288
log_i("ESP_SPP_DISCOVERY_COMP_EVT");
296289
if (param->disc_comp.status == ESP_SPP_SUCCESS) {
297290
log_i("ESP_SPP_DISCOVERY_COMP_EVT: spp connect to remote");
298-
esp_spp_connect(sec_mask, role_master, param->disc_comp.scn[0], _peer_bd_addr);
291+
esp_spp_connect(ESP_SPP_SEC_AUTHENTICATE, ESP_SPP_ROLE_MASTER, param->disc_comp.scn[0], _peer_bd_addr);
299292
}
300293
break;
301294
case ESP_SPP_OPEN_EVT://Client connection open
@@ -325,8 +318,9 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
325318
switch(event){
326319
case ESP_BT_GAP_DISC_RES_EVT:
327320
log_i("ESP_BT_GAP_DISC_RES_EVT");
328-
esp_log_buffer_hex(SPP_TAG, param->disc_res.bda, ESP_BD_ADDR_LEN);
329321
for (int i = 0; i < param->disc_res.num_prop; i++){
322+
uint8_t peer_bdname_len;
323+
peer_bdname[ESP_BT_GAP_MAX_BDNAME_LEN + 1];
330324
if (param->disc_res.prop[i].type == ESP_BT_GAP_DEV_PROP_EIR
331325
&& get_name_from_eir((uint8_t*)param->disc_res.prop[i].val, peer_bdname, &peer_bdname_len)){
332326
log_v("ESP_BT_GAP_DISC_RES_EVT : EIR : %s", peer_bdname);
@@ -366,7 +360,6 @@ static void esp_bt_gap_cb(esp_bt_gap_cb_event_t event, esp_bt_gap_cb_param_t *pa
366360
case ESP_BT_GAP_AUTH_CMPL_EVT:{
367361
if (param->auth_cmpl.stat == ESP_BT_STATUS_SUCCESS) {
368362
log_v("authentication success: %s", param->auth_cmpl.device_name);
369-
esp_log_buffer_hex(SPP_TAG, param->auth_cmpl.bda, ESP_BD_ADDR_LEN);
370363
} else {
371364
log_e("authentication failed, status:%d", param->auth_cmpl.stat);
372365
}
@@ -675,7 +668,7 @@ bool BluetoothSerial::connect(String remoteName)
675668
_remote_name[ESP_BT_GAP_MAX_BDNAME_LEN] = 0;
676669
log_i("master : remoteName");
677670
// will first resolve name to address
678-
return (esp_bt_gap_start_discovery(inq_mode, inq_len, inq_num_rsps) == ESP_OK);
671+
return (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS) == ESP_OK);
679672
}
680673

681674
bool BluetoothSerial::connect(uint8_t remoteAddress[])
@@ -702,7 +695,7 @@ bool BluetoothSerial::connect()
702695
} else if (_remote_name[0]) {
703696
log_i("master : remoteName");
704697
// will resolve name to address first - it may take a while
705-
return (esp_bt_gap_start_discovery(inq_mode, inq_len, inq_num_rsps) == ESP_OK);
698+
return (esp_bt_gap_start_discovery(ESP_BT_INQ_MODE_GENERAL_INQUIRY, INQ_LEN, INQ_NUM_RSPS) == ESP_OK);
706699
} else {
707700
log_e("Neither Remote name nor address was provided");
708701
}
@@ -725,15 +718,15 @@ bool BluetoothSerial::connected() {
725718
bool BluetoothSerial::isReady(bool checkMaster)
726719
{
727720
if (checkMaster && !_isMaster) {
728-
log_e("Master mode is not active. Call begin(localName, true) to enanbe Master mode");
721+
log_e("Master mode is not active. Call begin(localName, true) to enable Master mode");
729722
return false;
730723
}
731724
// btStarted() is not sufficient to indicate ESP_SPP_INIT_EVT is complete
732725
if (_isInitializing) {
733726
int retry = 10;
734727
do {
735728
delay(500);
736-
log_i("waiting for intialization to complete...");
729+
log_i("waiting for initialization to complete...");
737730
} while(!_isInitialized && retry-- > 0);
738731
}
739732
if (!_isInitialized) {

0 commit comments

Comments
 (0)