From d885d92c7b5c5db4b39b9f33c81970511c60928b Mon Sep 17 00:00:00 2001 From: yoh-there Date: Mon, 23 Aug 2021 21:30:15 +0200 Subject: [PATCH] Adjust device initalisation. Lint --- .../java/lu/fisch/canze/devices/CanSee.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/lu/fisch/canze/devices/CanSee.java b/app/src/main/java/lu/fisch/canze/devices/CanSee.java index cdd1220b..06b4fdcc 100755 --- a/app/src/main/java/lu/fisch/canze/devices/CanSee.java +++ b/app/src/main/java/lu/fisch/canze/devices/CanSee.java @@ -59,7 +59,7 @@ public void join() throws InterruptedException { // send a command and wait for an answer private String sendAndWaitForAnswer(String command, int waitMillis, int timeout) { - // empty incoming buffer. This is neccesary to ensure things get not horribly out of sync + // empty incoming buffer. This is necessary to ensure things get not horribly out of sync try { while (BluetoothManager.getInstance().available() > 0) { BluetoothManager.getInstance().read(); @@ -84,7 +84,7 @@ private String sendAndWaitForAnswer(String command, int waitMillis, int timeout) boolean stop = false; //Do not use StringBuilder as it's not thread safe //StringBuilder readBuffer = new StringBuilder(); - StringBuffer readBuffer = new StringBuffer(); + StringBuilder readBuffer = new StringBuilder(); // wait for answer long start = Calendar.getInstance().getTimeInMillis(); long runtime = 0; @@ -99,7 +99,7 @@ private String sendAndWaitForAnswer(String command, int waitMillis, int timeout) if (ch == EOM) { // stop if we reached the end or if no more data is available stop = true; } else { - // add it to the readBufferr + // add it to the readBuffer readBuffer.append(ch); } } @@ -146,12 +146,9 @@ private Message responseToMessage(Frame frame, String command, int timeout) { //wrongCount++; if (wrongCount > WRONG_THRESHOLD) { wrongCount = 0; - (new Thread(new Runnable() { - @Override - public void run() { - MainActivity.getInstance().stopBluetooth(false); - MainActivity.getInstance().reloadBluetooth(false); - } + (new Thread(() -> { + MainActivity.getInstance().stopBluetooth(false); + MainActivity.getInstance().reloadBluetooth(false); })).start(); } return new Message(frame, "-E-CanSee.rtm.empty", true); @@ -188,13 +185,13 @@ public boolean initDevice(int toughness) { @Override protected boolean initDevice(int toughness, int retries) { - //if (BuildConfig.BRANCH.equals("master")) { + if (BuildConfig.BRANCH.equals("master") || !BuildConfig.DEBUG) { sendAndWaitForAnswer("n110,0", 0, TIMEOUT_FREE); // disable all serial when on master branch sendAndWaitForAnswer("n114,0", 0, TIMEOUT_FREE); // disable all debugging when on master branch - //} else { - // sendAndWaitForAnswer("n110,1", 0, TIMEOUT_FREE); // enable all serial - // sendAndWaitForAnswer("n114,f6", 0, TIMEOUT_FREE); // enable all default debugging - //} + } else { + sendAndWaitForAnswer("n110,0", 0, TIMEOUT_FREE); // enable all serial + sendAndWaitForAnswer("n114,fe", 0, TIMEOUT_FREE); // enable all default debugging, except reception of free frames + } lastInitProblem = ""; return true; }