
我正在开发一个应用程序有连接到蓝牙设备的 Android 43。
我可以连接到 BLE 设备和从设备中读取 RSSI,通过使用 BluetoothGattreadRemoteRssi()。
我想要读的多个设备一次我已连接,但我可以只读 BLE RSSI 设备 RSSI 的最后一次,我连接的设备。
如果有两个 BLE 设备 A 和 B。我连接到A 的设备,并读取该 RSSI。之后,我连接到B 的设备,和我可以从设备 B读取 RSSI。但它并不读取设备 A的 RSSI,它只能从设备 B读取 RSSI。
在Mainjava ,它列出已连接的位置的所有设备。
当我单击该设备,在列表上,它把传送的设备的名称和地址到DeviceControljava。
final Intent qintent = new Intent(this, DeviceControlclass);
devicelistsetOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
HashMap<String, Object> select = (HashMap<String, Object>) devicelistgetItemAtPosition(arg2);
String name = (String) selectget(“name”);
String address = (String) selectget(“address”);
qintentputExtra(DeviceControlEXTRAS_DEVICE_NAME, name);
qintentputExtra(DeviceControlEXTRAS_DEVICE_ADDRESS, address);
startActivity(qintent);
}
});
DeviceControljava将调用BluetoothLeServicejava和连接到设备。
private final ServiceConnection mServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder service) {
// TODO Auto-generated method stub
mBluetoothLeService = ((BluetoothLeServiceLocalBinder) service)。getService();
if(!mBluetoothLeServiceinitialize()) {
Loge(TAG, “Unable to initialize Bluetooth”);
finish();
}
registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter());
mBluetoothLeServiceconnect(mDeviceAddress);
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
// TODO Auto-generated method stub
mBluetoothLeService = null;
}
};
BluetoothLeServicejava将连接到该设备。
public boolean connect(final String address) {
if (mBluetoothAdapter == null || address == null) {
Logw(TAG, “BluetoothAdapter not initialized or unspecified address”);
return false;
}
if(mBluetoothDeviceAddress != null && addressequals(mBluetoothDeviceAddress)
&& mBluetoothGatt != null) {
Logd(TAG, “Trying to use an existing mBluetoothGatt for connection”);
if(mBluetoothGattconnect()) {
mConnectionState = STATE_CONNECTING;
return true;
}else {
return false;
}
}
final BluetoothDevice device = mBluetoothAdaptergetRemoteDevice(address);
if(device == null) {
Logw(TAG, “Device not found Unable to connect”);
return false;
}
mBluetoothGatt = deviceconnectGatt(this, false, mGattCallback);
Logd(TAG, “Try to create a new connection”);
mBluetoothDeviceAddress = address;
mConnectionState =STATE_CONNECTING;
return true;
}
它连接到设备后,我可以使用 readRemoteRssi 来从设备中读取 RSSI。
public void readRemoteRssi() {
mBluetoothGattreadRemoteRssi();
}
但它只能读取 RSSI 的最后一个设备的我已连接。
当我看到日志时,它总是发送onCharacteristicWrite和readRemoteRssi()到我连接的最后一个设备。
我应该重新连接关贸总协定 》 或之前我想 RSSI 对读取或写入的 CharacteristicWrite 值的第一个设备重新连接到的第一个地址的设备概览
它不会有其他的方法来读取我已连接的所有设备的 RSSI 概览
解决方法 1:
使多个 BluetoothGatt 对象来连接多个设备分开,并调用 readRemoteRssi 一个接一个。
懒的和坏的示例中,您应该能够将那些 BluetoothGatt 对象放入数组
BluetoothGatt mBluetoothGatt1 = device1connectGatt(this, false, mGattCallback);
BluetoothGatt mBluetoothGatt2 = device2connectGatt(this, false, mGattCallback);
问题出在fprint是将整个array从上往下从左往右一个个字符输出,你的str本质上就是个2x18的矩阵,每个字母是一个元素,所以在fprintf之后按照访问顺序会输出”qpienigkhiunag uunniivveerrssiittyy“,你可以在输出的时候给str加个‘进行转制,结果不会出现之前的那种乱序,不过却不能换行
以下是可以正常输出的代码,采用for循环历遍str的每一行:
str=['qinghua university'
'peiking university'];
leng = size(str);
fprintf(fid,'\nexample6-2\nstr=\n');
for i=1:leng(1)
fprintf(fid,'%s\n',str(i,:));
end
以上就是关于如何读取一次,我连接的多个设备的 rssi 值全部的内容,包括:如何读取一次,我连接的多个设备的 rssi 值、matlab 怎么逐行输出字符串中的字母,每行只输出一个字符、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)