Browse Source

change data types for abs/rel command to int
add simulated axis class

Martin Kunz 2 years ago
parent
commit
258bcf8b93

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

@@ -1,7 +1,9 @@
 package at.acdp.urweb;
 
 import at.acdp.urweb.fhpp.FHMaster;
+import at.acdp.urweb.fhpp.FHMasterSim;
 import at.acdp.urweb.fhpp.FHPP;
+import at.acdp.urweb.fhpp.IFHMaster;
 import at.acdp.urweb.web.XRServer;
 import com.nmote.nanohttp.NanoServer;
 import com.nmote.xr.XR;
@@ -9,7 +11,7 @@ import org.slf4j.LoggerFactory;
 
 public class Main {
     private final static org.slf4j.Logger logger = LoggerFactory.getLogger(Main.class);
-    public static FHMaster fhm=new FHMaster();
+    public static IFHMaster fhm=new FHMasterSim();
     public static void main(String[] args) {
         Params app = null;
         try {

+ 6 - 1
src/main/java/at/acdp/urweb/fhpp/FHMaster.java

@@ -16,7 +16,7 @@ import io.netty.util.ReferenceCountUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class FHMaster {
+public class FHMaster implements IFHMaster {
     private final Logger logger = LoggerFactory.getLogger(getClass());
     public static int posfaktorNum=1;
     public static int posfaktorDiv=1;
@@ -27,6 +27,7 @@ public class FHMaster {
     public FHMaster() {
     }
 
+    @Override
     public void start(Params app) throws InterruptedException {
         started = true;
         ModbusTcpMasterConfig config = new ModbusTcpMasterConfig.Builder(app.axisIP)
@@ -59,6 +60,7 @@ public class FHMaster {
         f.join();
     }
 
+    @Override
     public void direktAuftrag(int pos, int speed, int start, boolean relative) {
         byte ccon=0x0;
         ccon|=(1<<0); // Enable drive
@@ -113,6 +115,7 @@ public class FHMaster {
                 },4);
     }
 
+    @Override
     public CompletableFuture<Status> readStatus() {
         if(master==null)
             return null;
@@ -143,6 +146,7 @@ public class FHMaster {
         return  fc;
     }
 
+    @Override
     public void bereitschaft() {
         List<ModbusRequest> blist = new ArrayList<>();
         blist.add(new WriteMultipleRegistersRequest(0,4, new byte[]{0b01000111,0,0,0,0,0,0,0}));
@@ -155,6 +159,7 @@ public class FHMaster {
         }
     }
 
+    @Override
     public void stop() {
         started = false;
     }

+ 67 - 0
src/main/java/at/acdp/urweb/fhpp/FHMasterSim.java

@@ -0,0 +1,67 @@
+
+
+package at.acdp.urweb.fhpp;
+
+import at.acdp.urweb.Params;
+import com.digitalpetri.modbus.codec.Modbus;
+import com.digitalpetri.modbus.master.ModbusTcpMaster;
+import com.digitalpetri.modbus.master.ModbusTcpMasterConfig;
+import com.digitalpetri.modbus.requests.ModbusRequest;
+import com.digitalpetri.modbus.requests.ReadHoldingRegistersRequest;
+import com.digitalpetri.modbus.requests.WriteMultipleRegistersRequest;
+import com.digitalpetri.modbus.responses.ReadHoldingRegistersResponse;
+import io.netty.util.ReferenceCountUtil;
+import io.netty.util.concurrent.CompleteFuture;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+public class FHMasterSim implements IFHMaster {
+    private final static Logger logger = LoggerFactory.getLogger(FHMasterSim.class);
+
+    private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
+    private volatile boolean started = false;
+    public FHMasterSim() {
+    }
+
+    @Override
+    public void start(Params app) throws InterruptedException {
+        started = true;
+        while(true) {
+            Thread.sleep(1000);
+            readStatus();
+        }
+    }
+
+
+
+    @Override
+    public void direktAuftrag(int pos, int speed, int start, boolean relative) {
+        logger.info("direktAuftrag {},{},{},{}", pos, speed, start, relative);
+    }
+
+    @Override
+    public CompletableFuture<Status> readStatus() {
+        Status s=new Status();
+        s.istPosition = 42;
+        s.enabled = true;
+        return CompletableFuture.completedFuture(s);
+    }
+
+
+    @Override
+    public void bereitschaft() {
+        logger.info("bereitschaft");
+
+    }
+
+    @Override
+    public void stop() {
+        started = false;
+    }
+}

+ 17 - 0
src/main/java/at/acdp/urweb/fhpp/IFHMaster.java

@@ -0,0 +1,17 @@
+package at.acdp.urweb.fhpp;
+
+import at.acdp.urweb.Params;
+
+import java.util.concurrent.CompletableFuture;
+
+public interface IFHMaster {
+    void start(Params app) throws InterruptedException;
+
+    void direktAuftrag(int pos, int speed, int start, boolean relative);
+
+    CompletableFuture<Status> readStatus();
+
+    void bereitschaft();
+
+    void stop();
+}

+ 5 - 9
src/main/java/at/acdp/urweb/web/XRServer.java

@@ -21,13 +21,11 @@ public class XRServer {
     }
 
     @XRMethod(value = "rel", help = "rel")
-    public static boolean rel(String pos, String speedS) {
+    public static boolean rel(int relPos, int speed) {
         try {
-            logger.info("rel  {}", pos);
+            logger.info("rel  {}", relPos);
             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) {
@@ -39,7 +37,6 @@ public class XRServer {
             Main.fhm.direktAuftrag(relPos, speed, 1, true);
             Thread.sleep(10);
 
-
             while(true) {
                 boolean reached=checkPos(targetPos);
                 if(reached) {
@@ -59,13 +56,12 @@ public class XRServer {
     }
 
     @XRMethod(value = "abs", help = "abs")
-    public boolean abs(String pos, String speedS) {
+    public boolean abs(int targetPos, int speed) {
         try {
 
-            int targetPos=Integer.parseInt(pos);
-            int speed=Integer.parseInt(speedS);
 
-            logger.info("Absolute to {} speed {}", pos, speed);
+
+            logger.info("Absolute to {} speed {}", targetPos, speed);
             Main.fhm.bereitschaft();
             if(!Main.fhm.readStatus().get().enabled) {
                 logger.info("Controller not enabled");