2025-06-27 00:32:57 +08:00
|
|
|
|
#ifndef BLE_DEMO_H__
|
|
|
|
|
#define BLE_DEMO_H__
|
|
|
|
|
|
|
|
|
|
#include "stdint.h"
|
|
|
|
|
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
#define BLE_MAX_LINKED 5
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD>֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
#define BLE_NOTICE_LEN 256
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
#define BLE_RETURN_LINE_LEN 512
|
|
|
|
|
|
|
|
|
|
/*******************************************************
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
֪ͨ<EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><EFBFBD>壺
|
2025-06-27 00:32:57 +08:00
|
|
|
|
------------------------------------------------------+
|
2025-07-05 19:47:28 +08:00
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> |obj_size |obj |op|data_size|data |
|
2025-06-27 00:32:57 +08:00
|
|
|
|
------------------------------------------------------+
|
2025-07-05 19:47:28 +08:00
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(byte)|1 |obj_size |1 |1 |data_size |
|
2025-06-27 00:32:57 +08:00
|
|
|
|
------------------------------------------------------+
|
|
|
|
|
|
|
|
|
|
********************************************************/
|
|
|
|
|
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
|
2025-06-27 00:32:57 +08:00
|
|
|
|
#define BLE_BUFF_LEN 512
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define BLE_UUID_TYPE_128 0x80
|
|
|
|
|
#define BLE_UUID_TYPE_32 0x20
|
|
|
|
|
#define BLE_UUID_TYPE_16 0x10
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
int buff_len;
|
|
|
|
|
int buff_used;
|
|
|
|
|
int read_ptr;
|
|
|
|
|
int save_ptr;
|
|
|
|
|
uint8_t buff[BLE_BUFF_LEN];
|
|
|
|
|
} ble_buff;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
uint8_t mac[6];
|
|
|
|
|
uint16_t conn_handle;
|
|
|
|
|
int linked;
|
|
|
|
|
ble_buff buff_recv;
|
|
|
|
|
}ble_device;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
uint8_t obj[4];
|
|
|
|
|
uint8_t obj_size;
|
|
|
|
|
uint8_t par[BLE_NOTICE_LEN];
|
|
|
|
|
int par_size;
|
|
|
|
|
}notice_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
2025-07-05 19:47:28 +08:00
|
|
|
|
char mode; //<2F><><EFBFBD><EFBFBD>ģʽ'i'<27><><EFBFBD>У<EFBFBD>'h'<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>'s'<27>ӻ<EFBFBD>
|
|
|
|
|
int linked; //<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
ble_device device[BLE_MAX_LINKED];
|
|
|
|
|
notice_t notice;
|
2025-07-05 19:47:28 +08:00
|
|
|
|
uint8_t conn_mac[6]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD>mac<61><63>ַ
|
|
|
|
|
uint8_t data_temp[BLE_BUFF_LEN]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>洢<EFBFBD><E6B4A2>
|
|
|
|
|
uint8_t return_line[BLE_RETURN_LINE_LEN]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ洢<DDB4><E6B4A2>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
void (*linked_change)(uint16_t handle,uint16_t state);
|
|
|
|
|
void (*recv_data)(uint16_t handle,uint8_t *data,int len);
|
|
|
|
|
void (*user_irq)(uint8_t *data,int len);
|
2025-07-05 19:47:28 +08:00
|
|
|
|
void *ret_event;//<2F><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
|
|
|
|
|
void *kno_event;//֪<><D6AA><EFBFBD>¼<EFBFBD>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
}ble_struct;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
|
{
|
|
|
|
|
uint8_t mac[6];
|
|
|
|
|
int8_t rssi;
|
|
|
|
|
char name[20];
|
|
|
|
|
}ble_mac_name;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//ble<6C><65>ʼ<EFBFBD><CABC>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
void ble_init(ble_struct *ble);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//bleȥ<65><C8A5>ʼ<EFBFBD><CABC>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
void ble_deinit(ble_struct *ble);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><>ȡָ<C8A1><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_get_recv_data(ble_struct *ble,uint16_t handle,uint8_t *buff,int read_len);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD><EFBFBD>ֽ綨<D6BD><E7B6A8>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_get_recv_data_by_end(ble_struct *ble,uint16_t handle,uint8_t *buff,int buff_size,uint8_t end_par);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸
|
2025-06-27 00:32:57 +08:00
|
|
|
|
ble_device *ble_find_device_by_index(ble_struct *ble,int index);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4>ı<EFBFBD><C4B1>ص<EFBFBD>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_set_callback_linked_change(ble_struct *ble,void (*linked_change)(uint16_t handle,uint16_t state));
|
2025-07-05 19:47:28 +08:00
|
|
|
|
// <20><><EFBFBD>ý<EFBFBD><C3BD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݻص<DDBB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˴˻ص<CBBB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ᱣ<EFBFBD>浽<EFBFBD><E6B5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
// <20><>ͨ<EFBFBD><CDA8> ble_get_recv_data | ble_get_recv_data_by_end <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB7><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_set_callback_recv_data(ble_struct *ble,void (*recv_data)(uint16_t handle,uint8_t *data,int len));
|
2025-07-05 19:47:28 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB>жϻص<CFBB>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_set_callback_user_irq(ble_struct *ble,void (*user_irq)(uint8_t *data,int len));
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_set_name(ble_struct *ble,char *name);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><>ȡ<EFBFBD>豸mac<61><63>ַ
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_get_mac(ble_struct *ble,uint8_t mac[6]);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_reboot(ble_struct *ble);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD>uuid
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_set_uuid(ble_struct *ble,uint8_t sub,uint8_t type,uint8_t *uuid);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD>/<2F>ر<EFBFBD><D8B1><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_set_data_transport(ble_struct *ble,uint8_t power);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_send_data(ble_struct *ble,uint16_t handle,uint8_t *buff,int len);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD>ӻ<EFBFBD>ģʽ
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_set_slave(ble_struct *ble);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>ģʽ
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_set_host(ble_struct *ble);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>Ĵӻ<C4B4>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_connect_by_mac(ble_struct *ble,uint8_t mac[6]);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F>Ͽ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>Ĵӻ<C4B4>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_discon_by_mac(ble_struct *ble,uint8_t mac[6]);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//ɨ<><C9A8>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_scan(ble_struct *ble,ble_mac_name mac[32],int *mac_num);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_user_cmd_set(ble_struct *ble,uint8_t *tx,int tx_len);
|
|
|
|
|
|
2025-07-05 19:47:28 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ݣ<EFBFBD>rx_len<65><6E>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3>ȣ<EFBFBD>ʧ<EFBFBD>ܷ<EFBFBD><DCB7><EFBFBD>0
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_user_cmd_get(ble_struct *ble,uint8_t *tx,int tx_len,uint8_t *rx,int *rx_len);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|