Răsfoiți Sursa

Added more debug, and do not start the analysis after an IO mask detection

Fabio Battaglia 4 ani în urmă
părinte
comite
91069c347c

+ 1 - 1
.vscode/settings.json

@@ -1,5 +1,5 @@
 {
-    "java.configuration.updateBuildConfiguration": "automatic",
+    "java.configuration.updateBuildConfiguration": "interactive",
     "files.exclude": {
         "**/.classpath": true,
         "**/.project": true,

+ 1 - 1
README.md

@@ -49,7 +49,7 @@ The following PAL models are supported:
 The format for command line execution is the following:
 
 ```text
-java -jar /path/to/dupal_analyzer.jar <serial_port> <pal_type> <output_file> [hex_output_mask]
+java -jar /path/to/dupal_analyzer.jar <serial_port> <pal_type> [<output_file> hex_output_mask]
 ```
 
 - **serial_port:** is just the serial port to use to connect to the DuPAL board. Connection is hardcoded at **57600bps 8n1** without flow control.

+ 4 - 0
docs/analysis.md

@@ -218,6 +218,10 @@ Intermediate states are also impossible to capture with the current hardware: as
 
 It may be possible to capture the intermediate state **if the outputs are sampled quickly enough** (the timing is also dependent on the type of PAL being under analisys). This might prove to be helpful with PALs that are using feedbacks extensively, but **it will require a new hardware project and a new firmware** and also a new analysis procedure.
 
+---
+
+Currently, if the PAL is programmed in such a way that it can only come out of a state (for example, the state it is in right after power up), but never come back into it again via a combination of inputs, we won't be able to perform a complete map of the states graph.
+
 ### A representation of the PAL
 
 To analyze all the possible states of a PAL device we can draw a directed **graph**:

+ 1 - 1
pom.xml

@@ -6,7 +6,7 @@
 
   <groupId>info.hkzlab.dupal.analyzer</groupId>
   <artifactId>dupal-analyzer</artifactId>
-  <version>0.1.3</version>
+  <version>0.1.4</version>
 
   <name>dupal-analyzer</name>
   <url>https://github.com/DuPAL-PAL-DUmper</url>

+ 5 - 6
src/main/java/info/hkzlab/dupal/analyzer/App.java

@@ -39,7 +39,7 @@ public class App {
     public static void main(String[] args) throws Exception {
         logger.info("DuPAL Analyzer " + version);
 
-        if (args.length < 3) {
+        if (args.length < 2) {
             StringBuffer supportedPALs = new StringBuffer();
 
             for(String palT : palTypes) {
@@ -47,7 +47,7 @@ public class App {
             }
 
             logger.error("Wrong number of arguments passed.\n"
-                    + "dupal_analyzer <serial_port> <pal_type> <output_file> [hex_output_mask]\n"
+                    + "dupal_analyzer <serial_port> <pal_type> [<output_file> hex_output_mask]\n"
                     + "Where <pal_type> can be:\n" + supportedPALs.toString() + "\n");
 
             return;
@@ -86,13 +86,12 @@ public class App {
             System.exit(-1);
         }
 
-        outFile = args[2];
-
         if(args.length >= 4) {
+            outFile = args[2];
             outMask = Integer.parseInt(args[3], 16);
+            
+            checkOutPath(outFile);
         }
-
-        checkOutPath(outFile);
     }
 
     private static void checkOutPath(String path) {

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

@@ -109,15 +109,18 @@ public class DuPALAnalyzer {
                 if(ioAsOutMask < 0) {
                     ioAsOutMask = detectIOTypeMask(dpci);
                     logger.info("Detected the following IO as Outputs mask: " + String.format("%02X", ioAsOutMask));
-                }
-                
-                OutState[] osArray = OSExplorer.exploreOutStates(dpci, ioAsOutMask);
+                    logger.info("Now, turn OFF and ON again the DuPAL to reset the PAL and run this tool again by specifying the mask and output file.");
 
-                logger.info("Got " + osArray.length + " output states!");
-                formatterOutput = JSONFormatter.formatJSON(dpci.palSpecs, ioAsOutMask, osArray);
+                    return;
+                } else {
+                    OutState[] osArray = OSExplorer.exploreOutStates(dpci, ioAsOutMask);
+
+                    logger.info("Got " + osArray.length + " output states!");
+                    formatterOutput = JSONFormatter.formatJSON(dpci.palSpecs, ioAsOutMask, osArray);
+                }
             }
 
-            saveOutputToFile(outFile, formatterOutput);
+            if(outFile != null) saveOutputToFile(outFile, formatterOutput);
         } catch(Exception e) {
             throw e;
         } finally {

+ 4 - 1
src/main/java/info/hkzlab/dupal/analyzer/palanalisys/explorers/OSExplorer.java

@@ -59,7 +59,10 @@ public class OSExplorer {
                     }
                     continue; // Loop again
 
-                } else break; // We're done: can't move to anywhere else
+                } else {
+                    logger.info("exploreOutStates() -> Can't find a path to an unexplored state from " + curState);
+                    break; // We're done: can't move anywhere else  
+                }
             }
 
             int nextIdx;

+ 13 - 2
src/main/java/info/hkzlab/dupal/analyzer/palanalisys/formatter/JSONFormatter.java

@@ -2,6 +2,8 @@ package info.hkzlab.dupal.analyzer.palanalisys.formatter;
 
 import org.json.JSONArray;
 import org.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import info.hkzlab.dupal.analyzer.devices.PALSpecs;
 import info.hkzlab.dupal.analyzer.palanalisys.graph.*;
@@ -9,6 +11,7 @@ import info.hkzlab.dupal.analyzer.palanalisys.simple.SimpleState;
 
 public class JSONFormatter {
     public static final int JSON_FORMAT_REVISION = 2;
+    private static final Logger logger = LoggerFactory.getLogger(JSONFormatter.class);
 
     private JSONFormatter() {};
    
@@ -41,8 +44,16 @@ public class JSONFormatter {
             OutLink[] oLinks = os.getOutLinks();
             RegLink[] rLinks = os.getRegLinks();
 
-            for(OutLink ol : oLinks) osLinks.put(buildObjectFromOutLink(ol));
-            for(RegLink rl : rLinks) regLinks.put(buildObjectFromRegLink(rl));
+            for(int idx = 0; idx < oLinks.length; idx++)  {
+                if(oLinks[idx] != null) osLinks.put(buildObjectFromOutLink(oLinks[idx]));
+                else logger.warn("formatJSON -> oLink "+idx+" is null in " + os + "!");
+            }
+
+           for(int idx = 0; idx < rLinks.length; idx++)  {
+                if(rLinks[idx] != null) regLinks.put(buildObjectFromRegLink(rLinks[idx]));
+                else logger.warn("formatJSON -> rLink "+idx+" is null in " + os + "!");
+            }
+
             osStates.put(buildObjectFromPINs(os.pins));
         }
 

+ 18 - 6
src/main/java/info/hkzlab/dupal/analyzer/palanalisys/graph/PathFinder.java

@@ -6,7 +6,12 @@ import java.util.LinkedList;
 import java.util.Map;
 import java.util.Queue;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 public class PathFinder {
+   private static final Logger logger = LoggerFactory.getLogger(PathFinder.class);
+
    private PathFinder() {};
 
    @SuppressWarnings("unchecked")
@@ -16,22 +21,29 @@ public class PathFinder {
        ArrayList<GraphLink> linkStack = null;
        GraphState currentState = start;
 
+       //logger.info("findPathToState() -> from:" + start + " to:" + dest);
+
        pathMap.put(start.hashCode(), new ArrayList<>()); // Bootstrap the pathMap by adding an empty path to the start state
 
        while(currentState != null) {
            linkStack = pathMap.get(currentState.hashCode()); // Get the map to the current state
            if(((dest == null) && !currentState.isStateFull()) ||
-           ((dest != null) && currentState.equals(dest))) return linkStack.toArray(new GraphLink[linkStack.size()]); // Ok, we found a state where we need to map other links
+           ((dest != null) && currentState.equals(dest)))  {
+                //logger.info("findPathToState() -> found path to: " + currentState);
+                return linkStack.toArray(new GraphLink[linkStack.size()]); // Ok, we found a state where we need to map other links
+           }
        
            GraphLink[] stateLinks = currentState.getLinks(); // Get links present in the current state
 
-            for(GraphLink l : stateLinks) { // For every link...
-                if(!pathMap.containsKey(l.getDestinationState().hashCode())) { // If it's not leading somewhere we've already visited or we've already put in our path map
+            for(int idx = 0; idx < stateLinks.length; idx++) { // For every link...
+                if(stateLinks[idx] == null) continue;
+
+                if(!pathMap.containsKey(stateLinks[idx].getDestinationState().hashCode())) { // If it's not leading somewhere we've already visited or we've already put in our path map
                     ArrayList<GraphLink> statePath = (ArrayList<GraphLink>)linkStack.clone(); // Copy the path to the current state
-                    statePath.add(l); // And append this link to it
+                    statePath.add(stateLinks[idx]); // And append this link to it
 
-                    pathMap.put(l.getDestinationState().hashCode(), statePath); // Then put this new path into the map
-                    statesQueue.add(l.getDestinationState()); // And add the state to the queue, to examine later
+                    pathMap.put(stateLinks[idx].getDestinationState().hashCode(), statePath); // Then put this new path into the map
+                    statesQueue.add(stateLinks[idx].getDestinationState()); // And add the state to the queue, to examine later
                 }
             }