Android的蓝牙onCharacteristicwrite状态133 [英] Android Bluetooth status 133 in onCharacteristicwrite

查看:5798
本文介绍了Android的蓝牙onCharacteristicwrite状态133的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Andr​​oid和现在做一个简单的应用程序,需要一些数据写入到外围设备。

I'm new to Android and now doing a simple app that requires writing some data into a peripheral device.

其实也没什么不顺心的三星GT-S7272C设备。但是,当我切换到索尼LT29i,总是会有一个状态133,当我试图写成一定的特点。我会给一些简要的code。

Actually nothing goes wrong in a Samsung GT-S7272C device. But when I switch to Sony LT29i, there will always be a status 133 when I'm trying to write into a certain characteristic. I will give out some brief code.

BluetoothGattService syncService = gatt.getService(SYNC_DATA_SERVICE);
BluetoothGattCharacteristic tChar = syncService.getCharacteristic(SYNC_TIME_INPUT_CHAR);
if (tChar == null) throw new AssertionError("characteristic null when sync time!");

int diff = /*a int*/;
tChar.setValue(diff, BluetoothGattCharacteristic.FORMAT_SINT32, 0);
gatt.writeCharacteristic(tChar);

和onCharacteristicWrite功能:

and the onCharacteristicWrite function:

@Override
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
    Log.d(TAG, String.format("Sync: onCharWrite, status = %d", status));
    try {
        if (status != BluetoothGatt.GATT_SUCCESS) throw new AssertionError("Error on char write");
        super.onCharacteristicWrite(gatt, characteristic, status);
        if (characteristic.getUuid().equals(SYNC_TIME_INPUT_CHAR)) {
            BluetoothGattService syncService = gatt.getService(SYNC_DATA_SERVICE);
            BluetoothGattCharacteristic tChar = syncService.getCharacteristic(SYNC_HEIGHT_INPUT_CHAR);
            if (tChar == null) throw new AssertionError("characteristic null when sync time!");
            tChar.setValue(/*another int*/, BluetoothGattCharacteristic.FORMAT_SINT32, 0);
            gatt.writeCharacteristic(tChar);
        }
        else if {
            ...
        }
    } catch (AssertionError e) {
        ...
    }

写入第一个特点有什么不妥和控制将达到onCharacteristicWrite并输入与地位的第一个如果语句 0 ,这意味着成功。问题是在如果语句中的第二次写入的动作,这也将引发onCharacteristicWrite功能,但产生的状态 133 ,其中不能在找到官方网站。然后,设备断开自动。

Writing into first characteristic has nothing wrong and control will reach the onCharacteristicWrite and enter the first if statement with status 0, which means success. Problem is the second writing action in the if statement, which will also trigger onCharacteristicWrite function but yield a status 133, which cannot be found in the official site. Then the device disconnect automatically.

我已经证实的数据类型和偏移是正确的。而由于其他设备它的作品真的很好,我觉得可能是不同的设备之间的蓝牙协议栈的实现,我应该做些更棘手的解决这个问题的一些微小的差异。

I've confirmed that the data type and the offset are all correct. And because in another device it works really nice, I think there might be some tiny differences of the bluetooth stack implementation between different device that I should do something more tricky to solve this problem.

我搜索的结果很长一段时间。一些结果导致我的C源$ C ​​$ C(对不起,我会后下面的链接,因为我没有足够的声誉发布超过2链接),但我只能找到 133 表示GATT_ERROR存在,这是不超过有益的只是一个 133 。我还发现,在谷歌组中的问题,讨论一些熟悉的问题,但我没能在这里找到一个解决方案。

I've search for result for a long time. Some results lead me to the C source code(Sorry, I will post the link below because I don't have enough reputation to post more than 2 links), but I can only find that 133 means GATT_ERROR there, which is not more helpful than just a 133. I've also found a issue in google group, discussing some familiar questions, but I failed to find a solution here.

我有点难过,因为,如果它出了故障,C code,就算我能找​​到什么是错的,我还没有办法去弥补我自己的code,对吧?

I'm a little bit sad because, if it is something wrong with the C code, even if I can locate what's wrong, I still have no way to make it right in my own code, right?

我希望有人之前有熟悉的体验,并可以给我一些建议。非常感谢!

I hope that someone has the familiar experience before and may give me some suggestions. Thanks a lot!

链接:


  • C源$ C ​​$ C: <$c$c>https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-4.4.2_r1/stack/include/gatt_api.h

问题: HTTPS://$c$c.google.com/p/android/issues/detail ID = 58381

推荐答案

我有一个类似的问题,当我试着写一些特点我不记得不过,如果我得到了同样的错误code与否。的(和它的工作在某些设备上,而它并没有在其他)。

I had a similar issue when I tried to write to some characteristic I can't remember though if i got the same error code or not. (And it worked on some devices while it didn't on others).

什么原来是这个问题是属性特性 writeType

What turned out to be the problem is the property of the characteristics and the writeType.

由于特性可以设置的值:

Because characteristics can have values set:


  • 无反应写

  • 与响应写

  • write without response OR
  • write with response

在引用这个属性,你必须设置 writeType 前的实际数据写入性能。

In reference to this property you have to set the writeType before writing the actual data to the characteristic.

一旦你的特性,但在写入之前可以设置的类型。

You can set the type once you get the Characteristic but before writing to it.

BluetoothGattCharacteristic tChar = syncService.getCharacteristic(SYNC_HEIGHT_INPUT_CHAR);
        if (tChar == null) throw new AssertionError("characteristic null when sync time!");

        // use one of them in regards of the Characteristic's property
        tChar.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
        //tChar.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);


        tChar.setValue(/*another int*/, BluetoothGattCharacteristic.FORMAT_SINT32, 0);
        gatt.writeCharacteristic(tChar);

这篇关于Android的蓝牙onCharacteristicwrite状态133的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