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

📄 usbspotchecker.java

📁 无线传感器网络节点Sun SPOT管理工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//            if(! oldMap.containsKey(k)) return true;//            if(! oldMap.get(k).equals(addrToUSBPortMap.get(k))) return true;//        }//        if(firstTime){//            firstTime = false;//            return true;//        }//        return false;//    }////    /*//     * Register in SPOTWorld properties.//     * The probe is slow, possibly because it relies on a timeout on the SPOT device(??)//     *///    public void recordNewSPOT(String addr, String port){//        // This is at times very slow//        boolean isBasestation = probeUSBForBasestation(port, addr);//        System.out.println("]]]]]]]]]]]]]]]]]]]]] END PROBE ]]]]]]]]]]]]]]]]]]]]]]]");//        String propString = "";//        if(isBasestation){//            addrToUSBPortMapBS.put(addr, port);//            System.out.println("addrToUSBPortMapBS = " + addrToUSBPortMapBS);//            propString = "known.basestation.";//        } else {//            addrToUSBPortMap.put(addr, port);//            propString = "known.nonbasestation.";//        }//        //Find the next unused name in spotworldProperties//        boolean found = false;//        int i = 0;//        System.out.println("RRRRRRRRRRRRRRRRRRRRRRRRRRR entering loop");//        while(found == false){//            if(! SpotWorld.getSPOTWorldProperties().containsKey(propString + i)){//                found = true;//                SpotWorld.getSPOTWorldProperties().put(propString + i, addr);//                System.out.println("Found new Sun SPOT, address = "          +//                        addr + ", saving to spotworld properties file as a " +//                        (isBasestation ? "basestation device." : "regular, non-basestation device. Suffix is " + i));//            }//            i++;//        }//        System.out.println("RRRRRRRRRRRRRRRRRRRRRRRRRRR exiting loop");////        System.out.println("spotworlproperties = " + SpotWorld.spotworldProperties);//    }////    public boolean probeUSBForBasestation(String port, String addr){//        boolean result = false;////        String s = "";//        // Test port for being a potential basestation.////        ByteArrayOutputStream baos = new ByteArrayOutputStream();//        /** NEW CODE **/////        BasestationChecker bc = new BasestationChecker(port);////        if (bc.checkIsBaseStation()){////            System.out.println("Baseetation check passed, " + addr + " on prt " + port + " IS a basestion");////            return true;////        } else {////            if(bc.isPortInUse()) System.out.println("PORT IS IN USE");////            System.out.println("Baseetation check failed, " + addr + " on prt " + port + " is NOT a basestion");////            return false;////        }//        /* END NEW CODE *///////        SpotSelector.spotPortOut = new PrintStream(baos);////        String[] args = new String[3];////        args[0] = "-t:basestation"; // Note this is likely a bug in SpotSelector as -t:basestation would seem logical but fails to find basestations.////        args[1] =  "-p" + port;////        args[2] =   "\"" + port + " (" + asUndottedAddress(addr) + ")\"";////        System.out.println("]]]]]]]]]]]]]]]]]]] PROBE ]]]]]]]]]]]]]]]]]]]]]]] arg0 = " + args[0]);////        System.out.println("]]]]]]]]]]]]]]]]]]] PROBE ]]]]]]]]]]]]]]]]]]]]]]] arg1 = " + args[1]);////        System.out.println("]]]]]]]]]]]]]]]]]]] PROBE ]]]]]]]]]]]]]]]]]]]]]]] arg2 = " + args[2]);//        long t = System.currentTimeMillis();////        SpotSelector.main(args);//        CheckBasestation cb = new CheckBasestation();////        result = cb.checkIsBaseStation(port);//        if (result) System.out.println(">>>>>>>>>>>>>>>>> " + port + " IS A BASESTATION");//        else System.out.println(">>>>>>>>>>>>>>>>>> " + port + " IS A BASESTATION");//////        s = baos.toString();////        System.out.println("]]]]]]]]]]]]]]]]]]] PROBE ]]]]]]]]]]]]]]]]]]]]]]] OUTPUT:  ");////        System.out.println(s);//        //Quick return, do not want to test more than we must.//        // as the probe can be disruptive and takes a good fraction of a second.////        if(s.startsWith("error") || s.startsWith("ERROR")) {////            result = false;////        } else {////            if(s.trim().equals(port.trim())){////                result = true;////            } else {////                throw new RuntimeException("While probing USB for a basestion, asked about " + port + ", but got answer about " + s);////            }////        }//        return result;//    }////////    public static String[] findBasestations(String[] ports){////        if(ports.length == 0) return new String[0];////        String[] result = null;////        String s = "";////        // Test each port for being a potential basestation.////        for( String port : ports){////            ByteArrayOutputStream baos = new ByteArrayOutputStream();////            SpotSelector.spotPortOut = new PrintStream(baos);////            String[] args = new String[2];////            args[0] = "-t:basestation";////            args[1] = port;////            long t = System.currentTimeMillis();////            SpotSelector.main(args);////            System.out.println("************************************** " + (System.currentTimeMillis() - t) / 1000.0 + "************ " + ports.length );////            s = baos.toString();////            //Quick return, do not want to test more than we must.////            // as the probe can be disruptive and takes a good fraction of a second.////            if(s.startsWith(LocaleUtil.getString("error"))) {////                result = new String[0];////            } else {////                result = new String[1];////                result[0] = s;////            }////        }////        return result;////    }//////    public void recordBasestationAddresses(Vector<String> addresses){//        try {//            for(String addr: addresses){//                BufferedWriter out = new BufferedWriter(new FileWriter("~/.sunspot.known.basestations"));//                out.write(addr);//                out.close();//            }//        } catch (IOException e) {//        }////    }////    /*//     * This runs the spotfinder command to crete a hashtable of (address,port) pairs.//     */    public Hashtable<String, String>  probeForAddrsAndPorts(){        String sunspotHome = System.getProperties().getProperty("sunspot.home");        Process p = null;        String command = sunspotHome + "/bin/spotfinder";        try {            p = Runtime.getRuntime().exec(command);        } catch (IOException ex) {            System.err.println(LocaleUtil.getString("error trying to run command") + command);            ex.printStackTrace();        }                // read the standard error of the command, where the spotfinder utility puts its answer.                BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));        int count = 0;        String s = "";        String reply = "";                while (!procDone(p)) {            try {                while((s=stdError.readLine()) !=null){                    count++;                    reply = reply+s+"\n";                }            } catch (IOException ex) {                ex.printStackTrace();            }        }        try {            stdError.close();        } catch (IOException ex) {            ex.printStackTrace();        }        String[] entries = reply.split(",");        if(entries[0].trim().equals("")) entries = new String[0];        Hashtable result = new Hashtable<String, String>();        for(String entry : entries){            String[] tokens = parseEntry(entry);            result.put(tokens[0], tokens[1]);        }        return result;    }    /*     * Uitlity to return a String array containing element 0 as the port and element 1 as the dotted IEEE address.     * This is based on the assumption that the "in" entry has both elements embedded in order like this     *  "<leadning whitespace>PPPPPPPPPPP<whitespace>(AAAAAAAAAAAAAAAA)<trailing whitespace>"     *  The result will be     *   result[0] = AAAA.AAAA.AAAA.AAAA     *   result[1] = PPPPPPPPPPP     */    public String[] parseEntry(String in){        String[] result = new String[2];        String s = in.trim();        String port = "";        String addr = "";        String[] tokens = s.split(" ");        if(tokens.length != 2) throw new RuntimeException(" Parse error on spotfinder output:  " + tokens);        port = (tokens[0]).trim();        String t1 = tokens[1].trim();        if((t1.charAt(0) != '(') || (t1.charAt(t1.length() - 1)) != ')') throw new RuntimeException(" Parse error on spotfinder output, no parenthese around IEEE address:  " + t1);        addr = t1.substring(1, t1.length() - 1);        result[0] = asDottedAddress(addr);        result[1] = port;        return result;    }    /*     * Utility: Takes a string with no dots and inserts 3 dots, spaced every 4 characters.     * This is simply to create an IEEE address in cannonical form.     */    public String asDottedAddress(String in){        StringBuffer out = new StringBuffer();        for (int i = 0; i < in.length(); i++) {            // This is not sufficient to catch all problems in the input, but perhaps better than nothing at all...            if(! Character.isLetterOrDigit(in.charAt(i))) throw new RuntimeException(" Parse error on spotfinder output:  non hex digit entry in IEEE address " + in);            out.append(in.charAt(i));            if(i == 3 || i == 7 || i == 11) out.append(".");        }        return out.toString();    }////    /*//     * Utility: Takes a string with dots as is typical and remove them.//     * This is simply to create an IEEE address in the form used by SpotSelector.//     *///    public String asUndottedAddress(String in){//        StringBuffer out = new StringBuffer();//        for (int i = 0; i < in.length(); i++) {//            // This is not sufficient to catch all problems in the input, but perhaps better than nothing at all...//            if(in.charAt(i) != '.') out.append(in.charAt(i));//        }//        return out.toString();//    }//    /*     * utilitiy to facilitate findBasestation method.     */    private boolean procDone(Process p) {        try {            int v = p.exitValue();            return true;        } catch(IllegalThreadStateException e) {            return false;        }    }////    public int getCheckInterval() {//        return checkInterval;//    }////    public void setCheckInterval(int checkInterval) {//        this.checkInterval = checkInterval;//    }////    public boolean isRunning() {//        return running;//    }////    public void setRunning(boolean running) {//        this.running = running;//    }}

⌨️ 快捷键说明

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