From 022fa8c638297678256e797a93fc33b16787168e Mon Sep 17 00:00:00 2001 From: "Christian S." Date: Sun, 17 May 2020 15:18:41 +0200 Subject: [PATCH] Add sender thread restart to main look, fix NPE --- .../csdev/ebus/core/EBusEbusdController.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/csdev/ebus/core/EBusEbusdController.java b/src/main/java/de/csdev/ebus/core/EBusEbusdController.java index 45fd5a3..d460d6c 100644 --- a/src/main/java/de/csdev/ebus/core/EBusEbusdController.java +++ b/src/main/java/de/csdev/ebus/core/EBusEbusdController.java @@ -175,11 +175,15 @@ private ByteBuffer parseLine(String readLine) throws IOException, InterruptedExc if (readLine.startsWith("-s")) { String tmp = readLine.substring(3, 5) + readLine.substring(6); + QueueEntry queueEntry = queue.getCurrent(); - currentSendId = queue.getCurrent().id; + // maybe the command is direct from ebusd and the binding + if (queueEntry != null) { + currentSendId = queueEntry.id; - // remove this entry from queue - queue.resetSendQueue(); + // remove this entry from queue + queue.resetSendQueue(); + } if (readLine.contains(":")) { String[] split = tmp.split(":"); @@ -254,6 +258,11 @@ public void run() { reconnect(); } + if (senderThread == null || !senderThread.isAlive()) { + // should not happened, but maybe it can help + startSenderThread(); + } + String readLine = reader.readLine(); // reset send id before parsing @@ -275,9 +284,6 @@ public void run() { this.fireOnEBusDataException(e, currentSendId); } catch (InterruptedIOException e) { - // re-enable the interrupt to stop the while loop - // Thread.currentThread().interrupt(); - // disable the interrupt, can be a simple java.net.SocketTimeoutException: Read timed out } catch (InterruptedException e) {