📄 s4commandinject.java
字号:
usage(); System.exit(-1); } command.set_type_data_type(S4_CMD_GET_LINK_INFO); short byte_arg = (short)Integer.parseInt(argv[3]); command.set_type_data_data_args_byte_arg(byte_arg); } else if (cmd.equals("get_rt")) { if (argv.length != 4) { usage(); System.exit(-1); } command.set_type_data_type(S4_CMD_GET_ROUTING_TABLE); short byte_arg = (short)Integer.parseInt(argv[3]); command.set_type_data_data_args_byte_arg(byte_arg); } else if (cmd.equals("get_root_info")) { if (argv.length != 4) { usage(); System.exit(-1); } command.set_type_data_type(S4_CMD_GET_ROOT_INFO); short byte_arg = (short)Integer.parseInt(argv[3]); command.set_type_data_data_args_byte_arg(byte_arg); } else if (cmd.equals("get_id")) { command.set_type_data_type(S4_CMD_GET_ID); } else if (cmd.equals("freeze")) { command.set_type_data_type(S4_CMD_FREEZE); } else if (cmd.equals("resume")) { command.set_type_data_type(S4_CMD_RESUME); } else if (cmd.equals("reset")) { command.set_type_data_type(S4_CMD_RESET); } else if (cmd.equals("route_to")) { if (argv.length < 5) { usage(); System.exit(-1); } command.set_type_data_type(S4_CMD_APP_ROUTE_TO); //short valid = 0; /* for (int i = 5; i < argv.length && i < 20; i++) { //valid |= 1 << (i-5); System.out.println("Setting coord "+i+" to " +(short)Integer.parseInt(argv[i])); command.setElement_type_data_data_args_dest_coords_comps( i-5,(short)Integer.parseInt(argv[i]) ); }*/ //changed by maoy short closestBeacon = (short)Integer.parseInt(argv[3]); System.out.println("Setting the closest beacon to "+ closestBeacon); command.set_type_data_data_args_dest_closest_beacon(closestBeacon); //command.set_type_data_data_args_dest_coords_valid(valid); command.set_type_data_data_args_dest_addr((short)Integer.parseInt(argv[4])); //command.set_type_data_data_args_dest_mode((byte)Integer.parseInt(argv[3])); } else if (cmd.equals("adv_route_to")) { //maoy: this is new if (argv.length < 8) { usage(); System.exit(-1); } command.set_type_data_type(S4_CMD_APP_ADV_ROUTE_TO); short closestBeacon = (short)Integer.parseInt(argv[3]); System.out.println("Setting the closest beacon to "+ closestBeacon); command.set_type_data_data_args_dest_closest_beacon(closestBeacon); command.set_type_data_data_args_dest_addr((short)Integer.parseInt(argv[4])); command.set_type_data_data_args_dest_init_delay((short)Integer.parseInt(argv[5])); command.set_type_data_data_args_dest_n_packets((short)Integer.parseInt(argv[6])); command.set_type_data_data_args_dest_interval((short)Integer.parseInt(argv[7])); } else { usage(); System.exit(-1); } try { System.err.print("Sending payload: "); for (int i = 0; i < command.dataLength(); i++) { System.err.print(Integer.toHexString(command.dataGet()[i] & 0xff)+ " "); } //System.err.println(command.toString()); System.err.println(); int port = baseport+gateway_addr; System.err.println("Starting connection to mote at "+host+":"+port); PhoenixSource source = BuildSource.makePhoenix("sf@"+host+":"+port, PrintStreamMessenger.err); MoteIF mote = new MoteIF(source); //MoteIF mote = new MoteIF(PrintStreamMessenger.err); // Need to wait for a response message to come back S4CommandInject bci = null; bci = new S4CommandInject(); S4CommandResponseMessage response = new S4CommandResponseMessage(); mote.registerListener(response, bci); mote.send(gateway_addr, command); synchronized (bci) { if (bci.response_received == false) { System.err.println("Waiting for response to command..."); bci.wait(TIMEOUT); } if (bci.response_received == false) { System.err.println("Warning: Timed out waiting for response to command!"); } } saveSequenceNo(sequenceNo+1); System.exit(0); } catch(Exception e) { e.printStackTrace(); } } public void messageReceived(int dest_addr, Message m) { S4CommandResponseMessage cm = (S4CommandResponseMessage) m; System.out.println("Received message"); short cmd = cm.get_type_data_type(); if (cmd==S4_CMD_GET_RADIO_PWR) { System.out.println("power: "+cm.get_type_data_data_args_byte_arg()); } else if (cmd==S4_CMD_GET_COORDS) { String s = ""; s += " [type_data.data.args.coords.comps="; for (int i = 0; i < 8; i++) { s += "0x"+Long.toHexString(cm.getElement_type_data_data_args_coords_comps(i) & 0xff)+" "; } s += "]\n"; System.out.println(s); } else if (cmd == S4_CMD_GET_ID ) { String s = ""; try { s += " [type_data.data.args.ident.install_id=0x"+Long.toHexString(cm.get_type_data_data_args_ident_install_id())+"]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } try { s += " [type_data.data.args.ident.compile_time=0x"+Long.toHexString(cm.get_type_data_data_args_ident_compile_time())+"]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } System.out.println(s); } else if (cmd == S4_CMD_GET_LINK_INFO ) { String s = ""; try { s += " [type_data.data.args.link_info.state=0x"+Long.toHexString(cm.get_type_data_data_args_link_info_state())+"]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } try { s += " [type_data.data.args.link_info.addr=0x"+Long.toHexString(cm.get_type_data_data_args_link_info_addr())+"]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } try { s += " [type_data.data.args.link_info.reverse_quality=0x"+Long.toHexString(cm.get_type_data_data_args_link_info_reverse_quality())+"]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } try { s += " [type_data.data.args.link_info.reverse_expiration=0x"+Long.toHexString(cm.get_type_data_data_args_link_info_reverse_expiration())+"]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } try { s += " [type_data.data.args.link_info.quality=0x"+Long.toHexString(cm.get_type_data_data_args_link_info_quality())+"]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } try { s += " [type_data.data.args.link_info.strength=0x"+Long.toHexString(cm.get_type_data_data_args_link_info_strength())+"]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } try { s += " [type_data.data.args.link_info.last_seqno=0x"+Long.toHexString(cm.get_type_data_data_args_link_info_last_seqno())+"]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } try { s += " [type_data.data.args.link_info.missed="; for (int i = 0; i < 3; i++) { s += "0x"+Long.toHexString(cm.getElement_type_data_data_args_link_info_missed(i) & 0xff)+" "; } s += "]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } try { s += " [type_data.data.args.link_info.received="; for (int i = 0; i < 3; i++) { s += "0x"+Long.toHexString(cm.getElement_type_data_data_args_link_info_received(i) & 0xff)+" "; } s += "]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } try { s += " [type_data.data.args.link_info.age=0x"+Long.toHexString(cm.get_type_data_data_args_link_info_age())+"]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } try { s += " [type_data.data.args.link_info.chances=0x"+Long.toHexString(cm.get_type_data_data_args_link_info_chances())+"]\n"; } catch (ArrayIndexOutOfBoundsException aioobe) { /* Skip field */ } System.out.println(s); } else { System.out.println("Received message: "+cm); //System.err.println(cm); } synchronized (this) { response_received = true; this.notifyAll(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -