mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 03:35:20 +00:00
app tries to send timer packet on RFCOMM credit or HCI packet sent event
This commit is contained in:
parent
8623207ae3
commit
7b668ea992
@ -28,7 +28,7 @@ CORE = \
|
||||
COMMON = \
|
||||
../src/hal_uart_dma.c \
|
||||
${BTSTACK_ROOT}/chipset-cc256x/bt_control_cc256x.c \
|
||||
${BTSTACK_ROOT}/chipset-cc256x/bluetooth_init_cc2564_2.5.c \
|
||||
${BTSTACK_ROOT}/chipset-cc256x/bluetooth_init_cc2560_2.42.c \
|
||||
${BTSTACK_ROOT}/src/hci.c \
|
||||
${BTSTACK_ROOT}/src/hci_cmds.c \
|
||||
${BTSTACK_ROOT}/src/hci_dump.c \
|
||||
|
@ -33,14 +33,37 @@
|
||||
#define HEARTBEAT_PERIOD_MS 1000
|
||||
|
||||
static uint8_t rfcomm_channel_nr = 1;
|
||||
static uint16_t rfcomm_channel_id;
|
||||
static uint16_t rfcomm_channel_id = 0;
|
||||
static uint8_t spp_service_buffer[100];
|
||||
static timer_source_t heartbeat;
|
||||
|
||||
static int real_counter = 0;
|
||||
static int counter_to_send = 0;
|
||||
|
||||
enum STATE {INIT, W4_CONNECTION, W4_CHANNEL_COMPLETE, ACTIVE} ;
|
||||
enum STATE state = INIT;
|
||||
|
||||
static void tryToSend(void){
|
||||
if (!rfcomm_channel_id) return;
|
||||
if (real_counter < counter_to_send) return;
|
||||
|
||||
char lineBuffer[30];
|
||||
sprintf(lineBuffer, "BTstack counter %04u\n\r", counter_to_send);
|
||||
printf(lineBuffer);
|
||||
int err = rfcomm_send_internal(rfcomm_channel_id, (uint8_t*) lineBuffer, strlen(lineBuffer));
|
||||
|
||||
switch (err){
|
||||
case 0:
|
||||
counter_to_send++;
|
||||
break;
|
||||
case BTSTACK_ACL_BUFFERS_FULL:
|
||||
break;
|
||||
default:
|
||||
printf("rfcomm_send_internal() -> err %d\n\r", err);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Bluetooth logic
|
||||
static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||
bd_addr_t event_addr;
|
||||
@ -97,36 +120,33 @@ static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size)
|
||||
break;
|
||||
|
||||
case ACTIVE:
|
||||
if (event != RFCOMM_EVENT_CHANNEL_CLOSED) break;
|
||||
|
||||
rfcomm_channel_id = 0;
|
||||
state = W4_CONNECTION;
|
||||
break;
|
||||
|
||||
switch(event){
|
||||
case DAEMON_EVENT_HCI_PACKET_SENT:
|
||||
case RFCOMM_EVENT_CREDITS:
|
||||
tryToSend();
|
||||
break;
|
||||
case RFCOMM_EVENT_CHANNEL_CLOSED:
|
||||
rfcomm_channel_id = 0;
|
||||
state = W4_CONNECTION;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void run_loop_register_timer(timer_source_t *timer, uint16_t period){
|
||||
run_loop_set_timer(timer, period);
|
||||
run_loop_add_timer(timer);
|
||||
}
|
||||
|
||||
static void timer_handler(timer_source_t *ts){
|
||||
|
||||
if (rfcomm_channel_id){
|
||||
static int counter = 0;
|
||||
char lineBuffer[30];
|
||||
sprintf(lineBuffer, "BTstack counter %04u\n\r", ++counter);
|
||||
printf(lineBuffer);
|
||||
int err = rfcomm_send_internal(rfcomm_channel_id, (uint8_t*) lineBuffer, strlen(lineBuffer));
|
||||
if (err) {
|
||||
printf("rfcomm_send_internal -> error %d", err);
|
||||
}
|
||||
}
|
||||
|
||||
// re-register timer
|
||||
real_counter++;
|
||||
run_loop_register_timer(ts, HEARTBEAT_PERIOD_MS);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user