Skip to content

Commit

Permalink
ESP32 IDF update
Browse files Browse the repository at this point in the history
CL: ESP32 IDF update to espressif/esp-idf@22fbcd2

PUBLISHED_FROM=42db3f5053c36dc4f9e0118a21808b0752b2bf3f
  • Loading branch information
Deomid Ryabkov authored and cesantabot committed Apr 20, 2018
1 parent c0d3a17 commit f5acd5e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
15 changes: 13 additions & 2 deletions include/mgos_bt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/esp32/esp32_bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 7 additions & 4 deletions src/esp32/esp32_bt_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 9 additions & 7 deletions src/esp32/esp32_bt_gattc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions src/mgos_bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f5acd5e

Please sign in to comment.