Skip to content
Snippets Groups Projects
Commit 15e030fc authored by schneider's avatar schneider
Browse files

change(ble): correctly handle connections in ble uart

parent a9bd7192
Branches
Tags
1 merge request!446Initial MicroPython BLE support (GATTS)
#include "uart.h"
#include "cccd.h"
#include "modules/modules.h"
#include "wsf_types.h"
#include "util/bstream.h"
#include "att_api.h"
#include "dm_api.h"
#include "app_api.h"
#include "FreeRTOS.h"
#include "timers.h"
......@@ -99,8 +102,6 @@ static const attsAttr_t uartAttrCfgList[] = {
};
dmConnId_t active_connection = 0;
static uint8_t UARTWriteCback(
dmConnId_t connId,
uint16_t handle,
......@@ -110,7 +111,6 @@ static uint8_t UARTWriteCback(
uint8_t *pValue,
attsAttr_t *pAttr
) {
active_connection = connId;
static bool was_r = false;
int i;
......@@ -129,27 +129,32 @@ static int ble_uart_lasttick = 0;
void ble_uart_flush(void)
{
if (ble_uart_buf_tx_fill > 0) {
if (active_connection) {
if (ble_uart_buf_tx_fill == 0) {
return;
}
dmConnId_t connId = AppConnIsOpen();
if (connId != DM_CONN_ID_NONE) {
if (AttsCccEnabled(connId, UART_TX_CH_CCC_IDX)) {
int x = xTaskGetTickCount() - ble_uart_lasttick;
if (x < 100) {
/*
* TODO: Ugly hack if we already
* sent something recently.
* Use ATTS_HANDLE_VALUE_CNF instead.
*/
* TODO: Ugly hack if we already
* sent something recently.
* Use ATTS_HANDLE_VALUE_CNF instead.
*/
vTaskDelay(100 - x);
}
AttsHandleValueNtf(
active_connection,
connId,
UART_TX_HDL,
ble_uart_buf_tx_fill,
ble_uart_tx_buf
);
ble_uart_lasttick = xTaskGetTickCount();
}
ble_uart_buf_tx_fill = 0;
}
ble_uart_buf_tx_fill = 0;
}
void ble_uart_write_char(uint8_t c)
......@@ -185,3 +190,14 @@ void bleuart_init(void)
/* Add the UART service */
AttsAddGroup(&uartCfgGroup);
}
void UartProcMsg(wsfMsgHdr_t *pMsg)
{
if (pMsg->event == ATTS_HANDLE_VALUE_CNF) {
if (pMsg->status == ATT_SUCCESS) {
}
}
if (pMsg->event == DM_CONN_OPEN_IND) {
ble_uart_buf_tx_fill = 0;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment