From 3ccf49f01dc62e7ffd56290ef0c4139bafbcafef Mon Sep 17 00:00:00 2001 From: gac-S_Changer Date: Fri, 16 Mar 2018 15:00:32 +0100 Subject: [PATCH] MainPanel prototype --- src/main/java/ch/psi/mxsc/EseraDetection.java | 2 +- src/main/java/ch/psi/mxsc/PuckDetection.java | 69 +++++++++++-------- src/main/java/ch/psi/mxsc/PuckState.java | 11 +-- 3 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/main/java/ch/psi/mxsc/EseraDetection.java b/src/main/java/ch/psi/mxsc/EseraDetection.java index 6ca6035..2efcc8a 100644 --- a/src/main/java/ch/psi/mxsc/EseraDetection.java +++ b/src/main/java/ch/psi/mxsc/EseraDetection.java @@ -38,7 +38,7 @@ public class EseraDetection implements AutoCloseable{ for (int i=0; i present = new ArrayList<>(); - for (String line:msg.split("\t")){ - try{ - line = line.trim(); - String[] tokens = line.split(" "); - int id = Integer.valueOf(tokens[0].substring(1)); - present.add(id); - PuckState puck = Controller.getInstance().getPuckState(id); - if (tokens.length<3){ - puck.clear(); - } else { - puck.set(tokens[1].trim().equals("1"),tokens[2].trim().equals("1")); - } - } catch (Exception ex){ - getLogger().log(Level.INFO, null, ex); + void processMessage(String str){ + try{ + //System.out.println(str); + List detection = (List) JsonSerializer.decode (str, List.class); + + int id=1; + for (List bus : detection){ + for (List sensor : bus){ + Integer indDetector = sensor.get(0); + Integer mecDetector = sensor.get(0); + PuckState puck = Controller.getInstance().getPuckState(id); + puck.set(mecDetector, indDetector); + + id++; + } } - } - for (int i=1; i<= Controller.NUMBER_OF_PUCKS; i++){ - if (!Arr.containsEqual(present.toArray(), i)){ - try{ - Controller.getInstance().getPuckState(i).clear(); - } catch (Exception ex){ - getLogger().log(Level.INFO, null, ex); - } - } - } + } catch (Exception ex){ + getLogger().log(Level.INFO, null, ex); + } } @Override @@ -128,4 +130,11 @@ public class PuckDetection extends DeviceBase{ thread = null; } } + + public static void main(String[] args) throws IOException, InterruptedException { + PuckDetection pd = new PuckDetection("PD","129.129.110.83:5556"); + pd.initialize(); + + Thread.sleep(100000); + } } diff --git a/src/main/java/ch/psi/mxsc/PuckState.java b/src/main/java/ch/psi/mxsc/PuckState.java index 3415329..6145875 100644 --- a/src/main/java/ch/psi/mxsc/PuckState.java +++ b/src/main/java/ch/psi/mxsc/PuckState.java @@ -34,15 +34,16 @@ public class PuckState { } } - void set(boolean mecSwitch, boolean indSwitch) { + void set(int mecSwitch, int indSwitch) { online = true; - this.mecSwitch = mecSwitch; - this.indSwitch = indSwitch; + //TODO: Hanfle -1 value: error + this.mecSwitch = mecSwitch ==1; + this.indSwitch = mecSwitch ==1; BasePlate basePlate = getBasePlate(); if (basePlate != null) { - if (mecSwitch != indSwitch) { + if (this.mecSwitch != this.indSwitch) { basePlate.getPucks()[id - 1].detection = Puck.Detection.Error; - } else if (mecSwitch) { + } else if (this.mecSwitch) { basePlate.getPucks()[id - 1].detection = Puck.Detection.Present; } else { basePlate.getPucks()[id - 1].detection = Puck.Detection.Empty;