Browse Source

allow comments in urscript
terminate urscript lines with \n

Martin Kunz 5 years ago
parent
commit
41e5bfb4b5

+ 1 - 3
src/main/java/at/acdp/urweb/Main.java

@@ -8,10 +8,8 @@ import java.io.IOException;
 public class Main {
 
     public static void main(String [ ] args) {
-        ScReadThread rt=new ScReadThread();
-
+        ScReadThread rt=new ScReadThread("192.168.20.156");
         new WebServer(8080,true,rt).start();
-
         Thread t=new Thread(rt);
         t.start();
 

+ 10 - 1
src/main/java/at/acdp/urweb/ScReadThread.java

@@ -9,8 +9,16 @@ import java.io.IOException;
 
 public class ScReadThread implements Runnable {
     private static final Logger log = LoggerFactory.getLogger(SecondaryClient.class);
+    private final String ip;
 
     SecondaryClient rde;
+
+
+    ScReadThread(String ip) {
+        this.ip=ip;
+    }
+
+
     @Override
     public void run() {
         while(true) {
@@ -23,7 +31,7 @@ public class ScReadThread implements Runnable {
     }
 
     private void read() throws IOException {
-        rde=new SecondaryClient("192.168.20.156", 30002);
+        rde=new SecondaryClient(ip, 30002);
         VersionMessage vm = rde.connect();
         while(true) {
             rde.readPackage();
@@ -31,6 +39,7 @@ public class ScReadThread implements Runnable {
     }
 
     public void writeCmd(String s) {
+        log.info("writecmd: "+s);
         rde.writeCmd(s);
 
     }

+ 31 - 0
src/main/java/at/acdp/urweb/sclient/Log.java

@@ -0,0 +1,31 @@
+package at.acdp.urweb.sclient;
+
+import at.acdp.urweb.sclient.data.ILogentry;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class Log {
+    private final static int LENGTH=100;
+    public ILogentry[] list=new ILogentry[LENGTH];
+    private int pos=0;
+
+
+
+    public void add(ILogentry le) {
+        synchronized (list) {
+            list[pos]=le;
+        }
+    }
+
+    public void get(int from) {
+        synchronized (list){
+            int idx=pos-from;
+            // ILogentry[] ret=new ILogentry[];
+            // System.arraycopy(list,from,ret,);
+        }
+
+    }
+
+
+}

+ 1 - 1
src/main/java/at/acdp/urweb/sclient/SecondaryClient.java

@@ -177,7 +177,7 @@ public class SecondaryClient {
         int robotMessageType = di.readUnsignedByte();
         switch (robotMessageType) {
             default:
-                log.info("unknown msg: " + (int) robotMessageType);
+                log.info("unknown msg:  " + (int) robotMessageType);
                 byte[] buf = new byte[size - 15];
                 di.readFully(buf);
         }

+ 1 - 1
src/main/java/at/acdp/urweb/sclient/data/AdditionalInfo.java

@@ -5,7 +5,7 @@ import at.acdp.urweb.CountDataInputStream;
 import java.io.DataInputStream;
 import java.io.IOException;
 
-public class AdditionalInfo implements IRead{
+public class AdditionalInfo implements IRead, ILogentry{
     public boolean freeDriveButtonPressed;
     public boolean freeDriveButtonEnabled;
     public boolean ioEnabledFreeDrive;

+ 4 - 0
src/main/java/at/acdp/urweb/sclient/data/ILogentry.java

@@ -0,0 +1,4 @@
+package at.acdp.urweb.sclient.data;
+
+public interface ILogentry {
+}

+ 23 - 1
src/main/java/at/acdp/urweb/web/WebServer.java

@@ -36,9 +36,31 @@ public class WebServer {
                         }
                         ex.startBlocking();
                         byte[] bytes = ex.getInputStream().readAllBytes();
-                        sc.writeCmd(new String(bytes));
+                        String cmd=new String(bytes);
+                        String[] lines=cmd.split("[\\r\\n]+");
+                        String res="";
+                        for(String line:lines) {
+                            line=line.trim();
+                            if(line.startsWith("//"))
+                                continue;
+                            if(line.startsWith("#"))
+                                continue;
+                            if(!line.endsWith("\n"))
+                                line+="\n";
+
+                            res+=line;
+                        }
+
+                        if(!cmd.endsWith("\n"))
+                            cmd+="\n";
+                        sc.writeCmd(cmd);
                     }
                 })
+                .get("/log",  ex -> {
+                    //ex.getOutputStream().
+
+                    // System.out.println(ex.getQueryParameters().get("id").getFirst());
+                })
                 .get("/test/{id}", ex -> {
                     System.out.println(ex.getQueryParameters().get("id").getFirst());
                 })

+ 15 - 5
webroot/index.html

@@ -13,7 +13,6 @@
 <div id="app">
     <textarea v-model="input" cols="80" rows="20"></textarea>
     <button v-on:click="send">send</button>
-    <div v-html="compiledMarkdown"></div>
 </div>
 
 <script>
@@ -22,7 +21,15 @@
         data: {
             input: '// rde.writeCmd("set_digital_out(2,True)");\n' +
                 '// rde.writeCmd("movej([-1.95,-1.58,-1.16,-1.15,-1.55,1.25], a=1.0, v=0.1)");\n' +
-                '//rde.writeCmd("freedrive_mode()");\n'
+                '//rde.writeCmd("freedrive_mode()");\n'+
+                'def asdf():\n' +
+                ' set_digital_out(3, True) \n' +
+                ' set_digital_out(4, True) \n' +
+                'end',
+            log: null
+        },
+        created: function() {
+            setTimeout(this.update, 1000);
         },
         methods: {
             send: function (event) {
@@ -31,9 +38,12 @@
                         return response;
                     });
             },
-            update: _.debounce(function (e) {
-                this.input = e.target.value
-            }, 300)
+            update: function (event) {
+                fetch('/log', {method: "GET"})
+                    .then(function (value) {
+                        this.data.log=value;
+                    })
+            }
         }
     })
 </script>