1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-16 10:03:50 +01:00

sys/stdio_nimble: fiter conn_handle

This commit is contained in:
Francisco Molina 2022-03-08 12:17:36 +01:00
parent d474b8ff8a
commit fc616a9916

View File

@ -237,39 +237,44 @@ static int _gap_event_cb(struct ble_gap_event *event, void *arg)
switch (event->type) { switch (event->type) {
case BLE_GAP_EVENT_CONNECT: case BLE_GAP_EVENT_CONNECT:
_debug_printf("BLE_GAP_EVENT_CONNECT\n"); _debug_printf("BLE_GAP_EVENT_CONNECT handle: %d\n", event->connect.conn_handle);
if (event->connect.status == 0) { if (event->connect.status == 0 && _conn_handle == 0) {
_status = STDIO_NIMBLE_CONNECTED; _status = STDIO_NIMBLE_CONNECTED;
if (CONFIG_STDIO_NIMBLE_CLEAR_BUFFER_ON_CONNECT) { if (CONFIG_STDIO_NIMBLE_CLEAR_BUFFER_ON_CONNECT) {
_purge_buffer(); _purge_buffer();
} }
_conn_handle = event->connect.conn_handle;
} }
else { else if (event->connect.conn_handle == _conn_handle) {
_conn_handle = 0;
_status = STDIO_NIMBLE_DISCONNECTED; _status = STDIO_NIMBLE_DISCONNECTED;
} }
break; break;
case BLE_GAP_EVENT_DISCONNECT: case BLE_GAP_EVENT_DISCONNECT:
_debug_printf("BLE_GAP_EVENT_DISCONNECT\n"); _debug_printf("BLE_GAP_EVENT_DISCONNECT %d\n", event->disconnect.conn.conn_handle);
_status = STDIO_NIMBLE_DISCONNECTED; if (event->disconnect.conn.conn_handle == _conn_handle) {
_status = STDIO_NIMBLE_DISCONNECTED;
_conn_handle = 0;
}
break; break;
case BLE_GAP_EVENT_SUBSCRIBE: case BLE_GAP_EVENT_SUBSCRIBE:
_debug_printf("BLE_GAP_EVENT_SUBSCRIBE\n"); _debug_printf("BLE_GAP_EVENT_SUBSCRIBE %d\n", event->subscribe.conn_handle);
if (event->subscribe.attr_handle == _val_handle_stdout) { if (event->subscribe.attr_handle == _val_handle_stdout) {
if (event->subscribe.cur_indicate == 1) { if (event->subscribe.cur_indicate == 1) {
_status = STDIO_NIMBLE_SUBSCRIBED; _status = STDIO_NIMBLE_SUBSCRIBED;
_conn_handle = event->subscribe.conn_handle;
} }
else { else {
_status = STDIO_NIMBLE_CONNECTED; _status = STDIO_NIMBLE_CONNECTED;
_conn_handle = 0;
} }
} }
break; break;
case BLE_GAP_EVENT_NOTIFY_TX: case BLE_GAP_EVENT_NOTIFY_TX:
_debug_printf("BLE_GAP_EVENT_NOTIFY_TX\n"); _debug_printf("BLE_GAP_EVENT_NOTIFY_TX %d\n", event->notify_tx.conn_handle);
if (event->notify_tx.indication == 1) { if (event->notify_tx.indication == 1 && (event->notify_tx.conn_handle == _conn_handle)) {
if (event->notify_tx.status == BLE_HS_EDONE) { if (event->notify_tx.status == BLE_HS_EDONE) {
_status = STDIO_NIMBLE_SUBSCRIBED; _status = STDIO_NIMBLE_SUBSCRIBED;
} }
@ -356,9 +361,11 @@ ssize_t stdio_write(const void *buffer, size_t len)
unsigned int consumed = tsrb_add(&_tsrb_stdout, buffer, len); unsigned int consumed = tsrb_add(&_tsrb_stdout, buffer, len);
if (!ble_npl_callout_is_active(&_send_stdout_callout)) { if (_status == STDIO_NIMBLE_SUBSCRIBED || _status == STDIO_NIMBLE_SENDING) {
/* bootstrap callout */ if (!ble_npl_callout_is_active(&_send_stdout_callout)) {
ble_npl_callout_reset(&_send_stdout_callout, CALLOUT_TICKS_MS); /* bootstrap callout */
ble_npl_callout_reset(&_send_stdout_callout, CALLOUT_TICKS_MS);
}
} }
return consumed; return consumed;