gatt

Android-BLE蓝牙原理

微笑、不失礼 提交于 2020-05-03 22:26:35
https://www.jianshu.com/p/f98e77c9ec65 蓝牙4.1BLE协议栈的结构图如下: PHY(Physical Layer):物理层,蓝牙是工作在2.4GHz附近,这是工业、科学、医疗ISM的频段,免许可证。WIFI也是工作在同一个频段。蓝牙把频段切分为40个通道,3个广播通道,37个数据通道,按照一个规律跳频通信。 LL(Linker Layer):链路层,用于控制设备的射频状态,设备将处于五种状态之一:等待、广告、扫描、初始化、连接。广播设备不需要建立连接就可以发送数据,而扫描设备接收广播设备发送的数据;发起连接的设备通过发送连接请求来回应广播设备,如果广播设备接受连接请求,那么广播设备与发起连接的设备将会进入连接状态。发起连接的设备称为主机,接受连接请求的设备称为从机。 HCI(Host Controller Interface):主机和控制器就是通过这个接口来进行同学的,通信的介质就是HCI命令。这层在协议栈中是可选的,一些小型终端可能没有,但是Android设备上肯定有,这层是蓝牙上层和芯片的交互必经之路,对于蓝牙硬件开发者,这里的log能够很好的帮助解决问题。 HOST部分要复杂一些,有链路控制和适配层(L2CAP),安全管理(SM)等。其中L2CAP和SM我们知道概念就可以了,这里就不多关注了。我们重点来看属性协议层,也就是ATT

第09节-使用BTStack编写蓝牙程序

守給你的承諾、 提交于 2020-05-03 21:51:06
Bluetooth LE Exploer(微软提供的)可以读取BLE蓝牙设备,可以读写它的值。本篇博客将使用BTStack写出一个精简版的Bluetooth LE Exploer。 涉及文件: btstack-master\example\le_data_channel_client.c btstack-master\example\Makefile.inc 注意 :在PC上使用软件Bluetooth LE Exploer来操作蓝牙模块时,使用系统自带的驱动; 使用btstack来操作蓝牙模块时,使用winusb驱动(使用zadig-2.4.exe安装此驱动) 在手机上使用蓝牙时,过程如下: 1. 扫描周边的蓝牙设备 2. 选择某个设备,连接它 3. 使用该设备 一、程序效果: 我们写的蓝牙程序也包含这3个过程,我设计出4个菜单: 1.主菜单: ********* Main Menu ********* [s] show scan menu [c] show connect menu [t] show test menu 可以在主菜单中: 输入s进入“Scan Menu”, 输入c进入“Connect Menu”, 输入t进入“Test Menu”。 2. 扫描菜单: ********* Scan Menu ********* [s] scan ble devices [t]

got error while download gattlib via pip3

不问归期 提交于 2020-03-17 10:38:19
问题 I use Ubuntu 16.04 64bit OS when I run $ sudo pip3 install gattlib I got this error message /usr/bin/ld: cannot find -lboost_python-py34 collect2: error: ld returned 1 exit status error: command 'x86_64-linux-gnu-g++' failed with exit status 1 I tried googling how to solve this but nothing works for me I want to use gatttool at python, so I need to install this How can I solve this? PS. I already downloaded libboost-dev 回答1: pip3 download gattlib tar xvzf ./gattlib-0.20150805.tar.gz cd

【代码】Androidの代码片段

寵の児 提交于 2020-02-29 14:34:42
UI SightFragment : Fragment 用户初见处理。 常见于 ViewPager 预加载前后页面,但希望页面等用户可见时才加载内容。 TokenActivity : Activity 恰当弹窗时机。 TransparentStatusBarActivity : 全透明状态栏。 状态 AppLifecycle : Application 前后台及 Activity 生命期处理。 工具 追踪 Log : 日志打印。可添加通道,输出到文件。 CrashHandler : 崩溃处理。将会记录奔溃日志到文件。 系统 Helper for accessing os properties : 系统属性访问: SystemProperties 、 build.prop 。 Helper for 3rd party roms : 第三方 ROM 兼容:Flyme、MIUI。 硬件 The bluetooth listener and profile proxy : 蓝牙开关、监听,以及操作系统蓝牙配置。 Tips View id should be unique in the hierarchy. Otherwise, save and restore state may occur exception. Reference: View保存状态的过程分析

How to find out if Bluetooth connection is encrypted?

独自空忆成欢 提交于 2020-02-25 05:32:27
问题 I am creating an BLE connection between a ble device and a mobile. the connection is first unsecured but will be updated to LESC just works from device side. This works fine so far. In Android (target SDK 28) I want to check (better getting an callback) if bluetooth connection is encrypted. I am using a BLE UART Service example. I have access to an BluetoothGatt and BluetoothDevice object. But all methods, variables I found are either private or @SystemApi. Can anyone help? Following some

