From 2e3f0fd59f1c8761696e8a1451e0695d3f305f9e Mon Sep 17 00:00:00 2001 From: caodd Date: Fri, 26 Apr 2019 18:13:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B6=85=E6=97=B6=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E8=AE=BE=E7=BD=AE=EF=BC=8C=E5=8F=AF=E4=BB=A5=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E5=B8=A7=E9=97=B4=E9=9A=94=E8=B6=85=E6=97=B6=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rxbluetoothhelper/experimental/Connection.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/helper/src/main/java/com/github/caoddx/rxbluetoothhelper/experimental/Connection.kt b/helper/src/main/java/com/github/caoddx/rxbluetoothhelper/experimental/Connection.kt index fde82ef..c2901d2 100644 --- a/helper/src/main/java/com/github/caoddx/rxbluetoothhelper/experimental/Connection.kt +++ b/helper/src/main/java/com/github/caoddx/rxbluetoothhelper/experimental/Connection.kt @@ -3,8 +3,8 @@ package com.github.caoddx.rxbluetoothhelper.experimental import android.annotation.SuppressLint import android.bluetooth.BluetoothDevice import android.bluetooth.BluetoothSocket -import com.github.caoddx.rxbluetoothhelper.experimental.ConnectionStatus.* import com.github.caoddx.rxbluetoothhelper.RxInputStream +import com.github.caoddx.rxbluetoothhelper.experimental.ConnectionStatus.* import io.reactivex.Observable import io.reactivex.Single import io.reactivex.schedulers.Schedulers @@ -163,17 +163,17 @@ class Connection(val tag: String) { * 根据时间间隔对数据进行分包,连续的数据视为一包,时间超过100ms即视为分包。 * 此方法会发射包数据,直到取消订阅。 */ - fun receiveFrames(): Observable> { - return receive().buffer(receive().debounce(100, TimeUnit.MILLISECONDS)) + fun receiveFrames(byteTimeoutInMilliseconds: Long = 100): Observable> { + return receive().buffer(receive().debounce(byteTimeoutInMilliseconds, TimeUnit.MILLISECONDS)) //.doOnNext { Timber.i("receive data: (len = %d)[%s]", it.size, it.toHexString()) } } /** * 在 frameTimeout 和 unit 指定的超时时间内,发射一包数据。空list代表超时 */ - fun receiveFrame(frameTimeout: Long, unit: TimeUnit): Single> { - return receiveFrames() - .timeout(frameTimeout, unit, Observable.just(emptyList())) // 超时发送一个空包,空包即代表“超时” + fun receiveFrame(byteTimeoutInMilliseconds: Long = 100, frameTimeoutInMilliseconds: Long): Single> { + return receiveFrames(byteTimeoutInMilliseconds) + .timeout(frameTimeoutInMilliseconds, TimeUnit.MILLISECONDS, Observable.just(emptyList())) // 超时发送一个空包,空包即代表“超时” .take(1).singleOrError() }