update server to auto-restart when files are changed
authoradam <adam@megacz.com>
Wed, 30 Jan 2008 07:34:30 +0000 (08:34 +0100)
committeradam <adam@megacz.com>
Wed, 30 Jan 2008 07:34:30 +0000 (08:34 +0100)
Makefile
src/edu/berkeley/fleet/fpga/Server.java

index 6446b41..88c7d9b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -65,16 +65,9 @@ verilog_files += $(shell find src -name \*.inc)
 runfpga: fleet.jar
        $(java) -jar fleet.jar target=fpga run
 
-program: upload
-       ssh root@goliath.megacz.com 'cd /afs/megacz.com/work/ml410/; ./program.sh ./main.bit'
-
-runserver:
-       java -Djava.library.path=lib -cp lib/RXTXcomm.jar:fleet.jar edu.berkeley.fleet.fpga.Server
-
 upload: fleet.jar build/fpga/main.bit
        mkdir -p build
        rsync -are ssh --progress --verbose ./ root@goliath:fleet/
-       rsync -zare ssh --progress --verbose build/fpga/main.bit root@goliath.megacz.com:/afs/megacz.com/work/ml410/
 
 uploadtest:
        make upload
index a3a4099..03b0442 100644 (file)
@@ -7,12 +7,21 @@ import java.util.*;
 
 public class Server {
 
+    static long jarFileTime = 0;
+    static long bitFileTime = 0;
+    static {
+        try {
+            jarFileTime = new File("fleet.jar").lastModified();
+            bitFileTime = new File("build/fpga/main.bit").lastModified();
+        } catch (Exception e) { throw new RuntimeException(e); }
+    }
+
     public static ServerSocket ss;
     public static void main(String[] args) throws Exception {
         System.err.println("programming...");
         Process proc = Runtime.getRuntime().exec(new String[] {
-                "/afs/megacz.com/work/ml410/program.sh",
-                "/afs/megacz.com/work/ml410/main.bit"
+                "misc/program.sh",
+                "build/fpga/main.bit"
             });
         BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
         String str = null;
@@ -25,6 +34,23 @@ public class Server {
             return;
         }
         System.err.println("done programming.");
+        new Thread() {
+            public void run() {
+                try {
+                    while(true) {
+                        Thread.sleep(500);
+                        if (jarFileTime != new File("fleet.jar").lastModified()) {
+                            System.err.println("jarfile modified; exiting...");
+                            System.exit(0);
+                        }
+                        if (bitFileTime != new File("build/fpga/main.bit").lastModified()) {
+                            System.err.println("bitfile modified; exiting...");
+                            System.exit(0);
+                        }
+                    }
+                } catch (Exception e) { throw new RuntimeException(e); }
+            }
+        }.start();
         ss = new ServerSocket(3133);
         while(true) {
             try {