summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
2cb7a96)
Binary reads require an explicit length, and do not work while
telemetry is running.
Signed-off-by: Keith Packard <keithp@keithp.com>
+ public void putchar(byte c) {
+ byte[] bytes = { c };
+ if (D) Log.d(TAG, "print(): begin");
+ try {
+ wait_connected();
+ output.write(bytes);
+ if (D) Log.d(TAG, "print(): Wrote byte: '" + c + "'");
+ } catch (IOException e) {
+ connection_lost();
+ } catch (InterruptedException e) {
+ connection_lost();
+ }
+ }
+
public int getchar() {
try {
wait_connected();
public int getchar() {
try {
wait_connected();
public abstract int getchar();
public abstract void print(String data);
public abstract int getchar();
public abstract void print(String data);
+ public abstract void putchar(byte c);
public abstract void close();
public static boolean debug = false;
public abstract void close();
public static boolean debug = false;
public LinkedList<LinkedBlockingQueue<AltosLine>> monitors = new LinkedList<LinkedBlockingQueue<AltosLine>> ();;
public LinkedBlockingQueue<AltosLine> reply_queue = new LinkedBlockingQueue<AltosLine>();
public LinkedList<LinkedBlockingQueue<AltosLine>> monitors = new LinkedList<LinkedBlockingQueue<AltosLine>> ();;
public LinkedBlockingQueue<AltosLine> reply_queue = new LinkedBlockingQueue<AltosLine>();
+ public LinkedBlockingQueue<byte[]> binary_queue = new LinkedBlockingQueue<byte[]>();
public synchronized void add_monitor(LinkedBlockingQueue<AltosLine> q) {
set_monitor(true);
public synchronized void add_monitor(LinkedBlockingQueue<AltosLine> q) {
set_monitor(true);
+ private int len_read = 0;
public void run () {
int c;
public void run () {
int c;
for (;;) {
c = getchar();
if (Thread.interrupted()) {
for (;;) {
c = getchar();
if (Thread.interrupted()) {
- if (debug)
- System.out.printf("INTERRUPTED\n");
break;
}
if (c == ERROR) {
break;
}
if (c == ERROR) {
System.out.printf("TIMEOUT\n");
continue;
}
System.out.printf("TIMEOUT\n");
continue;
}
+ if (c == '\r' && len_read == 0)
continue;
synchronized(this) {
continue;
synchronized(this) {
+ if (c == '\n' && len_read == 0) {
if (line_count != 0) {
add_bytes(line_bytes, line_count);
line_count = 0;
if (line_count != 0) {
add_bytes(line_bytes, line_count);
line_count = 0;
}
line_bytes[line_count] = (byte) c;
line_count++;
}
line_bytes[line_count] = (byte) c;
line_count++;
+ if (len_read !=0 && line_count == len_read) {
+ add_binary(line_bytes, line_count);
+ line_count = 0;
+ len_read = 0;
+ }
public String get_reply(int timeout) throws InterruptedException {
boolean can_cancel = can_cancel_reply();
String reply = null;
public String get_reply(int timeout) throws InterruptedException {
boolean can_cancel = can_cancel_reply();
String reply = null;
+ public byte[] get_binary_reply(int timeout, int len) throws InterruptedException {
+ boolean can_cancel = can_cancel_reply();
+ byte[] bytes = null;
+
+ synchronized(this) {
+ len_read = len;
+ }
+ try {
+ ++in_reply;
+
+ flush_output();
+
+ reply_abort = false;
+ reply_timeout_shown = false;
+ for (;;) {
+ bytes = binary_queue.poll(timeout, TimeUnit.MILLISECONDS);
+ if (bytes != null) {
+ cleanup_reply_timeout();
+ break;
+ }
+ if (!remote || !can_cancel || check_reply_timeout()) {
+ bytes = null;
+ break;
+ }
+ }
+
+ } finally {
+ --in_reply;
+ }
+ return bytes;
+ }
+
public void add_telem(AltosLine line) throws InterruptedException {
for (int e = 0; e < monitors.size(); e++) {
LinkedBlockingQueue<AltosLine> q = monitors.get(e);
public void add_telem(AltosLine line) throws InterruptedException {
for (int e = 0; e < monitors.size(); e++) {
LinkedBlockingQueue<AltosLine> q = monitors.get(e);
+ public void add_binary(byte[] bytes, int len) throws InterruptedException {
+ byte[] dup = new byte[len];
+
+ if (debug)
+ System.out.printf ("\t\t\t\t\t%d:", len);
+ for(int i = 0; i < len; i++) {
+ dup[i] = bytes[i];
+ if (debug)
+ System.out.printf(" %02x", dup[i]);
+ }
+ if (debug)
+ System.out.printf("\n");
+
+ binary_queue.put(dup);
+ }
+
public void flush_output() {
for (String s : pending_output)
System.out.print(s);
public void flush_output() {
for (String s : pending_output)
System.out.print(s);
+ public boolean is_loader() {
+ boolean ret = false;
+ printf("v\n");
+ try {
+ for (;;) {
+ String line = get_reply();
+
+ if (line == null)
+ return false;
+ if (line.startsWith("software-version"))
+ break;
+ if (line.startsWith("altos-loader"))
+ ret = true;
+ }
+ } catch (InterruptedException ie) {
+ }
+ return ret;
+ }
+
+ public void to_loader() {
+ printf("X\n");
+ flush_output();
+ close();
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException ie) {
+ }
+ }
+
public boolean remote;
public int serial;
public String name;
public boolean remote;
public int serial;
public String name;
+ public void putchar(byte c) {
+ if (altos != null) {
+ if (debug)
+ System.out.printf(" %02x", (int) c & 0xff);
+ if (libaltos.altos_putchar(altos, (char) c) != 0) {
+ close_serial();
+ }
+ }
+ }
+
public void print(String data) {
for (int i = 0; i < data.length(); i++)
putc(data.charAt(i));
public void print(String data) {
for (int i = 0; i < data.length(); i++)
putc(data.charAt(i));