Fabio Battaglia преди 4 години
родител
ревизия
a655dd5704

+ 6 - 2
src/main/java/info/hkzlab/dupal/analyzer/board/boardio/DuPALAnalyzer.java

@@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
 import info.hkzlab.dupal.analyzer.devices.*;
 import info.hkzlab.dupal.analyzer.exceptions.*;
 import info.hkzlab.dupal.analyzer.palanalisys.explorers.OSExplorer;
+import info.hkzlab.dupal.analyzer.palanalisys.graph.OutState;
 import info.hkzlab.dupal.analyzer.utilities.BitUtils;
 
 public class DuPALAnalyzer {
@@ -81,9 +82,12 @@ public class DuPALAnalyzer {
             DuPALAnalyzerException {
         if(ioAsOutMask < 0) {
             ioAsOutMask = detectIOTypeMask(dpci);
-            logger.info("detectIOTypeMask -> Detected the following IO Type mask: " + String.format("%06X", ioAsOutMask));
+            logger.info("startAnalisys() -> Detected the following IO Type mask: " + String.format("%06X", ioAsOutMask));
         }
 
-        OSExplorer.exploreOutStates(dpci, ioAsOutMask);
+        OutState[] osArray = OSExplorer.exploreOutStates(dpci, ioAsOutMask);
+
+        logger.info("Got " + osArray.length + " output states!");
+        for(OutState os : osArray) logger.info(os.toString());
     }
 }

+ 13 - 6
src/main/java/info/hkzlab/dupal/analyzer/palanalisys/explorers/OSExplorer.java

@@ -39,15 +39,19 @@ public class OSExplorer {
                 logger.info("exploreOutStates() -> " + curState + " is full.");
                 ArrayList<GraphLink> linkPath = PathFinder.findPathToNearestUnfilledState(curState);
                 if(linkPath != null && !linkPath.isEmpty()) {
-                    for(GraphLink l : linkPath) dpci.write(l.getLinkInputs()); // Walk the path to the new state
+                    for(GraphLink l : linkPath) {
+                        logger.info("exploreOutStates() -> Walking link " + l);
+                        dpci.write(l.getLinkInputs()); // Walk the path to the new state
+                        //try { Thread.sleep(1); } catch(InterruptedException e) {};
+                    }
                     curState = (OutState) (linkPath.get(linkPath.size() - 1)).getDestinationState();
                     logger.info("exploreOutStates() -> walked path to state " + curState);
 
-                    // Do some doublecheckin
-                    int pins = (dpci.read() & ~curState.pins.hiz) & (pSpecs.getMask_O_R() | ioAsOutMask);
+                    // Do some doublechecking
+                    int pins = (dpci.read() & (ioAsOutMask | pSpecs.getMask_O_R())) & ~curState.pins.hiz;
                     int expected_pins = ((curState.pins.out & ~curState.pins.hiz) & (pSpecs.getMask_O_R() | ioAsOutMask));
                     if(pins != expected_pins) {
-                        logger.error("exploreOutStates() -> Mismatch in expected pins ("+String.format("E:%02X|A:%02X", pins, expected_pins)+") after walink path to state " + curState);
+                        logger.error("exploreOutStates() -> Mismatch in expected pins ("+String.format("E:%02X|A:%02X", expected_pins, pins)+") after walking path to state " + curState);
                         throw new DuPALAnalyzerException("exploreOutStates() -> Mismatch in expected pins after walking to state " + curState);
                     }
                     continue; // Loop again
@@ -62,7 +66,7 @@ public class OSExplorer {
             OutLink ol = new OutLink(curState, nOutState, w_idx);
             curState.addOutLink(ol);
 
-            logger.info("Creating link ["+nextIdx+"/"+(maxLinks-1)+"] - " + ol);
+            logger.info("exploreOutStates() -> Creating link ["+nextIdx+"/"+(maxLinks-1)+"] - " + ol);
 
             curState = nOutState;
         }
@@ -75,7 +79,6 @@ public class OSExplorer {
         int w_idx = BitUtils.scatterBitField(idx, pSpecs.getMask_IN());
         w_idx |= BitUtils.scatterBitField((idx >> pSpecs.getPinCount_IN()), pSpecs.getMask_IO_W() & ~ioAsOut_W);
 
-
         return w_idx;
     }
 
@@ -88,10 +91,14 @@ public class OSExplorer {
         int w_idx = calcolateWriteINFromIdx(idx, pSpecs, ioAsOutMask);
 
         dpci.write(w_idx);
+        //try { Thread.sleep(5); } catch(InterruptedException e) {};
         pinState_A = dpci.read();
         dpci.write(w_idx | pSpecs.getMask_O_W() | ioAsOut_W); // Try to force the outputs
+        //try { Thread.sleep(5); } catch(InterruptedException e) {};
         pinState_B = dpci.read();
 
+        logger.info("getOutStateForIdx() -> pinstate " + String.format("%02X", pinState_A) + " | w: " + String.format("%02X", w_idx));
+
         // TODO: Check that the IOs that we consider as inputs are actually inputs, and are not remaining set to other values (which would mean they're actually outputs)
 
         OutStatePins osp = extractOutPinStates(pSpecs, ioAsOutMask, pinState_A, pinState_B);

+ 2 - 1
src/main/java/info/hkzlab/dupal/analyzer/palanalisys/graph/OutState.java

@@ -46,7 +46,8 @@ public class OutState implements GraphState {
     public int hashCode() {
         int hash = 7;
 
-        hash = pins.hashCode()*31 + links.length;
+        hash = hash*31 + pins.hashCode();
+        hash = hash*31 + links.length;
 
         return hash;
     }