2013-11-09 23:48:36 +00:00
|
|
|
/*
|
2013-11-14 15:55:07 +00:00
|
|
|
* Copyright (C) 2011-2013 by BlueKitchen GmbH
|
2013-11-09 23:48:36 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the copyright holders nor the names of
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
* 4. This software may not be used in a commercial product
|
|
|
|
* without an explicit license granted by the copyright holder.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
|
|
|
|
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//
|
|
|
|
// BLE Client
|
|
|
|
//
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: Supports only a single connection
|
|
|
|
|
2014-01-19 16:30:17 +00:00
|
|
|
#ifndef __BLE_CLIENT_H
|
|
|
|
#define __BLE_CLIENT_H
|
2013-11-09 23:48:36 +00:00
|
|
|
|
2014-01-19 16:45:57 +00:00
|
|
|
#include "btstack-config.h"
|
2013-11-09 23:48:36 +00:00
|
|
|
|
|
|
|
#include <btstack/utils.h>
|
2014-04-28 21:47:59 +00:00
|
|
|
#include "gatt_client.h"
|
2013-11-09 23:48:36 +00:00
|
|
|
|
|
|
|
#if defined __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-11-29 21:42:15 +00:00
|
|
|
#define LE_CENTRAL_MAX_INCLUDE_DEPTH 3
|
2013-11-09 23:48:36 +00:00
|
|
|
|
2014-04-28 21:47:59 +00:00
|
|
|
|
|
|
|
//*************** le central client
|
2013-11-09 23:48:36 +00:00
|
|
|
|
|
|
|
typedef struct ad_event {
|
|
|
|
uint8_t type;
|
|
|
|
uint8_t event_type;
|
|
|
|
uint8_t address_type;
|
|
|
|
bd_addr_t address;
|
|
|
|
uint8_t rssi;
|
|
|
|
uint8_t length;
|
|
|
|
uint8_t * data;
|
|
|
|
} ad_event_t;
|
|
|
|
|
2014-04-25 14:25:33 +00:00
|
|
|
typedef enum{
|
2014-04-25 18:45:17 +00:00
|
|
|
P_IDLE,
|
2013-11-14 11:23:33 +00:00
|
|
|
P_W2_CONNECT,
|
|
|
|
P_W4_CONNECTED,
|
2013-11-14 15:55:07 +00:00
|
|
|
P_CONNECTED,
|
2014-04-25 10:46:42 +00:00
|
|
|
P_W2_CANCEL_CONNECT,
|
|
|
|
P_W4_CONNECT_CANCELLED,
|
|
|
|
P_W2_DISCONNECT,
|
2014-04-25 14:25:33 +00:00
|
|
|
P_W4_DISCONNECTED
|
|
|
|
} le_central_state_t;
|
|
|
|
|
2014-04-25 19:36:10 +00:00
|
|
|
typedef struct le_central{
|
2013-11-14 11:23:33 +00:00
|
|
|
linked_item_t item;
|
2014-04-25 19:36:10 +00:00
|
|
|
le_central_state_t le_central_state;
|
2014-04-28 21:47:59 +00:00
|
|
|
|
2013-11-14 11:23:33 +00:00
|
|
|
uint8_t address_type;
|
|
|
|
bd_addr_t address;
|
2013-11-10 23:40:05 +00:00
|
|
|
uint16_t handle;
|
2014-04-25 14:29:32 +00:00
|
|
|
} le_central_t;
|
2014-02-28 22:34:08 +00:00
|
|
|
|
2014-04-25 19:36:10 +00:00
|
|
|
typedef struct le_central_connection_complete_event{
|
|
|
|
uint8_t type;
|
|
|
|
le_central_t * device;
|
|
|
|
uint8_t status;
|
|
|
|
} le_central_connection_complete_event_t;
|
|
|
|
|
2013-11-09 23:48:36 +00:00
|
|
|
|
2014-04-28 21:47:59 +00:00
|
|
|
//*************** gatt client
|
2014-03-17 21:54:51 +00:00
|
|
|
|
|
|
|
|
2014-03-06 15:49:48 +00:00
|
|
|
|
2014-04-25 15:08:51 +00:00
|
|
|
void ble_client_init();
|
2014-04-28 21:09:35 +00:00
|
|
|
void le_central_init();
|
|
|
|
|
2014-04-28 21:47:59 +00:00
|
|
|
void le_central_register_handler(void (*le_callback)(le_event_t * event));
|
|
|
|
void ble_client_register_packet_handler(void (*le_callback)(le_event_t * event));
|
2013-11-09 23:48:36 +00:00
|
|
|
|
2013-11-28 10:54:41 +00:00
|
|
|
le_command_status_t le_central_start_scan();
|
2013-11-10 23:40:05 +00:00
|
|
|
// creates one event per found peripheral device
|
|
|
|
// { type (8), addr_type (8), addr(48), rssi(8), ad_len(8), ad_data(ad_len*8) }
|
2013-11-28 10:54:41 +00:00
|
|
|
le_command_status_t le_central_stop_scan();
|
2013-11-09 23:48:36 +00:00
|
|
|
|
2014-04-25 19:36:10 +00:00
|
|
|
le_command_status_t le_central_connect(le_central_t *context, uint8_t addr_type, bd_addr_t addr);
|
|
|
|
le_command_status_t le_central_disconnect(le_central_t *context);
|
2013-11-09 23:48:36 +00:00
|
|
|
|
2013-11-29 10:19:43 +00:00
|
|
|
|
2013-11-09 23:48:36 +00:00
|
|
|
#if defined __cplusplus
|
|
|
|
}
|
2014-01-19 16:30:17 +00:00
|
|
|
#endif
|
|
|
|
#endif // __BLE_CLIENT_H
|