⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spotinfotable.java

📁 无线传感器网络节点Sun SPOT管理工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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.IOException;import java.util.Iterator;import java.util.Vector;/** * The SpotInfoTable class represents all spot devices connected to the computer *  * @author Christian P黨ringer *  */public class SpotInfoTable {    /**         * defines the default timeout for basestation detection         */    public static final int CHECKBASESTATION_TIMEOUT = 2000;    private Vector spotInfoTableVector;    private boolean isVerbose;    private boolean isVeryVerbose;    private String removedDevicesString;    public boolean containedDevicesInUse;    public SpotInfoTable(String spotPorts) {	this(spotPorts, false, false);    }    public SpotInfoTable(String spotPorts, boolean isVerbose,	    boolean isVeryVerbose) {	this.isVerbose = isVerbose;	this.isVeryVerbose = isVeryVerbose;	spotInfoTableVector = new Vector();	String[] spotPortsArray = spotPorts.split(",");	for (int i = 0; i < spotPortsArray.length; i++) {	    try {		SpotInfo si = new SpotInfo(spotPortsArray[i]);		spotInfoTableVector.add(si);	    } catch (IOException e) {		// TODO Auto-generated catch block		if (this.isVerbose)		    e.printStackTrace(SpotSelector.infoOut);	    }	}	containedDevicesInUse = false;    }    public int size() {	return spotInfoTableVector.size();    }    public Iterator iterator() {	return spotInfoTableVector.iterator();    }    public SpotInfo get(int index) {	return (SpotInfo) (spotInfoTableVector.get(index));    }    private boolean checkIsBaseStation(SpotInfo spotInfo) {	try {	    if (spotInfo == null)		return false;	    if (spotInfo.type == SpotInfo.TYPE_BASESTATION)		return true;	    if (spotInfo.type == SpotInfo.TYPE_NONBASESTATION)		return false;	    Integer checkBasestationTimeout =		    Integer.getInteger("spotselector.checkbasestation.timeout");	    if (checkBasestationTimeout == null) {		checkBasestationTimeout = new Integer(CHECKBASESTATION_TIMEOUT);		if (isVerbose)		    SpotSelector.infoOut			    .println("Using default timeout for checkbasestation: "				    + CHECKBASESTATION_TIMEOUT + " ms");	    } else if (isVerbose)		SpotSelector.infoOut			.println("Using timeout for checkbasestation  from spotselector.checkbasestation.timeout property: "				+ checkBasestationTimeout + " ms");	    // String libraryPath = System.getProperty("java.library.path");	    /*                 * if (System.getProperty("java.library.path") == null) { throw                 * new IOException("Property java.library.path not set.1"); }                 */	    String libraryPath = System.getProperty("sunspot.lib");	    if (libraryPath == null) {		throw new IOException("Property sunspot.lib not set");	    }	    if (isVeryVerbose)		SpotSelector.infoOut.println("java.library.path:\""			+ libraryPath + "\"");	    String debugClientClassPath =		    System.getProperty("debugclient.classpath");	    if (debugClientClassPath == null) {		throw new IOException("Property debugclient.classpath not set");	    }	    if (isVeryVerbose)		SpotSelector.infoOut.println("java.library.path:\""			+ libraryPath + "\"");	    // Unfortunately it's necessary to define the class and the	    // library path as environment variables,	    // as using it directly in the command string as argument for	    // Runtime.execute causes problems	    // when spaces are in the class or library path. Quoting with	    // double quotes works on windows but not on the Mac.	    String[] executeEnvironment =		    new String[] {			    // "CLASSPATH="+libraryPath +                                // "/spotselector.jar"+			    // System.getProperty("path.separator") +			    // System.getProperty("java.class.path"),			    "CLASSPATH=" + libraryPath + "/spotselector.jar"				    + System.getProperty("path.separator")				    + debugClientClassPath,			    "PATH=" + libraryPath, // For			    // Windows			    "LD_LIBRARY_PATH=" + libraryPath, // For linux			    "DYLD_LIBRARY_PATH=" + libraryPath // For mac?		    };	    String verboseString = "";	    if (isVeryVerbose)		verboseString = " -Dverbose=true ";	    String executeCommand =		    "java "			    + verboseString			    + " com.sun.spot.checkbasestation.CheckBasestation  "			    + spotInfo.serialPort;	    if (isVeryVerbose) {		SpotSelector.infoOut.println("Executing: " + executeCommand); // TODO		SpotSelector.infoOut.println("\tEnvironment: "			+ executeEnvironment[0] + "\n\t"			+ executeEnvironment[1] + "\n\t"			+ executeEnvironment[2] + "\n\t"			+ executeEnvironment[3]); // TODO	    }	    // pathseparator	    Process checkBasestationProcess =		    Runtime.getRuntime().exec(executeCommand,			    executeEnvironment);	    ExecWatchdogTimer execWatchdogTimer =		    new ExecWatchdogTimer(checkBasestationTimeout.intValue(),			    checkBasestationProcess, isVeryVerbose);	    ExecOutputHandler execOutputHandler =		    new ExecOutputHandler(checkBasestationProcess			    .getInputStream(), execWatchdogTimer, isVeryVerbose);	    ExecOutputHandler execErrorHandler =		    new ExecOutputHandler(checkBasestationProcess			    .getErrorStream(), execWatchdogTimer, isVeryVerbose);	    execOutputHandler.start();	    execErrorHandler.start();	    if (isVeryVerbose)		SpotSelector.infoOut.println("Starting watchdog timer");	    execWatchdogTimer.start();	    if (isVeryVerbose)		SpotSelector.infoOut			.println("Waiting for process to return...");	    boolean applicationExited = false;	    do {		try {		    checkBasestationProcess.waitFor();		    applicationExited = true;		} catch (InterruptedException e) {		    // TODO Auto-generated catch block		    if (isVeryVerbose)			e.printStackTrace(SpotSelector.infoOut);		}	    } while (applicationExited != true);	    if (isVeryVerbose)		SpotSelector.infoOut.println("Check basestation returned");	    if (checkBasestationProcess.exitValue() == 0) {		spotInfo.setType(SpotInfo.TYPE_BASESTATION);		if (isVeryVerbose)		    SpotSelector.infoOut.println("port " + spotInfo.serialPort			    + " is a basestation");		return true;	    } else if (checkBasestationProcess.exitValue() == 2) {		spotInfo.setType(SpotInfo.TYPE_UNKNOWN_AND_PORT_IN_USE);		containedDevicesInUse = true;		if (isVeryVerbose)		    SpotSelector.infoOut.println("port " + spotInfo.serialPort			    + " is in use by another application");		return false;	    } else {		spotInfo.setType(SpotInfo.TYPE_NONBASESTATION);		if (isVeryVerbose)		    SpotSelector.infoOut.println("port " + spotInfo.serialPort			    + " is not a basestation");		return false;	    }	} catch (IOException e) {	    // TODO Auto-generated catch block

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -