MacroState.java 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package net.hkzlab.palanalisys;
  2. import java.util.ArrayList;
  3. public class MacroState {
  4. public static final String MS_PRE_TAG = "MS_";
  5. public final String tag;
  6. public final boolean[] rpin_status;
  7. public final SubState[] substates;
  8. public MacroState(final String tag, final boolean[] rpin_status, int outPins) {
  9. this.tag = tag;
  10. this.rpin_status = rpin_status;
  11. int possible_bin_sstates = 2 ^ outPins;
  12. ArrayList<SubState> sStates = new ArrayList<>();
  13. byte[] pstatus;
  14. for(int idx = 0; idx < possible_bin_sstates; idx++) {
  15. pstatus = new byte[outPins];
  16. // Generate this binary combination
  17. for(int idx_bit = 0; idx_bit < outPins; idx_bit++) {
  18. pstatus[idx_bit] = (byte)((idx >> idx_bit) & 0x01);
  19. }
  20. sStates.add(new SubState(tag, pstatus));
  21. // Generate the remaining combinations with hi-z
  22. for(int hiz_idx = 0; hiz_idx < possible_bin_sstates; hiz_idx++) {
  23. for(int idx_bit = 0; idx_bit < outPins; idx_bit++) {
  24. byte[] oc_pstatus = new byte[outPins];
  25. oc_pstatus[idx_bit] = ((hiz_idx >> idx_bit) & 0x01) > 0 ? -1 : pstatus[idx_bit];
  26. }
  27. sStates.add(new SubState(tag, pstatus));
  28. }
  29. }
  30. substates = sStates.toArray(new SubState[sStates.size()]);
  31. }
  32. @Override
  33. public String toString() {
  34. StringBuffer strBuf = new StringBuffer();
  35. strBuf.append(MS_PRE_TAG+tag+" - ");
  36. for(boolean rpin : rpin_status) strBuf.append(rpin ? '1':'0');
  37. return strBuf.toString();
  38. }
  39. }