Bladeren bron

message parser wip

Martin Kunz 6 jaren geleden
bovenliggende
commit
8d54486d79

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

@@ -12,10 +12,9 @@ public class Main {
         try {
             new WebServer(8080,true).start();
             //GetRobotRealtimeData rd=new GetRobotRealtimeData("192.168.20.107", 30003);
-            SecondaryClient rde=new SecondaryClient("192.168.20.107", 30002);
+            SecondaryClient rde=new SecondaryClient("192.168.20.144", 30002);
             rde.connect();
-
-            //rde.writeCmd("set_digital_out(1,True)\n");
+            rde.writeCmd("set_digital_out(1,True)\n");
 
 
             // rde.writeCmd("set_digital_out(2,True)\n");

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

@@ -1,5 +1,6 @@
 package at.acdp.urweb.sclient;
 
+import at.acdp.urweb.sclient.data.MessageType;
 import at.acdp.urweb.sclient.data.VersionMessage;
 
 import java.io.*;
@@ -27,29 +28,36 @@ public class SecondaryClient {
         VersionMessage vm = new VersionMessage();
         vm.readVersionMessage(in);
         System.out.println(vm);
-        readReply(in);
+        while(in.available()>0) {
+            readReply(in);
+
+        }
     }
 
     private void readReply(DataInputStream di) throws IOException {
-        int size=di.readInt();
-        int mType= di.readByte() &0xff;
+        byte[] asdf=new byte[150];
+        //di.readFully(asdf);
+        System.out.println(asdf);
+
+        int size=di.readInt(); //4
+        int mType= di.readByte() &0xff; //+1=5
         switch (mType) {
-            case 20:
-                long ts=di.readLong();
-                byte source=di.readByte();
-                int robotMessageType=di.readByte() & 0xff;
+            case MessageType.ROBOT_MESSAGE:
+                long ts=di.readLong();//+8=11
+                byte source=di.readByte(); //+1=12
+                int robotMessageType=di.readByte() & 0xff; //+1=13
                 switch(robotMessageType) {
+
                     default:
                         System.out.println("rtype: " +robotMessageType);
                         int x=di.available();
-                        byte[] buf=new byte[size-15];
-                        di.read(buf);
+                        byte[] buf=new byte[size-10];
+                        di.readFully(buf);
                         System.out.println(buf);
                 }
                 break;
             case 16:
                 System.out.println("16 msg" + mType);
-
                 int remaining=size-5;
                 while (remaining >0) {
                     int sublength = in.readInt();
@@ -63,8 +71,8 @@ public class SecondaryClient {
                 break;
             default:
                 System.out.println("unknown msg" + mType);
-                byte[] buf=new byte[size];
-                di.read(buf);
+                byte[] buf=new byte[size-5];
+                di.readFully(buf);
         }
     }
 
@@ -73,7 +81,6 @@ public class SecondaryClient {
             System.out.println("send cmd:" + cmd);
             os.write(cmd.getBytes(StandardCharsets.UTF_8));
             readReply(in);
-
         } catch (IOException e) {
             e.printStackTrace();
         }

+ 6 - 0
src/main/java/at/acdp/urweb/sclient/data/MessageType.java

@@ -0,0 +1,6 @@
+package at.acdp.urweb.sclient.data;
+
+public class MessageType {
+    public static final int ROBOT_MESSAGE=20;
+    public static final int PROGRAM_STATE_MESSAGE=25;
+}

+ 13 - 0
src/main/java/at/acdp/urweb/sclient/data/PackageType.java

@@ -0,0 +1,13 @@
+package at.acdp.urweb.sclient.data;
+
+public class PackageType {
+    public static final int CARTESIAN_INFO=4;
+    public static final int MASTERBOARD_DATA=3;
+    public static final int TOOL_DATA=2;
+    public static final int KINEMATICS_INFO=5;
+    public static final int CONFIGURATION_DATA=6;
+    public static final int FORCE_MODE_DATA=7;
+    public static final int ADDITIONAL_INFO=8;
+    public static final int NEEDED_FOR_CALIB_DATA=9;
+    public static final int TOOL_COMM_INFO=11;
+}

+ 13 - 0
src/main/java/at/acdp/urweb/sclient/data/RobotMessageType.java

@@ -0,0 +1,13 @@
+package at.acdp.urweb.sclient.data;
+
+public class RobotMessageType {
+    public static final int VERSION=3;
+    public static final int SAFETY_MODE=5;
+    public static final int ERROR_CODE=6;
+    public static final int KEY=7;
+    public static final int PROGRAM_LABEL=1;
+    public static final int POPUP=2;
+    public static final int REQUEST_VALUE=9;
+    public static final int TEXT=0;
+    public static final int RUNTIME_EXCEPTION=10;
+}

+ 7 - 0
src/main/java/at/acdp/urweb/sclient/data/RobotMessageTypeProgramState.java

@@ -0,0 +1,7 @@
+package at.acdp.urweb.sclient.data;
+
+public class RobotMessageTypeProgramState {
+    public static final int VARIABLE_UPDATE=2;
+    public static final int GLOBAL_VARIABLES_SETUP=0;
+    public static final int GLOBAL_VARIABLES_UPDATE=1;
+}

+ 5 - 0
src/main/java/at/acdp/urweb/web/WebServer.java

@@ -3,6 +3,8 @@ package at.acdp.urweb.web;
 import java.nio.file.Paths;
 import io.undertow.Handlers;
 import io.undertow.Undertow;
+import io.undertow.server.HttpHandler;
+import io.undertow.server.HttpServerExchange;
 import io.undertow.server.handlers.resource.PathResourceManager;
 import org.slf4j.LoggerFactory;
 
@@ -21,6 +23,9 @@ public class WebServer {
         Undertow.Builder builder = Undertow.builder();
         builder.addHttpListener(port, "0.0.0.0");
         builder.setHandler(Handlers.routing()
+                .get("/test/{id}", ex -> {
+                    System.out.println(ex.getQueryParameters().get("id").getFirst());
+                })
                 .get("/*", resource(new PathResourceManager(Paths.get("webroot"), 100))
                         .setDirectoryListingEnabled(true))
         );