DanaR: fix message locking

This commit is contained in:
Milos Kozak 2023-08-29 19:13:25 +02:00
parent a7d330e87f
commit f16229c4ed
2 changed files with 9 additions and 10 deletions

View file

@ -33,8 +33,6 @@ public class SerialIOThread extends Thread {
private final MessageHashTableBase hashTable; private final MessageHashTableBase hashTable;
private final DanaPump danaPump; private final DanaPump danaPump;
private final Object lock = new Object();
public SerialIOThread(AAPSLogger aapsLogger, BluetoothSocket rfcommSocket, MessageHashTableBase hashTable, DanaPump danaPump) { public SerialIOThread(AAPSLogger aapsLogger, BluetoothSocket rfcommSocket, MessageHashTableBase hashTable, DanaPump danaPump) {
super(); super();
this.hashTable = hashTable; this.hashTable = hashTable;
@ -84,7 +82,7 @@ public class SerialIOThread extends Thread {
// process the message content // process the message content
message.setReceived(true); message.setReceived(true);
message.handleMessage(extractedBuff); message.handleMessage(extractedBuff);
synchronized (lock) { synchronized (message) {
message.notifyAll(); message.notifyAll();
} }
} }

View file

@ -40,6 +40,7 @@ import java.util.concurrent.ScheduledFuture
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@Suppress("SpellCheckingInspection")
@Singleton @Singleton
class BLECommonService @Inject internal constructor( class BLECommonService @Inject internal constructor(
private val injector: HasAndroidInjector, private val injector: HasAndroidInjector,
@ -399,15 +400,15 @@ class BLECommonService @Inject internal constructor(
} }
} }
if (message != null) { message?.let {
aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + message!!.friendlyName + " " + DiaconnG8Packet.toHex(data)) aapsLogger.debug(LTag.PUMPBTCOMM, "<<<<< " + it.friendlyName + " " + DiaconnG8Packet.toHex(data))
// process received data // process received data
message!!.handleMessage(data) it.handleMessage(data)
message!!.setReceived() it.setReceived()
synchronized(message!!) { synchronized(it) {
// notify to sendMessage // notify to sendMessage
message!!.notifyAll() it.notifyAll()
} }
} else aapsLogger.error("Unknown message received " + DiaconnG8Packet.toHex(data)) } ?: aapsLogger.error("Unknown message received " + DiaconnG8Packet.toHex(data))
} }
} }