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

📄 sunspot.java

📁 无线传感器网络节点Sun SPOT管理工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        buffer.append(s.charAt(s.length() - 2));                        buffer.append(s.charAt(s.length() - 1));                    }                }                // Read in the public key stored on disk.                try {                    BufferedReader in = new BufferedReader(new FileReader(System.getProperty("keyStoreDir") + "/sdk.key"));                    String line = in.readLine();                    while (line != null) {                        // find the public key entry in the file.                        if (line.startsWith("SDKPublicKey")) {                            String[] split = line.split("=");                            // if the public key matched what we have                            if (split[1].equals(buffer.toString()))                                dict.put("Public key on device matches key on host", "true");                            else                                dict.put("Public key on device matches key on host", "false");                        }                        line = in.readLine();                    }                    in.close();                } catch (FileNotFoundException ex) {                    dict.put("Public key on device matches key on host", "Error reading the public key");                } catch (IOException ex) {                    dict.put("Public key on device matches key on host", "Error reading the public key");                }                dict.put("Configuration Properties", "");                for (int i = ++index; i < args.size(); i+= 2)                    dict.put(args.elementAt(i).toString(), args.elementAt(i + 1).toString());                                obj.displaySPOTInfo(dict);            }        });        return methods;    }        /* Update the UI w.r.t. name, available appliations, and currently active apps. */     public void refresh() {        // flush what apps we have available and get a possibly new set from the SPOT        flushAvailableAppsCache();        refillAvailableAppsCache();        getName();                // ask the SPOT if we have any apps currently running.        Vector <Application> oldApps = getApplications();        for(Application oldApp : oldApps){            (oldApp.getVirtualParent()).removeVirtualObject(oldApp);        }        Runnable rn = new Runnable() {            public void run() {                Vector[] msgs = sendSPOTMessage("REFRESH");                if(msgs == null) System.err.println(" Error in sending REFRESH Message inside Sunspot > refresh()");                for (int i = 0; i < msgs.length; i++) System.out.println(msgs[i]);                if (msgs.length > 0) {                    Vector<String> appInfo = (Vector<String>) msgs[0];                    for (int i = 1; i < appInfo.size(); i+= 2) {                        appArrived(appInfo.elementAt(i), appInfo.elementAt(i + 1));                    }                }             }        };                // Don't hang the UI and don't allow people to keep hammering        // Refresh while it's in the process of refreshing.        if (menuUtilityThread == null || !menuUtilityThread.isAlive()) {            menuUtilityThread = new Thread(rn);            menuUtilityThread.start();        }    }         /*     * The autoRunString is a space-delimited collection of class names     */    public AppManagerPanel showAppManager(IUIObject obj, String autoRunString){        Component c = (Component) obj.getView();        System.out.println("COMPONENT C IS " + c);        while(c.getParent() != null) c = c.getParent();        JFrame frame = (JFrame) c;        String[] arcs = autoRunString.split(" ");        /* the AppManagerPanel call requires a Vector of String */        Vector<String> initialAutoRunClasses = new Vector<String>();        for (int i = 0; i < arcs.length; i++) {                initialAutoRunClasses.add(arcs[i]);        }        AppManagerPanel p = AppManagerPanel.openNew(frame , getAvailableApps(), initialAutoRunClasses);        return p;    }         /**      * Gets the name from the SPOT and caches it.       * Overrides the super method, which constructs a name based on the class.     */    public String getName() {        if (nameCache == null) {            Vector[] v;            try {                v = sendSPOTMessage("GET_NAME");                if ((v != null) && (v.length > 0)) {                    nameCache = (String) v[0].elementAt(1);                } else {                    nameCache = "<can\'t get name>";                }            } catch(Exception e) {                nameCache = "<can\'t get name>";            }         }        return nameCache;    }        /**      * Set the new name of this SPOT which is stored as a persistent property on the device     * The name "<default>" is special, it removes the SPOTs name property so it takes on initial state.      * On the SPOTWorld side the initial state is nameCache == null.     */    public void setName(String s) throws IOException {         Vector args = new Vector<String>();        args.addElement(s);        Vector[] v = sendSPOTMessage("SET_NAME", args);        if (v != null) {            if(s.equals("<default>")) {                nameCache = null;                getName(); //will cause the new default nmae made by this SPOT to be fetched.            } else {                nameCache = s;            }            return;        }        throw new IOException("Name could not be set.");    }        public void startRemotePrinting(IUIObject obj){        RemotePrintWindow w = new RemotePrintWindow();         Vector[] reply = sendSPOTMessage("SHOW_SYSTEM_PRINTOUT");        if(reply.length < 1) {            obj.tellUser("Unable to start remote printing\n(Sun SPOT did not reply with a port #)");            return;        }        String answer = (String) reply[0].elementAt(1);        int portNum = Integer.decode(answer); //Automatic unboxing.         w.open(obj, "currentIsolate", "System ", portNum, this);    }        public void stopRemotePrintingApp(String isolateID, int port){        sendSPOTMessage("STOP_REMOTE_PRINT_APP", isolateID, "" + port );    }        public double secondsSinceLastSignOfLife(){        return (System.currentTimeMillis() - lastHeardFromSpot) / 1000.0 ;    }         public void refillAvailableAppsCache(){        Vector[] v = sendSPOTMessage("GET_AVAILABLE_APPS");        if(v.length == 0) return;        if(v.length > 1) {            msg("This is odd: Multiple replies to request for available apps.");        }         //Remove the SWS status message -- Robert        Vector<String> result = (Vector<String>) v[0];        for (int i = 0; i < result.size(); i++) {            if (result.elementAt(i).contains("GET_AVAILABLE_APPS"))                result.removeElementAt(i);            break;        }                setAvailableAppsCache(result);    }        public void startApp(String className) {        Vector args = new Vector();        args.add(className);        asyncSendSPOTMessage("START_APP", args );    }        public void justHeardFromSPOT(int rssi){        setLastHeardFromSpot(System.currentTimeMillis());        setLastRSSI(rssi);    }        public long getLastHeardFromSpot() {        return lastHeardFromSpot;    }        public void setLastHeardFromSpot(long lastHeardFromSpot) {        this.lastHeardFromSpot = lastHeardFromSpot;    }        public int getLastRSSI() {        return lastRSSI;    }        public void setLastRSSI(int lastRSSI) {        this.lastRSSI = lastRSSI;    }        public Vector<Application> getApplications(){        Vector<Application> v = new Vector<Application>();        for(IVirtualObject ivo : getVirtualParent().getVirtualObjectsCopy()){            if(ivo instanceof Application ){                Application app = (Application) ivo;                if(app.getHost() == this){                    v.add(app);                }            }        }        return v;    }        public void exitAllApplications(){        Vector<Application> apps = getApplications();        for(Application app : apps){            app.exit();        }    }        public void connect() {                  ConnectionManager radioManager = RadioConnectionManager.getInstance();        radioManager.setPort(60);        try {            msg(LocaleUtil.getString("Trying to connect to") + " : " + getAddress());            radioConn = radioManager.openConnectionTo(getAddress());        } catch (IOException ex) {            ex.printStackTrace();        }                radioManager.registerMessageListener(this);    }             public void startSpotCastTx(){        asyncSendSPOTMessage("START_SPOTCAST_TX");    }        public void stopSpotCastTx(){        asyncSendSPOTMessage("STOP_SPOTCAST_TX");    }        /************ MESSAGE SENDING *********/    public Vector[] sendSPOTMessage(String msg) {        return sendSPOTMessage(msg, new Vector());    }        public Vector[] sendSPOTMessage(String msg, String arg) {        Vector v = new Vector();        v.add(arg);        return sendSPOTMessage(msg,v);    }        public Vector[] sendSPOTMessage(String msg, String arg0, String arg1) {        Vector v = new Vector();        v.add(arg0);        v.add(arg1);        return sendSPOTMessage(msg,v);    }        public Vector[] sendSPOTMessage(String subj, Vector args) {        SpotMessage sm = new SpotMessage(subj);        for(Object obj : args) sm.addElement(obj);        try {            Vector[] r = null;            //    synchronized (radioConn) {            r = radioConn.send(sm);            return r;            //   }        } catch (IOException ex) {            ex.printStackTrace();        }        return null;    }        /*********** EXPERIMENTAL -- ASYNCHRONOUS MESSAGE SENDS -- HAVE NO REPLY, EXCEPT AT LOWER LEVEL **************/        public void asyncSendSPOTMessage(String msg) {        asyncSendSPOTMessage(msg, new Vector());    }        /* convenience method */    public void asyncSendSPOTMessage(String msg, String arg) {        Vector args = new Vector();        args.addElement(arg);        asyncSendSPOTMessage(msg, args);    }        /* convenience method */    public void asyncSendSPOTMessage(String msg, String arg0, String arg1) {        Vector args = new Vector();        args.addElement(arg0);        args.addElement(arg1);        asyncSendSPOTMessage(msg, args);    }        public void asyncSendSPOTMessage(final String subj, final Vector args) {        Thread t = new Thread() {            public void run(){                SpotMessage sm = new SpotMessage(subj);                for (int i = 0; i < args.size(); i++) {                    sm.addElement(args.elementAt(i));                }                try {                    Vector[] r = null;                    //  synchronized (spotConnection) {                    r = radioConn.send(sm);                    //   }                } catch (IOException ex) {                    ex.printStackTrace();                }            }        };        t.start();        return;    }}

⌨️ 快捷键说明

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