Martin Kunz 2 years ago
parent
commit
82c2478909

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

@@ -54,24 +54,22 @@ public class RTDEClient implements Runnable {
 
     // Internal method that actually reads the data
     private void readSocket() throws IOException, InterruptedException {
-        while (true) {
-            int length = dis.readShort();
-            int type=dis.readByte();
-            if(type==waitingRequest.getType()) {
-                waitingRequest.read(dis);
-                waitingRequestSem.release();
-            } else switch(type) {
-                case RTDE_TEXT_MESSAGE:
-                    var rpv = new RtdeTextMessage();
-                    request(rpv);
-                    logger.info("RTDE_TEXT_MESSAGE", rpv.text);
-                    break;
+        int length = dis.readShort();
+        int type=dis.readByte();
+        if(type==waitingRequest.getType()) {
+            waitingRequest.read(dis);
+            waitingRequestSem.release();
+        } else switch(type) {
+            case RTDE_TEXT_MESSAGE:
+                var rpv = new RtdeTextMessage();
+                request(rpv);
+                logger.info("RTDE_TEXT_MESSAGE", rpv.text);
+                break;
 
-                default: {
-                    logger.warn(String.format("Unexpected package type: %d", type));
-                    byte[] buf=new byte[length];
-                    dis.readFully(buf);
-                }
+            default: {
+                logger.warn(String.format("Unexpected package type: %d", type));
+                byte[] buf=new byte[length];
+                dis.readFully(buf);
             }
         }
     }
@@ -112,7 +110,9 @@ public class RTDEClient implements Runnable {
     public void init() throws IOException, InterruptedException {
         var rpv = new RtdeRequestProtocolVersion();
         request(rpv);
+        logger.info("RtdeRequestProtocolVersion succes:" + rpv.success);
         var ruv = new RtdeRequestURVersion();
         request(ruv);
+        logger.info(String.format("RtdeRequestURVersion: %d.%d.%d.%d",ruv.major, ruv.minor, ruv.build, ruv.bugfix));
     }
 }

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

@@ -26,26 +26,4 @@ public interface IRtdeData<T> {
         dos.writeByte(getType());
     }
 
-    default void readHeader(DataInputStream dis) throws IOException {
-        setReplySize(dis.readShort());
-        int cmd = dis.readByte();
-        if(cmd==getType())
-            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(), cmd));
-    }
-
 }

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

@@ -33,7 +33,6 @@ public class RtdeRequestProtocolVersion implements IRtdeData {
 
     @Override
     public RtdeRequestProtocolVersion read(DataInputStream d) throws IOException {
-        readHeader(d);
         success = d.readBoolean();
         return this;
     }

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

@@ -33,7 +33,6 @@ public class RtdeRequestURVersion implements IRtdeData {
 
     @Override
     public RtdeRequestURVersion read(DataInputStream di) throws IOException {
-        readHeader(di);
         major=di.readInt();
         minor=di.readInt();
         bugfix=di.readInt();

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

@@ -30,7 +30,6 @@ public class RtdeTextMessage implements IRtdeData {
 
     @Override
     public RtdeTextMessage read(DataInputStream di) throws IOException {
-        readHeader(di);
         int mLength=di.readByte();
         byte[] msgb=new byte[mLength];
         di.readFully(msgb);