|
@@ -5,6 +5,8 @@ import com.nmote.xr.XRMethod;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
+
|
|
|
public class XRServer {
|
|
|
private final static Logger logger = LoggerFactory.getLogger(XRServer.class);
|
|
|
|
|
@@ -19,39 +21,120 @@ public class XRServer {
|
|
|
}
|
|
|
|
|
|
@XRMethod(value = "rel", help = "rel")
|
|
|
- public static void rel(String pos) {
|
|
|
- logger.info("Relative to {} Begin", pos);
|
|
|
- System.out.println("rel: "+pos);
|
|
|
- Main.fhm.direktAuftrag(Integer.parseInt(pos),0,true);
|
|
|
- waitMC(true);
|
|
|
- Main.fhm.direktAuftrag(Integer.parseInt(pos),1,true);
|
|
|
- waitMC(true);
|
|
|
- logger.info("Relative to {} End", pos);
|
|
|
+ public static boolean rel(String pos, String speedS) {
|
|
|
+ try {
|
|
|
+ logger.info("rel {}", pos);
|
|
|
+ int curPos=Main.fhm.readStatus().get().istPosition;
|
|
|
+ int relPos=Integer.parseInt(pos);
|
|
|
+ int targetPos=curPos+relPos;
|
|
|
+ int speed=Integer.parseInt(speedS);
|
|
|
+ logger.info("Relative by {} from {} to {} speed {}", relPos, curPos, targetPos, speed);
|
|
|
+ Main.fhm.bereitschaft();
|
|
|
+ if(!Main.fhm.readStatus().get().enabled) {
|
|
|
+ logger.info("Controller not enabled");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Main.fhm.direktAuftrag(relPos, speed,0, true);
|
|
|
+ Thread.sleep(10);
|
|
|
+ Main.fhm.direktAuftrag(relPos, speed, 1, true);
|
|
|
+ Thread.sleep(10);
|
|
|
+
|
|
|
+
|
|
|
+ while(true) {
|
|
|
+ boolean reached=checkPos(targetPos);
|
|
|
+ if(reached) {
|
|
|
+ logger.info("Reached {}", targetPos);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Thread.sleep(100);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (ExecutionException|InterruptedException e) {
|
|
|
+ logger.warn("abs failed", e);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
@XRMethod(value = "abs", help = "abs")
|
|
|
- public static void abs(String pos) {
|
|
|
- logger.info("Absolute to {} Begin", pos);
|
|
|
- Main.fhm.direktAuftrag(Integer.parseInt(pos),0, false);
|
|
|
- waitMC(true);
|
|
|
- Main.fhm.direktAuftrag(Integer.parseInt(pos),1, false);
|
|
|
- waitMC(true);
|
|
|
- logger.info("Absolute to {} End", pos);
|
|
|
- }
|
|
|
+ public boolean abs(String pos, String speedS) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ int targetPos=Integer.parseInt(pos);
|
|
|
+ int speed=Integer.parseInt(speedS);
|
|
|
+
|
|
|
+ logger.info("Absolute to {} speed {}", pos, speed);
|
|
|
+ Main.fhm.bereitschaft();
|
|
|
+ if(!Main.fhm.readStatus().get().enabled) {
|
|
|
+ logger.info("Controller not enabled");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Main.fhm.direktAuftrag(targetPos, speed, 0, false);
|
|
|
+ Thread.sleep(100);
|
|
|
+ Main.fhm.direktAuftrag(targetPos, speed, 1, false);
|
|
|
|
|
|
- private static void waitMC(boolean what) {
|
|
|
- logger.info("Waiting for MC");
|
|
|
while(true) {
|
|
|
- Status s = Main.fhm.readStatus().join();
|
|
|
- if (s.mc == what) break;
|
|
|
+ boolean reached=checkPos(targetPos);
|
|
|
+ if(reached) {
|
|
|
+ logger.info("Reached {}", targetPos);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Thread.sleep(100);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
- logger.info("Got MC");
|
|
|
+ } catch (ExecutionException|InterruptedException e) {
|
|
|
+ logger.warn("abs failed", e);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- private static void checkPos(int pos) {
|
|
|
+ @XRMethod(value = "getpos", help = "getpos")
|
|
|
+ public static int getpos() {
|
|
|
+ logger.info("GetPos");
|
|
|
+ try {
|
|
|
+ return Main.fhm.readStatus().get().istPosition;
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (ExecutionException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ @XRMethod(value = "ready", help = "ready")
|
|
|
+ public static void ready() {
|
|
|
+ logger.info("Ready Begin");
|
|
|
+ Main.fhm.bereitschaft();
|
|
|
+ logger.info("Ready End");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean checkPos(int pos) {
|
|
|
+ try {
|
|
|
+ Status s= Main.fhm.readStatus().get();
|
|
|
+ int curPos = s.istPosition;
|
|
|
+
|
|
|
|
|
|
+ logger.info("curpos {} ({})", curPos, pos);
|
|
|
+ if(curPos==pos) {
|
|
|
+ logger.info("reached {}", pos);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ Thread.sleep(500);
|
|
|
+ } catch (ExecutionException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@XRMethod(value = "status", help = "Returns status")
|
|
|
public static String status() {
|
|
|
var x=Main.fhm.readStatus();
|