Skip to content

Commit f5acd5e

Browse files
Deomid Ryabkovcesantabot
authored andcommitted
ESP32 IDF update
CL: ESP32 IDF update to espressif/esp-idf@22fbcd2 PUBLISHED_FROM=42db3f5053c36dc4f9e0118a21808b0752b2bf3f
1 parent c0d3a17 commit f5acd5e

File tree

5 files changed

+40
-17
lines changed

5 files changed

+40
-17
lines changed

include/mgos_bt.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,17 @@
2828
extern "C" {
2929
#endif
3030

31+
enum mgos_bt_addr_type {
32+
MGOS_BT_ADDR_TYPE_NONE = 0,
33+
MGOS_BT_ADDR_TYPE_PUBLIC = 1,
34+
MGOS_BT_ADDR_TYPE_RANDOM_STATIC = 2,
35+
MGOS_BT_ADDR_TYPE_RANDOM_NON_RESOLVABLE = 3,
36+
MGOS_BT_ADDR_TYPE_RANDOM_RESOLVABLE = 4,
37+
};
38+
3139
struct mgos_bt_addr {
3240
uint8_t addr[6];
41+
enum mgos_bt_addr_type type;
3342
};
3443

3544
/* Binary-equivalent to the ESP32 esp_bt_uuid_t */
@@ -43,13 +52,15 @@ struct mgos_bt_uuid {
4352
} __attribute__((packed));
4453

4554
/* Each byte is transformed into 3 bytes: "XX:", and last byte into "XX\0" */
46-
#define MGOS_BT_ADDR_STR_LEN (sizeof(struct mgos_bt_addr) * 3)
55+
#define MGOS_BT_ADDR_STR_LEN (sizeof(struct mgos_bt_addr) * 3 + 2 /* type */)
4756
#define MGOS_BT_UUID_STR_LEN (sizeof(struct mgos_bt_uuid) * 3)
4857
#define MGOS_BT_DEV_NAME_LEN 32
4958

5059
#define BT_ADDR_STR_LEN MGOS_BT_ADDR_STR_LEN
5160

52-
const char *mgos_bt_addr_to_str(const struct mgos_bt_addr *addr, char *out);
61+
#define MGOS_BT_ADDR_STRINGIFY_TYPE 1
62+
const char *mgos_bt_addr_to_str(const struct mgos_bt_addr *addr, uint32_t flags,
63+
char *out);
5364
bool mgos_bt_addr_from_str(const struct mg_str addr_str,
5465
struct mgos_bt_addr *addr);
5566
int mgos_bt_addr_cmp(const struct mgos_bt_addr *a,

src/esp32/esp32_bt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include "mgos_sys_config.h"
3737

3838
const char *esp32_bt_addr_to_str(const esp_bd_addr_t addr, char *out) {
39-
return mgos_bt_addr_to_str((const struct mgos_bt_addr *) &addr[0], out);
39+
return mgos_bt_addr_to_str((const struct mgos_bt_addr *) &addr[0], 0, out);
4040
}
4141

4242
bool esp32_bt_addr_from_str(const struct mg_str addr_str, esp_bd_addr_t addr) {

src/esp32/esp32_bt_gap.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,17 @@ static void esp32_gap_ev_handler(esp_gap_ble_cb_event_t ev,
203203
char buf[BT_ADDR_STR_LEN], hexbuf[MGOS_BT_GAP_ADV_DATA_LEN * 2 + 1];
204204
const struct mg_str name = mgos_bt_gap_parse_name(p->ble_adv);
205205
cs_to_hex(hexbuf, p->ble_adv, MGOS_BT_GAP_ADV_DATA_LEN);
206-
LOG(LL_DEBUG,
207-
("SCAN_RESULT %d %s [%.*s] rssi %d srl %d adl %d [%s]",
208-
p->search_evt, esp32_bt_addr_to_str(p->bda, buf), (int) name.len,
209-
name.p, p->rssi, p->scan_rsp_len, p->adv_data_len, hexbuf));
210206
memcpy(data.addr.addr, p->bda, sizeof(data.addr.addr));
207+
data.addr.type = (enum mgos_bt_addr_type)(p->ble_addr_type + 1);
211208
memcpy(data.adv_data, p->ble_adv, sizeof(data.adv_data));
212209
memcpy(data.scan_rsp, p->ble_adv + sizeof(data.adv_data),
213210
sizeof(data.scan_rsp));
211+
LOG(LL_DEBUG,
212+
("SCAN_RESULT %d %s [%.*s] dt %d at %d et %d rssi %d "
213+
"srl %d adl %d [%s]",
214+
p->search_evt, esp32_bt_addr_to_str(p->bda, buf), (int) name.len,
215+
name.p, p->dev_type, p->ble_addr_type, p->ble_evt_type, p->rssi,
216+
p->scan_rsp_len, p->adv_data_len, hexbuf));
214217
mgos_event_trigger_schedule(MGOS_BT_GAP_EVENT_SCAN_RESULT, &data,
215218
sizeof(data));
216219
} else {

src/esp32/esp32_bt_gattc.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ bool mgos_bt_gattc_connect(const struct mgos_bt_addr *addr) {
9090
char buf[MGOS_BT_ADDR_STR_LEN];
9191
uint8_t *a = (uint8_t *) addr->addr;
9292
if (esp32_bt_is_scanning()) return false;
93-
esp_err_t err = esp_ble_gattc_open(s_gattc_if, a, true);
94-
LOG(LL_DEBUG, ("CONNECT %s: %d", esp32_bt_addr_to_str(a, buf), err));
93+
esp_err_t err = esp_ble_gattc_open(s_gattc_if, a, addr->type - 1, true);
94+
LOG(LL_DEBUG,
95+
("CONNECT %s: %d",
96+
mgos_bt_addr_to_str(addr, MGOS_BT_ADDR_STRINGIFY_TYPE, buf), err));
9597
return err == ESP_OK;
9698
}
9799

@@ -182,10 +184,10 @@ static void esp32_bt_gattc_ev(esp_gattc_cb_event_t ev, esp_gatt_if_t iface,
182184
di.chr = *(struct mgos_bt_uuid *) &el.uuid;
183185
di.handle = el.char_handle;
184186
di.prop = el.properties;
185-
LOG(LL_DEBUG,
186-
(" discovery: %s %s %s %hhx", mgos_bt_addr_to_str(&di.addr, buf1),
187-
mgos_bt_uuid_to_str(&di.svc, buf2),
188-
mgos_bt_uuid_to_str(&di.chr, buf3), di.prop));
187+
LOG(LL_DEBUG, (" discovery: %s %s %s %hhx",
188+
mgos_bt_addr_to_str(&di.addr, 1, buf1),
189+
mgos_bt_uuid_to_str(&di.svc, buf2),
190+
mgos_bt_uuid_to_str(&di.chr, buf3), di.prop));
189191
mgos_event_trigger_schedule(MGOS_BT_GATTC_EVENT_DISCOVERY_RESULT, &di,
190192
sizeof(di));
191193
count = 1;
@@ -373,7 +375,7 @@ static void esp32_bt_gattc_ev(esp_gattc_cb_event_t ev, esp_gatt_if_t iface,
373375
esp32_bt_addr_to_str(p->remote_bda, buf)));
374376
break;
375377
}
376-
case ESP_GATTC_READ_MUTIPLE_EVT: {
378+
case ESP_GATTC_READ_MULTIPLE_EVT: {
377379
const struct gattc_read_char_evt_param *p = &ep->read;
378380
enum cs_log_level ll = ll_from_status(p->status);
379381
LOG(ll, ("READ_MUTIPLE st %d cid %u h %u val_len %u", p->status,

src/mgos_bt.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,24 @@
2222
#include "mgos_bt_gattc.h"
2323
#include "mgos_system.h"
2424

25-
const char *mgos_bt_addr_to_str(const struct mgos_bt_addr *addr, char *out) {
25+
const char *mgos_bt_addr_to_str(const struct mgos_bt_addr *addr, uint32_t flags,
26+
char *out) {
2627
sprintf(out, "%02x:%02x:%02x:%02x:%02x:%02x", addr->addr[0], addr->addr[1],
2728
addr->addr[2], addr->addr[3], addr->addr[4], addr->addr[5]);
29+
if (flags & MGOS_BT_ADDR_STRINGIFY_TYPE) {
30+
sprintf(out + 17, ",%d", (addr->type & 7));
31+
}
2832
return out;
2933
}
3034

3135
bool mgos_bt_addr_from_str(const struct mg_str addr_str,
3236
struct mgos_bt_addr *addr) {
3337
uint8_t *p = addr->addr;
34-
return sscanf(addr_str.p, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", p,
35-
p + 1, p + 2, p + 3, p + 4, p + 5) == 6;
38+
int at = 0;
39+
int n = sscanf(addr_str.p, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx,%d", p,
40+
p + 1, p + 2, p + 3, p + 4, p + 5, &at);
41+
addr->type = (enum mgos_bt_addr_type) at;
42+
return n == 6 || n == 7;
3643
}
3744

3845
int mgos_bt_addr_cmp(const struct mgos_bt_addr *a,

0 commit comments

Comments
 (0)