فهرست منبع

Add basic code for PAL states

Baglio Tabifata 4 سال پیش
والد
کامیت
cae0159381
3فایلهای تغییر یافته به همراه112 افزوده شده و 1 حذف شده
  1. 6 1
      src/net/hkzlab/dupal/App.java
  2. 52 0
      src/net/hkzlab/palanalisys/MacroState.java
  3. 54 0
      src/net/hkzlab/palanalisys/SubState.java

+ 6 - 1
src/net/hkzlab/dupal/App.java

@@ -2,11 +2,13 @@ package net.hkzlab.dupal;
 
 import net.hkzlab.dupal.boardio.DuPALManager;
 import net.hkzlab.dupal.dupalproto.DuPALProto;
+import net.hkzlab.palanalisys.SubState;
 
 public class App {
     public static void main(String[] args) throws Exception {
         DuPALManager dpm = new DuPALManager("/dev/ttyUSB0");
 
+        /*
         try {
             System.out.println(dpm.enterRemoteMode());
 
@@ -27,6 +29,9 @@ public class App {
         } finally {
             dpm.cleanup();
         }
-        
+        */
+        SubState ss = new SubState("TEST", new byte[] {-1, 0, -1, 0, -1, -1});
+        System.out.println(ss.toString());
+        System.out.println(ss.hashCode());
     }
 }

+ 52 - 0
src/net/hkzlab/palanalisys/MacroState.java

@@ -0,0 +1,52 @@
+package net.hkzlab.palanalisys;
+
+import java.util.ArrayList;
+
+public class MacroState {
+    public static final String MS_PRE_TAG = "MS_";
+
+    public final String tag;
+    public final boolean[] rpin_status;
+    public final SubState[] substates;
+
+    public MacroState(final String tag, final boolean[] rpin_status, int outPins) {
+        this.tag = tag;
+        this.rpin_status = rpin_status;
+
+        int possible_bin_sstates = 2 ^ outPins;
+        ArrayList<SubState> sStates = new ArrayList<>();
+        byte[] pstatus;
+        for(int idx = 0; idx < possible_bin_sstates; idx++) {
+            pstatus = new byte[outPins];
+
+            // Generate this binary combination
+            for(int idx_bit = 0; idx_bit < outPins; idx_bit++) {
+                pstatus[idx_bit] = (byte)((idx >> idx_bit) & 0x01);
+            }
+
+            sStates.add(new SubState(tag, pstatus));
+
+            // Generate the remaining combinations with hi-z
+            for(int hiz_idx = 0; hiz_idx < possible_bin_sstates; hiz_idx++) {
+                for(int idx_bit = 0; idx_bit < outPins; idx_bit++) {
+                    byte[] oc_pstatus = new byte[outPins];
+                    oc_pstatus[idx_bit] = ((hiz_idx >> idx_bit) & 0x01) > 0 ? -1 : pstatus[idx_bit];
+                }  
+
+                sStates.add(new SubState(tag, pstatus));
+            }
+        }
+
+        substates = sStates.toArray(new SubState[sStates.size()]);
+    }
+
+    @Override
+    public String toString() {
+        StringBuffer strBuf = new StringBuffer();
+        strBuf.append(MS_PRE_TAG+tag+" - ");
+
+        for(boolean rpin : rpin_status) strBuf.append(rpin ? '1':'0');
+
+        return strBuf.toString();
+    }
+}

+ 54 - 0
src/net/hkzlab/palanalisys/SubState.java

@@ -0,0 +1,54 @@
+package net.hkzlab.palanalisys;
+
+import java.util.Arrays;
+
+public class SubState {
+    public static final String SS_PRE_TAG = "SS_";
+
+    public final String tag;
+    public final byte[] pin_status;
+
+    public SubState(final String tag, final byte[] pin_status) {
+        this.tag = tag;
+        this.pin_status = pin_status;
+    } 
+
+    @Override
+    public String toString() {
+        StringBuffer strBuf = new StringBuffer();
+        strBuf.append(SS_PRE_TAG+tag+" - ");
+
+        for(byte pin : pin_status) {
+            if(pin < 0) strBuf.append('x');
+            else if (pin == 0) strBuf.append(0);
+            else strBuf.append(1);
+        }
+
+        return strBuf.toString();
+    }
+
+    @Override
+    public int hashCode() {
+        int hash = 0;
+
+        for(int idx = 0; idx < pin_status.length; idx++) {
+            int byte_idx = idx % 4;
+            hash ^= (pin_status[idx] & 0xFF) << (8 * byte_idx);
+        }
+
+        return hash;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if(this == o) return true;
+        if(o == null) return false;
+        if(this.getClass() != o.getClass()) return false;
+
+        SubState ops = (SubState)o;
+        if(!ops.tag.equals(this.tag)) return false;
+        if(!Arrays.equals(ops.pin_status, this.pin_status)) return false;
+
+        return true;
+    }
+}