请教BLE 中的sever和jdk1.8 ftpclient问题角色问题

&>&&>&移动开发&>&iOS&>&IOS BLE server&client background mode
IOS BLE server&client background mode
上传大小:80KB
IOS BLE server&client,后台运行,对得起10分。
综合评分:0(0位用户评分)
所需积分:10
下载次数:8
审核通过送C币
iOS电子图书大全
创建者:qq_
[资源优选]第十八期:20个热门的SWIFT源码
创建者:nigelyq
【资源优选】第九期:最热门的20个iOS精品源代码
创建者:nigelyq
{%username%}回复{%com_username%}{%time%}\
/*点击出现回复框*/
$(".respond_btn").on("click", function (e) {
$(this).parents(".rightLi").children(".respond_box").show();
e.stopPropagation();
$(".cancel_res").on("click", function (e) {
$(this).parents(".res_b").siblings(".res_area").val("");
$(this).parents(".respond_box").hide();
e.stopPropagation();
/*删除评论*/
$(".del_comment_c").on("click", function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_invalid/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parents(".conLi").remove();
alert(data.msg);
$(".res_btn").click(function (e) {
var q = $("#form1").serializeArray();
console.log(q);
var res_area_r = $.trim($(".res_area_r").val());
if (res_area_r == '') {
$(".res_text").css({color: "red"});
$.post("/index.php/comment/do_comment_reply/", q,
function (data) {
if (data.succ == 1) {
var $dd = $target.parents('dd');
var $wrapReply = $dd.find('.respond_box');
console.log($wrapReply);
var mess = $(".res_area_r").val();
var str = str.replace(/{%header%}/g, data.header)
.replace(/{%href%}/g, 'http://' + window.location.host + '/user/' + data.username)
.replace(/{%username%}/g, data.username)
.replace(/{%com_username%}/g, _username)
.replace(/{%time%}/g, data.time)
.replace(/{%id%}/g, data.id)
.replace(/{%mess%}/g, mess);
$dd.after(str);
$(".respond_box").hide();
$(".res_area_r").val("");
$(".res_area").val("");
$wrapReply.hide();
alert(data.msg);
}, "json");
//填充回复
function KeyP(v) {
$(".res_area_r").val($.trim($(".res_area").val()));
/*删除回复*/
$(".del_comment_r").on("click", function (e) {
var id = $(e.target).attr("id");
$.getJSON('/index.php/comment/do_comment_del/' + id,
function (data) {
if (data.succ == 1) {
$(e.target).parent().parent().parent().parent().parent().remove();
$(e.target).parents('.res_list').remove()
alert(data.msg);
评论共有0条
上传者其他资源上传者专辑
iOS 7 SDK: 如何使用后台获取(Background Fetch)
数据结构与计算机原理.rar
清华 殷人昆C++数据结构课件
IE6.0EXE浏览器高速下载
移动开发热门标签
VIP会员动态
前端开发重难点
17年软考最新真题及解析
物联网全栈开发专题
二十大技术领域优质资源
spring mvc+mybatis+mysql+maven+bootstrap 整合实现增删查改简单实例.zip
CSDN&vip年卡&4000万程序员的必选
IOS BLE server&client background mode
会员到期时间:剩余下载次数:
积分不足!
资源所需积分
当前拥有积分
您可以选择
程序员的必选
绿色安全资源
资源所需积分
当前拥有积分
VIP年卡全年1200次免积分下载
你当前的下载分为234。
你还不是VIP会员
开通VIP会员权限,免积分下载
你下载资源过于频繁,请输入验证码
你下载资源过于频繁,请输入验证码
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
若举报审核通过,可奖励20下载分
被举报人:
lipeiran1987
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:四、BLE(中) - arduino - 博客园
随笔 - 16, 文章 - 0, 评论 - 0, 引用 - 0
1.1&&&&&& GATT Manager
GATT MGR模块管理所有的GATT服务,同时也是连接GATT模块与GATT ServiceS模块的桥梁。
1.1.1&&& 主要功能模块
先来看一张该模块的API关系图,sink_gatt_manager.c里面定义的接口主要供ApplicationLayer调用和回调,如用户(BLE Server)调用sinkGattManagerStartAdvertising()开始进行广播,用户(BLE Client)调用sinkGattManagerStartConnection()开始进行BLE连接。该该部分同时负责接收和处理来自ApplicationLayer的消息——GATT_MANAGER_DISCONNECT_IND,GATT_MANAGER_REGISTER_WITH_GATT_CFM等GATT_MANAGER_XXX系列消息。这些消息主要用来处理注册连接确认,断开连接请求等事件。
&&&&&& Gatt_nanager_handler.c主要定义和实现了内部回调函数gattManagerMessageHandler(),该接口主要接收来自GATT模块的GATT_XXX系列消息,以及GATT MGR内部的消息GATT_MANAGER_INTERNAL_MSG_XXX。处理这些消息的函数接口主要分布在gatt_manager_server.c和gatt_manager_client.c两个函数内部。
&&&&&& 根据BLE工作的角色不同,BLE分别定义了两套接口,分别完成客户和服务的角色的任务。
&&&&&&&& 作为BLE客户主要完成的任务有:
1.连接到服务器。这里包括主导发起连接至服务器,以及接收到服务器连接请求的确认。即:GattManagerConnectToRemoteServer()用来主动发起连接请求,在接收到GATT_CONNECT_CFM消息后,调用gattManagerClientRemoteServerConnected ()接口用于确认连接,完成连接的三次握手过程。
2. GATT支持notification和indication操作,因此客户端需要有着两种请求操作对应的接口。gattManagerClientRemoteServerNotification()和gattManagerClientRemoteServerIndication()就是为了实现这两种操作巍峨设计的。
3. 获取服务器的服务。根据GATT标准,获取服务的服务主要有:获取服务器主要GATT服务,获取某个GATT服务的所有特征值定义,获取某个GATT服务的特征值描述符,读/写某个特征值等。
&&&&&&&& 作为BLE服务器主要完成的任务有:
1.广播,以及处理客户端的连接请求。gattManagerServerAdvertising()开启广播,GattManagerWaitForRemoteClient()等待远程客户发起连接,gattManagerServerConnectInd()处理连接请求。gattManagerServerRemoteClientConnected()处理连接请求确认(三次握手最后一次)消息。
2.注册GATT service。GattManagerRegisterServer()向GATT MGR模块注册一个GATT service。
3.处理来自客户端的GATT操作,如access,indication,notification等。其中indication,notification操作都是由服务器主动对客户端发起的操作,因此客户端和服务器端处理的消息刚好是互为匹配的,即服务器处理的消息有(GATT_ACCESS_IND, GATT_NOTIFICATION_CFM, GATT_INDICATION_CFM),客户端对应的处理消息有(ATT_ACCESS_RSP, GATT_NOTIFICATION_IND, GATT_INDICATION_IND)。
1.1.2&&& GATT数据库
作为GATT的服务器,通常需要存储比较多的数据来支撑多个不同的GATT服务,因此在GATT服务器端,建立一个数据库是必要的。在CSR的BlueCore和CSRμEnergy软件开发工具包(SDK)中使用了一种特殊的数据库目标语言。该数据库通过GATT数据库生成器(CSR提供的gattdbgen.exe)自动生成。这就允许应用程序开发者以一种简单易读,便于维护的方式来创建一个数据库,避免采用诸如SDP这种用复杂的二进制形式表示方式。
数据库的生成
GATT数据库生成器输入一个用jeason语言描述的GATT服务文件foobar.db,输出一个foobar.c和foobar.h文件,这两个文件可以作为ADK工程的一部分进行编译和链接。可见数据库的生产是在整个工程编译前,准确的说是在预编译阶段就已经完成了。显然这样生产的数据是一个准常量的数据库,不能往里面新增记录,即不能动态的添加GATT服务,所有的服务必须在编译前就已经确定好。
例如,在ADK的sink例程中,sink_gatt_db.db作为数据库生成器的输入文件,输出sink_gatt_db.c和sink_gatt_db.h。
其中xxx_db.c文件有const uint16 gattDatabase[] = {}存储数据库记录。并提供两个接口工外部操作数据库,这两个接口分别为:
uint16 *GattGetDatabase(uint16 *len); &/*获取数据库存储区首地址*/
uint16 GattGetDatabaseSize(void);&&&&& /*获取数据库大小*/
在xxx_db.h文件中,除了GattGetDatabase()和GattGetDatabaseSize()接口的声明外,还有数据库中所有ATT记录的句柄(UUID)的宏定义,通常以HANDLE_GAIA_XXX的形式定义。通过该宏,可以快速索引某条ATT记录。
BLE在初始化GATT Manager模块时,对GATT database进行了初始化:
initialiseGattWithServers()-&
GattManagerRegisterConstDB(&gattDatabase[0], GattGetDatabaseSize());
例如某个gaia_db.db内容为:
primary_service {
&&& uuid : 0x01,&
&&& name : "GAIA_SERVICE",
&&& characteristic {
&&&&&&& uuid&&&&&&& : 0x02,
&&&&&&& name&&&&&&& : "GAIA_COMMAND_ENDPOINT",
&&&&&&& flags&&&&&& : [ FLAG_IRQ, FLAG_DYNLEN, FLAG_ENCR_W ],
&&&&&&& properties& : [ write ],
&&&&&&& value&&&&&& : 0x0
则其生成的gaia_db.c文件如下:
/* Static GATT database */
const uint16 gattDatabase[] = {
&&& /* 0001: Primary Service 0001 */
&&& /* 0002: Characteristic Declaration 0002 */
&&& 0x3, 0x0,
&&& /* 0003: . */
&&& 0xdd01, 0x0000,
uint16 *GattGetDatabase(uint16 *len)
&&& uint16 *rc = PanicUnlessMalloc(sizeof(gattDatabase));
&&& *len = sizeof(gattDatabase);
&&& memmove(rc, gattDatabase, sizeof(gattDatabase));
uint16 GattGetDatabaseSize(void)
&&& return sizeof(gattDatabase);
其生成的gaia_db.h文件如下:
#define HANDLE_GAIA_SERVICE&&&&&&&&&&& &(0x0001)
#define HANDLE_GAIA_SERVICE_END&&&&&&&& (0xffff)
#define HANDLE_GAIA_COMMAND_ENDPOINT&&& (0x0003)
uint16 *GattGetDatabase(uint16 *len);
uint16 GattGetDatabaseSize(void);
数据库维护
&&&&&&&& GATT数据库的数据单元是ATT记录,通过某条ATT记录的句柄(handler)可以快速和唯一地访问该条记录,例如,如果希望访问电池服务的电量特征值,该条特征值定义封装在一条句柄为0x0003的ATT记录中,通过句柄0x0003找到该条ATT记录,ATT.value即对应着电池电量值。蓝牙(23)
Bluetooth Low Energy(以下简称LE),使用2.4GHz ISM信号进行通信,采用跳频接收以抗干扰和衰减。传输速率带宽是1Mb/s。
频带和通道
LE频带是2.4GHz-2483.5MHz,40channel,channel的中心频率是2402+K×2MHz,(K=0,...,39)
发射器特性
LE使用两种接入策略FDMA(Frequency division multiple access)和TDMA(time division multiple access)。
频分复用是分成40个物理通道,由2MHz间隔,时分复用是基于轮询的策略,数据传输和对应的应答都在预先设定的时间发生。
时域把物理通道分成时间单位,称为events。有两种类型的event,广播和连接事件。
advertiser在广播PHY传输广播数据包的设备。
scanner在广播通道上接收广播包而并没有打算去连接广播设备的设备
initiator:和处于监听设备建立连接的设备
一旦连接建立,处于监听的设备将变成master,而广播的设备变成slave。
处于piconet的设备使用特定的跳频方式,调频算法由一个发起设备在连接设备请求阶段发出的一个字段决定。
PDU protocol data unit。
BLE Physical layer
BLE模块可以包括发射器和接收器,或者只有一个。
发射器特性
高斯频移键控Gaussian Frequency Shift Keying(GFSK),其带宽周期乘积BT=0.5。调制的索引介于0.45~0.55之间。
BLE专有名词
Generic Attribute Profile (GATT)-GATT profile是发送和接收通过BLE link传输的“attributes”短数据包通用规范。当前所有的LE应用profile基于GATT。
Attribute Protocol (ATT)—GATT是建立在Attribute Protocol(ATT)之上的协议,通常成为GATT/ATT。ATT是针对BLE设备优化的协议。每一个attribute由UUID唯一标识,UUID通常是128-bit格式。ATT传输的attribute被格式化为characteristics和service
Characteristic—包含一个值以及0-n描述特性值的描述符;
Descriptor—描述符用于描述attribute的characteristics值。
Service—是属性的集合。
Roles and Responsibilities
Central vs. peripheral.这用于BLE自身连接。中心角色的设备负责扫描,查找广播的设备,而peripheral设备发送广播。GATT server vs. GATT client。用于描述建立连接的设备之间是如何交互的。
应用程序为了使用Bluetooth特性,应用程序必须请求Bluetooth权限BLUETOOTH。
如果应用程序要发起设备发现或者操作蓝牙设置,还需要声明BLUETOOTH_ADMIN权限。
在manifest文件申请权限
&uses-permission android:name=&android.permission.BLUETOOTH&/&
&uses-permission android:name=&android.permission.BLUETOOTH_ADMIN&/&如果想要app只在具有BLE能力的设备上运行,则需要在manifest中做如下声明:
&uses-feature android:name=&android.hardware.bluetooth_le& android:required=&true&/&如果想在不具有BLE能力的设备上也使用该app,则要做如下声明
&uses-feature android:name=&android.hardware.bluetooth_le& android:required=&false&/&在运行时可以使用检测是否具有BLE能力。
// Use this check to determine whether BLE is supported on the device. Then
// you can selectively disable BLE-related features.
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
在应用程序能够使用BLE方式进行通信时,需要确定设备是支持BLE的,并且BLE使能了。如果&uses-feature.../&设置成了false,则需要进行检查。
如果设备支持BLE,但是disable了,则应用程序可以请求用户使能蓝牙。这个过程使用BluetoothAdapter两个步骤完成。
1.获得BlueoothAdapter
任何蓝牙activity需要申请BluetoothAdapter。BluetoothAdapter代表了拥有了蓝牙适配器的设备。
// Initializes Bluetooth adapter.
final BluetoothManager bluetoothManager =
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
2,使能Bluetooth
接下来需要确认蓝牙是使能的,这可以使用方法检查。如果没有使能,则弹窗提示用户使能。
private BluetoothAdapter mBluetoothA
// Ensures Bluetooth is available on the device and it is enabled. If not,
// displays a dialog requesting user permission to enable Bluetooth.
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
搜索BLE设备
使用方法索BLE设备,该方法的参数是,应用程序必须实现这个回调函数,因为这指明了扫描结果是如何返回的。因为扫描比较耗电,最好遵循如下指导:
1.一旦发现需要的设备,停止扫描。
2.不要循环扫描,设置扫描时限
* Activity for scanning and displaying available BLE devices.
public class DeviceScanActivity extends ListActivity {
private BluetoothAdapter mBluetoothA
private boolean mS
private Handler mH
// Stops scanning after 10 seconds.
private static final long SCAN_PERIOD = 10000;
private void scanLeDevice(final boolean enable) {
if (enable) {
// Stops scanning after a pre-defined scan period.
mHandler.postDelayed(new Runnable() {
public void run() {
mScanning =
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}, SCAN_PERIOD);
mScanning =
mBluetoothAdapter.startLeScan(mLeScanCallback);
mScanning =
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}如果想只扫描特定类型的BLE设备,可以提供UUID参数调用
如下,用于发送BLE扫描结果。
private LeDeviceListAdapter mLeDeviceListA
// Device scan callback.
private BluetoothAdapter.LeScanCallback mLeScanCallback =
new BluetoothAdapter.LeScanCallback() {
public void onLeScan(final BluetoothDevice device, int rssi,
byte[] scanRecord) {
runOnUiThread(new Runnable() {
public void run() {
mLeDeviceListAdapter.addDevice(device);
mLeDeviceListAdapter.notifyDataSetChanged();
连接GATT Server
和BLE设备交互的第一步是和其建立连接,也就是和GATT server建立连接。使用方法建立这种连接。该方法有三个参数:对象,autoConnect(bool值,用于指示是否自动连接),以及一个引用。
mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
其返回BluetoothGatt实例,获得该实例后可以执行GATT client操作了。调用这(Android app)是GATT client。用于将结果返回给client,如连接状态等。
在这个例子中,BLE app提供一个activity(DeviceControlActivity)来连接,显示数据以及显示GATT服务和特性。基于用户输入,该activity与BluetoothLeService交互。
// A service that interacts with the BLE device via the Android BLE API.
public class BluetoothLeService extends Service {
private final static String TAG = BluetoothLeService.class.getSimpleName();
private BluetoothManager mBluetoothM
private BluetoothAdapter mBluetoothA
private String mBluetoothDeviceA
private BluetoothGatt mBluetoothG
private int mConnectionState = STATE_DISCONNECTED;
private static final int STATE_DISCONNECTED = 0;
private static final int STATE_CONNECTING = 1;
private static final int STATE_CONNECTED = 2;
public final static String ACTION_GATT_CONNECTED =
&com.example.bluetooth.le.ACTION_GATT_CONNECTED&;
public final static String ACTION_GATT_DISCONNECTED =
&com.example.bluetooth.le.ACTION_GATT_DISCONNECTED&;
public final static String ACTION_GATT_SERVICES_DISCOVERED =
&com.example.bluetooth.le.ACTION_GATT_SERVICES_DISCOVERED&;
public final static String ACTION_DATA_AVAILABLE =
&com.example.bluetooth.le.ACTION_DATA_AVAILABLE&;
public final static String EXTRA_DATA =
&com.example.bluetooth.le.EXTRA_DATA&;
public final static UUID UUID_HEART_RATE_MEASUREMENT =
UUID.fromString(SampleGattAttributes.HEART_RATE_MEASUREMENT);
// Various callback methods defined by the BLE API.
private final BluetoothGattCallback mGattCallback =
new BluetoothGattCallback() {
public void onConnectionStateChange(BluetoothGatt gatt, int status,
int newState) {
String intentA
if (newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_CONNECTED;
mConnectionState = STATE_CONNECTED;
broadcastUpdate(intentAction);
Log.i(TAG, &Connected to GATT server.&);
Log.i(TAG, &Attempting to start service discovery:& +
mBluetoothGatt.discoverServices());
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
intentAction = ACTION_GATT_DISCONNECTED;
mConnectionState = STATE_DISCONNECTED;
Log.i(TAG, &Disconnected from GATT server.&);
broadcastUpdate(intentAction);
// New services discovered
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);
Log.w(TAG, &onServicesDiscovered received: & + status);
// Result of a characteristic read operation
public void onCharacteristicRead(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic,
int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
}不论哪个回调被触发,其调用broadcastUpdate()方法。本节数据格式的解析基于Bluetooth Heart RateMeasurement profile 规范。
private void broadcastUpdate(final String action) {
final Intent intent = new Intent(action);
sendBroadcast(intent);
private void broadcastUpdate(final String action,
final BluetoothGattCharacteristic characteristic) {
final Intent intent = new Intent(action);
// This is special handling for the Heart Rate Measurement profile. Data
// parsing is carried out as per profile specifications.
if (UUID_HEART_RATE_MEASUREMENT.equals(characteristic.getUuid())) {
int flag = characteristic.getProperties();
int format = -1;
if ((flag & 0x01) != 0) {
format = BluetoothGattCharacteristic.FORMAT_UINT16;
Log.d(TAG, &Heart rate format UINT16.&);
format = BluetoothGattCharacteristic.FORMAT_UINT8;
Log.d(TAG, &Heart rate format UINT8.&);
final int heartRate = characteristic.getIntValue(format, 1);
Log.d(TAG, String.format(&Received heart rate: %d&, heartRate));
intent.putExtra(EXTRA_DATA, String.valueOf(heartRate));
// For all other profiles, writes the data formatted in HEX.
final byte[] data = characteristic.getValue();
if (data != null && data.length & 0) {
final StringBuilder stringBuilder = new StringBuilder(data.length);
for(byte byteChar : data)
stringBuilder.append(String.format(&%02X &, byteChar));
intent.putExtra(EXTRA_DATA, new String(data) + &\n& +
stringBuilder.toString());
sendBroadcast(intent);
回到DeviceControlActivity,这些事件由处理。
// Handles various events fired by the Service.
// ACTION_GATT_CONNECTED: connected to a GATT server.
// ACTION_GATT_DISCONNECTED: disconnected from a GATT server.
// ACTION_GATT_SERVICES_DISCOVERED: discovered GATT services.
// ACTION_DATA_AVAILABLE: received data from the device. This can be a
// result of read or notification operations.
private final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) {
mConnected =
updateConnectionState(R.string.connected);
invalidateOptionsMenu();
} else if (BluetoothLeService.ACTION_GATT_DISCONNECTED.equals(action)) {
mConnected =
updateConnectionState(R.string.disconnected);
invalidateOptionsMenu();
clearUI();
} else if (BluetoothLeService.
ACTION_GATT_SERVICES_DISCOVERED.equals(action)) {
// Show all the supported services and characteristics on the
// user interface.
displayGattServices(mBluetoothLeService.getSupportedGattServices());
} else if (BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action)) {
displayData(intent.getStringExtra(BluetoothLeService.EXTRA_DATA));
获取BLE设备Attribute
一旦应用和GATT server建立连接。其可以读写attribute,如下代码片段迭代查询server的服务和特性并且用UI显示出来。
public class DeviceControlActivity extends Activity {
// Demonstrates how to iterate through the supported GATT
// Services/Characteristics.
// In this sample, we populate the data structure that is bound to the
// ExpandableListView on the UI.
private void displayGattServices(List&BluetoothGattService& gattServices) {
if (gattServices == null)
String uuid =
String unknownServiceString = getResources().
getString(R.string.unknown_service);
String unknownCharaString = getResources().
getString(R.string.unknown_characteristic);
ArrayList&HashMap&String, String&& gattServiceData =
new ArrayList&HashMap&String, String&&();
ArrayList&ArrayList&HashMap&String, String&&& gattCharacteristicData
= new ArrayList&ArrayList&HashMap&String, String&&&();
mGattCharacteristics =
new ArrayList&ArrayList&BluetoothGattCharacteristic&&();
// Loops through available GATT Services.
for (BluetoothGattService gattService : gattServices) {
HashMap&String, String& currentServiceData =
new HashMap&String, String&();
uuid = gattService.getUuid().toString();
currentServiceData.put(
LIST_NAME, SampleGattAttributes.
lookup(uuid, unknownServiceString));
currentServiceData.put(LIST_UUID, uuid);
gattServiceData.add(currentServiceData);
ArrayList&HashMap&String, String&& gattCharacteristicGroupData =
new ArrayList&HashMap&String, String&&();
List&BluetoothGattCharacteristic& gattCharacteristics =
gattService.getCharacteristics();
ArrayList&BluetoothGattCharacteristic& charas =
new ArrayList&BluetoothGattCharacteristic&();
// Loops through available Characteristics.
for (BluetoothGattCharacteristic gattCharacteristic :
gattCharacteristics) {
charas.add(gattCharacteristic);
HashMap&String, String& currentCharaData =
new HashMap&String, String&();
uuid = gattCharacteristic.getUuid().toString();
currentCharaData.put(
LIST_NAME, SampleGattAttributes.lookup(uuid,
unknownCharaString));
currentCharaData.put(LIST_UUID, uuid);
gattCharacteristicGroupData.add(currentCharaData);
mGattCharacteristics.add(charas);
gattCharacteristicData.add(gattCharacteristicGroupData);
接收GATT通知
在特定属性改变时。BLE app被要求通知server。这使用实现。
private BluetoothGatt mBluetoothG
BluetoothGattCharacter
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
UUID.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);一旦对一些特性注册了通知,如果远端设备的特性变化,则会触发回调函数。
// Characteristic notification
public void onCharacteristicChanged(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic) {
broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
关闭Client App
调用close方法完成。
public void close() {
if (mBluetoothGatt == null) {
mBluetoothGatt.close();
mBluetoothGatt =
蓝牙5.0核心规范已发布,一些新特性如下:有效传输距离是4.2LE版本的4倍(理论上可达300米),传输速度将是4.2LE版本的2倍(速度上限为24Mbps)。蓝牙5.0还支持室内定位导航功能(结合WiFi可以实现精度小于1米的室内定位),允许无需配对接受信标的数据(比如广告、Beacon(点对多点)、位置信息等,传输率提高了8倍),针对物联网进行了很多底层优化。
client端示例下载地址:http://download.csdn.net/detail/shichaog/9707586
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:224035次
积分:3878
积分:3878
排名:第8031名
原创:161篇
评论:77条
(1)(4)(12)(8)(3)(9)(2)(3)(7)(3)(8)(6)(14)(5)(6)(3)(7)(4)(1)(3)(5)(3)(1)(3)(7)(4)(20)(1)(1)(2)(3)(3)(3)(3)(5)
基于Linux3.10版本下tcp/ip协议主线的网络协议栈源码级剖析

我要回帖

更多关于 client sever 的文章

 

随机推荐