Skip to content

Commit 022e026

Browse files
committed
Basic read support
1 parent 0dc0440 commit 022e026

File tree

4 files changed

+183
-61
lines changed

4 files changed

+183
-61
lines changed

include/esp32/esp32_bt.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
#include "host/ble_uuid.h"
2323
#include "nimble/ble.h"
2424

25-
#define MGOS_BT_DEV_NAME_LEN 32
26-
#define BT_UUID_STR_LEN (ESP_UUID_LEN_128 * 2 + ESP_UUID_LEN_128)
27-
2825
#ifdef __cplusplus
2926
extern "C" {
3027
#endif
@@ -33,9 +30,10 @@ extern "C" {
3330

3431
void mgos_bt_addr_to_esp32(const struct mgos_bt_addr *in, ble_addr_t *out);
3532
void esp32_bt_addr_to_mgos(const ble_addr_t *in, struct mgos_bt_addr *out);
33+
const char *esp32_bt_addr_to_str(const ble_addr_t *addr, char *out);
3634

3735
void mgos_bt_uuid_to_esp32(const struct mgos_bt_uuid *in, ble_uuid_any_t *out);
38-
void esp32_bt_uuid_to_mgos(const ble_uuid_any_t *in, struct mgos_bt_uuid *out);
36+
void esp32_bt_uuid_to_mgos(const ble_uuid_t *in, struct mgos_bt_uuid *out);
3937
const char *esp32_bt_uuid_to_str(const ble_uuid_t *uuid, char *out);
4038

4139
extern uint8_t own_addr_type;

include/mgos_bt.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ struct mgos_bt_uuid {
5050
};
5151

5252
/* Each byte is transformed into 3 bytes: "XX:", and last byte into "XX\0" */
53-
#define MGOS_BT_ADDR_STR_LEN (sizeof(struct mgos_bt_addr) * 3 + 2 /* type */)
54-
#define MGOS_BT_UUID_STR_LEN (sizeof(struct mgos_bt_uuid) * 3)
55-
#define MGOS_BT_DEV_NAME_LEN 32
53+
#define MGOS_BT_ADDR_STR_LEN (6 * 3 + 2 /* type */)
54+
#define MGOS_BT_UUID_STR_LEN (16 * 3)
55+
#define MGOS_BT_DEV_NAME_LEN (32)
5656

5757
#define BT_ADDR_STR_LEN MGOS_BT_ADDR_STR_LEN
5858

src/esp32/esp32_bt.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,35 @@ void esp32_bt_addr_to_mgos(const ble_addr_t *in, struct mgos_bt_addr *out) {
8181
out->addr[5] = in->val[0];
8282
}
8383

84+
const char *esp32_bt_addr_to_str(const ble_addr_t *addr, char *out) {
85+
struct mgos_bt_addr maddr;
86+
esp32_bt_addr_to_mgos(addr, &maddr);
87+
return mgos_bt_addr_to_str(&maddr, MGOS_BT_ADDR_STRINGIFY_TYPE, out);
88+
}
89+
8490
void mgos_bt_uuid_to_esp32(const struct mgos_bt_uuid *in, ble_uuid_any_t *out) {
8591
out->u.type = in->len * 8;
8692
memcpy(out->u128.value, in->uuid.uuid128, 16);
8793
}
8894

89-
void esp32_bt_uuid_to_mgos(const ble_uuid_any_t *in, struct mgos_bt_uuid *out) {
90-
out->len = in->u.type / 8;
91-
memcpy(out->uuid.uuid128, in->u128.value, 16);
95+
void esp32_bt_uuid_to_mgos(const ble_uuid_t *in, struct mgos_bt_uuid *out) {
96+
out->len = in->type / 8;
97+
switch (in->type) {
98+
case BLE_UUID_TYPE_16:
99+
out->uuid.uuid16 = ((const ble_uuid16_t *) in)->value;
100+
break;
101+
case BLE_UUID_TYPE_32:
102+
out->uuid.uuid32 = ((const ble_uuid32_t *) in)->value;
103+
break;
104+
case BLE_UUID_TYPE_128:
105+
memcpy(out->uuid.uuid128, ((const ble_uuid128_t *) in)->value, 16);
106+
break;
107+
}
92108
}
93109

94110
const char *esp32_bt_uuid_to_str(const ble_uuid_t *uuid, char *out) {
95111
struct mgos_bt_uuid uuidm;
96-
esp32_bt_uuid_to_mgos((const ble_uuid_any_t *) uuid, &uuidm);
112+
esp32_bt_uuid_to_mgos(uuid, &uuidm);
97113
return mgos_bt_uuid_to_str(&uuidm, out);
98114
}
99115

0 commit comments

Comments
 (0)