|
@@ -1,107 +0,0 @@
|
|
|
-package at.acdp.urweb.web;
|
|
|
-
|
|
|
-import at.acdp.urweb.Params;
|
|
|
-import at.acdp.urweb.RobotCommand;
|
|
|
-import at.acdp.urweb.URBot;
|
|
|
-import at.acdp.urweb.rt.GetRobotRealtimeData;
|
|
|
-import at.acdp.urweb.sclient.URLog;
|
|
|
-import com.eclipsesource.json.JsonArray;
|
|
|
-import net.schmizz.sshj.SSHClient;
|
|
|
-import net.schmizz.sshj.xfer.FileSystemFile;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-
|
|
|
-import static spark.Spark.*;
|
|
|
-
|
|
|
-public class WebServer {
|
|
|
- private final static org.slf4j.Logger logger = LoggerFactory.getLogger(WebServer.class);
|
|
|
- private URBot urbot;
|
|
|
- private final Params params;
|
|
|
- private GetRobotRealtimeData rtbot;
|
|
|
-
|
|
|
- public WebServer(Params params) {
|
|
|
- this.params = params;
|
|
|
- }
|
|
|
-
|
|
|
- public void start() {
|
|
|
- this.urbot=new URBot(params.robotIP, params.robotPort);
|
|
|
- this.urbot.start();
|
|
|
- // this.rtbot=new GetRobotRealtimeData(params.robotIP, params.rtPort);
|
|
|
- // this.rtbot.start();
|
|
|
- port(params.port);
|
|
|
- if (!params.webroot.isEmpty())
|
|
|
- staticFileLocation(params.webroot);
|
|
|
- else
|
|
|
- staticFiles.location("/webroot");
|
|
|
-
|
|
|
- post("/cmd", (req, res) -> {
|
|
|
- var cmd=req.queryParams("script");
|
|
|
- if(cmd==null)
|
|
|
- cmd=req.body();
|
|
|
- RobotCommand rc=new RobotCommand(cmd);
|
|
|
- rc.cpeeCallback = req.headers("CPEE-CALLBACK");
|
|
|
- rc.cpeeCallbackId = req.headers("CPEE-CALLBACK-ID");
|
|
|
- rc.cpeeInstanceURL = req.headers("CPEE-INSTANCE-URL");
|
|
|
- if (Boolean.valueOf(req.queryParams("callback"))) {
|
|
|
- res.header("CPEE-CALLBACK", "true");
|
|
|
- rc.doCpeeCallback = true;
|
|
|
- }
|
|
|
- urbot.sendCmd(rc);
|
|
|
- return "";
|
|
|
- });
|
|
|
-
|
|
|
- post("/freedrive", (req, res) -> {
|
|
|
- urbot.sendFreedrive(1);
|
|
|
- return "";
|
|
|
- });
|
|
|
- post("/digital/:which", (req, res) -> {
|
|
|
- int which=Integer.parseInt(req.params("which"));
|
|
|
- boolean val = Boolean.valueOf(new String(req.raw().getInputStream().readAllBytes()));
|
|
|
- urbot.setDigital(which, val);
|
|
|
- return "";
|
|
|
- });
|
|
|
- get("/digital/:which", (req, res) -> {
|
|
|
- int which=Integer.parseInt(req.params("which"));
|
|
|
- boolean d=urbot.getDigital(which);
|
|
|
- res.body(String.valueOf(d));
|
|
|
- return "";
|
|
|
- });
|
|
|
- get("/log/:from", (req, res) -> {
|
|
|
- int from=Integer.parseInt(req.params("from"));
|
|
|
- from=Integer.max(0,from);
|
|
|
- var r = URLog.get(from);
|
|
|
- return r.toJSON();
|
|
|
- });
|
|
|
- get("/cmdq", (req, res) -> {
|
|
|
- JsonArray jsa=new JsonArray();
|
|
|
- for(var c:urbot.getCmdq()) {
|
|
|
- jsa.add(c.toJSON());
|
|
|
- }
|
|
|
- return jsa.toString();
|
|
|
- });
|
|
|
- get("/running", (req, res) -> {
|
|
|
- var rc=urbot.getRunningScript();
|
|
|
- if(rc.isPresent()) {
|
|
|
- return rc.get().toJSON();
|
|
|
- }
|
|
|
- return "[{}]";
|
|
|
- });
|
|
|
- get("/files/:path", (req, res) -> {
|
|
|
- String path=req.params("from");
|
|
|
- SSHClient ssh = new SSHClient();
|
|
|
- // ssh.useCompression(); // Can lead to significant speedup (needs JZlib in classpath)
|
|
|
- ssh.loadKnownHosts();
|
|
|
- ssh.connect(params.robotIP, params.robotPort);
|
|
|
- try {
|
|
|
- ssh.authPublickey(System.getProperty(params.sshUsername));
|
|
|
- ssh.newSCPFileTransfer().download(path, new FileSystemFile("C:\\tmp\\"));
|
|
|
-
|
|
|
- }catch (Exception e) {
|
|
|
- logger.warn("",e);
|
|
|
-
|
|
|
- } finally{
|
|
|
- ssh.disconnect();
|
|
|
- }
|
|
|
- return "[{}]";
|
|
|
- });
|
|
|
- }
|
|
|
-}
|