我现在解决了之前的使用问题,但是当我正在编写结束字节时这样做:
case "OTAEND":
Log.d("OTAEND", "Called");
handler.postDelayed(new Runnable() {
@Override
public void run() {
writeOtaControl((byte) 0x03);
}
},500);
break;
使用此方法:
/**WRITES BYTE TO OTA CONTROL CHARACTERISTIC*****************************************/
public boolean writeOtaControl(byte ctrl) {
Log.d("writeOtaControl", "Called");
if (bluetoothGatt.getService(ota_service)!=null){
BluetoothGattCharacteristic charac = bluetoothGatt.getService(ota_service).getCharacteristic(ota_control);
if (charac != null) {
Log.d("Instance ID", "" + charac.getInstanceId());
charac.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT);
Log.d("charac_properties", "" + charac.getProperties());
byte[] control = new byte[1];
control[0] = ctrl;
charac.setValue(control);
bluetoothGatt.writeCharacteristic(charac);
return true;
} else {
Log.d("characteristic", "null");
}
} else {
Log.d("service", "null");
}
return false;
}
在这个回调中,我获得了错误代码 129 的状态,这在BLE的文档中都没有。
@Override //CALLBACK ON CHARACTERISTIC WRITE (PROPERTY: WHITE)
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
if (status != 0){ // Error Handling
Log.d("onCharWrite", "status: " + Integer.toHexString(status));
final int error = status;
runOnUiThread(new Runnable() { //Display error on Toast
@Override
public void run() {
Toast.makeText(getBaseContext(), charErrorHandling(error), Toast.LENGTH_LONG).show();
}
});
这是我的HCl日志: