📄 spotselector.java
字号:
/* * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is * described in this document. In particular, and without limitation, these intellectual property rights may * include one or more of the U.S. patents listed at http://www.sun.com/patents and one or more additional patents * or pending patent applications in the U.S. and in other countries. * * U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. * standard license agreement and applicable provisions of the FAR and its supplements. * * Use is subject to license terms. * * This distribution may include materials developed by third parties. Sun, Sun Microsystems, the Sun logo and * Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. * * Copyright (c) 2006 Sun Microsystems, Inc. Tous droits r?serv?s. * * Sun Microsystems, Inc. d?tient les droits de propri?t? intellectuels relatifs ? la technologie incorpor?e dans * le produit qui est d?crit dans ce document. En particulier, et ce sans limitation, ces droits de propri?t? * intellectuelle peuvent inclure un ou plus des brevets am?ricains list?s ? l'adresse http://www.sun.com/patents * et un ou les brevets suppl?mentaires ou les applications de brevet en attente aux Etats - Unis et dans les * autres pays. * * L'utilisation est soumise aux termes du contrat de licence. * * Cette distribution peut comprendre des composants d?velopp?s par des tierces parties. * Sun, Sun Microsystems, le logo Sun et Java sont des marques de fabrique ou des marques d?pos?es de Sun * Microsystems, Inc. aux Etats-Unis et dans d'autres pays. */package com.sun.spot.spotworld.usb.spotselector;import java.io.PrintStream;/** * The SpotSelector class invokes an appropriate implementation for selection of * the spot and defines the interface for such implementations * * @author Christian P黨ringer * */abstract public class SpotSelector { /** * This string allows to distinguish in the ant script between error * messages and a sucessfully retrieved port */ public static final String ERROR_STRING = "ERROR"; public static PrintStream infoOut = System.out; public static PrintStream spotPortOut = System.err; protected SpotInfoTable spotInfoTable; protected boolean isInteractive; protected String sunSpotDefaultPort; protected String portList; protected boolean hasSunSpotDefaultPort; protected boolean isVerbose; protected boolean hasDefaultBaseStationPort; protected boolean isFindBaseStation; protected String defaultBaseStationPort; protected boolean isVeryVerbose; protected boolean isScanAllBaseStations; /** * @param args * Usage: spotselector [-i] [-v] [-pdefaultport] * <portlist> defaultport is what the program looks for * -i enables interactive mode -v verbose portlist is a * comma separated list of ports returned by the platform * specific executable, e.g. "COM1 (idxxx), COM2 * (idxxxx)" or "/dev/tty.usbmodemxyZ, * /dev/tty.usbmodemPQR" * * <fill out logic from whoteboard> If it cannot find the specified port * (or another suitable one based on user input) returns -1 If * interaction not enabled and default */ public static void main(String[] args) { if (args.length < 1) { infoOut.println("No parameter provided.\n"); printUsage(); System.exit(-1); } String allPorts = ""; String defaultPort = ""; boolean isInteractive = false; boolean isVerbose = false; boolean isVeryVerbose = false; boolean isScanAllBaseStations = false; boolean isFindBaseStation = false; for (int i = 0; i < args.length; i++) { if (!args[i].startsWith("-")) { allPorts = args[i]; break; } else { if (args[i].equals("-h")) { printUsage(); System.exit(-1); } else if (args[i].equals("-v")) { isVerbose = true; } else if (args[i].equals("-vv")) { isVeryVerbose = true; isVerbose = true; } else if (args[i].equals("-t:basestation")) { isFindBaseStation = true; } else if (args[i].equals("-scanallbasestations")) { isScanAllBaseStations = true; } else if (args[i].startsWith("-p")) { if (args[i].length() == 2) { infoOut .println("command line argument 'p' must specifiy serial port"); printUsage(); System.exit(-1); } defaultPort = args[i].substring(2); } else if (args[i].equals("-i")) { isInteractive = true; } } } if (isVerbose) { infoOut.println("isFindBaseStation: " + isFindBaseStation); infoOut.println("Ports found:" + allPorts); } SpotSelector spotselector; spotselector = new CommandLineSpotSelector(allPorts, defaultPort, isFindBaseStation, isScanAllBaseStations, isInteractive, isVerbose, isVeryVerbose); // Retrieves the port (or the error message) to use and prints it to the // stream // read by the calling ant script. spotPortOut.print(spotselector.getPortOfSpotToUse()); // System.exit(ret); //Don't do that in ant if not executed with // fork=true } abstract protected String getPortOfSpotToUse(); private static void printUsage() { infoOut.println("SpotSelector [options] port_list\nOptions:\n\t-h prints this information\n\t"); // TODO: usage information }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -