Bluetoe 开源项目使用教程

Bluetoe 开源项目使用教程

bluetoeC++ Framework to build Bluetooth LE Server (GATT)项目地址:https://gitcode.com/gh_mirrors/bl/bluetoe

1. 项目的目录结构及介绍

Bluetoe 项目的目录结构如下:

bluetoe/
├── examples/
│   ├── blinky_server/
│   ├── ...
├── include/
│   ├── bluetoe/
│   │   ├── server.hpp
│   │   ├── device.hpp
│   │   ├── ...
├── src/
│   ├── link_layer/
│   ├── ...
├── tests/
│   ├── test_cases/
│   ├── ...
├── CMakeLists.txt
├── README.md
├── LICENSE
├── ...

目录结构介绍

  • examples/: 包含多个示例项目,展示了如何使用 Bluetoe 框架构建蓝牙 LE 服务器。
  • include/bluetoe/: 包含 Bluetoe 框架的核心头文件,定义了服务器、设备、特性等关键组件。
  • src/: 包含 Bluetoe 框架的源代码,特别是链接层(link_layer)的实现。
  • tests/: 包含测试用例,用于验证 Bluetoe 框架的正确性和稳定性。
  • CMakeLists.txt: CMake 构建文件,用于配置和构建项目。
  • README.md: 项目的基本介绍和使用说明。
  • LICENSE: 项目的许可证文件,采用 MIT 许可证。

2. 项目的启动文件介绍

Bluetoe 项目的启动文件通常位于 examples/ 目录下。以 blinky_server 为例,启动文件为 main.cpp

启动文件 main.cpp 介绍

#include <bluetoe/server.hpp>
#include <bluetoe/device.hpp>
#include <nrf.h>

using namespace bluetoe;

// LED1 on a nRF52 eval board
static constexpr int io_pin = 17;

static std::uint8_t io_pin_write_handler(bool state) {
    // On an nRF52 eval board the pin is connected to the LED's cathode
    // This inverts the logic
    NRF_GPIO->OUT = state ? NRF_GPIO->OUT & ~(1 << io_pin) : NRF_GPIO->OUT | (1 << io_pin);
}

using blinky_server = server<
    service<
        service_uuid<0xC11169E1, 0x6252, 0x4450, 0x931C, 0x1B43A318783B>,
        characteristic<
            requires_encryption,
            free_write_handler<bool, io_pin_write_handler>
        >
    >
>;

blinky_server gatt_device;

int main() {
    // Init GPIO pin
    NRF_GPIO->PIN_CNF[io_pin] = (GPIO_PIN_CNF_DRIVE_S0H1 << GPIO_PIN_CNF_DRIVE_Pos) |
                                (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);

    gatt_device.run();
}

启动文件功能介绍

  • main.cpp: 这是项目的入口文件,包含了 Bluetoe 服务器的定义和初始化代码。
  • blinky_server: 定义了一个蓝牙 LE 服务器,包含一个服务和一个特性,允许客户端控制一个 IO 引脚。
  • io_pin_write_handler: 处理客户端写入操作的回调函数,用于控制 IO 引脚的状态。
  • main(): 初始化 GPIO 引脚,并启动 Bluetoe 服务器。

3. 项目的配置文件介绍

Bluetoe 项目的配置文件主要是 CMakeLists.txt,用于配置项目的构建过程。

配置文件 CMakeLists.txt 介绍

cmake_minimum_required(VERSION 3.10)
project(bluetoe)

set(CMAKE_CXX_STANDARD 11)

include_directories(include)

add_subdirectory(src)
add_subdirectory(tests)
add_subdirectory(examples)

# 其他配置项...

配置文件功能介绍

  • cmake_minimum_required(VERSION 3.10): 指定 CMake 的最低版本要求。
  • project(bluetoe): 定义项目名称。
  • set(CMAKE_CXX_STANDARD 11): 设置 C++ 标准为 C++11。
  • include_directories(include): 包含头文件目录。
  • add_subdirectory(src): 添加源代码目录。
  • add_subdirectory(tests): 添加测试代码目录。
  • add_subdirectory(examples): 添加示例代码目录。

通过这些配置,可以方便地构建和测试 Bluetoe 项目。

bluetoeC++ Framework to build Bluetooth LE Server (GATT)项目地址:https://gitcode.com/gh_mirrors/bl/bluetoe

  • 12
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蒋闯中Errol

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值