Commit 5f16ef72 authored by Chengzhao Li's avatar Chengzhao Li
Browse files

- update sendPeripheralDataToCentral. P.S should test after get the new phones

parent ffaa372f
......@@ -1061,21 +1061,22 @@ import java.util.concurrent.ConcurrentHashMap;
Integer centralMtu = this.mCentralMTUs.get(centralAddress);
if (mSendCharacteristic != null && centralDevice != null && centralMtu != null) {
List<byte[]> msgs = makeMsg(message, centralMtu);
synchronized (mMessageSendQueue) {
Log.d(TAG, "sendPeripheralDataToCentral: current queue size:" + mMessageSendQueue.size());
boolean shouldExecute = this.mMessageSendQueue.size() == 0;
List<NCMCMessageData> tmpMessageQueue = new LinkedList<>();
for (byte[] msg : msgs) {
NCMCMessageData msgData = new NCMCMessageData(centralAddress, true);
msgData.addData(msg);
this.mMessageSendQueue.add(msgData);
}
for (byte[] msg : msgs) {
NCMCMessageData msgData = new NCMCMessageData(centralAddress, true);
msgData.addData(msg);
tmpMessageQueue.add(msgData);
}
synchronized (mMessageSendQueue) {
Log.d(TAG, "sendPeripheralDataToCentral: current queue size:" + mMessageSendQueue.size() + " tmpQueue size:" + tmpMessageQueue.size());
this.mMessageSendQueue.addAll(tmpMessageQueue);
if (shouldExecute) {
executeSendPeripheralData();
if (this.mMessageSendQueue.size() == tmpMessageQueue.size()) {
executeSendPeripheralData(); // trigger execute write when this is the first message in the queue.
}
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment