App.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 String outDir = null;
  14. public static void main(String[] args) throws Exception {
  15. System.out.println("DuPAL Analyzer " + version);
  16. if (args.length < 3) {
  17. StringBuffer supportedPALs = new StringBuffer();
  18. for(String palT : palTypes) {
  19. supportedPALs.append("\t"+palT+"\n");
  20. }
  21. logger.error("Wrong number of arguments passed.\n"
  22. + "dupal_analyzer <serial_port> <pal_type> <output_dir> [hex_output_mask]\n"
  23. + "Where <pal_type> can be:\n" + supportedPALs.toString() + "\n");
  24. return;
  25. }
  26. parseArgs(args);
  27. DuPALManager dpm = new DuPALManager(serialDevice);
  28. DuPALCmdInterface dpci = new DuPALCmdInterface(dpm, pspecs);
  29. DuPALAnalyzer dpan = new DuPALAnalyzer(dpci, outMask, outDir);
  30. if (!dpm.enterRemoteMode()) {
  31. System.out.println("Unable to put DuPAL board in REMOTE MODE!");
  32. System.exit(-1);
  33. }
  34. Runtime.getRuntime().addShutdownHook(new Thread() {
  35. @Override
  36. public void run() {
  37. dpci.reset();
  38. }
  39. });
  40. dpan.startAnalisys();
  41. }
  42. private static void parseArgs(String[] args) {
  43. serialDevice = args[0];
  44. try {
  45. Class<?> specsClass = Class.forName("info.hkzlab.dupal.analyzer.devices.PAL" + args[1].toUpperCase() + "Specs");
  46. pspecs = (PALSpecs) specsClass.getConstructor().newInstance(new Object[]{});
  47. } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException
  48. | InvocationTargetException | NoSuchMethodException | SecurityException e) {
  49. logger.error("Invalid PAL type selected.");
  50. System.exit(-1);
  51. }
  52. outDir = args[2];
  53. if(args.length >= 4) {
  54. outMask = Integer.parseInt(args[3], 16);
  55. }
  56. }
  57. }