Browse Source

data package has no reply data

Martin Kunz 2 years ago
parent
commit
5cc594543d

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

@@ -41,6 +41,7 @@ public class Main {
             r.request(start);
 
             var pos=new RtdeInDataPackage(si);
+            pos.put("input_int_register_24","66");
             r.request(pos);
 
 

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

@@ -50,17 +50,21 @@ public class RTDEClient implements Runnable {
         if(readThread.getId()==Thread.currentThread().getId()) {
             logger.error("request() must not be called from readThread.");
         }
-        waitingRequest=data;
+        if(data.hasReply()) {
+            waitingRequest=data;
+        }
         data.send(dos);
-        waitingRequestSem.acquire();
-        waitingRequest=null;
+        if(data.hasReply()) {
+            waitingRequestSem.acquire();
+            waitingRequest=null;
+        }
         return;
     }
 
     // Internal method that actually reads the data
     private void readSocket() throws IOException, InterruptedException {
         int length = dis.readShort();
-        int type=dis.readByte();
+        int type=dis.readByte() & 0xFF;
         var wreq=waitingRequest;
         if(wreq != null && type==wreq.getType()) {
             waitingRequest.read(dis, length-3);

+ 4 - 0
src/main/java/at/acdp/urweb/rtde/packets/IRtdeData.java

@@ -12,6 +12,10 @@ public interface IRtdeData<T> {
 
     int getType();
 
+    default boolean hasReply() {
+        return true;
+    }
+
     T read(DataInputStream di, int length) throws IOException;
 
     T send(DataOutputStream dos) throws IOException;

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

@@ -17,6 +17,7 @@ public class RtdeControlStart implements IRtdeData {
 
     @Override
     public RtdeControlStart read(DataInputStream di, int length) throws IOException {
+
         accepted= di.readBoolean();
         return this;
     }

+ 41 - 2
src/main/java/at/acdp/urweb/rtde/packets/RtdeInDataPackage.java

@@ -29,13 +29,43 @@ public class RtdeInDataPackage implements IRtdeData {
 
     @Override
     public RtdeInDataPackage read(DataInputStream di, int length) throws IOException {
-        int recipeID=di.readByte();
         return this;
     }
 
+    private int calcSize() {
+        int size = 0;
+        for (int i = 0; i < inputs.variables.size(); i++) {
+            String output = inputs.variables.get(i);
+            String type = inputs.types.get(i);
+            switch (type) {
+                case "BOOL":
+                case "UINT8":
+                    size+=1;
+                    break;
+                case "UINT32":
+                case "INT32":
+                    size+=4;
+                    break;
+                case "UINT64":
+                case "DOUBLE":
+                    size+=8;
+                    break;
+                case "VECTOR3D":
+                case "VECTOR6INT32":
+                case "VECTOR6UINT32":
+                    size+=24;
+                    break;
+                case "VECTOR6D":
+                    size+=48;
+                    break;
+            }
+        }
+        return size;
+    }
+
     @Override
     public RtdeInDataPackage send(DataOutputStream dos) throws IOException {
-        sendHeader(dos,0);
+        sendHeader(dos,calcSize()+1);
         dos.writeByte(inputs.recipe);
         for(int i=0; i<inputs.variables.size(); i++) {
             String output = inputs.variables.get(i);
@@ -92,4 +122,13 @@ public class RtdeInDataPackage implements IRtdeData {
         }
         return this;
     }
+
+    public void put(String key, String value) {
+        pdata.put(key, value);
+    }
+
+    @Override
+    public boolean hasReply() {
+        return false;
+    }
 }