[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drain/tools Drain.java,
1.1, 1.2 DrainConnector.java, 1.1, 1.2 Makefile, 1.1, 1.2
Gilman Tolle
gtolle at users.sourceforge.net
Thu Mar 3 19:13:59 PST 2005
- Previous message: [Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drain Drain.h, 1.3,
1.4 DrainC.nc, 1.3, 1.4 DrainLinkEstM.nc, 1.3, 1.4 DrainM.nc,
1.3, 1.4
- Next message: [Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drain Drain.h, 1.4,
1.5 DrainLinkEstM.nc, 1.4, 1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-1.x/beta/Drain/tools
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16031/tools
Modified Files:
Drain.java DrainConnector.java Makefile
Log Message:
Working on a reverse-routing system over the Drain tree...initial success, but still a ways to go before it's really usable.
Index: Drain.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/tools/Drain.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Drain.java 3 Mar 2005 02:04:13 -0000 1.1
--- Drain.java 4 Mar 2005 03:13:56 -0000 1.2
***************
*** 7,37 ****
import java.net.*;
! public class Drain implements Runnable {
private MoteIF moteIF;
! private int treeInstance = (int)((double)Math.random() * (double)255);
! private static int BEACON_PERIOD = 4;
! private int beaconPeriod;
! private int spAddr;
! private int beaconSeqno = 1;
! DrainBeaconMsg beaconMsg = new DrainBeaconMsg();
! public Drain(int period) {
! String moteid = Env.getenv("MOTEID");
! if (moteid != null) {
! this.spAddr = Integer.parseInt(moteid);
! } else {
! try {
! byte[] localAddr = InetAddress.getLocalHost().getAddress();
! this.spAddr = localAddr[2];
! this.spAddr <<= 8;
! this.spAddr += localAddr[3];
! } catch (Exception e) {
! this.spAddr = 0xFFFE;
! }
! }
beaconMsg.set_linkSource(spAddr);
--- 7,36 ----
import java.net.*;
! public class Drain implements MessageListener {
private MoteIF moteIF;
+ private int spAddr;
! private ArrayList children = new ArrayList();
! private static int BEACON_DELAY = 4;
! public Drain() {
! setSPAddr();
! startMoteIF();
! moteIF.registerListener(new DrainRegisterMsg(), this);
! }
! public void buildTree() {
! buildTree(BEACON_DELAY);
! }
!
! public void buildTree(int delay) {
!
! int treeInstance = (int)((double)Math.random() * (double)255);
! DrainBeaconMsg beaconMsg = new DrainBeaconMsg();
!
! children.clear();
! children.add(new Integer(0));
beaconMsg.set_linkSource(spAddr);
***************
*** 41,85 ****
beaconMsg.set_cost(0);
beaconMsg.set_ttl((short)15);
!
beaconMsg.set_beaconSeqno((short)0);
! beaconMsg.set_beaconDelay((byte)period);
beaconMsg.set_beaconOffset((short)0);
! try {
! moteIF = new MoteIF((Messenger)null);
! } catch (Exception e) {
! System.out.println("ERROR: Couldn't contact serial forwarder.");
! System.exit(1);
! }
!
! System.out.println("Drain Tree Builder - myAddr = " + spAddr + ", tree = " + treeInstance);
send(beaconMsg);
-
- System.exit(0);
- /*
- Thread thread = new Thread(this);
- thread.setDaemon(true);
- thread.start();
- */
}
! public void run() {
! while(true) {
! try {
! System.out.print(".");
! send(beaconMsg);
! Thread.sleep(beaconPeriod*1024);
} catch (Exception e) {
! e.printStackTrace();
}
}
}
public synchronized void send(Message m) {
try {
! moteIF.send(MoteIF.TOS_BCAST_ADDR, m);
} catch (IOException e) {
e.printStackTrace();
--- 40,133 ----
beaconMsg.set_cost(0);
beaconMsg.set_ttl((short)15);
!
beaconMsg.set_beaconSeqno((short)0);
! beaconMsg.set_beaconDelay((byte)delay);
beaconMsg.set_beaconOffset((short)0);
! System.err.println("Drain Tree Builder");
! System.err.println("myAddr = " + spAddr +
! ", treeInstance = " + treeInstance +
! ", delay = " + delay);
send(beaconMsg);
}
! public void send(int to, int type, Message m, int size) {
!
! DrainMsg drainMsg = new DrainMsg(DrainMsg.DEFAULT_MESSAGE_SIZE + size);
! int numBits = numBits(children.size());
! int index = to & (int)(Math.pow(2,numBits) - 1);
! int remainderAddr = to >> numBits;
!
! System.err.println("bitsNeeded=" + numBits +
! ", index=" + index +
! ", remainderAddr=" + remainderAddr);
!
! int linkDest = ((Integer)children.get(index)).intValue();
!
! System.err.println("linkDest=" + linkDest);
!
! drainMsg.set_type((byte)type);
! drainMsg.set_dir((byte)1);
! drainMsg.set_ttl((byte)15);
! drainMsg.set_source(spAddr);
! drainMsg.set_dest(remainderAddr);
! drainMsg.dataSet(m.dataGet(), 0, drainMsg.offset_data(0), size);
!
! System.err.println(drainMsg);
+ sendTo(linkDest, drainMsg);
+ }
+
+ synchronized public void messageReceived(int to, Message m) {
+ DrainRegisterMsg regMsg = (DrainRegisterMsg) m;
+ if (to == spAddr) {
+ Integer addr = new Integer(regMsg.get_linkSource());
+ children.add(addr);
+ System.out.println("New child: linkAddr=" + addr +
+ ", childNum=" + children.indexOf(addr) +
+ ", totalChildren=" + (children.size() - 1));
+
+ regMsg.set_linkSource(spAddr);
+ regMsg.set_destAddr(children.indexOf(addr));
+ regMsg.set_op((byte)2);
+
+ sendTo(addr.intValue(), regMsg);
+ }
+ }
+
+ private void setSPAddr() {
+ String moteid = Env.getenv("MOTEID");
+ if (moteid != null) {
+ this.spAddr = Integer.parseInt(moteid);
+ } else {
+ try {
+ byte[] localAddr = InetAddress.getLocalHost().getAddress();
+ this.spAddr = localAddr[2];
+ this.spAddr <<= 8;
+ this.spAddr += localAddr[3];
} catch (Exception e) {
! this.spAddr = 0xFFFE;
}
}
}
+ private void startMoteIF() {
+ try {
+ moteIF = new MoteIF((Messenger)null);
+ } catch (Exception e) {
+ System.out.println("ERROR: Couldn't contact serial forwarder.");
+ System.exit(1);
+ }
+ }
+
public synchronized void send(Message m) {
+ sendTo(MoteIF.TOS_BCAST_ADDR, m);
+ }
+
+ public synchronized void sendTo(int to, Message m) {
try {
! moteIF.send(to, m);
} catch (IOException e) {
e.printStackTrace();
***************
*** 91,94 ****
--- 139,165 ----
}
+ /**
+ * fast integer log2 approximation.
+ * @param n number to take log2 of, n >= 5.
+ * @return 8 * (log2( n ) - 1 )
+ */
+ private int numBits( int n ) {
+ return (int)Math.round(Math.ceil(Math.log(n)/Math.log(2)));
+ }
+
+ private int reverseBits( int v ) {
+ int t = v; // t will have the reversed bits of v
+ int i;
+
+ for (i = 32 * 8 - 1; i > 0; i--)
+ {
+ t |= v & 1;
+ t <<= 1;
+ v >>= 1;
+ }
+ t |= v & 1;
+ return t;
+ }
+
public static void main(String args[]) {
***************
*** 97,106 ****
System.exit(1);
}
!
if (args.length == 1) {
! Drain mtb = new Drain(Integer.parseInt(args[0]));
! } else {
! Drain mtb = new Drain(BEACON_PERIOD);
}
}
}
--- 168,203 ----
System.exit(1);
}
!
! Drain drain = new Drain();
! int delay = BEACON_DELAY;
!
if (args.length == 1) {
! delay = Integer.parseInt(args[0]);
}
+
+ drain.buildTree(delay);
+
+ try {
+ Thread.sleep(1024*delay*4);
+ } catch (InterruptedException e) {}
+
+ int to;
+ String line = null;
+ BufferedReader stdin =
+ new BufferedReader(new InputStreamReader(System.in));
+
+ do {
+ try {
+ line = null;
+ System.out.print("Addr? ");
+ line = stdin.readLine();
+ to = Integer.parseInt(line);
+
+ System.out.println("Sending to: " + to);
+
+ drain.send(to, 30, new DrainRegisterMsg(),
+ DrainRegisterMsg.DEFAULT_MESSAGE_SIZE);
+ } catch (IOException e) {}
+ } while (line != null);
}
}
Index: DrainConnector.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/tools/DrainConnector.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** DrainConnector.java 3 Mar 2005 02:04:13 -0000 1.1
--- DrainConnector.java 4 Mar 2005 03:13:56 -0000 1.2
***************
*** 9,13 ****
public class DrainConnector implements MessageListener {
! private static int DEBUG = 0;
public static int TOS_BCAST_ADDR = 0xffff;
--- 9,13 ----
public class DrainConnector implements MessageListener {
! private static int DEBUG = 2;
public static int TOS_BCAST_ADDR = 0xffff;
Index: Makefile
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drain/tools/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Makefile 3 Mar 2005 02:04:13 -0000 1.1
--- Makefile 4 Mar 2005 03:13:56 -0000 1.2
***************
*** 7,11 ****
# List of message classes to build
! MSGS = DrainMsg.java DrainBeaconMsg.java
CONSTS =
INITIAL_TARGETS = $(MSGS) $(CONSTS)
--- 7,11 ----
# List of message classes to build
! MSGS = DrainMsg.java DrainBeaconMsg.java DrainRegisterMsg.java
CONSTS =
INITIAL_TARGETS = $(MSGS) $(CONSTS)
***************
*** 21,24 ****
--- 21,27 ----
$(MIG) -java-classname=DrainBeaconMsg $(BETA)/Drain/Drain.h DrainBeaconMsg -o $@
+ DrainRegisterMsg.java: $(BETA)/Drain/Drain.h
+ $(MIG) -java-classname=DrainRegisterMsg $(BETA)/Drain/Drain.h DrainRegisterMsg -o $@
+
cleanmig:
rm -f $(MSGS) $(CONSTS) platforms.properties
- Previous message: [Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drain Drain.h, 1.3,
1.4 DrainC.nc, 1.3, 1.4 DrainLinkEstM.nc, 1.3, 1.4 DrainM.nc,
1.3, 1.4
- Next message: [Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drain Drain.h, 1.4,
1.5 DrainLinkEstM.nc, 1.4, 1.5
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-beta-commits
mailing list