App.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package info.hkzlab.dupal.analyzer;
  2. import java.lang.reflect.InvocationTargetException;
  3. import org.slf4j.*;
  4. import info.hkzlab.dupal.analyzer.board.boardio.*;
  5. import info.hkzlab.dupal.analyzer.devices.*;
  6. public class App {
  7. public static volatile String[] palTypes = { PAL16L8Specs.PAL_TYPE, PAL10L8Specs.PAL_TYPE };
  8. private final static Logger logger = LoggerFactory.getLogger(DuPALManager.class);
  9. private final static String version = App.class.getPackage().getImplementationVersion();
  10. private static String serialDevice = null;
  11. private static PALSpecs pspecs = null;
  12. private static int outMask = -1;
  13. private static boolean padTable = true;
  14. private static String outFile = null;
  15. public static void main(String[] args) throws Exception {
  16. System.out.println("DuPAL Analyzer " + version);
  17. if (args.length < 3) {
  18. StringBuffer supportedPALs = new StringBuffer();
  19. for(String palT : palTypes) {
  20. supportedPALs.append("\t"+palT+"\n");
  21. }
  22. logger.error("Wrong number of arguments passed.\n"
  23. + "dupal_analyzer <serial_port> <pal_type> <output_file> [pad_table: Y|N] [hex_output_mask]\n"
  24. + "Where <pal_type> can be:\n" + supportedPALs.toString() + "\n");
  25. return;
  26. }
  27. parseArgs(args);
  28. DuPALManager dpm = new DuPALManager(serialDevice);
  29. DuPALCmdInterface dpci = new DuPALCmdInterface(dpm, pspecs);
  30. DuPALAnalyzer dpan = new DuPALAnalyzer(dpci, outMask, outFile);
  31. if (!dpm.enterRemoteMode()) {
  32. System.out.println("Unable to put DuPAL board in REMOTE MODE!");
  33. System.exit(-1);
  34. }
  35. Runtime.getRuntime().addShutdownHook(new Thread() {
  36. @Override
  37. public void run() {
  38. dpci.reset();
  39. }
  40. });
  41. dpan.startAnalisys(padTable);
  42. }
  43. private static void parseArgs(String[] args) {
  44. serialDevice = args[0];
  45. try {
  46. Class<?> specsClass = Class.forName("info.hkzlab.dupal.analyzer.devices.PAL" + args[1].toUpperCase() + "Specs");
  47. pspecs = (PALSpecs) specsClass.getConstructor().newInstance(new Object[]{});
  48. } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException
  49. | InvocationTargetException | NoSuchMethodException | SecurityException e) {
  50. logger.error("Invalid PAL type selected.");
  51. System.exit(-1);
  52. }
  53. outFile = args[2];
  54. if(args.length >= 4) {
  55. padTable = args[3].equalsIgnoreCase("Y");
  56. }
  57. if(args.length >= 5) {
  58. outMask = Integer.parseInt(args[4], 16);
  59. }
  60. }
  61. }