Parcourir la source

Begin adding code for simple explorer

Baglio Tabifata il y a 5 ans
Parent
commit
fa39c1fe8f

+ 15 - 8
src/main/java/info/hkzlab/dupal/analyzer/board/boardio/DuPALAnalyzer.java

@@ -5,7 +5,9 @@ import org.slf4j.LoggerFactory;
 
 import info.hkzlab.dupal.analyzer.exceptions.*;
 import info.hkzlab.dupal.analyzer.palanalisys.explorers.OSExplorer;
+import info.hkzlab.dupal.analyzer.palanalisys.explorers.SimpleExplorer;
 import info.hkzlab.dupal.analyzer.palanalisys.graph.OutState;
+import info.hkzlab.dupal.analyzer.palanalisys.simple.SimpleState;
 import info.hkzlab.dupal.analyzer.utilities.BitUtils;
 
 public class DuPALAnalyzer {
@@ -93,15 +95,20 @@ public class DuPALAnalyzer {
         dpci.setLED(led, true);
 
         try {
-            if(ioAsOutMask < 0) {
-                ioAsOutMask = detectIOTypeMask(dpci);
-                logger.info("startAnalisys() -> Detected the following IO Type mask: " + String.format("%06X", ioAsOutMask));
+            if((dpci.palSpecs.getPinCount_IO() == 0) && (dpci.palSpecs.getPinCount_RO() == 0)) { // Purely combinatorial and no feedbacks, we can perform simple bruteforcing
+                SimpleState[] ssArray = SimpleExplorer.exploreStates(dpci);
+                for(SimpleState ss : ssArray) logger.info(ss.toString());
+            } else { // Either registered, or with feedbacks
+                if(ioAsOutMask < 0) {
+                    ioAsOutMask = detectIOTypeMask(dpci);
+                    logger.info("startAnalisys() -> Detected the following IO Type mask: " + String.format("%06X", ioAsOutMask));
+                }
+
+                OutState[] osArray = OSExplorer.exploreOutStates(dpci, ioAsOutMask);
+
+                logger.info("Got " + osArray.length + " output states!");
+                for(OutState os : osArray) logger.info(os.toString());
             }
-
-            OutState[] osArray = OSExplorer.exploreOutStates(dpci, ioAsOutMask);
-
-            logger.info("Got " + osArray.length + " output states!");
-            for(OutState os : osArray) logger.info(os.toString());
         } catch(Exception e) {
             throw e;
         } finally {

+ 25 - 0
src/main/java/info/hkzlab/dupal/analyzer/palanalisys/explorers/SimpleExplorer.java

@@ -0,0 +1,25 @@
+package info.hkzlab.dupal.analyzer.palanalisys.explorers;
+
+import java.util.ArrayList;
+
+import info.hkzlab.dupal.analyzer.board.boardio.DuPALCmdInterface;
+import info.hkzlab.dupal.analyzer.exceptions.DuPALBoardException;
+import info.hkzlab.dupal.analyzer.palanalisys.simple.SimpleState;
+import info.hkzlab.dupal.analyzer.utilities.BitUtils;
+
+public class SimpleExplorer {
+    private SimpleExplorer() {
+    };
+
+    public static SimpleState[] exploreStates(final DuPALCmdInterface dpci) throws DuPALBoardException {
+        ArrayList<SimpleState> ssList = new ArrayList<>();
+        int maxIdx = 1 << dpci.palSpecs.getPinCount_IN();
+
+        for(int idx = 0; idx < maxIdx; idx++) {
+            int w_idx = BitUtils.scatterBitField(idx, dpci.palSpecs.getMask_IN());
+            dpci.write(w_idx);
+        }
+
+        return ssList.toArray(new SimpleState[ssList.size()]);
+    }
+}

+ 18 - 0
src/main/java/info/hkzlab/dupal/analyzer/palanalisys/simple/SimpleState.java

@@ -0,0 +1,18 @@
+package info.hkzlab.dupal.analyzer.palanalisys.simple;
+
+public class SimpleState {
+    public final int input;
+    public final int output;
+    public final int hiz;
+    
+    public SimpleState(final int input, final int output, final int hiz) {
+        this.input = input;
+        this.output = output;
+        this.hiz = hiz;
+    }
+
+    @Override
+    public String toString() {
+        return "SS[I:"+String.format("%06X", input)+"|O:"+String.format("%02X", output)+"|Z:"+String.format("%02X", hiz)+"]";
+    }
+}