Skip to content

Commit f93aa9b

Browse files
committed
more parts of CQC
1 parent 3589b2e commit f93aa9b

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

src/main/java/com/gluonhq/strange/cqc/CQCSession.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
import java.io.DataOutputStream;
44
import java.io.IOException;
5+
import java.io.InputStream;
56
import java.io.OutputStream;
67
import java.net.Socket;
78

89
public class CQCSession {
910

1011
private Socket socket;
1112
private OutputStream os;
13+
private InputStream is;
1214
private short appId;
1315

1416
public CQCSession() {
@@ -24,13 +26,34 @@ public void connect(String host, int port) throws IOException {
2426
}
2527

2628
public void sendHello() throws IOException {
27-
sendCqcHeadercd op - (Protocol.CQC_TP_HELLO, 0);
29+
sendCqcHeader(Protocol.CQC_TP_HELLO, 0);
2830
}
2931

3032
public void createQubit() throws IOException {
3133
sendSimpleCommand(Protocol.CQC_CMD_NEW, (short)0);
3234
}
3335

36+
private void sendComman() {
37+
38+
}
39+
public void createEPR(String name) throws IOException {
40+
sendCommand(Protocol.CQC_CMD_EPR,(short)0,true,false, true, 12);
41+
// sendSimpleCommand(Protocol.CQC_CMD_EPR, (short)0);
42+
}
43+
44+
public ResponseMessage readMessage() throws IOException {
45+
if (is == null) {
46+
is = socket.getInputStream();
47+
}
48+
byte[] msg = new byte[256];
49+
int len = is.read(msg);
50+
if (len < 8) {
51+
throw new IOException ("Can't read message if it has less than 8 bytes (got "+len+")");
52+
}
53+
ResponseMessage answer = new ResponseMessage(msg, len);
54+
return answer;
55+
}
56+
3457
static short appIdCounter = 0;
3558

3659
private static synchronized short getNextAppId() {
@@ -49,15 +72,20 @@ private void sendCqcHeader(byte type, int len) throws IOException {
4972
dos.writeShort(appId);
5073
dos.writeInt(len);
5174
dos.flush();
52-
// byte[] data = new byte[8];
53-
// data[0] = Protocol.VERSION;
54-
// data[1] = type;
55-
// data[2] = (byte)(appId & 0xff);
56-
// data[3] = (byte)((appId >> 8) & 0xff);
57-
5875
}
76+
5977
private void sendCommand(byte command, short qubit_id, boolean notify, boolean action, boolean block, int length) throws IOException {
6078
sendCqcHeader(Protocol.CQC_TP_COMMAND, length);
79+
if (command == Protocol.CQC_CMD_EPR) {
80+
DataOutputStream dos = new DataOutputStream(os);
81+
dos.writeShort(0); // qubit_id
82+
dos.writeByte(command);
83+
dos.writeByte(0);
84+
dos.writeShort(1);
85+
dos.writeShort(2);
86+
dos.writeInt(4);
87+
dos.flush();
88+
}
6189

6290
}
6391

src/main/java/com/gluonhq/strange/cqc/Protocol.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ public class Protocol {
66

77
public static final byte CQC_TP_HELLO = 0x0;
88
public static final byte CQC_TP_COMMAND = 0x1;
9+
public static final byte CQC_TP_EPR_OK = 0x6;
910

1011
public static final byte CQC_CMD_NEW = 0x1;
12+
public static final byte CQC_CMD_EPR = 0x7;
13+
public static final byte CQC_CMD_EPR_RECV = 0x8;
14+
1115
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.gluonhq.strange.cqc;
2+
3+
public class ResponseMessage {
4+
5+
final byte type;
6+
7+
public ResponseMessage(byte[] msg, int length) {
8+
type = msg[1];
9+
}
10+
11+
public byte getType() {
12+
return type;
13+
}
14+
}

0 commit comments

Comments
 (0)