package altosui;
-import java.lang.*;
import java.io.*;
-import java.util.concurrent.*;
-import java.util.*;
-
-import libaltosJNI.*;
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;
}
}
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]) ||
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