📄 .#testmeasure.java.1.4
字号:
/* ex: set tabstop=4 shiftwidth=4 expandtab:*/ /* $Id: TestMeasure.java,v 1.4 2006/03/13 05:04:41 maoy Exp $ */package net.tinyos.cr;import java.io.*;import java.util.*;import net.tinyos.message.*;import net.tinyos.packet.*;import net.tinyos.util.*;import net.tinyos.testbed.*;public class TestMeasure { public static final byte COMPONENTS = 2; //private static final int[] REPS = {450, 900 , 1800,3600,7200,14200}; //private static final int[] REPS = {10 , 20,40,80,160,320 }; //private static final int[] REPS = {4500,500,1000,2000,4000}; //private static final int[] INTERVALS = {1000,500,250,125,62}; //Mica2 1:30h //private static final int[] REPS = {2400,1000,2000,5000}; //private static final int[] INTERVALS = {1000,500,250,100}; //private static final int INITIAL_INTERVAL = 600000; private static final int[] REPS = {25000,1000,2000,5000}; private static final int[] INTERVALS = {1000,500,250,100}; //private static final int INITIAL_INTERVAL = 3600000; private static final int INITIAL_INTERVAL = 300000; private static final int MAX_EXECUTION_TIME = 2; private static String host; private static int baseport; private Vector motes; private int step = 0; private int reps = 0; private int delay = 0; Timer timer; class RemindTask extends TimerTask { public void run() { System.err.println("Time's up!"); timer.cancel(); //Terminate the timer thread System.exit(1); } } public TestMeasure(int seconds) { timer = new Timer(); timer.schedule(new RemindTask(), seconds*1000); } public TestMeasure(TestBedConfig tbConfig, String host, int basePort) { /* motes = new Vector(); Iterator motesIt = tbConfig.getMotesIterator(); TestBedConfig.TestBedConfigMote configMote; while (motesIt.hasNext()) { configMote = (TestBedConfig.TestBedConfigMote) motesIt.next(); motes.addElement(new MeasureMote(configMote.getId(), host, basePort)); } Iterator tbMotesIt; step = 0; reps = REPS[step]; delay = INTERVALS[step]; //Initial delay System.out.println("Starting test. "); MeasureMote source = null; MeasureMote dest = null; source = (MeasureMote)motes.elementAt(0); boolean led_on = true; for (int i=8;i<10;i++){ //source.sendLedCommand(led_on); source.sendCountCommand(i);// check try { Thread.sleep(1000); } catch (Exception e) {e.printStackTrace(System.err); System.exit(0);} led_on = !led_on; } source.sendMeasureCommand(100, 200, (short)10); System.exit(0);*/ } private static void printUsage() { System.err.println("usage: TestMeasure gw_node cmd_node command [arguments]"); } private static void runCommand(String[] args) { int gwid = Integer.parseInt(args[0]); int id = Integer.parseInt(args[1]); String cmd = args[2]; MeasureMote mote = new MeasureMote(gwid, host, baseport, id); TestMeasure t = new TestMeasure(MAX_EXECUTION_TIME); if (cmd.equals("count")) { int src = Integer.parseInt(args[3]); mote.exitAfterReceive = true; mote.sendCountCommand(src); } //added by Feng Wang else if (cmd.equals("rssi")) { int src = Integer.parseInt(args[3]); mote.exitAfterReceive = true; mote.sendRSSICommand(src); } else if (cmd.equals("measure")){ int n_packets = Integer.parseInt(args[3]); int interval = Integer.parseInt(args[4]); short power = (short) Integer.parseInt(args[5]); short seq = (short) Integer.parseInt(args[6]); mote.exitAfterReceive = true; mote.sendMeasureCommand(n_packets, interval, power, seq); } else if (cmd.equals("clear")){ //System.out.println("TestMeasure: clearing..."); mote.exitAfterReceive = true; mote.sendClearCommand(); } else if (cmd.equals("led")) { mote.exitAfterReceive = true; mote.sendLedCommand(false); } else if (cmd.equals("version")) { mote.exitAfterReceive = true; mote.sendVersionCommand(); } else{ System.err.println("unknown command"); } //System.out.println("command finished"); } public static void main(String[] args) throws IOException { //CRTestBedConfig tbConfig; if (args.length >2) { host = "localhost"; baseport = 9200; runCommand(args); } else { printUsage(); System.exit(-1); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -