Skip to content

Commit fb7c900

Browse files
committed
pbdrv/bluetooth: RFCOMM socket API.
This implements the complete RFCOMM socket API, including listen, connect, send and recv. This does not contain python bindings for the API. Tested via manual ping-pong testing for both listen and connect, against a Windows desktop. EV3<->EV3 not yet tested.
1 parent 172feea commit fb7c900

File tree

20 files changed

+1464
-29
lines changed

20 files changed

+1464
-29
lines changed

.vscode/c_cpp_properties.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"gcc",
8080
"MICROPY_MODULE_FROZEN_MPY",
8181
"MICROPY_ROM_TEXT_COMPRESSION",
82+
"HAVE_UMM_MALLOC=1"
8283
],
8384
"compilerArgs": [
8485
"-Wall",
@@ -286,7 +287,8 @@
286287
],
287288
"defines": [
288289
"MICROPY_MODULE_FROZEN_MPY",
289-
"MICROPY_ROM_TEXT_COMPRESSION"
290+
"MICROPY_ROM_TEXT_COMPRESSION",
291+
"HAVE_UMM_MALLOC=1"
290292
],
291293
"compilerArgs": [
292294
"-mthumb",
@@ -404,7 +406,8 @@
404406
],
405407
"defines": [
406408
"MICROPY_MODULE_FROZEN_MPY",
407-
"MICROPY_USE_READLINE=1"
409+
"MICROPY_USE_READLINE=1",
410+
"HAVE_UMM_MALLOC=1",
408411
],
409412
"compilerPath": "/usr/bin/gcc",
410413
"cStandard": "c11",

bricks/_common/common.mk

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,16 @@ BTSTACK_BLE_SRC_C += $(addprefix lib/btstack/src/ble/,\
414414
sm.c \
415415
)
416416

417+
BTSTACK_CLASSIC_SRC_C = $(addprefix lib/btstack/src/classic/,\
418+
btstack_link_key_db_memory.c \
419+
rfcomm.c \
420+
sdp_client.c \
421+
sdp_client_rfcomm.c \
422+
sdp_server.c \
423+
sdp_util.c \
424+
spp_server.c \
425+
)
426+
417427
BTSTACK_SRC_C += $(addprefix lib/btstack/chipset/cc256x/,\
418428
btstack_chipset_cc256x.c \
419429
)
@@ -517,7 +527,7 @@ SRC_STM32_USB_DEV += $(addprefix lib/pbio/drv/usb/stm32_usbd/,\
517527
SRC_UMM_MALLOC = lib/umm_malloc/src/umm_malloc.c
518528

519529
ifeq ($(PB_LIB_UMM_MALLOC),1)
520-
CFLAGS += -I$(PBTOP)/lib/umm_malloc/src
530+
CFLAGS += -I$(PBTOP)/lib/umm_malloc/src -DHAVE_UMM_MALLOC=1
521531
endif
522532

523533
# NXT OS
@@ -571,6 +581,7 @@ ifeq ($(PB_LIB_BTSTACK),1)
571581
ifneq ($(CI_MODE),1)
572582
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_SRC_C:.c=.o))
573583
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_BLE_SRC_C:.c=.o))
584+
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_CLASSIC_SRC_C:.c=.o))
574585
$(BUILD)/lib/btstack/%.o: CFLAGS += -Wno-error
575586
endif
576587
endif

lib/pbio/drv/bluetooth/bluetooth.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ void pbdrv_bluetooth_cancel_operation_request(void) {
548548
#if PBDRV_CONFIG_BLUETOOTH_NUM_CLASSIC_CONNECTIONS
549549
// Revisit: Cancel all.
550550
pbdrv_bluetooth_classic_task_context.cancel = true;
551+
pbdrv_bluetooth_rfcomm_cancel_connection();
551552
#endif // PBDRV_CONFIG_BLUETOOTH_NUM_CLASSIC_CONNECTIONS
552553
}
553554

@@ -684,6 +685,10 @@ pbio_error_t pbdrv_bluetooth_close_user_tasks(pbio_os_state_t *state, pbio_os_ti
684685
// Requests peripheral operations to cancel, if they support it.
685686
pbdrv_bluetooth_cancel_operation_request();
686687

688+
#if PBDRV_CONFIG_BLUETOOTH_NUM_CLASSIC_CONNECTIONS
689+
pbdrv_bluetooth_rfcomm_disconnect_all();
690+
#endif // PBDRV_CONFIG_BLUETOOTH_NUM_CLASSIC_CONNECTIONS
691+
687692
for (peri_index = 0; peri_index < PBDRV_CONFIG_BLUETOOTH_NUM_PERIPHERALS; peri_index++) {
688693
peri = pbdrv_bluetooth_peripheral_get_by_index(peri_index);
689694

lib/pbio/drv/bluetooth/bluetooth.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ typedef struct {
9797

9898
pbio_error_t pbdrv_bluetooth_inquiry_scan_func(pbio_os_state_t *state, void *context);
9999

100+
// The following functions are defined in each Bluetooth implementation that
101+
// supports RFCOMM sockets.
102+
103+
// Cancels all pending connection attempts. Called e.g. when the user interrupts
104+
// execution to drop into the debug REPL.
105+
void pbdrv_bluetooth_rfcomm_cancel_connection();
106+
107+
// Disconnects all active RFCOMM connections and cleans up all sockets. Called
108+
// during user program termination.
109+
void pbdrv_bluetooth_rfcomm_disconnect_all();
110+
100111
#endif // PBDRV_CONFIG_BLUETOOTH
101112

102113
#endif // _INTERNAL_PBDRV_BLUETOOTH_H_

0 commit comments

Comments
 (0)