我正在开发一个应用程序,我必须在其中连接到 Android 4.3 上的蓝牙设备。
我想通过 Android 应用程序更改 CC2541 Keyfob 的名称。
我的想法是:
1.有一个纯文本,我可以在我的 Android 应用程序中输入我想要的名称。
2. 输入姓名后,我按下按钮发送此文本。
3.如果CC2541从Android应用程序接收到这个文本,它将改变keyfobdemo.c中以下代码的deviceName[]中的文本:
static uint8 deviceName[] =
{
// complete name
0x0b, // length of first data structure (11 bytes excluding length byte)
0x09, // AD Type = Complete local name
0x4b, // 'K'
0x65, // 'e'
0x79, // 'y'
0x66, // 'f'
0x6f, // 'o'
0x62, // 'b'
0x64, // 'd'
0x65, // 'e'
0x6d, // 'm'
0x6f, // 'o'
};
问题如下:
1.如何在Android应用程序4.3中将文本数据发送到CC2541 keyfob ??
2.CC2541端如何接收文本数据??
3.我需要使用任何个人资料吗?
对不起我的英语和这些问题。
谢谢你的指导。
编辑
我试图使用 0x2A00 来获取设备名称服务,但是当我调用 Device_Name 函数时它发现它不起作用。
Name_Service 为空。
private static final UUID Device_Name_UUID = UUID.fromString("00002a00-0000-1000-8000-00805f9b34fb");
private static final UUID Write_UUID = UUID.fromString("00001800-0000-1000-8000-00805f9b34fb");
public void Device_Name(){
BluetoothGattService Name_Service = mBluetoothGatt.getService(Write_UUID );
if(Name_Service == null) {
Log.d(TAG, "Name_Service service not found!");
return;
}
BluetoothGattCharacteristic DeviceName = Name_Service.getCharacteristic(Device_Name_UUID);
if(DeviceName == null) {
Log.d(TAG, "DeviceName charateristic not found!");
return;
}
}
Log.v(TAG, "readCharacteristic(DeviceName) = " + mBluetoothGatt.readCharacteristic(DeviceName));
String i = "123";
DeviceName.setValue(i);
Log.v(TAG, "writeCharacteristic(DeviceName) = " + mBluetoothGatt.writeCharacteristic(DeviceName));
它显示以下日志:
V/BluetoothLeService( 3680): readCharacteristic(DeviceName) = true
V/BluetoothLeService( 3680): writeCharacteristic(DeviceName) = false
D/audio_hw_primary( 1752): found out /dev/snd/pcmC0D0p
W/audio_hw_primary( 1752): out_write() limiting sleep time 45351 to 23219
W/audio_hw_primary( 1752): out_write() limiting sleep time 34263 to 23219
W/audio_hw_primary( 1752): out_write() limiting sleep time 33696 to 23219
D/BtGatt.btif( 2646): btif_gattc_upstreams_evt: Event 3
I/BtGatt.btif( 2646): set_read_value unformat.len = 13
D/BtGatt.GattService( 2646): onReadCharacteristic() - address=90:59:AF:0B:8A:AB, status=0, length=13
D/BluetoothGatt( 3680): onCharacteristicRead() - Device=90:59:AF:0B:8A:AB UUID=00002a00-0000-1000-8000-00805f9b34fb Status=0
它读取成功,我可以得到设备的名称。
我引用了Bluetooth Page-Device Name,格式为 UTF-8 字符串。但是它写特征是假的。