Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
[fw/altos] / altoslib / AltosLink.java
index 62bd82b93c2ae617c4d67a305696e99a32bd3ba7..639d2ac784a4f63642a5310ec1aef91658a38b36 100644 (file)
@@ -55,8 +55,11 @@ public abstract class AltosLink implements Runnable {
 
        public void printf(String format, Object ... arguments) {
                String  line = String.format(format, arguments);
-               if (debug)
-                       pending_output.add(line);
+               if (debug) {
+                       synchronized (pending_output) {
+                               pending_output.add(line);
+                       }
+               }
                try {
                        print(line);
                } catch (InterruptedException ie) {
@@ -286,12 +289,14 @@ public abstract class AltosLink implements Runnable {
                binary_queue.put(dup);
        }
 
-       public void flush_output() {
+       public synchronized void flush_output() {
                if (pending_output == null)
                        return;
-               for (String s : pending_output)
-                       System.out.print(s);
-               pending_output.clear();
+               synchronized (pending_output) {
+                       for (String s : pending_output)
+                               System.out.print(s);
+                       pending_output.clear();
+               }
        }
 
        public void flush_input(int timeout) throws InterruptedException {
@@ -422,8 +427,10 @@ public abstract class AltosLink implements Runnable {
 
        public void set_callsign(String callsign) {
                this.callsign = callsign;
-               printf ("c c %s\n", callsign);
-               flush_output();
+               if (callsign != null) {
+                       printf ("c c %s\n", callsign);
+                       flush_output();
+               }
        }
 
        public boolean is_loader() throws InterruptedException {
@@ -462,7 +469,7 @@ public abstract class AltosLink implements Runnable {
                if (telemetry_rate < 0)
                        telemetry_rate = AltosPreferences.telemetry_rate(serial);
                set_telemetry_rate(telemetry_rate);
-               if (callsign.equals(""))
+               if (callsign == null || callsign.equals(""))
                        callsign = AltosPreferences.callsign();
                set_callsign(callsign);
                printf("p\nE 0\n");