📄 buildsource.java
字号:
if (rate.equals("mica2dot")) return 19200; return Integer.parseInt(rate); } /** * Make an old, broken serial-port packet source * @param args "COMn[:baudrate][,packetSize]" ("COM1" if args is null) * baudrate is an integer or mote name (rene, mica, mica2, mica2dot). * The default baudrate is 19200. * @return The new packet source, or null if the arguments are invalid */ public static PacketSource makeArgsOldSerial(String args) { if (args == null) args = "COM1"; ParseArgs parser = new ParseArgs(args, ":,"); String port = parser.next(); int baudrate = decodeBaudrate(parser.next()); String packetSizeS = parser.next(); if (packetSizeS == null) { return makeOldSerial(port, baudrate); } else { int packetSize = Integer.parseInt(packetSizeS); return makeOldSerial(port, baudrate, packetSize); } } /** * Make an old, broken serial-port packet source * @param port javax.comm serial port name ("COMn:") * @param baudrate requested baudrate * @param packetSize packet size to use * @return The new packet source */ public static PacketSource makeOldSerial(String port, int baudrate, int packetSize) { return new BrokenPacketizer("old-serial@" + port + ":" + baudrate, packetSize, new SerialByteSource(port, baudrate)); } /** * Make an old, broken serial-port packet source with the default * packet size. * @param port javax.comm serial port name ("COMn:") * @param baudrate requested baudrate * @return The new packet source */ public static PacketSource makeOldSerial(String port, int baudrate) { return makeOldSerial(port, baudrate, net.tinyos.message.MoteIF.defaultPacketSize); } /** * Make a serial-port packet source. Serial packet sources report * missing acknowledgements via a false result to writePacket. * @param args "COMn[:baudrate]" ("COM1" if args is null) * baudrate is an integer or mote name (rene, mica, mica2, mica2dot). * The default baudrate is 19200. * @return The new packet source, or null if the arguments are invalid */ public static PacketSource makeArgsSerial(String args) { if (args == null) args = "COM1"; ParseArgs parser = new ParseArgs(args, ":"); String port = parser.next(); int baudrate = decodeBaudrate(parser.next()); return makeSerial(port, baudrate); } /** * Make a serial-port packet source. Serial packet sources report * missing acknowledgements via a false result to writePacket. * @param port javax.comm serial port name ("COMn:") * @param baudrate requested baudrate * @return The new packet source */ public static PacketSource makeSerial(String port, int baudrate) { return new Packetizer("serial@" + port + ":" + baudrate, new SerialByteSource(port, baudrate)); } /** * Make an old, broken serial-port packet source for a network-accessible * serial port * @param args "hostname:portnumber[,packetSize]" (no default) * @return The new packet source, or null if the arguments are invalid */ public static PacketSource makeArgsOldNetwork(String args) { if (args == null) return null; ParseArgs parser = new ParseArgs(args, ":,"); String host = parser.next(); String portS = parser.next(); if (portS == null) return null; int port = Integer.parseInt(portS); String packetSizeS = parser.next(); if (packetSizeS == null) { return makeOldNetwork(host, port); } else { int packetSize = Integer.parseInt(packetSizeS); return makeOldNetwork(host, port, packetSize); } } /** * Make an old, broken serial-port packet source for a network-accessible * serial port * @param host hostname of network-accessible serial port * @param port tcp/ip port number * @param packetSize packet size to use * @return The new packet source */ public static PacketSource makeOldNetwork(String host, int port, int packetSize) { return new BrokenPacketizer("old-network@" + host + ":" + port, packetSize, new NetworkByteSource(host, port)); } /** * Make an old, broken serial-port packet source for a network-accessible * serial port with the default packet size * @param host hostname of network-accessible serial port * @param port tcp/ip port number * @return The new packet source */ public static PacketSource makeOldNetwork(String host, int port) { return makeOldNetwork(host, port, net.tinyos.message.MoteIF.defaultPacketSize); } /** * Make a serial-port packet source for a network-accessible serial * port. Serial packet sources report missing acknowledgements via a * false result to writePacket. * @param args "hostname:portnumber" (no default) * @return The new packet source, or null if the arguments are invalid */ public static PacketSource makeArgsNetwork(String args) { if (args == null) return null; ParseArgs parser = new ParseArgs(args, ":"); String host = parser.next(); String portS = parser.next(); if (portS == null) return null; int port = Integer.parseInt(portS); return makeNetwork(host, port); } /** * Make a serial-port packet source for a network-accessible serial * port. Serial packet sources report missing acknowledgements via a * false result to writePacket. * @param host hostname of network-accessible serial port * @param port tcp/ip port number * @return The new packet source */ public static PacketSource makeNetwork(String host, int port) { return new Packetizer("network@" + host + ":" + port, new NetworkByteSource(host, port)); } // We create tossim sources using reflection to avoid depending on // tossim at compile-time /** * Make a tossim serial port (node 0) packet source * @param args "hostname" ("localhost" for null) (on which tossim runs) * @return The new packet source */ public static PacketSource makeArgsTossimSerial(String args) { if (args == null) args = "localhost"; return makeTossimSerial(args); } /** * Make a tossim serial port (node 0) packet source * @param host hostname on which tossim runs * @return The new packet source */ public static PacketSource makeTossimSerial(String host) { return makeTossimSource("TossimSerialSource", host); } /** * Make a tossim radio packet source * @param args "hostname" ("localhost" for null) (on which tossim runs) * @return The new packet source */ public static PacketSource makeArgsTossimRadio(String args) { if (args == null) args = "localhost"; return makeTossimRadio(args); } /** * Make a tossim radio packet source * @param host hostname on which tossim runs * @return The new packet source */ public static PacketSource makeTossimRadio(String host) { return makeTossimSource("TossimRadioSource", host); } private static PacketSource makeTossimSource(String name, String host) { try { Class[] oneStringArg = new Class[1]; oneStringArg[0] = Class.forName("java.lang.String"); Object[] args = new Object[1]; args[0] = host; Class tossimSource = Class.forName("net.tinyos.sim.packet." + name); return (PacketSource)tossimSource.getConstructor(oneStringArg).newInstance(args); } catch (Exception e) { System.err.println("Couldn't instantiate tossim packet source"); System.err.println("Did you compile tossim?"); return null; } } /** * Parse a string into tokens based on a sequence of delimiters * Given delimiters (single characters) d1, d2, ..., dn, this * class recognises strings of the form s0[d1s1][d2s2]...[dnsn], * where s<i-1> does not contain character di * This is unambiguous if all di are distinct. If not, strings * are attributed to the earliest possible si (so if the delimiters * are : and :, and the input string is foo:bar, then s0 is foo, * s1 is bar and s2 is null */ static class ParseArgs { String tokens[]; int tokenIndex; ParseArgs(String s, String delimiterSequence) { int count = delimiterSequence.length(); tokens = new String[count + 1]; tokenIndex = 0; // Fill in the tokens int i = 0, lastMatch = 0; while (i < count) { int pos = s.indexOf(delimiterSequence.charAt(i++)); if (pos >= 0) { // When we finally find a delimiter, we know where // the last token ended tokens[lastMatch] = s.substring(0, pos); lastMatch = i; s = s.substring(pos + 1); } } tokens[lastMatch] = s; } String next() { return tokens[tokenIndex++]; } } public static void main(String[] args) { System.err.println(sourceHelp()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -