X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosDebug.java;h=23e38bc02f9df4f5896aad3a1d38341d39c7bb05;hp=8d435b667d5ecb584b118bed27a5d9945b4abb92;hb=95268d681c9a6652d84db383f55a4fe8a4ac5173;hpb=51c7741040d95c5deece939dae5e4136cc04afc4 diff --git a/altosui/AltosDebug.java b/altosui/AltosDebug.java index 8d435b66..23e38bc0 100644 --- a/altosui/AltosDebug.java +++ b/altosui/AltosDebug.java @@ -21,6 +21,7 @@ import java.lang.*; import java.io.*; import java.util.concurrent.*; import java.util.*; +import org.altusmetrum.AltosLib.*; import libaltosJNI.*; @@ -62,7 +63,10 @@ public class AltosDebug extends AltosSerial { void ensure_debug_mode() { if (!debug_mode) { printf("D\n"); - flush_input(); + try { + flush_input(); + } catch (InterruptedException ie) { + } debug_mode = true; } } @@ -160,7 +164,11 @@ public class AltosDebug extends AltosSerial { int i = 0; byte[] data = new byte[length]; while (i < length) { - String line = get_reply().trim(); + String line = get_reply(); + + if (line == null) + throw new IOException("Timeout in read_bytes"); + line = line.trim(); String tokens[] = line.split("\\s+"); for (int j = 0; j < tokens.length; j++) { if (!Altos.ishex(tokens[j]) || @@ -169,7 +177,12 @@ public class AltosDebug extends AltosSerial { String.format ("Invalid read_bytes reply \"%s\"", line)); try { - data[i + j] = (byte) Integer.parseInt(tokens[j], 16); + if (i + j >= length) + throw new IOException( + String.format + ("Invalid read_bytes reply \"%s\"", line)); + else + data[i + j] = (byte) Integer.parseInt(tokens[j], 16); } catch (NumberFormatException ne) { throw new IOException( String.format