|
@@ -2,6 +2,7 @@ package at.acdp.urweb.sclient;
|
|
|
|
|
|
import at.acdp.urweb.CountDataInputStream;
|
|
|
import at.acdp.urweb.sclient.data.*;
|
|
|
+import io.undertow.util.FileUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
@@ -11,8 +12,6 @@ import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
public class SecondaryClient {
|
|
|
private static final Logger log = LoggerFactory.getLogger(SecondaryClient.class);
|
|
|
-
|
|
|
-
|
|
|
private final String ip;
|
|
|
private final int port;
|
|
|
private volatile boolean _running = true;
|
|
@@ -29,12 +28,18 @@ public class SecondaryClient {
|
|
|
this.rt = new Socket(ip, port);
|
|
|
this.os = rt.getOutputStream();
|
|
|
this.in = new CountDataInputStream(rt.getInputStream());
|
|
|
+// byte[] data=new byte[4096];
|
|
|
+// this.in.readFully(data);
|
|
|
+// FileOutputStream fos = new FileOutputStream("data2.txt");
|
|
|
+// fos.write(data);
|
|
|
+// fos.close();
|
|
|
+
|
|
|
VersionMessage vm = new VersionMessage();
|
|
|
vm.read(in, -1);
|
|
|
return vm;
|
|
|
}
|
|
|
|
|
|
- public int readReply(CountDataInputStream di, boolean isSub) throws IOException {
|
|
|
+ public int readReply(CountDataInputStream di) throws IOException {
|
|
|
int beforeCount=di.getCount();
|
|
|
int size = di.readInt(); //4
|
|
|
int pType = di.readByte() & 0xff; //+1=5
|
|
@@ -45,6 +50,24 @@ public class SecondaryClient {
|
|
|
case MessageType.ROBOT_STATE:
|
|
|
readRobotState(di, size);
|
|
|
break;
|
|
|
+ default:
|
|
|
+ log.warn("unknown ptype: "+pType+", size: "+size);
|
|
|
+ byte[] pack=new byte[size-5];
|
|
|
+ di.readFully(pack);
|
|
|
+ }
|
|
|
+ int afterCount=di.getCount();
|
|
|
+ int diff=afterCount-beforeCount-size;
|
|
|
+ if(diff!=0) {
|
|
|
+ log.warn("size mismatch: " +diff + "package type: "+pType);
|
|
|
+ }
|
|
|
+ return size;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int readSub(CountDataInputStream di) throws IOException {
|
|
|
+ int beforeCount=di.getCount();
|
|
|
+ int size = di.readInt(); //4
|
|
|
+ int pType = di.readByte() & 0xff; //+1=5
|
|
|
+ switch (pType) {
|
|
|
case PackageType.ROBOT_MODE_DATA:
|
|
|
var md=readRobotModeData(di, size);
|
|
|
log.info(md.toString());
|
|
@@ -150,22 +173,20 @@ public class SecondaryClient {
|
|
|
|
|
|
void readRobotMessage(CountDataInputStream di, int size) throws IOException {
|
|
|
long ts = di.readLong();
|
|
|
- char source = (char) (di.readByte() & 0xFF);
|
|
|
- char robotMessageType = (char) (di.readByte() & 0xFF);
|
|
|
+ byte source = di.readByte();
|
|
|
+ int robotMessageType = di.readUnsignedByte();
|
|
|
switch (robotMessageType) {
|
|
|
default:
|
|
|
- log.warn("unknown msg" + (int) robotMessageType);
|
|
|
- //byte[] buf=new byte[size-11];
|
|
|
- byte[] buf = new byte[size - 10];
|
|
|
+ log.info("unknown msg: " + (int) robotMessageType);
|
|
|
+ byte[] buf = new byte[size - 15];
|
|
|
di.readFully(buf);
|
|
|
- System.out.println(buf);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void readRobotState(CountDataInputStream di, int size) throws IOException {
|
|
|
int remaining=size-5;
|
|
|
while(remaining>0)
|
|
|
- remaining-=readReply(di, true);
|
|
|
+ remaining-=readSub(di);
|
|
|
}
|
|
|
|
|
|
CartesianInfo readCartesianInfo(CountDataInputStream di, int size) throws IOException {
|
|
@@ -222,6 +243,6 @@ public class SecondaryClient {
|
|
|
}
|
|
|
|
|
|
public void readPackage() throws IOException {
|
|
|
- readReply(in, false);
|
|
|
+ readReply(in);
|
|
|
}
|
|
|
}
|