diff --git a/epicardium/ble/epic_ble_api.c b/epicardium/ble/epic_ble_api.c index b37ca2aa8e86519a482bf389490166442fc6114f..726d26a949ece4dbefbebc4d7e9f0b8b8c9e818e 100644 --- a/epicardium/ble/epic_ble_api.c +++ b/epicardium/ble/epic_ble_api.c @@ -5,6 +5,7 @@ #include "api/interrupt-sender.h" #include "wsf_buf.h" +#include "app_api.h" #include "svc_core.h" #include "FreeRTOS.h" @@ -92,6 +93,16 @@ void ble_epic_dm_api_event(dmEvt_t *dm_event) } } +void epic_ble_close_connection(uint8_t connId) +{ + AppConnClose(connId); +} + +int epic_ble_is_connection_open(void) +{ + return AppConnIsOpen(); +} + int epic_ble_set_device_name(const uint8_t *buf, uint16_t len) { return epic_ble_atts_set_attr(GAP_DN_HDL, buf, len); diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index 12f7b86fbd4c172e432c3d40d63202b7bb87b266..f8bb96cc4e7f6bf1d5226f6446bbe06bedcd3721 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -177,6 +177,8 @@ typedef _Bool bool; #define API_BLE_GET_ATT_WRITE 0x1BD #define API_BLE_FREE_ATT_WRITE 0x1BE #define API_BLE_ATTS_DYN_ADD_CHARACTERISTIC 0x1BF +#define API_BLE_CLOSE_CONNECTION 0x170 +#define API_BLE_IS_CONNECTION_OPEN 0x171 #define API_BLE_SET_DEVICE_NAME 0x172 #define API_BLE_GET_DEVICE_NAME 0x173 #define API_BLE_GET_ADDRESS 0x174 @@ -2607,7 +2609,8 @@ API(API_BLE_ATTS_HANDLE_VALUE_IND, int epic_ble_atts_handle_value_ind(uint8_t co API(API_BLE_ATTS_SET_BUFFER, int epic_ble_atts_set_buffer(uint16_t value_handle, size_t len, bool append)); API(API_BLE_FREE_EVENT, int epic_ble_free_event(struct epic_ble_event *e)); - +API(API_BLE_CLOSE_CONNECTION, void epic_ble_close_connection(uint8_t connId)); +API(API_BLE_IS_CONNECTION_OPEN, int epic_ble_is_connection_open(void)); API(API_BLE_SET_DEVICE_NAME, int epic_ble_set_device_name(const uint8_t *buf, uint16_t len)); API(API_BLE_GET_DEVICE_NAME, int epic_ble_get_device_name(uint8_t **buf, uint16_t *len)); API(API_BLE_GET_ADDRESS, void epic_ble_get_address(uint8_t *addr)); diff --git a/pycardium/modules/modbluetooth_card10.c b/pycardium/modules/modbluetooth_card10.c index f64eab4cb1ba8152d79d5b903705309d2b5e7c19..adcc21efe781b9416c6a6dd29c0b5e2a68a7010b 100644 --- a/pycardium/modules/modbluetooth_card10.c +++ b/pycardium/modules/modbluetooth_card10.c @@ -352,10 +352,12 @@ int mp_bluetooth_gap_advertise_start( const uint8_t *sr_data, size_t sr_data_len ) { - // Temporarily going to scanner drops the connection + // Dropping any current connection starts advertising on the card10 // TODO: modify the advertising data - epic_ble_set_mode(false, true); - epic_ble_set_mode(false, false); + int connection = epic_ble_is_connection_open(); + if (connection > 0) { + epic_ble_close_connection(connection); + } return 0; } @@ -631,7 +633,7 @@ int mp_bluetooth_gatts_set_buffer(uint16_t value_handle, size_t len, bool append // Disconnect from a central or peripheral. int mp_bluetooth_gap_disconnect(uint16_t conn_handle) { - raise(); + epic_ble_close_connection(conn_handle); return 0; }