feat: add csv auto export
This commit is contained in:
@@ -90,7 +90,7 @@ open class BleListener(private val deviceAddress: String?) {
|
||||
|
||||
open fun isRelevantMessage(address: String?): Boolean {
|
||||
if (deviceAddress != null && deviceAddress == address) {
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
return deviceAddress == null
|
||||
}
|
||||
@@ -165,7 +165,7 @@ private fun BluetoothGatt.printGattTable() {
|
||||
separator = "\n|--",
|
||||
prefix = "|--"
|
||||
) {
|
||||
"${it.uuid.toString()} | " +
|
||||
"${it.uuid} | " +
|
||||
"readable: ${it.isReadable()}, " +
|
||||
"writable: ${it.isWritable()}, " +
|
||||
"writableWithoutResponse: ${it.isWritableWithoutResponse()}, " +
|
||||
@@ -325,7 +325,11 @@ class ConnectionManager(val context: Context, bleAdapter: BluetoothAdapter) {
|
||||
|
||||
|
||||
fun connect(device: BluetoothDevice) {
|
||||
if (device.isConnected()) {
|
||||
Log.i("ConnectionManager", "connecting to " +device.address)
|
||||
|
||||
val isConnecting = pendingOperation != null && pendingOperation is Connect && (pendingOperation as Connect).device.address == device.address
|
||||
|
||||
if(device.isConnected() or isConnecting or operationQueue.any { it.device.address === device.address && it is Connect }) {
|
||||
Log.e("ConnectionManager", "Already connected to ${device.address}!")
|
||||
} else {
|
||||
enqueueOperation(Connect(device, context))
|
||||
@@ -528,7 +532,7 @@ class ConnectionManager(val context: Context, bleAdapter: BluetoothAdapter) {
|
||||
}
|
||||
|
||||
is SetNotification -> with(operation) {
|
||||
val characteristic = gatt.getService(serviceId)?.getCharacteristic(charId);
|
||||
val characteristic = gatt.getService(serviceId)?.getCharacteristic(charId)
|
||||
|
||||
if (characteristic == null) {
|
||||
Log.e("ConnectionManager", "Char $charId (${serviceId}) not found!")
|
||||
@@ -560,7 +564,7 @@ class ConnectionManager(val context: Context, bleAdapter: BluetoothAdapter) {
|
||||
payload =
|
||||
if (characteristic.isIndicatable())
|
||||
BluetoothGattDescriptor.ENABLE_INDICATION_VALUE
|
||||
else BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE;
|
||||
else BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
|
||||
|
||||
} else {
|
||||
if (!gatt.setCharacteristicNotification(characteristic, false)) {
|
||||
@@ -613,7 +617,7 @@ class ConnectionManager(val context: Context, bleAdapter: BluetoothAdapter) {
|
||||
it.onConnectToBondedFailed(gatt)
|
||||
}
|
||||
signalEndOfOperation(operation)
|
||||
} else if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||
} else if (status == GATT_SUCCESS) {
|
||||
if (newState == BluetoothProfile.STATE_CONNECTED) {
|
||||
Log.i(
|
||||
"ConnectionManager",
|
||||
@@ -649,7 +653,7 @@ class ConnectionManager(val context: Context, bleAdapter: BluetoothAdapter) {
|
||||
|
||||
override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) {
|
||||
with(gatt) {
|
||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
||||
if (status == GATT_SUCCESS) {
|
||||
Log.w(
|
||||
"ConnectionManager",
|
||||
"Discovered ${services.size} services for ${device.address}."
|
||||
@@ -673,7 +677,7 @@ class ConnectionManager(val context: Context, bleAdapter: BluetoothAdapter) {
|
||||
override fun onMtuChanged(gatt: BluetoothGatt, mtu: Int, status: Int) {
|
||||
Log.w(
|
||||
"ConnectionManager",
|
||||
"ATT MTU changed to $mtu, success: ${status == BluetoothGatt.GATT_SUCCESS}"
|
||||
"ATT MTU changed to $mtu, success: ${status == GATT_SUCCESS}"
|
||||
)
|
||||
|
||||
val operation = pendingOperation
|
||||
@@ -689,7 +693,7 @@ class ConnectionManager(val context: Context, bleAdapter: BluetoothAdapter) {
|
||||
) {
|
||||
with(characteristic) {
|
||||
when (status) {
|
||||
BluetoothGatt.GATT_SUCCESS -> {
|
||||
GATT_SUCCESS -> {
|
||||
Log.i(
|
||||
"ConnectionManager",
|
||||
"Read characteristic $uuid (service: ${service.uuid}): ${value.toHexString()}"
|
||||
|
||||
Reference in New Issue
Block a user