Browse Source

rtde input package

Martin Kunz 2 years ago
parent
commit
a3377164d6

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

@@ -6,6 +6,7 @@ import at.acdp.urweb.fhpp.FHPP;
 import at.acdp.urweb.fhpp.IFHMaster;
 import at.acdp.urweb.rtde.RTDEClient;
 import at.acdp.urweb.rtde.packets.RtdeControlStart;
+import at.acdp.urweb.rtde.packets.RtdeSetupInputs;
 import at.acdp.urweb.rtde.packets.RtdeSetupOutputs;
 import at.acdp.urweb.web.FestoXRServer;
 import com.nmote.nanohttp.NanoServer;
@@ -35,6 +36,10 @@ public class Main {
                     .addVariable("target_speed_fraction")
                     .addVariable("speed_scaling");
             r.request(so);
+            var si=new RtdeSetupInputs()
+                    .addVariable("input_int_register_24");
+            r.request(si);
+            System.out.println(si.recipe);
 
             var start=new RtdeControlStart();
             r.request(start);

+ 1 - 1
src/main/java/at/acdp/urweb/rtde/CommandType.java

@@ -6,7 +6,7 @@ public class CommandType {
     public final static int RTDE_TEXT_MESSAGE = 77;
     public final static int RTDE_DATA_PACKAGE = 85;
     public final static int RTDE_CONTROL_PACKAGE_SETUP_OUTPUTS = 79;
-    public final static int RTDE_CONTROL_PACKAGE_SETUP_INPUTS = 118;
+    public final static int RTDE_CONTROL_PACKAGE_SETUP_INPUTS = 73;
     public final static int RTDE_CONTROL_PACKAGE_START = 83;
     public final static int RTDE_CONTROL_PACKAGE_PAUSE = 80;
 

+ 1 - 1
src/main/java/at/acdp/urweb/rtde/RTDEClient.java

@@ -72,7 +72,7 @@ public class RTDEClient implements Runnable {
             case RTDE_TEXT_MESSAGE:
                 var rpv = new RtdeTextMessage();
                 rpv.read(dis, length-3);
-                logger.info("RTDE_TEXT_MESSAGE", rpv.text);
+                logger.info(String.format("RTDE_TEXT_MESSAGE: %s", rpv.text));
                 break;
             case RTDE_DATA_PACKAGE:
                 var p = new RtdeDataPackage(outputs);

+ 1 - 0
src/main/java/at/acdp/urweb/rtde/packets/RtdeDataPackage.java

@@ -26,6 +26,7 @@ public class RtdeDataPackage implements IRtdeData {
         return pdata;
     }
 
+
     @Override
     public RtdeDataPackage read(DataInputStream di, int length) throws IOException {
         int recipeID=di.readByte();

+ 50 - 0
src/main/java/at/acdp/urweb/rtde/packets/RtdeSetupInputs.java

@@ -0,0 +1,50 @@
+package at.acdp.urweb.rtde.packets;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static at.acdp.urweb.rtde.CommandType.RTDE_CONTROL_PACKAGE_SETUP_INPUTS;
+import static at.acdp.urweb.rtde.CommandType.RTDE_CONTROL_PACKAGE_SETUP_OUTPUTS;
+
+public class RtdeSetupInputs implements IRtdeData {
+    public int recipe;
+    public List<String> variables=new ArrayList<>();
+    public List<String> types=new ArrayList<>();
+    public String typesText;
+
+    public RtdeSetupInputs() {
+    }
+
+    public RtdeSetupInputs addVariable(String name) {
+        variables.add(name);
+        return this;
+    }
+
+    @Override
+    public int getType() {
+        return RTDE_CONTROL_PACKAGE_SETUP_INPUTS;
+    }
+
+    @Override
+    public RtdeSetupInputs read(DataInputStream d, int length) throws IOException {
+        recipe = d.readByte();
+        byte[] text=new byte[length-1];
+        d.readFully(text);
+        typesText=new String(text);
+        types.addAll(Arrays.asList(typesText.split(",")));
+        return this;
+    }
+
+    @Override
+    public RtdeSetupInputs send(DataOutputStream dos) throws IOException {
+        var payload = String.join(",", variables).getBytes();
+        sendHeader(dos, payload.length);
+        dos.write(payload);
+        dos.flush();
+        return this;
+    }
+}