From f5acd5efa35081803a12b23e772715daa53ce58d Mon Sep 17 00:00:00 2001 From: Deomid Ryabkov Date: Fri, 20 Apr 2018 15:13:38 +0100 Subject: [PATCH] ESP32 IDF update CL: ESP32 IDF update to https://github.com/espressif/esp-idf/commit/22fbcd276c90049b906702fde1744fd24d438be3 PUBLISHED_FROM=42db3f5053c36dc4f9e0118a21808b0752b2bf3f --- include/mgos_bt.h | 15 +++++++++++++-- src/esp32/esp32_bt.c | 2 +- src/esp32/esp32_bt_gap.c | 11 +++++++---- src/esp32/esp32_bt_gattc.c | 16 +++++++++------- src/mgos_bt.c | 13 ++++++++++--- 5 files changed, 40 insertions(+), 17 deletions(-) diff --git a/include/mgos_bt.h b/include/mgos_bt.h index cf64024..d03592c 100644 --- a/include/mgos_bt.h +++ b/include/mgos_bt.h @@ -28,8 +28,17 @@ extern "C" { #endif +enum mgos_bt_addr_type { + MGOS_BT_ADDR_TYPE_NONE = 0, + MGOS_BT_ADDR_TYPE_PUBLIC = 1, + MGOS_BT_ADDR_TYPE_RANDOM_STATIC = 2, + MGOS_BT_ADDR_TYPE_RANDOM_NON_RESOLVABLE = 3, + MGOS_BT_ADDR_TYPE_RANDOM_RESOLVABLE = 4, +}; + struct mgos_bt_addr { uint8_t addr[6]; + enum mgos_bt_addr_type type; }; /* Binary-equivalent to the ESP32 esp_bt_uuid_t */ @@ -43,13 +52,15 @@ struct mgos_bt_uuid { } __attribute__((packed)); /* Each byte is transformed into 3 bytes: "XX:", and last byte into "XX\0" */ -#define MGOS_BT_ADDR_STR_LEN (sizeof(struct mgos_bt_addr) * 3) +#define MGOS_BT_ADDR_STR_LEN (sizeof(struct mgos_bt_addr) * 3 + 2 /* type */) #define MGOS_BT_UUID_STR_LEN (sizeof(struct mgos_bt_uuid) * 3) #define MGOS_BT_DEV_NAME_LEN 32 #define BT_ADDR_STR_LEN MGOS_BT_ADDR_STR_LEN -const char *mgos_bt_addr_to_str(const struct mgos_bt_addr *addr, char *out); +#define MGOS_BT_ADDR_STRINGIFY_TYPE 1 +const char *mgos_bt_addr_to_str(const struct mgos_bt_addr *addr, uint32_t flags, + char *out); bool mgos_bt_addr_from_str(const struct mg_str addr_str, struct mgos_bt_addr *addr); int mgos_bt_addr_cmp(const struct mgos_bt_addr *a, diff --git a/src/esp32/esp32_bt.c b/src/esp32/esp32_bt.c index f783500..b580d7a 100644 --- a/src/esp32/esp32_bt.c +++ b/src/esp32/esp32_bt.c @@ -36,7 +36,7 @@ #include "mgos_sys_config.h" const char *esp32_bt_addr_to_str(const esp_bd_addr_t addr, char *out) { - return mgos_bt_addr_to_str((const struct mgos_bt_addr *) &addr[0], out); + return mgos_bt_addr_to_str((const struct mgos_bt_addr *) &addr[0], 0, out); } bool esp32_bt_addr_from_str(const struct mg_str addr_str, esp_bd_addr_t addr) { diff --git a/src/esp32/esp32_bt_gap.c b/src/esp32/esp32_bt_gap.c index 9f31f5c..1964dad 100644 --- a/src/esp32/esp32_bt_gap.c +++ b/src/esp32/esp32_bt_gap.c @@ -203,14 +203,17 @@ static void esp32_gap_ev_handler(esp_gap_ble_cb_event_t ev, char buf[BT_ADDR_STR_LEN], hexbuf[MGOS_BT_GAP_ADV_DATA_LEN * 2 + 1]; const struct mg_str name = mgos_bt_gap_parse_name(p->ble_adv); cs_to_hex(hexbuf, p->ble_adv, MGOS_BT_GAP_ADV_DATA_LEN); - LOG(LL_DEBUG, - ("SCAN_RESULT %d %s [%.*s] rssi %d srl %d adl %d [%s]", - p->search_evt, esp32_bt_addr_to_str(p->bda, buf), (int) name.len, - name.p, p->rssi, p->scan_rsp_len, p->adv_data_len, hexbuf)); memcpy(data.addr.addr, p->bda, sizeof(data.addr.addr)); + data.addr.type = (enum mgos_bt_addr_type)(p->ble_addr_type + 1); memcpy(data.adv_data, p->ble_adv, sizeof(data.adv_data)); memcpy(data.scan_rsp, p->ble_adv + sizeof(data.adv_data), sizeof(data.scan_rsp)); + LOG(LL_DEBUG, + ("SCAN_RESULT %d %s [%.*s] dt %d at %d et %d rssi %d " + "srl %d adl %d [%s]", + p->search_evt, esp32_bt_addr_to_str(p->bda, buf), (int) name.len, + name.p, p->dev_type, p->ble_addr_type, p->ble_evt_type, p->rssi, + p->scan_rsp_len, p->adv_data_len, hexbuf)); mgos_event_trigger_schedule(MGOS_BT_GAP_EVENT_SCAN_RESULT, &data, sizeof(data)); } else { diff --git a/src/esp32/esp32_bt_gattc.c b/src/esp32/esp32_bt_gattc.c index 64267be..c68bd2c 100644 --- a/src/esp32/esp32_bt_gattc.c +++ b/src/esp32/esp32_bt_gattc.c @@ -90,8 +90,10 @@ bool mgos_bt_gattc_connect(const struct mgos_bt_addr *addr) { char buf[MGOS_BT_ADDR_STR_LEN]; uint8_t *a = (uint8_t *) addr->addr; if (esp32_bt_is_scanning()) return false; - esp_err_t err = esp_ble_gattc_open(s_gattc_if, a, true); - LOG(LL_DEBUG, ("CONNECT %s: %d", esp32_bt_addr_to_str(a, buf), err)); + esp_err_t err = esp_ble_gattc_open(s_gattc_if, a, addr->type - 1, true); + LOG(LL_DEBUG, + ("CONNECT %s: %d", + mgos_bt_addr_to_str(addr, MGOS_BT_ADDR_STRINGIFY_TYPE, buf), err)); return err == ESP_OK; } @@ -182,10 +184,10 @@ static void esp32_bt_gattc_ev(esp_gattc_cb_event_t ev, esp_gatt_if_t iface, di.chr = *(struct mgos_bt_uuid *) &el.uuid; di.handle = el.char_handle; di.prop = el.properties; - LOG(LL_DEBUG, - (" discovery: %s %s %s %hhx", mgos_bt_addr_to_str(&di.addr, buf1), - mgos_bt_uuid_to_str(&di.svc, buf2), - mgos_bt_uuid_to_str(&di.chr, buf3), di.prop)); + LOG(LL_DEBUG, (" discovery: %s %s %s %hhx", + mgos_bt_addr_to_str(&di.addr, 1, buf1), + mgos_bt_uuid_to_str(&di.svc, buf2), + mgos_bt_uuid_to_str(&di.chr, buf3), di.prop)); mgos_event_trigger_schedule(MGOS_BT_GATTC_EVENT_DISCOVERY_RESULT, &di, sizeof(di)); count = 1; @@ -373,7 +375,7 @@ static void esp32_bt_gattc_ev(esp_gattc_cb_event_t ev, esp_gatt_if_t iface, esp32_bt_addr_to_str(p->remote_bda, buf))); break; } - case ESP_GATTC_READ_MUTIPLE_EVT: { + case ESP_GATTC_READ_MULTIPLE_EVT: { const struct gattc_read_char_evt_param *p = &ep->read; enum cs_log_level ll = ll_from_status(p->status); LOG(ll, ("READ_MUTIPLE st %d cid %u h %u val_len %u", p->status, diff --git a/src/mgos_bt.c b/src/mgos_bt.c index 99023b4..03017bc 100644 --- a/src/mgos_bt.c +++ b/src/mgos_bt.c @@ -22,17 +22,24 @@ #include "mgos_bt_gattc.h" #include "mgos_system.h" -const char *mgos_bt_addr_to_str(const struct mgos_bt_addr *addr, char *out) { +const char *mgos_bt_addr_to_str(const struct mgos_bt_addr *addr, uint32_t flags, + char *out) { sprintf(out, "%02x:%02x:%02x:%02x:%02x:%02x", addr->addr[0], addr->addr[1], addr->addr[2], addr->addr[3], addr->addr[4], addr->addr[5]); + if (flags & MGOS_BT_ADDR_STRINGIFY_TYPE) { + sprintf(out + 17, ",%d", (addr->type & 7)); + } return out; } bool mgos_bt_addr_from_str(const struct mg_str addr_str, struct mgos_bt_addr *addr) { uint8_t *p = addr->addr; - return sscanf(addr_str.p, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", p, - p + 1, p + 2, p + 3, p + 4, p + 5) == 6; + int at = 0; + int n = sscanf(addr_str.p, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx,%d", p, + p + 1, p + 2, p + 3, p + 4, p + 5, &at); + addr->type = (enum mgos_bt_addr_type) at; + return n == 6 || n == 7; } int mgos_bt_addr_cmp(const struct mgos_bt_addr *a,