|
@@ -7,6 +7,7 @@ import okhttp3.*;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
+import java.awt.*;
|
|
|
import java.util.concurrent.BlockingQueue;
|
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
|
import java.util.concurrent.Semaphore;
|
|
@@ -38,25 +39,26 @@ public class URBot {
|
|
|
try {
|
|
|
while (true) {
|
|
|
var c = cmdq.take();
|
|
|
- write(c.cmd);
|
|
|
+ sc.writeCmd(c);
|
|
|
while (true) {
|
|
|
cmdDoneSem.acquire();
|
|
|
- if (currentAck.id == c.id && currentAck.message.equals("URWEB_END"))
|
|
|
+ if (currentAck.id == c.id && currentAck.message.equals("URWEB_END")) {
|
|
|
+ if (c.cpeeCallback != null) {
|
|
|
+ ackCPEE(c);
|
|
|
+ }
|
|
|
break;
|
|
|
- }
|
|
|
- if (c.cpeeCallback != null) {
|
|
|
- ackCPEE(c);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} catch (InterruptedException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
});
|
|
|
+ queueThread.start();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- private void write(String program) {
|
|
|
- String[] lines = program.split("[\\r\\n]+");
|
|
|
+ private void write(RobotCommand rc) {
|
|
|
+ String[] lines = rc.cmd.split("[\\r\\n]+");
|
|
|
String res = "";
|
|
|
for (String line : lines) {
|
|
|
line = line.trim();
|
|
@@ -68,10 +70,20 @@ public class URBot {
|
|
|
line += "\n";
|
|
|
res += line;
|
|
|
}
|
|
|
- if (!program.endsWith("\n"))
|
|
|
- program += "\n";
|
|
|
+ if (!res.endsWith("\n"))
|
|
|
+ res += "\n";
|
|
|
+ res=res.trim();
|
|
|
+ int id = nextID.getAndIncrement();
|
|
|
+ if(res.endsWith("end")) {
|
|
|
+ res=res.substring(0, res.length()-3);
|
|
|
+ res+=String.format("$ %s \"URWEB_END\"\nend\n", id);
|
|
|
+ }
|
|
|
try {
|
|
|
- this.cmdq.put(new RobotCommand(nextID.getAndIncrement(), program));
|
|
|
+ rc.id=id;
|
|
|
+ // rc.cmd = String.format("def urweb():\n%s\n$ %s \"URWEB_END\"\nend\n", res, id);
|
|
|
+ rc.cmd = res;
|
|
|
+
|
|
|
+ this.cmdq.put(rc);
|
|
|
} catch (InterruptedException e) {
|
|
|
Thread.currentThread().interrupt();
|
|
|
}
|
|
@@ -117,7 +129,11 @@ public class URBot {
|
|
|
return ((mb.digitalOutputBits & (1 << which)) > 0);
|
|
|
}
|
|
|
|
|
|
- public void sendCmd(String cmd) {
|
|
|
- write(String.format("def urweb():\n{}\nend\n", cmd));
|
|
|
+ public void sendCmd(RobotCommand cmd) {
|
|
|
+ write(cmd);
|
|
|
+ }
|
|
|
+
|
|
|
+ public BlockingQueue<RobotCommand> getCmdq() {
|
|
|
+ return cmdq;
|
|
|
}
|
|
|
}
|