2025-06-27 00:32:57 +08:00
|
|
|
|
#ifndef BLE_DEMO_H__
|
|
|
|
|
|
#define BLE_DEMO_H__
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "stdint.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef u8
|
|
|
|
|
|
# define u8 uint8_t
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifndef u16
|
|
|
|
|
|
# define u16 uint16_t
|
|
|
|
|
|
#endif
|
|
|
|
|
|
#ifndef u32
|
|
|
|
|
|
# define u32 uint32_t
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
#define BLE_MAX_NOTICE 1
|
|
|
|
|
|
|
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 25
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
{
|
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];
|
|
|
|
|
|
uint8_t notice[BLE_MAX_NOTICE][BLE_NOTICE_LEN];
|
|
|
|
|
|
int notice_used;
|
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[30]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>洢<EFBFBD><E6B4A2>
|
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
|
|
|
|
//<2F><><EFBFBD><EFBFBD>֪ͨ<CDA8><D6AA>Ϣ
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_deal_notice(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
|
|
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EEB7B5>
|
2025-06-27 00:32:57 +08:00
|
|
|
|
int ble_get_cmd_return(ble_struct *ble,uint8_t *buff,int *buff_size);
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|