1 Star 0 Fork 0

何亚红/WinBle

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

WinBle

A set of classes for enumerating and interacting with Bluetooth low energy devices on the windows platform.

Requirements

  • Windows 10
  • Devices must be paired and enumerated by the windows ble driver

Example Code

Read a Characteristic

// The characteristic must have IsReadable set to true or an exception will be thrown
BleGattCharacteristicValue value = characteristic->getValue();

Write a Characteristic Value

// The characteristic must have IsSignedWritable, IsWritable, IsWritableWithoutResponse set to true or an exception will be thrown
UCHAR values[] = { 'H', 'I', '\r', '\n' };

characteristic->setValue(values, 4);

Subscribe to a Characteristic Notification

// The callback for the characteristic notification
void HandleCallback(BleGattNotificationData& data)
{
    cout << "Received callback data: " << data.getDataSize() << endl;
}

// Enumerate characteristic descriptors
characteristic->enumerateBleDescriptors();

// Get the list of descriptors
list<BleGattDescriptor *> descriptors = characteristic->getBleDescriptors();

if (descriptors.size() > 0)
{
    // Get the characteristic descriptor
    BleGattDescriptor *descriptor = descriptors.front();

    // The callback function
    const std::function<void(BleGattNotificationData&)> callback = HandleCallback;

    // Enable notifications for the characteristic IsNotifiable or IsIndicatable must be true for the characteristic or an exception will be thrown
    characteristic->enableNotifications(callback);

    // Enable the subscription notification for the characteristic
    descriptor->setIsSubscribeToNotification();

    // Disable the notification
    characteristic->disableNotifications();

    // Clear the subscription notification
    descriptor->clearIsSubscribeToNotification();
}

Windows Bluetooth Tracing

Windows Bluetooth tracing requires the download of a WPRP file from the Microsoft Git hub repo eere. The readme.md document in the Microsoft Git hub repo describes the steps to enable the tracing.

When this tracing is complete the stop command will write the trace contents to an ETL file that is provided as a parameter to the command.

The generated ETL file is a binary file in order to parse it to a readable form, a tool called BTETLParse.exe is required to convert the ETL. The tool supports a number of different formats of output, namely:

  • CFA
    • Can be opened with Teledyne LeCroy Wireless Protocol Suite
  • HCI
    • This is a plain text file
  • PCAP
    • This can be opened with wireshark

Instructions for the BTETLParse.exe tool can be found Here

The BTETLParse.exe tool can be downloaded from Here

编译

Visual Studio

直接打开WinBle.sln即可。

MSYS2 Mingw32/Mingw64

使用CMake编译,需要使用最新版的MSYS2。由于MSYS2的gcc暂时不支持BLE(截至编辑时),故从Windows10 SDK中复制了相应的库及头文件。

MIT License Copyright (c) 2017 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

A set of C++ classes to abstract the win32 api calls required to enumerate and interact with ble devices on windows 展开 收起
C++ 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/HEYAHONG/WinBle.git
git@gitee.com:HEYAHONG/WinBle.git
HEYAHONG
WinBle
WinBle
mingw

搜索帮助