|
@@ -1,12 +1,16 @@
|
|
package at.acdp.urweb.sclient;
|
|
package at.acdp.urweb.sclient;
|
|
|
|
|
|
import at.acdp.urweb.sclient.data.*;
|
|
import at.acdp.urweb.sclient.data.*;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
import java.net.Socket;
|
|
import java.net.Socket;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
public class SecondaryClient {
|
|
public class SecondaryClient {
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(SecondaryClient.class);
|
|
|
|
+
|
|
|
|
|
|
private final String ip;
|
|
private final String ip;
|
|
private final int port;
|
|
private final int port;
|
|
@@ -20,20 +24,18 @@ public class SecondaryClient {
|
|
this.port = port;
|
|
this.port = port;
|
|
}
|
|
}
|
|
|
|
|
|
- public void connect() throws IOException {
|
|
|
|
|
|
+ public VersionMessage connect() throws IOException {
|
|
this.rt = new Socket(ip, port);
|
|
this.rt = new Socket(ip, port);
|
|
this.os = rt.getOutputStream();
|
|
this.os = rt.getOutputStream();
|
|
this.in = new DataInputStream(rt.getInputStream());
|
|
this.in = new DataInputStream(rt.getInputStream());
|
|
VersionMessage vm = new VersionMessage();
|
|
VersionMessage vm = new VersionMessage();
|
|
vm.readVersionMessage(in);
|
|
vm.readVersionMessage(in);
|
|
- System.out.println(vm);
|
|
|
|
- readReply(in);
|
|
|
|
|
|
+ return vm;
|
|
}
|
|
}
|
|
|
|
|
|
- private void readReply(DataInputStream di) throws IOException {
|
|
|
|
|
|
+ public void readReply(DataInputStream di) throws IOException {
|
|
|
|
|
|
int size = di.readInt(); //4
|
|
int size = di.readInt(); //4
|
|
- System.out.println("size: " + size);
|
|
|
|
int pType = di.readByte() & 0xff; //+1=5
|
|
int pType = di.readByte() & 0xff; //+1=5
|
|
switch (pType) {
|
|
switch (pType) {
|
|
case MessageType.ROBOT_MESSAGE:
|
|
case MessageType.ROBOT_MESSAGE:
|
|
@@ -50,6 +52,15 @@ public class SecondaryClient {
|
|
break;
|
|
break;
|
|
case PackageType.CARTESIAN_INFO:
|
|
case PackageType.CARTESIAN_INFO:
|
|
readCartesianInfo(di, size);
|
|
readCartesianInfo(di, size);
|
|
|
|
+ break;
|
|
|
|
+ case PackageType.KINEMATICS_INFO:
|
|
|
|
+ readKinemsticsInfo(di, size);
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ default:
|
|
|
|
+ log.warn("unknown ptype: "+pType+", size: "+size);
|
|
|
|
+ byte[] pack=new byte[size-5];
|
|
|
|
+ di.readFully(pack);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -81,9 +92,14 @@ public class SecondaryClient {
|
|
|
|
|
|
CartesianInfo readCartesianInfo(DataInputStream di, int size) throws IOException {
|
|
CartesianInfo readCartesianInfo(DataInputStream di, int size) throws IOException {
|
|
CartesianInfo ci = new CartesianInfo();
|
|
CartesianInfo ci = new CartesianInfo();
|
|
- //TODO: parse
|
|
|
|
|
|
+ ci.read(di);
|
|
return ci;
|
|
return ci;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ KinematicsInfo readKinemsticsInfo(DataInputStream di, int size) throws IOException {
|
|
|
|
+ KinematicsInfo ki = new KinematicsInfo();
|
|
|
|
+ ki.read(di, size);
|
|
|
|
+ return ki;
|
|
}
|
|
}
|
|
|
|
|
|
ModeData readRobotModeData(DataInputStream di, int size) throws IOException {
|
|
ModeData readRobotModeData(DataInputStream di, int size) throws IOException {
|
|
@@ -125,11 +141,13 @@ public class SecondaryClient {
|
|
try {
|
|
try {
|
|
System.out.println("send cmd:" + cmd);
|
|
System.out.println("send cmd:" + cmd);
|
|
os.write(cmd.getBytes(StandardCharsets.UTF_8));
|
|
os.write(cmd.getBytes(StandardCharsets.UTF_8));
|
|
- readReply(in);
|
|
|
|
- readReply(in);
|
|
|
|
- readReply(in);
|
|
|
|
|
|
+
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public void readPackage() throws IOException {
|
|
|
|
+ readReply(in);
|
|
|
|
+ }
|
|
}
|
|
}
|