[Tinyos-beta-commits]
CVS: tinyos-1.x/beta/Drip/tools/java/net/tinyos/drip
DripDaemon.java, NONE, 1.1
Gilman Tolle
gtolle at users.sourceforge.net
Thu Aug 18 23:23:31 PDT 2005
- Previous message: [Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drip Drip.h, 1.5,
1.6 DripM.nc, 1.7, 1.8 DripStateM.nc, 1.6, 1.7
- Next message: [Tinyos-beta-commits] CVS: tinyos-1.x/beta/platform/pxa27x
PXA27XUSBClientM.nc, 1.2, 1.3 ReceiveBData.nc, 1.2,
1.3 SendJTPacket.nc, 1.1, 1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-1.x/beta/Drip/tools/java/net/tinyos/drip
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3953
Added Files:
DripDaemon.java
Log Message:
This is a daemon version of Drip that the NESTFE Wakeup depends on.
--- NEW FILE: DripDaemon.java ---
package net.tinyos.drip;
import net.tinyos.message.*;
import net.tinyos.util.*;
import org.apache.log4j.*;
import java.io.*;
import java.text.*;
import java.util.*;
public class DripDaemon implements MessageListener {
private Logger log = Logger.getLogger(DripDaemon.class.getName());
MoteIF moteIF;
int id;
int seqno;
Message store;
int storeSize;
boolean storeForever;
boolean newStore;
boolean doneInjecting;
Timer trickle = new Timer();
TimerTask trickleTimer = new DripSender();
int period;
int round;
public DripDaemon(int id) {
log.info("Started id=" + id);
try {
moteIF = new MoteIF();
moteIF.registerListener(new DripMsg(), this);
} catch (Exception e) {
System.out.println("ERROR: Couldn't contact serial forwarder.");
System.exit(1);
}
this.id = id;
}
public void storeOnce(Message m, int size) {
store(m, size, false);
}
public void storeForever(Message m, int size) {
store(m, size, true);
}
private void store(Message m, int size, boolean forever) {
log.info("id=" + id + ": storing new message");
doneInjecting = false;
store = m;
storeSize = size;
storeForever = forever;
newStore = true;
seqno = DripConsts.DRIP_SEQNO_OLDEST;
round = 0;
period = DripConsts.DRIP_TIMER_PERIOD * (1 << round);
trickleTimer.cancel();
trickleTimer = new DripSender();
trickle.schedule(trickleTimer, period);
}
public void messageReceived(int to, Message m) {
DripMsg msg = (DripMsg)m;
int newId = msg.get_metadata_id();
int newSeqno = msg.get_metadata_seqno();
log.info("id=" + id + ": received msg id=" + newId + ",seqno=" + newSeqno);
if (newId != id) {
return;
}
if (doneInjecting) {
return;
}
if (newStore) {
seqno = newSeqno;
log.info("id=" + id + ": heard packet with old seqno = " + seqno);
incrementSeqno();
log.info("id=" + id + ": injecting packet with new seqno = " + seqno);
newStore = false;
} else {
if (!storeForever) {
if (seqno == newSeqno) {
log.info("id=" + id + ": done injecting");
doneInjecting = true;
trickleTimer.cancel();
}
}
}
if (seqno != newSeqno) {
round = 0;
period = DripConsts.DRIP_TIMER_PERIOD * (1 << round);
trickleTimer.cancel();
trickleTimer = new DripSender();
trickle.schedule(trickleTimer, period);
}
}
class DripSender extends TimerTask {
public void run() {
log.info("id=" + id + ": sending msg seqno=" + seqno);
DripMsg dripMsg = new DripMsg(DripMsg.DEFAULT_MESSAGE_SIZE + storeSize);
dripMsg.set_metadata_id((short)id);
dripMsg.set_metadata_seqno((short)seqno);
dripMsg.dataSet(store.dataGet(), 0, dripMsg.offset_data(0),
storeSize);
send(dripMsg);
if (round < DripConsts.DRIP_MAX_SEND_INTERVAL) {
round++;
}
period = DripConsts.DRIP_TIMER_PERIOD * (1 << round);
trickleTimer = new DripSender();
trickle.schedule(trickleTimer, period);
}
}
private void send(Message m) {
try {
moteIF.send(MoteIF.TOS_BCAST_ADDR, m);
} catch (IOException e) {
e.printStackTrace();
System.out.println("ERROR: Can't send message");
System.exit(1);
} catch (Exception e) {
e.printStackTrace();
}
}
private void incrementSeqno() {
seqno = (seqno + 1) % 256;
seqno = (seqno + 1) % 256;
while ((seqno & ~DripConsts.DRIP_WAKEUP_BIT) == DripConsts.DRIP_SEQNO_OLDEST ||
(seqno & ~DripConsts.DRIP_WAKEUP_BIT) == DripConsts.DRIP_SEQNO_NEWEST ||
(seqno & ~DripConsts.DRIP_WAKEUP_BIT) == DripConsts.DRIP_SEQNO_UNKNOWN) {
seqno = (seqno + 1) % 256;
seqno = (seqno + 1) % 256;
}
}
}
- Previous message: [Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drip Drip.h, 1.5,
1.6 DripM.nc, 1.7, 1.8 DripStateM.nc, 1.6, 1.7
- Next message: [Tinyos-beta-commits] CVS: tinyos-1.x/beta/platform/pxa27x
PXA27XUSBClientM.nc, 1.2, 1.3 ReceiveBData.nc, 1.2,
1.3 SendJTPacket.nc, 1.1, 1.2
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-beta-commits
mailing list