我想通过BLE将数据传输到设备。每次传输的字节数为64。
现在的问题是,当我通过setMaxBatchSize(ex 64)修改MTU时,mRxBleConnection.getMtu()返回默认的MTU(23)。
def score_house(house):
# score house
score = 0
if (house.windows > 2): score += 10
if (house.garage): score += 10
if (house.fence == 'broken'): score += 80
return score
private void connect(RxBleDevice rxBleDevice){
connectionObservable = rxBleDevice.establishConnection(false)
.subscribe(rxBleConnection -> {
mRxBleConnection = rxBleConnection;
rxBleConnection.setupNotification(MainActivity.MY_UUID);
longWrite();
});
}
private void longWrite(){
mRxBleConnection.setupNotification(MainActivity.MY_UUID)
.flatMap(ob -> ob.merge(
mRxBleConnection.createNewLongWriteBuilder()
.setCharacteristicUuid(MainActivity.MY_UUID)
.setBytes(HexString.hexToBytes(writeData))
.setMaxBatchSize(64)
.build(),ob)
)
.subscribe(bytes -> {
Log.i(TAG,mRxBleConnection.getMtu());
doResponse(HexString.bytesToHex(bytes));
},throwable -> {
});
}
日志
Disposable writeSubscription = mRxBleConnection.requestMtu(176)
.subscribe(
integer -> {
Log.i(TAG, "longWrite: "+integer);
},
throwable ->{
}
);
mtu始终为23。
答案 0 :(得分:0)
回答主题中的问题-见下文
LongWriteOperationBuilder.setMaxBatchSize()
Javadoc:
/**
* Setter for a maximum size of a byte array that may be write at once
* If this is not specified - the default value of the connection's MTU is used
*
* @param maxBatchSize the maximum size of a byte array to write at once
* @return the LongWriteOperationBuilder
*/
如果未指定.setMaxBatchSize()
,则使用从MTU派生的值。这是一种暗示。并不是说设置此属性会更改MTU。
此外,当您尝试设置其他MTU时,您会在日志中看到未接受新值-您要通信的外围设备不允许这样做。