added le_central_register_handler, started connect/disconnect

This commit is contained in:
mila@ringwald.ch 2013-11-11 22:51:29 +00:00
parent 63dbd537f8
commit 42fe45bd0c
2 changed files with 39 additions and 7 deletions

View File

@ -45,19 +45,30 @@
#include <stdlib.h>
#include <string.h>
#include <btstack/run_loop.h>
#include <btstack/hci_cmds.h>
#include "config.h"
#include "ble_client.h"
#include "ad_parser.h"
#include "debug.h"
#include "btstack_memory.h"
#include "hci.h"
#include "hci_dump.h"
#include "l2cap.h"
#include "att.h"
#include "ad_parser.h"
void (*le_central_callback)(le_central_event_t * event);
static void dummy_notify(le_central_event_t* event){}
void le_central_register_handler(void (*le_callback)(le_central_event_t* event)){
le_central_callback = dummy_notify;
if (le_callback != NULL){
le_central_callback = le_callback;
}
}
static void hexdump2(void *data, int size){
int i;
@ -100,6 +111,29 @@ void gatt_client_stop_scan(){
gatt_client_run();
}
void le_central_connect(le_peripheral_t *context, uint8_t addr_type, bd_addr_t addr){
//TODO: add peripheral to list
if (!hci_can_send_packet_now(HCI_COMMAND_DATA_PACKET)) return;
hci_send_cmd(&hci_le_create_connection,
1000, // scan interval: 625 ms
1000, // scan interval: 625 ms
0, // don't use whitelist
0, // peer address type: public
addr, // remote bd addr
addr_type, // random or public
80, // conn interval min
80, // conn interval max (3200 * 0.625)
0, // conn latency
2000, // supervision timeout
0, // min ce length
1000 // max ce length
);
}
/*
void le_central_cancel_connect(le_peripheral_t *context){
hci_send_cmd(&hci_le_create_connection_cancel);
}*/
static void dump_ad_event(ad_event_t e){
printf("evt-type %u, addr-type %u, addr %s, rssi %u, length adv %u, data: ", e.event_type,

View File

@ -81,17 +81,15 @@ typedef struct le_characteristic{
} le_characteristic_t;
void (*le_central_callback)(le_central_event_t * event);
void le_central_init();
// void le_central_register_handler( btstack_packet_handler_t handler);
void le_central_register_handler(void (*le_callback)(le_central_event_t * event));
void le_central_start_scan();
// creates one event per found peripheral device
// { type (8), addr_type (8), addr(48), rssi(8), ad_len(8), ad_data(ad_len*8) }
void le_central_stop_scan();
uint16_t le_central_connect(le_peripheral_t *context, uint8_t addr_type, bd_addr_t addr);
void le_central_connect(le_peripheral_t *context, uint8_t addr_type, bd_addr_t addr);
void le_central_cancel_connect(le_peripheral_t *context);
void le_central_get_services(le_peripheral_t *context);