IRtdeData.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package at.acdp.urweb.rtde.packets;
  2. import at.acdp.urweb.rtde.RTDEClient;
  3. import org.slf4j.LoggerFactory;
  4. import java.io.DataInputStream;
  5. import java.io.DataOutputStream;
  6. import java.io.IOException;
  7. public interface IRtdeData<T> {
  8. final static org.slf4j.Logger logger = LoggerFactory.getLogger(RTDEClient.class);
  9. int getType();
  10. int getSize();
  11. void setReplySize(int i);
  12. T read(DataInputStream di) throws IOException;
  13. T send(DataOutputStream dos) throws IOException;
  14. default void sendHeader(DataOutputStream dos) throws IOException {
  15. dos.writeShort(getSize());
  16. dos.writeByte(getType());
  17. }
  18. default void readHeader(DataInputStream dis) throws IOException {
  19. setReplySize(dis.readShort());
  20. int cmd = dis.readByte();
  21. if(cmd==getType())
  22. return;
  23. if (cmd==77) {
  24. int mLength=dis.readByte();
  25. byte[] mText = new byte[mLength];
  26. dis.readFully(mText);
  27. String m=new String(mText);
  28. logger.info(m);
  29. int sLength=dis.readByte();
  30. byte[] sText = new byte[sLength];
  31. dis.readFully(sText);
  32. String s=new String(sText);
  33. logger.info(s);
  34. int warning=dis.readByte();
  35. String w=String.valueOf(warning);
  36. } else throw new IOException(String.format("Expected %d, got %d", getType(), cmd));
  37. }
  38. }