|
@@ -10,10 +10,6 @@ import java.io.DataInputStream;
|
|
|
import java.io.DataOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.net.Socket;
|
|
|
-import java.net.SocketException;
|
|
|
-import java.net.UnknownHostException;
|
|
|
-import java.nio.ByteBuffer;
|
|
|
-import java.util.List;
|
|
|
import java.util.concurrent.Semaphore;
|
|
|
|
|
|
import static at.acdp.urweb.rtde.CommandType.*;
|
|
@@ -31,6 +27,7 @@ public class RTDEClient implements Runnable {
|
|
|
private final boolean _running = true;
|
|
|
private DataOutputStream dos;
|
|
|
private DataInputStream dis;
|
|
|
+ private Thread readThread;
|
|
|
|
|
|
|
|
|
public RTDEClient(String ip, int port) {
|
|
@@ -39,13 +36,16 @@ public class RTDEClient implements Runnable {
|
|
|
}
|
|
|
|
|
|
public void start() throws IOException, InterruptedException {
|
|
|
- Thread readThread = new Thread(this);
|
|
|
+ readThread = new Thread(this);
|
|
|
readThread.start();
|
|
|
socketOpen.acquire();
|
|
|
init();
|
|
|
}
|
|
|
|
|
|
- private void request(IRtdeData data) throws IOException, InterruptedException {
|
|
|
+ public void request(IRtdeData data) throws IOException, InterruptedException {
|
|
|
+ if(readThread.getId()==Thread.currentThread().getId()) {
|
|
|
+ logger.error("request() must not be called from readThread.");
|
|
|
+ }
|
|
|
waitingRequest=data;
|
|
|
data.send(dos);
|
|
|
waitingRequestSem.acquire();
|
|
@@ -57,7 +57,7 @@ public class RTDEClient implements Runnable {
|
|
|
int length = dis.readShort();
|
|
|
int type=dis.readByte();
|
|
|
if(type==waitingRequest.getType()) {
|
|
|
- waitingRequest.read(dis);
|
|
|
+ waitingRequest.read(dis, length-3);
|
|
|
waitingRequestSem.release();
|
|
|
} else switch(type) {
|
|
|
case RTDE_TEXT_MESSAGE:
|
|
@@ -99,14 +99,6 @@ public class RTDEClient implements Runnable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void send_output_setup(List<String> variables, List<String> types, int frequency) throws IOException {
|
|
|
- var payload = String.join(",", variables);
|
|
|
- byte[] p = payload.getBytes();
|
|
|
- ByteBuffer bytes = ByteBuffer.allocate(8 + p.length);
|
|
|
- bytes.putDouble(frequency);
|
|
|
- bytes.put(p);
|
|
|
- }
|
|
|
-
|
|
|
public void init() throws IOException, InterruptedException {
|
|
|
var rpv = new RtdeRequestProtocolVersion();
|
|
|
request(rpv);
|