|
@@ -32,8 +32,7 @@ public class WebServer {
|
|
|
.post("/cmd", new HttpHandler() {
|
|
|
@Override
|
|
|
public void handleRequest(HttpServerExchange ex) throws Exception {
|
|
|
- dispatch(ex, this);
|
|
|
- ex.startBlocking();
|
|
|
+ if(!dispatch(ex,this)) return;
|
|
|
byte[] bytes = ex.getInputStream().readAllBytes();
|
|
|
String cmd=new String(bytes);
|
|
|
urbot.sendProgram(cmd);
|
|
@@ -46,6 +45,24 @@ public class WebServer {
|
|
|
urbot.sendFreedrive(1);
|
|
|
}
|
|
|
})
|
|
|
+ .post("/digital/{which}", new HttpHandler() {
|
|
|
+ @Override
|
|
|
+ public void handleRequest(HttpServerExchange ex) throws Exception {
|
|
|
+ if(!dispatch(ex,this)) return;
|
|
|
+ int which= Integer.parseInt(ex.getQueryParameters().get("which").getFirst());
|
|
|
+ boolean val = Boolean.valueOf(new String(ex.getInputStream().readAllBytes()));
|
|
|
+ urbot.setDigital(which, val);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .get("/digital/{which}", new HttpHandler() {
|
|
|
+ @Override
|
|
|
+ public void handleRequest(HttpServerExchange ex) throws Exception {
|
|
|
+ if(!dispatch(ex,this)) return;
|
|
|
+ int which= Integer.parseInt(ex.getQueryParameters().get("which").getFirst());
|
|
|
+ boolean res=urbot.getDigital(which);
|
|
|
+ ex.getResponseSender().send(String.valueOf(res));
|
|
|
+ }
|
|
|
+ })
|
|
|
.get("/log/{from}", ex -> {
|
|
|
var x=ex.getQueryParameters().get("from").getFirst();
|
|
|
int from= Integer.parseInt(ex.getQueryParameters().get("from").getFirst());
|
|
@@ -63,10 +80,12 @@ public class WebServer {
|
|
|
server.start();
|
|
|
}
|
|
|
|
|
|
- private void dispatch(HttpServerExchange ex, HttpHandler handler) {
|
|
|
+ private boolean dispatch(HttpServerExchange ex, HttpHandler handler) {
|
|
|
if (ex.isInIoThread()) {
|
|
|
ex.dispatch(handler);
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
+ ex.startBlocking();
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|