Android Using BluetoothGattServer

痴心易碎 提交于 2020-02-01 09:41:50
问题 For an application I have need for an android device to be both a Ble Gatt peripheral and server to accept both incoming and send outgoing messages; however, it seems I cannot find much information pertaining to setting up and maintaining the server other than looking at projects of others in github. Can anyone show me the correct solution or guide me to more information regarding setting up BluetoothGattServer. 回答1: I would like to quickly mention, that most of the Android devices in use don

Android4.3 蓝牙BLE初步

自闭症网瘾萝莉.ら 提交于 2020-01-26 05:14:11
一、关键概念: Generic Attribute Profile (GATT) 通过BLE连接,读写属性类小数据的Profile通用规范。现在所有的BLE应用Profile都是基于GATT的。 Attribute Protocol (ATT) GATT是基于ATT Protocol的。ATT针对BLE设备做了专门的优化,具体就是在传输过程中使用尽量少的数据。每个属性都有一个唯一的UUID,属性将以characteristics and services的形式传输。 Characteristic Characteristic可以理解为一个数据类型,它包括一个value和0至多个对次value的描述(Descriptor)。 Descriptor 对Characteristic的描述,例如范围、计量单位等。 Service Characteristic的集合。例如一个service叫做“Heart Rate Monitor”,它可能包含多个Characteristics,其中可能包含一个叫做“heart rate measurement"的Characteristic。 二、角色和职责: Android设备与BLE设备交互有两组角色: 中心设备和外围设备(Central vs. peripheral); GATT server vs. GATT client. Central vs.

Bluedroid 函数分析:bta_dm_gattc_register

人走茶凉 提交于 2020-01-24 02:04:49
我们先来看看在bluedroid 里面有多少地方调用到这里: 可以看出除了 它自己声明的地方,有三处 调用到这个函数。 一处是 进行discovery,一处是进行search的时候,还有一次是bta_dm_sys_hw_cback 中,这个在bta_dm_enable的时候就已经注册了,所有其实最先注册的地方就是bta_dm_sys_hw_cback ,以后即使有地方调用该函数进行GATT 注册,也不会真正的再次注册。 另外 这个函数 其实是BTA_GATTC_AppRegister的包装,但是它限定了app_uuid 全部为0x87,由此我们得知此uuid 标识device manager 模块注册到gatt 中情况。 下面进行函数的分析: /******************************************************************************* ** ** Function bta_dm_gattc_register ** ** Description Register with GATTC in DM if BLE is needed. ** ** ** Returns void ** *********************************************************************

GATT scan的流程

守給你的承諾、 提交于 2020-01-24 02:02:28
BLE scan 在bluedroid的实现中,有两个接口:一个是discovery,一个是ble observe,这两者有什么区别呢? 这里追了一下代码发现,inquiry 是上层调用search 相关的接口的实现函数,ble observe 是调用GATT scan的接口的实现函数,这篇文章分析一下,在调用GATT 接口实现scan的流程。 GATT的服务代码逻辑在哪里实现的呢?其核心代码的实现是bluedroid里面,但是,上层的应用是不可能直接调用协议栈的代码的,其实在bluedroid上面还会进行封装一个GATT的服务,其实现在package/app/Bluetooth下面的GattService.java,这里面实现了关于GATT相关的各种接口,应用层的代码通过binder 调用绑定到这些接口,并完成一系列的调用。 看一下GattService.java的实现: /** * Handlers for incoming service calls */ private static class BluetoothGattBinder extends IBluetoothGatt.Stub implements IProfileServiceBinder { private GattService mService; public BluetoothGattBinder

android4.3 Bluetooth(le)分析之startLeScan分析

梦想与她 提交于 2020-01-24 01:53:41
BluetoothAdapter.java中有low enery(le)的一些方法,android提供了这些方法,但源码中并未找到这些方法的调用之处。本文档主要分析这类方法的执行流程,来了解下le到底做了些什么。 本文主要就是分析下startLeScan方法(两个重载方法)。 public boolean startLeScan(LeScanCallback callback) { return startLeScan(null, callback); } public boolean startLeScan(UUID[] serviceUuids, LeScanCallback callback) { if (DBG) Log.d(TAG, "startLeScan(): " + serviceUuids); synchronized(mLeScanClients) { if (mLeScanClients.containsKey(callback)) { if (DBG) Log.e(TAG, "LE Scan has already started"); return false; } try { //获取BluetoothGattBinder类的实例,该类的定义在GattService.java中 IBluetoothGatt iGatt = mManagerService