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

📄 s4commandinject.java

📁 state strech routing protocl
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* ex: set tabstop=4 shiftwidth=4 expandtab:*/ /* $Id: S4CommandInject.java,v 1.7 2006/03/09 23:14:41 maoy Exp $ *//** * @author Rodrigo Fonseca, based on BCastInject by Robert Szewczyk adopted by Yun Mao for S4 */package net.tinyos.cr;import net.tinyos.util.*;import java.io.*;import java.util.Properties;import net.tinyos.message.*;import net.tinyos.cr.messages.*;import net.tinyos.packet.*;import net.tinyos.util.*;public class S4CommandInject implements MessageListener, S4Constants {    static Properties p = new Properties();    public static final int TIMEOUT = 1000;    public static final String host = "localhost";    public static final int baseport = 9200;    public boolean response_received = false;             public static void usage() {    System.err.println("Usage: java net.tinyos.cr.S4CommandInject"+                   " <gateway> <address> <command> [arguments]");        System.err.println("\twhere <command> and [arguments] can " +                    "be one of the following:");        System.err.println("\t\thello");        System.err.println("\t\tled_on");        System.err.println("\t\tled_off");        System.err.println("\t\tset_root <id>");        System.err.println("\t\tget_root");        System.err.println("\t\tset_coords <coords: x1 x2 x3 x...>");        System.err.println("\t\tget_coords");        System.err.println("\t\tset_radio <power>");        System.err.println("\t\tget_radio");        System.err.println("\t\tget_info");        System.err.println("\t\tget_neighbor <n - neighbor index>");        System.err.println("\t\tget_link_info <n - link index> ");        System.err.println("\t\tget_root_info <n - root id>");        System.err.println("\t\tget_id");        System.err.println("\t\tfreeze");        System.err.println("\t\tresume");        System.err.println("\t\treset");        System.err.println("\t\tget_rt <n - routing table index>");                System.err.println("\t\troute_to <closes_beacon> <dest_id>");        System.err.println("\t\tadv_route_to <closes_beacon> <dest_id> <inital_delay> <n_packets> <interval>");        System.err.println("\tand <address> can be either");        System.err.println("\t\tBCAST or an integer (in hex or decimal)");    }    public static short restoreSequenceNo() {    try {        FileInputStream fis = new FileInputStream("cmd.properties");        p.load(fis);        short i = (short)Integer.parseInt(p.getProperty("sequenceNo", "1"));        fis.close();        return i;    } catch (IOException e) {        p.setProperty("sequenceNo", "1");        return 1;    }    }    public static void saveSequenceNo(int i) {    try {        FileOutputStream fos = new FileOutputStream("cmd.properties");        p.setProperty("sequenceNo", Integer.toString(i));        p.store(fos, "#Properties for S4CommandInject\n");    } catch (IOException e) {        System.err.println("Exception while saving sequence number" +                   e);        e.printStackTrace();    }    }    public static void main(String[] argv) throws IOException{        String cmd;        byte group_id = 0x7d; //maoy: it's fixed here        byte am = 0;        short mote_id = 0;        int gateway_addr = 0;        short sequenceNo = 0;                if (argv.length < 3) {          usage();          System.exit(-1);        }            //gateway_addr        try {            if (argv[0].startsWith("0x") || argv[0].startsWith("0X")) {                gateway_addr = (byte)Integer.parseInt(argv[0].substring(2), 16);            } else {                gateway_addr = (byte)Integer.parseInt(argv[0]);            }        } catch (NumberFormatException nfe) {            usage();            System.exit(-1);        }                       //address        if (argv[1].equals("BCAST")) {          mote_id = TOS_BCAST_ADDR;        }else {          try {            if (argv[1].startsWith("0x") || argv[1].startsWith("0X")) {              mote_id = (short)Integer.parseInt(argv[1].substring(2), 16);            } else {              mote_id = (short)Integer.parseInt(argv[1]);            }          } catch (NumberFormatException nfe) {            usage();            System.exit(-1);          }        }                //command and possible arguments        cmd = argv[2];            System.err.println("Args: group "+group_id+", dest "+mote_id+", " + cmd);                S4CommandMessage command = new S4CommandMessage();            sequenceNo = restoreSequenceNo();        command.set_header_last_hop(TOS_UART_ADDR);        command.set_header_seqno(sequenceNo);        command.set_type_data_hopcount((short)1);        //command.set_type_data_origin(TOS_UART_ADDR);        //command.set_type_data_origin(mote_id);        //int gateway_addr = 3;        command.set_type_data_gateway_addr(gateway_addr);        command.set_type_data_cmd_addr(mote_id);                command.set_type_data_data_seqno(sequenceNo);        command.set_type_data_data_flags((short)0);            if (cmd.equals("hello")) {            command.set_type_data_type(S4_CMD_HELLO);            mote_id =  TOS_BCAST_ADDR;        } else if (cmd.equals("led_on")) {            command.set_type_data_type(S4_CMD_LED_ON);        } else if (cmd.equals("led_off")) {            command.set_type_data_type(S4_CMD_LED_OFF);        } else if (cmd.equals("set_root")) {            if (argv.length != 4) {                usage();                System.exit(-1);            }            command.set_type_data_type(S4_CMD_SET_ROOT_BEACON);            short byte_arg = (byte)Integer.parseInt(argv[3]);            command.set_type_data_data_args_byte_arg(byte_arg);        } else if (cmd.equals("get_root")) {            command.set_type_data_type(S4_CMD_IS_ROOT_BEACON);            }/* else if (cmd.equals("set_coords")) {            if (argv.length < 4) {                usage();                System.exit(-1);            }            command.set_type_data_type(S4_CMD_SET_COORDS);            //short valid = 0;              for (int i = 3; i < argv.length && i < 20; i++) {                //valid |= 1 << (i-3);                command.setElement_type_data_data_args_dest_coords_comps(                    i-3,(short)Integer.parseInt(argv[i])                );            }            //command.set_type_data_data_args_dest_coords_valid(valid);            }*/ else if (cmd.equals("get_coords")) {            command.set_type_data_type(S4_CMD_GET_COORDS);        } else if (cmd.equals("set_radio")) {            if (argv.length != 4) {                usage();                System.exit(-1);            }            command.set_type_data_type(S4_CMD_SET_RADIO_PWR);            short byte_arg = (short)Integer.parseInt(argv[3]);            command.set_type_data_data_args_byte_arg(byte_arg);        } else if (cmd.equals("get_radio")) {            command.set_type_data_type(S4_CMD_GET_RADIO_PWR);        } else if (cmd.equals("get_info")) {            command.set_type_data_type(S4_CMD_GET_INFO);        } else if (cmd.equals("get_neighbor")) {            if (argv.length != 4) {                usage();                System.exit(-1);            }            command.set_type_data_type(S4_CMD_GET_NEIGHBOR);            short byte_arg = (short)Integer.parseInt(argv[3]);            command.set_type_data_data_args_byte_arg(byte_arg);        } else if (cmd.equals("get_link_info")) {            if (argv.length != 4) {

⌨️ 快捷键说明

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