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

📄 sunspot.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.participants;import com.sun.spot.communication.connections.ConnectionManager;import com.sun.spot.communication.connections.ConnectionWorker;import com.sun.spot.communication.connections.RadioConnectionManager;import com.sun.spot.communication.messages.IMessageObserver;import com.sun.spot.communication.messages.SpotMessage;import com.sun.spot.spotworld.SpotWorld;import com.sun.spot.spotworld.common.LocaleUtil;import com.sun.spot.spotworld.common.UICommand;import com.sun.spot.spotworld.gui.AppManagerPanel;import com.sun.spot.spotworld.gui.IUIObject;import com.sun.spot.spotworld.gui.RemotePrintWindow; import com.sun.spot.spotworld.virtualobjects.*;import java.awt.Component;import java.io.BufferedReader;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.util.HashMap;import java.util.LinkedHashMap;import java.util.Vector;import javax.swing.JFrame; /** * Proxy to a generic SunSPOT. Currently only used as a superclass for eSPOT. * * @author arshan, randy, robert */public class SunSPOT extends SquawkHost implements IMessageObserver {        ConnectionWorker radioConn = null;    private long lastHeardFromSpot = -1;    private int lastRSSI = -1;    private String nameCache;   //A SPOT holds it's name on board, in flash.    private String autoRunApps; //Holds the space-separated names of classes to run at startup.        // When a UICommand issues a synchronous send a new thread is spawned to    // prevent the UI from hanging whilst waiting for the response.    private Thread menuUtilityThread = null;           /**********************  MESSAGES *FROM* THE ACTUAL SPOT **********************/    public Vector receive(SpotMessage spotMessage) {         msg("Received message: " + spotMessage.getSubject());        if (spotMessage.getSubject().equals("APP_ARRIVED")) {            if (spotMessage.getAddress().equals(getAddress()))                appArrived( (String)(spotMessage.toVector()).elementAt(1), (String)(spotMessage.toVector()).elementAt(2) );            Vector v = new Vector();            v.add("OK");            return v;        }        if (spotMessage.getSubject().equals("APP_STATUS")) {            String[] args = (String[])spotMessage.toVector().toArray(new String[0]);            appStatus(args[1],args[2]);            return new Vector();        }        if (spotMessage.getSubject().equals("NAME")) {             Vector<String> args = (Vector<String>) spotMessage.toVector();            for (int i = 1; i < args.size(); i+= 2) {                if (((String) args.elementAt(i)).equals("NAME")) {                    nameCache = (String) args.elementAt(i + 1);                     notifyUIObjects();                }            }                        return new Vector();        }                return null;    }        public void appArrived(String isoID, String status){        msg("[appArrived] " + isoID);        Application app = null;        SpotWorld sw = (SpotWorld)getVirtualRoot();        /* Is this ID already out there? */        for(IVirtualObject ivo : sw.getVirtualObjectsCopy()){            if(ivo instanceof Application){                if(((Application)ivo).getIsolateID().equals(isoID)){                    app = (Application)ivo;                    msg("[appArrived] App already in the world");                    app.setHost(this);                }            }        }         if(app == null) {            /* make a new app since we did not find it out there */            msg("[appArrived] Creating a new instance of Application, adding it to SPOTWorld");            app = new Application();            app.setHost(this);            app.setIsolateID(isoID);            sw.addVirtualObject(app);        }         appStatus(isoID, status);    }        public void appStatus(String isoID, String status){        for(Application app : getApplications()){            if(app.getIsolateID().equals(isoID)){                if(status.equals("MIGRATING")){                    app.setState(Application.AppState.MIGRATING);                } else if(status.equals("PAUSED")){                    app.setState(Application.AppState.PAUSED);                } else if(status.equals("ALIVE")){                    app.setState(Application.AppState.RUNNING);                } else if(status.equals("NEW")){                    app.setState(Application.AppState.NEW);                } else if(status.equals("BEING_DEBUGGED")){                    app.setState(Application.AppState.BEING_DEBUGGED);                } else if(status.equals("EXITED")){                    app.delete();                }            }        }    }    /********************** END MESSAGES *FROM* THE ACTUAL SPOT **********************/         /*     * This central method specifies the UI to this device.     * TO DO: Refactor so that some of these are implemented in the superclass     * Each element represents e.g: a menu item. However, it could be a typed-in     * command on a command line interface.     */    public Vector<UICommand> getSpotMethods() {        Vector<UICommand> methods = new Vector<UICommand>();                methods.addElement(new UICommand() {            public String getName() {                return "Set Name";            }             public String getToolTip() {                return "Set the name of this SPOT";            }             public void run(IUIObject obj) {                try {                    setName(obj.getNewNameFromUser());                    notifyUIObjects();                } catch (IOException ex) {                    System.out.println(ex.getMessage());                    ex.printStackTrace();                }            }        });                methods.addElement(new UICommand() {            public String getName() {                return "System isolate (Kami) printout";            }             public String getToolTip() {                return "Show System.out for the \"Kami\" isolate on this SPOT";            }            public void run(IUIObject obj) {                startRemotePrinting(obj);            }        });                methods.addElement(new UICommand() {            public String getName() {                return "Startup Apps ...";            }            public String getToolTip() {                return "Set which classes run at startup on the SPOT.";            }             public void run(IUIObject obj) {                Vector[] v = sendSPOTMessage("GET_AUTORUN_APPS");                autoRunApps = "";                if (v != null && (v.length != 0)) {                    if(v[0].size() != 0)                        autoRunApps = (String) v[0].elementAt(1);                  }                AppManagerPanel p = showAppManager(obj, autoRunApps);                Vector<String> arc = p.getAutoRunClasses();                 String out = "";                for(String c : arc){                    out = out + " " + c;                }                if( out.length() > 0) out = out.substring(1); // remove inital " "                 sendSPOTMessage("SET_AUTORUN_APPS", out);            }        });        methods.addElement(new UICommand() {            public String getName() {                return "Blink LEDs";            }            public String getToolTip() {                return "Purpose is for this SPOT to make itself known";            }            public void run(IUIObject obj) {                asyncSendSPOTMessage("WHO_AM_I");            }        });                methods.addElement(new UICommand() {            public String getName() {                return "Reset";            }            public String getToolTip() {                return "Reset this SPOT";            }            public void run(IUIObject obj) {                obj.tellUser("If plugged into USB, you must press\nthe control button to restart.");                asyncSendSPOTMessage("RESET");            }        });                methods.addElement(new UICommand() {            public String getName() {                return "Deploy application suite ...";            }            public String getToolTip() {                return "Deploy a new application over the air to this SPOT.";            }            public void run(final IUIObject obj) {                // Call spotclient directly to see if forks a new JVM                // Ideally we would call ant for everything here, but at the                // moment we can't share the basestation so we have to call                // spot client directly.--Robert                obj.doDeployment();             }        });                methods.addElement(new UICommand() {            public String getName() {                return "Get Info";            }            public String getToolTip() {                return "Get information about this SPOT";            }            public void run(IUIObject obj) {                Vector[] msgs = sendSPOTMessage("GET_INFO");                Vector args = (Vector) msgs[0];                System.out.println(args);                                // Remove the status message                if (((String) args.elementAt(0)).contains("GET_INFO")) args.removeElementAt(0);                                // Parse reply here                System.out.println(args);                HashMap<String, String> dict = new LinkedHashMap<String, String>();                int index = 0;                                dict.put("IEEE Address", (String) args.elementAt(index));                                dict.put("Application Slot Contents", "");                byte size = new Byte(args.elementAt(++index).toString());                for (byte i = 0; i < size; i++) {                    dict.put((new Integer(i)).toString() + ":", (String) args.elementAt(++index));                    dict.put("" + i + ": " + args.elementAt(++index).toString() + " bytes at", "0x" + Integer.toHexString((Integer) args.elementAt(++index)));                }                                dict.put("Startup", "");                dict.put("Squawk Startup Command Line", (String) args.elementAt(++index));                                if ((Boolean) args.elementAt(++index)) dict.put("Basestation", "Yes");                else dict.put("Basestation", "No");                                if ((Boolean) args.elementAt(++index)) dict.put("OTA Command Server", "Enabled");                else dict.put("OTA Command Server", "Disabled");                                               dict.put("Library Suite", "");                dict.put("Spot Library Hash", "0x" + Integer.toHexString((Integer) args.elementAt(++index)));                dict.put("Security", "");                // Form a string of hexadecimal bytes that represents the public                // key on the SPOT.                StringBuffer buffer = new StringBuffer();                // read in the length of the string                int keyLength = (Integer) args.elementAt(++index);                for (int i = 0; i < keyLength; i++) {                    // read an element in.                    String s = Integer.toHexString((Byte) args.elementAt(++index));                    // if there is only one byte add a leading 0.                    if (s.length() == 1) {                        buffer.append("0");                        buffer.append(s);                    // if there are two bytes then add it to our buffer                    } else if (s.length() == 2) {                        buffer.append(s);                    // the string is longer than two bytes so extract the last                    // two bytes.                        } else {

⌨️ 快捷键说明

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