[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Drip/tools/java/net/tinyos/drip Drip.java, 1.1, 1.2

Gilman Tolle gtolle at users.sourceforge.net
Thu Apr 14 16:48:00 PDT 2005


Update of /cvsroot/tinyos/tinyos-1.x/beta/Drip/tools/java/net/tinyos/drip
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31415

Modified Files:
	Drip.java 
Log Message:
added a second send command for sending drip messages to a client that is duty-cycling its radio.

Index: Drip.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/beta/Drip/tools/java/net/tinyos/drip/Drip.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Drip.java	15 Mar 2005 01:11:16 -0000	1.1
--- Drip.java	14 Apr 2005 23:47:58 -0000	1.2
***************
*** 19,26 ****
  
    public static boolean DEBUG = false;
!   
    int id;
    int seqno;
    int sendCount = 0;
  
    Timer trickle;
--- 19,40 ----
  
    public static boolean DEBUG = false;
!   public static int SEND_COUNT = 6;
!   public static int SEND_RATE = 1024;
! 
!   public static int WAKEUP_SEND_COUNT = 25;
!   public static int WAKEUP_SEND_RATE = 40;
! 
!   private static final int IDLE = 0;
!   private static final int PROBING = 1;
!   private static final int SENDING_SEQNO = 2;
!   private static final int SENT_SEQNO = 3;
!   private static final int SENDING_NEW = 4;
! 
!   private int state = IDLE;
! 
    int id;
    int seqno;
    int sendCount = 0;
+   int maxSendCount;
  
    Timer trickle;
***************
*** 49,56 ****
      dripMsg.dataSet(msg.dataGet(), 0, dripMsg.offset_data(0),
  		    msgSize);
-     hasMessage = true;
-     seqno = DripConsts.DRIP_SEQNO_OLDEST;
      sendCount = 0;
!     trickle.schedule(this, 0, 1024);
      try {
        wait();
--- 63,71 ----
      dripMsg.dataSet(msg.dataGet(), 0, dripMsg.offset_data(0),
  		    msgSize);
      sendCount = 0;
!     state = PROBING;
!     seqno = DripConsts.DRIP_SEQNO_OLDEST;
!     maxSendCount = SEND_COUNT;
!     trickle.schedule(this, 0, SEND_RATE);
      try {
        wait();
***************
*** 60,91 ****
    }
  
    private synchronized void sendDone() {
      notifyAll();
    }
  
    public void run() {
  
!     sendCount++;
! 
!     if (sendCount > 6) {
        trickle.cancel();
        sendDone();
      }
  	
!     if (hasMessage) {
  
!       if (sendCount > 5 && seqno == DripConsts.DRIP_SEQNO_OLDEST) {
! 	seqno = DripConsts.DRIP_SEQNO_NEWEST;
! 	hasMessage = false;
        }
  
!       dripMsg.set_metadata_id((short)id);
!       dripMsg.set_metadata_seqno((byte)seqno);
! 	    
!       if (DEBUG) {
! 	System.out.println("Sending Msg: id=" + id + ",seqno=" + seqno);
!       }
!       send(dripMsg);
      }
    }
  
--- 75,133 ----
    }
  
+   public synchronized void sendWakeup(Message msg, int msgSize) {
+     trickle = new Timer();
+     dripMsg = new DripMsg(DripMsg.DEFAULT_MESSAGE_SIZE + msgSize);
+     dripMsg.dataSet(msg.dataGet(), 0, dripMsg.offset_data(0),
+ 		    msgSize);
+     sendCount = 0;
+     state = SENDING_NEW;
+     seqno = DripConsts.DRIP_SEQNO_NEWEST;
+     maxSendCount = WAKEUP_SEND_COUNT;
+     trickle.schedule(this, 0, WAKEUP_SEND_RATE);
+     try {
+       wait();
+     } catch (InterruptedException e) {
+       // return
+     }
+   }
+     
    private synchronized void sendDone() {
      notifyAll();
+     state = IDLE;
    }
  
    public void run() {
  
!     if (sendCount > maxSendCount) {
        trickle.cancel();
        sendDone();
      }
  	
!     dripMsg.set_metadata_id((short)id);
  
!     switch (state) {
!     case PROBING:
!       dripMsg.set_metadata_seqno((byte)DripConsts.DRIP_SEQNO_OLDEST);
!     case SENDING_SEQNO:
!       if (sendCount == maxSendCount) {
! 	// last chance
! 	dripMsg.set_metadata_seqno((byte)DripConsts.DRIP_SEQNO_NEWEST);
! 	state = SENT_SEQNO;
!       } else {
! 	dripMsg.set_metadata_seqno((byte)seqno);
        }
+     case SENT_SEQNO:
+       trickle.cancel();
+       sendDone();
+     case SENDING_NEW:
+       dripMsg.set_metadata_seqno((byte)DripConsts.DRIP_SEQNO_NEWEST);
+     default:
+     }
  
!     if (DEBUG) {
!       System.out.println("Sending Msg: id=" + id + ",seqno=" + seqno);
      }
+     send(dripMsg);
+     sendCount++;
    }
  
***************
*** 115,134 ****
        System.out.println("Received Msg: id=" + newId + ",seqno=" + newSeqno);
      }
! 	
!     if ((seqno == DripConsts.DRIP_SEQNO_OLDEST || sendCount > 5) 
! 	&& hasMessage) {
! 	    
        seqno = newSeqno;
        incrementSeqno();
!       sentOK = false;
!     }
! 	
!     if (sentOK == false && seqno == newSeqno) {
!       if (DEBUG) {
! 	System.out.println("Message Injected Successfully");
        }
!       sentOK = true;
!       hasMessage = false;
!       sendDone();
      }
    }
--- 157,174 ----
        System.out.println("Received Msg: id=" + newId + ",seqno=" + newSeqno);
      }
! 
!     switch (state) {
!     case PROBING:
        seqno = newSeqno;
        incrementSeqno();
!       state = SENDING_SEQNO;
!     case SENDING_SEQNO:
!       if (seqno == newSeqno) {
! 	if (DEBUG) {
! 	  System.out.println("Message Injected Successfully");
! 	}
! 	state = SENT_SEQNO;
        }
!     default:
      }
    }
***************
*** 151,155 ****
      msg.set_data((short)Integer.parseInt(data));
  
!     drip.send(msg, TestDripMsg.DEFAULT_MESSAGE_SIZE);
      System.exit(0);
    }
--- 191,199 ----
      msg.set_data((short)Integer.parseInt(data));
  
!     if (args.length > 1 && args[1].equals("wake")) {
!       drip.sendWakeup(msg, TestDripMsg.DEFAULT_MESSAGE_SIZE);
!     } else {
!       drip.send(msg, TestDripMsg.DEFAULT_MESSAGE_SIZE);
!     }
      System.exit(0);
    }



More information about the Tinyos-beta-commits mailing list