소스 검색

Wire up table formatting code

Baglio Tabifata 5 년 전
부모
커밋
9380c1a060

+ 13 - 3
src/main/java/info/hkzlab/dupal/analyzer/board/boardio/DuPALAnalyzer.java

@@ -6,6 +6,7 @@ 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.formatter.EspressoFormatter;
 import info.hkzlab.dupal.analyzer.palanalisys.graph.OutState;
 import info.hkzlab.dupal.analyzer.palanalisys.simple.SimpleState;
 import info.hkzlab.dupal.analyzer.utilities.BitUtils;
@@ -94,20 +95,29 @@ public class DuPALAnalyzer {
 
         dpci.setLED(led, true);
 
+        String header = null;
+        String[] table = null;
+        String footer = null;
+
+        footer = EspressoFormatter.formatEspressoFooter();
+
         try {
             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());
+                table = EspressoFormatter.formatEspressoTable(dpci.palSpecs, ssArray);
+                header = EspressoFormatter.formatEspressoTableHeader(dpci.palSpecs, 0);
+                
+                logger.info("Got " + ssArray.length + " output states!");
             } 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));
                 }
-
+                
+                header = EspressoFormatter.formatEspressoTableHeader(dpci.palSpecs, ioAsOutMask);
                 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;

+ 43 - 1
src/main/java/info/hkzlab/dupal/analyzer/palanalisys/formatter/EspressoFormatter.java

@@ -1,6 +1,10 @@
 package info.hkzlab.dupal.analyzer.palanalisys.formatter;
 
+import java.util.ArrayList;
+
 import info.hkzlab.dupal.analyzer.devices.PALSpecs;
+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 EspressoFormatter {
@@ -38,5 +42,43 @@ public class EspressoFormatter {
         
         return strBuf.toString();
     }
-    
+   
+    public static String[] formatEspressoTable(PALSpecs pSpecs, OutState[] states) {
+        ArrayList<String> tableRows = new ArrayList<>();
+
+        for(OutState ss : states) {
+
+        }
+
+        return tableRows.toArray(new String[tableRows.size()]);
+    }
+
+    public static String[] formatEspressoTable(PALSpecs pSpecs, SimpleState[] states) {
+        ArrayList<String> tableRows = new ArrayList<>();
+
+        StringBuffer strBuf = new StringBuffer();
+        for(SimpleState ss : states) {
+            strBuf.delete(0, strBuf.length());
+            
+            int inputs = BitUtils.consolidateBitField(ss.input, pSpecs.getMask_IN());
+            int output = BitUtils.consolidateBitField(ss.output, pSpecs.getMask_O_R());
+            int hiz = BitUtils.consolidateBitField(ss.hiz, pSpecs.getMask_O_R());
+            for(int idx = 0; idx < pSpecs.getPinCount_IN(); idx++) strBuf.append((char)(((inputs >> idx) & 0x01) + 0x30));
+            strBuf.append(' ');
+            for(int idx = 0; idx < pSpecs.getPinCount_O(); idx++) {
+                boolean hiz_pin = ((hiz >> idx) & 0x01) != 0;
+                strBuf.append(hiz_pin ? '-' : (char)(((output >> idx) & 0x01) + 0x30));
+            }
+            for(int idx = 0; idx < pSpecs.getPinCount_O(); idx++) strBuf.append((char)(((hiz >> idx) & 0x01) + 0x30));
+            strBuf.append('\n');
+
+            tableRows.add(strBuf.toString());
+        }
+
+        return tableRows.toArray(new String[tableRows.size()]);
+    }
+
+    public static String formatEspressoFooter() {
+        return ".e\n\n";
+    }
 }