Browse Source

return status as map

Martin Kunz 2 years ago
parent
commit
fd1c412d0f
1 changed files with 36 additions and 5 deletions
  1. 36 5
      src/main/java/at/acdp/urweb/web/FestoXRServer.java

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

@@ -5,6 +5,8 @@ import com.nmote.xr.XRMethod;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.HashMap;
+import java.util.Map;
 import java.util.concurrent.ExecutionException;
 
 public class FestoXRServer {
@@ -129,16 +131,45 @@ public class FestoXRServer {
         return false;
     }
 
-
-
     @XRMethod(value = "status", help = "Returns status")
-    public static String status() {
+    public static Map<String, Object> status() {
         var x=Main.fhm.readStatus();
         try {
-            return x==null?"<null>":x.get().toString();
+            if(x==null)
+                return null;
+            var ret= x.get();
+            Map<String, Object> m=new HashMap<>();
+
+            m.put("opm", ret.istMoment);
+            m.put("fct", ret.abs);
+            m.put("rdyen", true);
+            m.put("fault", ret.com);
+            m.put("warn", ret.dev);
+            m.put("open", ret.fault);
+            m.put("enabled", ret.fct);
+
+            m.put("ref", ret.ref);
+            m.put("still", ret.still);
+            m.put("dev", ret.dev);
+            m.put("mov", ret.mov);
+            m.put("teach", ret.teach);
+            m.put("mc", ret.mc);
+            m.put("ack", ret.ack);
+            m.put("halt", ret.halt);
+
+            m.put("func", ret.func);
+            m.put("fgrp", ret.fgrp);
+            m.put("fnum", ret.fnum);
+            m.put("com", ret.com);
+            m.put("abs", ret.abs);
+            m.put("istMoment", ret.istMoment);
+            m.put("istPosition", ret.istPosition);
+            m.put("halt", ret.halt);
+
+            return m;
         } catch (Exception e) {
             e.printStackTrace();
-            return e.toString();
+            return null;
         }
     }
 }