[Firebug-cvs] firebug/project/java/src/org/firebug/gps gpsBcast.java,1.1,1.2
Brought to you by:
doolin
From: <cs...@us...> - 2003-05-23 17:16:02
|
Update of /cvsroot/firebug/firebug/project/java/src/org/firebug/gps In directory sc8-pr-cvs1:/tmp/cvs-serv8109 Modified Files: gpsBcast.java Log Message: fixed typo in var names Index: gpsBcast.java =================================================================== RCS file: /cvsroot/firebug/firebug/project/java/src/org/firebug/gps/gpsBcast.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** gpsBcast.java 23 May 2003 15:30:44 -0000 1.1 --- gpsBcast.java 23 May 2003 17:15:59 -0000 1.2 *************** *** 1,158 **** ! package org.firebug.gps; ! ! import net.tinyos.util.*; ! import java.io.*; ! import java.util.Properties; ! import net.tinyos.message.*; ! ! public class gpsBcast implements MessageListener { ! static Properties p = new Properties(); ! public static final byte UTC = 1; ! public static final byte LONGITUDE = 2; ! public static final byte NS_INDICATOR = 3; ! public static final byte LATITUDE = 4; ! public static final byte EW_INDICATOR = 5; ! ! public boolean read_log_done = false; ! ! public static final short TOS_BCAST_ADDR = (short) 0xffff; ! ! public static void usage() { ! System.err.println("Usage: java net.tinyos.tools.gpsBcast"+ ! " <group_id> <command> [arguments]"); ! System.err.println("\twhere <command> and [arguments] can be one of the following:"); ! System.err.println("\t\tUTC [dest_address]"); ! System.err.println("\t\tLONGITUDE [dest_address]"); ! System.err.println("\t\tNS_INDICATOR [dest_address]"); ! System.err.println("\t\tLATITUDE [dest_address]"); ! System.err.println("\t\tEW_INDICATOR [dest_address]"); ! } ! ! public static byte restoreSequenceNo() { ! try { ! FileInputStream fis = new FileInputStream("bcast.properties"); ! p.load(fis); ! byte i = (byte)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("bcast.properties"); ! p.setProperty("sequenceNo", Integer.toString(i)); ! p.store(fos, "#Properties for gpsBcast\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 = 0; ! byte sequenceNo = 0; ! ! if (argv.length < 2) { ! usage(); ! System.exit(-1); ! } ! ! try { ! group_id = (byte)(Integer.parseInt(argv[0]) & 0xff); ! } catch (NumberFormatException nfe) { ! usage(); ! System.exit(-1); ! } ! ! cmd = argv[1]; ! ! gpsCmdMsg packet = new gpsCmdMsg(); ! ! sequenceNo = restoreSequenceNo(); ! packet.set_seqno(sequenceNo); ! packet.set_hop_count((short)0); ! packet.set_source(0); ! ! if (cmd.equals("UTC")) { ! packet.set_action(UTC); ! short address = (short)Integer.parseInt(argv[2]); ! packet.set_args_rl_args_destaddr(address); ! } else if (cmd.equals("LONGITUDE")) { ! packet.set_action(LONGITUDE); ! short address = (short)Integer.parseInt(argv[2]); ! packet.set_args_rl_args_destaddr(address); ! } else if (cmd.equals("NS_INDICATOR")) { ! packet.set_action(NS_INDICATOR); ! short address = (short)Integer.parseInt(argv[2]); ! packet.set_args_rl_args_destaddr(address); ! } else if (cmd.equals("LATITUDE")) { ! packet.set_action(LATITUDE); ! short address = (short)Integer.parseInt(argv[2]); ! packet.set_args_rl_args_destaddr(address); ! } else if (cmd.equals("EW_INDICATOR")) { ! packet.set_action(EW_INDICATOR); ! short address = (short)Integer.parseInt(argv[2]); ! packet.set_args_rl_args_destaddr(address); ! } else { ! usage(); ! System.exit(-1); ! } ! ! try { ! System.err.print("Sending payload: "); ! for (int i = 0; i < packet.dataLength(); i++) { ! System.err.print(Integer.toHexString(packet.dataGet()[i] & 0xff)+ " "); ! } ! System.err.println(); ! ! MoteIF mote = new MoteIF("127.0.0.1", 9000, group_id); ! ! gpsBcast bc = null; ! bc = new gpsBcast(); ! mote.registerListener(new LogMsg(), bc); ! mote.start(); ! mote.send(TOS_BCAST_ADDR, packet); ! ! synchronized (bc) { ! if (bc.read_log_done == false) { ! System.err.println("Waiting for response to read_log..."); ! bc.wait(10000); ! } ! if (bc.read_log_done == false) { ! System.err.println("Warning: Timed out waiting for response to read_log command!"); ! } ! } ! ! saveSequenceNo(sequenceNo+1); ! System.exit(0); ! ! } catch(Exception e) { ! e.printStackTrace(); ! } ! ! } ! ! public void messageReceived(int dest_addr, Message m) { ! LogMsg lm = (LogMsg) m; ! System.err.println("Received log message: "+lm); ! ! System.err.print("Log values: "); ! for (int i = 0; i < lm.numElements_log(); i++) { ! short val = lm.getElement_log(i); ! System.err.print(Integer.toHexString((int)val)+" "); ! } ! System.err.println(""); ! ! synchronized (this) { ! read_log_done = true; ! this.notifyAll(); ! } ! } ! ! } ! --- 1,158 ---- ! package org.firebug.gps; ! ! import net.tinyos.util.*; ! import java.io.*; ! import java.util.Properties; ! import net.tinyos.message.*; ! ! public class gpsBcast implements MessageListener { ! static Properties p = new Properties(); ! public static final byte UTC = 1; ! public static final byte LATITUDE = 2; ! public static final byte NS_INDICATOR = 3; ! public static final byte LONGITUDE = 4; ! public static final byte EW_INDICATOR = 5; ! ! public boolean read_log_done = false; ! ! public static final short TOS_BCAST_ADDR = (short) 0xffff; ! ! public static void usage() { ! System.err.println("Usage: java net.tinyos.tools.gpsBcast"+ ! " <group_id> <command> [arguments]"); ! System.err.println("\twhere <command> and [arguments] can be one of the following:"); ! System.err.println("\t\tUTC [dest_address]"); ! System.err.println("\t\tLATITUDE [dest_address]"); ! System.err.println("\t\tNS_INDICATOR [dest_address]"); ! System.err.println("\t\tLONGITUDE [dest_address]"); ! System.err.println("\t\tEW_INDICATOR [dest_address]"); ! } ! ! public static byte restoreSequenceNo() { ! try { ! FileInputStream fis = new FileInputStream("bcast.properties"); ! p.load(fis); ! byte i = (byte)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("bcast.properties"); ! p.setProperty("sequenceNo", Integer.toString(i)); ! p.store(fos, "#Properties for gpsBcast\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 = 0; ! byte sequenceNo = 0; ! ! if (argv.length < 2) { ! usage(); ! System.exit(-1); ! } ! ! try { ! group_id = (byte)(Integer.parseInt(argv[0]) & 0xff); ! } catch (NumberFormatException nfe) { ! usage(); ! System.exit(-1); ! } ! ! cmd = argv[1]; ! ! gpsCmdMsg packet = new gpsCmdMsg(); ! ! sequenceNo = restoreSequenceNo(); ! packet.set_seqno(sequenceNo); ! packet.set_hop_count((short)0); ! packet.set_source(0); ! ! if (cmd.equals("UTC")) { ! packet.set_action(UTC); ! short address = (short)Integer.parseInt(argv[2]); ! packet.set_args_rl_args_destaddr(address); ! } else if (cmd.equals("LONGITUDE")) { ! packet.set_action(LONGITUDE); ! short address = (short)Integer.parseInt(argv[2]); ! packet.set_args_rl_args_destaddr(address); ! } else if (cmd.equals("NS_INDICATOR")) { ! packet.set_action(NS_INDICATOR); ! short address = (short)Integer.parseInt(argv[2]); ! packet.set_args_rl_args_destaddr(address); ! } else if (cmd.equals("LATITUDE")) { ! packet.set_action(LATITUDE); ! short address = (short)Integer.parseInt(argv[2]); ! packet.set_args_rl_args_destaddr(address); ! } else if (cmd.equals("EW_INDICATOR")) { ! packet.set_action(EW_INDICATOR); ! short address = (short)Integer.parseInt(argv[2]); ! packet.set_args_rl_args_destaddr(address); ! } else { ! usage(); ! System.exit(-1); ! } ! ! try { ! System.err.print("Sending payload: "); ! for (int i = 0; i < packet.dataLength(); i++) { ! System.err.print(Integer.toHexString(packet.dataGet()[i] & 0xff)+ " "); ! } ! System.err.println(); ! ! MoteIF mote = new MoteIF("127.0.0.1", 9000, group_id); ! ! gpsBcast bc = null; ! bc = new gpsBcast(); ! mote.registerListener(new LogMsg(), bc); ! mote.start(); ! mote.send(TOS_BCAST_ADDR, packet); ! ! synchronized (bc) { ! if (bc.read_log_done == false) { ! System.err.println("Waiting for response to read_log..."); ! bc.wait(10000); ! } ! if (bc.read_log_done == false) { ! System.err.println("Warning: Timed out waiting for response to read_log command!"); ! } ! } ! ! saveSequenceNo(sequenceNo+1); ! System.exit(0); ! ! } catch(Exception e) { ! e.printStackTrace(); ! } ! ! } ! ! public void messageReceived(int dest_addr, Message m) { ! LogMsg lm = (LogMsg) m; ! System.err.println("Received log message: "+lm); ! ! System.err.print("Log values: "); ! for (int i = 0; i < lm.numElements_log(); i++) { ! short val = lm.getElement_log(i); ! System.err.print(Integer.toHexString((int)val)+" "); ! } ! System.err.println(""); ! ! synchronized (this) { ! read_log_done = true; ! this.notifyAll(); ! } ! } ! ! } ! |