Martin Kunz 2 years ago
parent
commit
4c884ee5b9
1 changed files with 40 additions and 15 deletions
  1. 40 15
      src/main/java/at/acdp/urweb/rtde/RTDEClient.java

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

@@ -38,7 +38,7 @@ public class RTDEClient implements Runnable {
             dos = new DataOutputStream(rt.getOutputStream());
             dis = new DataInputStream(rt.getInputStream());
 
-            negotiate_protocol_version();
+            init();
             //Thread readThread = new Thread(this);
             //readThread.start();
             // send_output_setup(List.of(OutParams.timestamp), List.of(), 125);
@@ -68,7 +68,7 @@ public class RTDEClient implements Runnable {
     @Override
     public void run() {
         try {
-            negotiate_protocol_version();
+            init();
         } catch (IOException e) {
             e.printStackTrace();
         }
@@ -103,9 +103,13 @@ public class RTDEClient implements Runnable {
         // sendAndReceive(rpv, bytes.array());
     }
 
-    public void negotiate_protocol_version() throws IOException {
+    public void init() throws IOException {
         var rpv = new RtdeRequestProtocolVersion();
         sendAndReceive(rpv);
+        var ruv = new RtdeRequestURVersion();
+        sendAndReceive(ruv);
+
+
     }
 
     private interface RtdeData<T> {
@@ -113,7 +117,7 @@ public class RTDEClient implements Runnable {
 
         int getSize();
 
-        void setSize(int i);
+        void setReplySize(int i);
 
 
         T read(DataInputStream di) throws IOException;
@@ -126,16 +130,32 @@ public class RTDEClient implements Runnable {
         }
 
         default void readHeader(DataInputStream dis) throws IOException {
-            setSize(dis.readShort());
+            setReplySize(dis.readShort());
             int cmd = dis.readByte();
-            if (cmd != getType().getVal())
-                throw new IOException(String.format("Expected %d, got %d", getType().getVal(), cmd));
+            if(cmd==getType().getVal())
+                return;
+            if (cmd==77) {
+                int mLength=dis.readByte();
+                byte[] mText = new byte[mLength];
+                dis.readFully(mText);
+                String m=new String(mText);
+                logger.info(m);
+                int sLength=dis.readByte();
+                byte[] sText = new byte[sLength];
+                dis.readFully(sText);
+                String s=new String(sText);
+                logger.info(s);
+                int warning=dis.readByte();
+                String w=String.valueOf(warning);
+
+            } else throw new IOException(String.format("Expected %d, got %d", getType().getVal(), cmd));
         }
 
     }
 
     private class RtdeRequestURVersion implements RtdeData {
-        private int size;
+        private int replySize;
+        private int major, minor, bugfix, build;
 
         @Override
         public CommandType getType() {
@@ -144,17 +164,22 @@ public class RTDEClient implements Runnable {
 
         @Override
         public int getSize() {
-            return 5;
+            return 3;
         }
 
         @Override
-        public void setSize(int s) {
-            size = s;
+        public void setReplySize(int s) {
+            replySize = s;
         }
 
         @Override
         public RtdeRequestURVersion read(DataInputStream di) throws IOException {
             readHeader(di);
+            major=di.readInt();
+            minor=di.readInt();
+            bugfix=di.readInt();
+            build=di.readInt();
+
             return this;
         }
 
@@ -167,7 +192,7 @@ public class RTDEClient implements Runnable {
 
     private class RtdeRequestProtocolVersion implements RtdeData {
         public boolean success;
-        private int size;
+        private int replySize;
 
         @Override
         public CommandType getType() {
@@ -176,12 +201,12 @@ public class RTDEClient implements Runnable {
 
         @Override
         public int getSize() {
-            return size;
+            return 5;
         }
 
         @Override
-        public void setSize(int size) {
-            this.size = size;
+        public void setReplySize(int size) {
+            this.replySize = size;
         }
 
         @Override