Browse Source

return OK on abs/rel success
simulated axis returns target pos in status

Martin Kunz 3 years ago
parent
commit
0a877f2c16

+ 3 - 1
src/main/java/at/acdp/urweb/fhpp/FHMasterSim.java

@@ -26,6 +26,7 @@ public class FHMasterSim implements IFHMaster {
 
     private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
     private volatile boolean started = false;
+    private int curPos=-1;
     public FHMasterSim() {
     }
 
@@ -43,12 +44,13 @@ public class FHMasterSim implements IFHMaster {
     @Override
     public void direktAuftrag(int pos, int speed, int start, boolean relative) {
         logger.info("direktAuftrag {},{},{},{}", pos, speed, start, relative);
+        curPos=pos;
     }
 
     @Override
     public CompletableFuture<Status> readStatus() {
         Status s=new Status();
-        s.istPosition = 42;
+        s.istPosition = curPos;
         s.enabled = true;
         return CompletableFuture.completedFuture(s);
     }

+ 8 - 8
src/main/java/at/acdp/urweb/web/FestoXRServer.java

@@ -21,7 +21,7 @@ public class FestoXRServer {
     }
 
     @XRMethod(value = "rel", help = "rel")
-    public static boolean rel(int relPos, int speed) {
+    public static String rel(int relPos, int speed) {
         try {
             logger.info("rel  {}", relPos);
             int curPos=Main.fhm.readStatus().get().istPosition;
@@ -30,7 +30,7 @@ public class FestoXRServer {
             Main.fhm.bereitschaft();
             if(!Main.fhm.readStatus().get().enabled) {
                 logger.info("Controller not enabled");
-                return false;
+                return "Controller not enabled";
             }
             Main.fhm.direktAuftrag(relPos, speed,0, true);
             Thread.sleep(10);
@@ -41,7 +41,7 @@ public class FestoXRServer {
                 boolean reached=checkPos(targetPos);
                 if(reached) {
                     logger.info("Reached {}", targetPos);
-                    return true;
+                    return "OK";
                 }
                 try {
                     Thread.sleep(100);
@@ -51,18 +51,18 @@ public class FestoXRServer {
             }
         } catch (ExecutionException|InterruptedException e) {
             logger.warn("abs failed", e);
+            return "abs failed: "+e.toString() ;
         }
-        return false;
     }
 
     @XRMethod(value = "abs", help = "abs")
-    public boolean abs(int targetPos, int speed) {
+    public static String abs(int targetPos, int speed) {
         try {
             logger.info("Absolute to {} speed {}", targetPos, speed);
             Main.fhm.bereitschaft();
             if(!Main.fhm.readStatus().get().enabled) {
                 logger.info("Controller not enabled");
-                return false;
+                return "Controller not enabled";
            }
         Main.fhm.direktAuftrag(targetPos, speed, 0, false);
         Thread.sleep(100);
@@ -72,7 +72,7 @@ public class FestoXRServer {
             boolean reached=checkPos(targetPos);
             if(reached) {
                 logger.info("Reached {}", targetPos);
-                return true;
+                return "OK";
             }
             try {
                 Thread.sleep(100);
@@ -82,8 +82,8 @@ public class FestoXRServer {
         }
         } catch (ExecutionException|InterruptedException e) {
             logger.warn("abs failed", e);
+            return "abs failed: "+e.toString();
         }
-        return false;
     }
 
     @XRMethod(value = "getpos", help = "getpos")