资源简介
由于bluez并没有提供官方可用的C语言 gatt库,所以我对源码结构做了些修改,把用到的ap编译成静态库,使用前阅读readme.txt
详情参考https://blog.csdn.net/u010659887/article/details/85329276
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include “bluetooth/bluetooth.h“
#include “bluetooth/l2cap.h“
#include “bluetooth/hci.h“
#include “bluetooth/hci_lib.h“
#include “bluetooth/sdp.h“
#include “uuid.h“
#include “src/shared/mainloop.h“
#include “src/shared/util.h“
#include “src/shared/att.h“
#include “src/shared/queue.h“
#include “src/shared/gatt-db.h“
#include “src/shared/gatt-client.h“
#define COLOR_OFF “\x1B[0m“
#define COLOR_RED “\x1B[0;91m“
#define COLOR_GREEN “\x1B[0;92m“
#define COLOR_YELLOW “\x1B[0;93m“
#define COLOR_BLUE “\x1B[0;94m“
#define COLOR_MAGENTA “\x1B[0;95m“
#define COLOR_BOLDGRAY “\x1B[1;30m“
#define COLOR_BOLDWHITE “\x1B[1;37m“
#define ATT_CID 4
struct client {
int fd;
struct bt_att *att;
struct gatt_db *db;
struct bt_gatt_client *gatt;
unsigned int reliable_session_id;
};
//打印UUID
static void print_uuid(const bt_uuid_t *uuid)
{
char uuid_str[MAX_LEN_UUID_STR];
bt_uuid_t uuid128;
bt_uuid_to_uuid128(uuid &uuid128);
bt_uuid_to_string(&uuid128 uuid_str sizeof(uuid_str));
printf(“%s\n“ uuid_str);
}
static void print_prompt(void)
{
printf(COLOR_BLUE “[GATT client]“ COLOR_OFF “# “);
fflush(stdout);
}
static void print_incl(struct gatt_db_attribute *attr void *user_data)
{
struct client *cli = user_data;
uint16_t handle start end;
struct gatt_db_attribute *service;
bt_uuid_t uuid;
if (!gatt_db_attribute_get_incl_data(attr &handle &start &end))
return;
service = gatt_db_get_attribute(cli->db start);
if (!service)
return;
gatt_db_attribute_get_service_uuid(service &uuid);
printf(“\t “ COLOR_GREEN “include“ COLOR_OFF “ - handle: “
“0x%04x - start: 0x%04x end: 0x%04x“
“uuid: “ handle start end);
print_uuid(&uuid);
}
static void print_desc(struct gatt_db_attribute *attr void *user_data)
{
printf(“\t\t “ COLOR_MAGENTA “descr“ COLOR_OFF
“ - handle: 0x%04x uuid: “
gatt_db_attribute_get_handle(attr));
print_uuid(gatt_db_attribute_get_type(attr));
}
static void print_chrc(struct gatt_db_attribute *attr void *user_data)
{
uint16_t handle value_handle;
uint8_t properties;
uint16_t ext_prop;
bt_uuid_t uuid;
if (!gatt_db_attribute_get_char_data(attr &handle
&value_handle
&properties
&ext_prop
&uuid))
return;
printf(“\t “ COLOR_YELLOW “charac“ COLOR_OFF
“ - start: 0x%04x value: 0x%04x “
“props: 0x%02x ext_props: 0x%04x uuid: “
handle value_handle properties ext_prop);
print_uuid(&uuid);
gatt_db_service_foreach_desc(attr print_desc NULL);
}
//打印改变的service
static void print_service(struct gatt_db_attribute *attr void *user_data)
{
struct client *cli = user_data;
uint16_t start end;
bool primary;
bt_uuid_t uuid;
if (!gatt_db
相关资源
- 数据结构(C语言版).严蔚敏_吴伟民
- 单片机C语言400例
- 电磁场有限元--PDF和源程序
- 个人物品管理程序
- 新华三校招和社招技术研发类笔试题
- 数据结构考研教案__清华·C语言版
- Visual C++ Redistributable for Visual Studio 2
- 钱能C++程序设计教程第二版pdf高清带
- C语言实现贪吃蛇大量注释+用到的库文
- C语言名题精选百则 技巧篇_冼镜光编
- C语言程序设计苏小红.zip
- C语言的png和jpeg图片格式转换为bmp格式
- C语言推箱子游戏有注释文档
- 天津城建大学C语言考试题库2011-2013
- Windows环境下socket编程C语言编写
- 纯C语言写的sift算法,亲测,可用,可
- C语言程序设计(第三版)-谭浩强.p
- 古诗收集程序C语言
- Microsoft Visual C++ 2013 Redistributable Pack
- 单片机C语言400例.rar
- 明解C语言:中级篇
- C语言深度解剖(第2版)解开程序员面
- C语言操作MySQL数据库
- 基于目标距离的S型速度曲线规划
- C语言的圣经 - K&R的C程序设计语言第
- C语言项目开发全程实录源码
- stm8S从入门到精通
- 51单片机轻松入门__基于STC15W4K系列(
- 计算机二级c语言模拟软件破解版
- 嗨翻C语言,head first c的中文版,高清
评论
共有 条评论