[Tinyos-2-commits] CVS: tinyos-2.x/apps/tests/TestDIP DipInject.java, NONE, 1.1 Makefile, 1.1, 1.2 README, 1.2, 1.3

Kaisen Lin kaisenl at users.sourceforge.net
Sat Feb 16 02:55:35 PST 2008


Update of /cvsroot/tinyos/tinyos-2.x/apps/tests/TestDIP
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv31821

Modified Files:
	Makefile README 
Added Files:
	DipInject.java 
Log Message:
Dip Data Injector

--- NEW FILE: DipInject.java ---

import java.io.*;
import net.tinyos.message.*;
import net.tinyos.util.*;

public class DipInject implements MessageListener
{
    MoteIF mote;

    DipInject(DipMsg dipmsg) {
        mote = new MoteIF(PrintStreamMessenger.err);
        mote.registerListener(dipmsg, this);
    }

    public synchronized void messageReceived(int dest_addr, Message message)
    {
	// do nothing for now
    }

    void sendDipDataMsg(int key, long version, short[] data) {
	int totalsize = DipMsg.DEFAULT_MESSAGE_SIZE +
	    DipDataMsg.DEFAULT_MESSAGE_SIZE +
	    DipData.DEFAULT_MESSAGE_SIZE;
	DipMsg dm = new DipMsg(totalsize);
	dm.set_type((short)3);

	DipDataMsg ddm = new DipDataMsg(dm, DipMsg.DEFAULT_MESSAGE_SIZE);
	ddm.set_key(key);
        ddm.set_version(version);
        ddm.set_size((short)data.length);

        DipData dd = new DipData(ddm, DipDataMsg.DEFAULT_MESSAGE_SIZE); 
        dd.set_data(data);

        try {
	    mote.send(MoteIF.TOS_BCAST_ADDR, dd);
	}
        catch(IOException e) {
	    System.err.println("Cannot send message");
	}
    }

    public static void main(String args[]) {
	int i;

        System.out.println("Usage: java DipInject [key] [version] [hex data delimit space in quotes]");
        int k = Integer.parseInt(args[0], 16);
        long v = Long.parseLong(args[1]);
        String hexdata[] = args[2].split(" ");
	short d[];

        if(hexdata.length > 16) {
            System.err.println("Data too long, keep it <= 16 bytes please");
	}

	d = new short[hexdata.length];
        for(i = 0; i < d.length; i++)
            d[i] = Short.parseShort(hexdata[i], 16);

        System.out.println("Key: " + k);
        System.out.println("Version: " + v);
        System.out.print("Data: ");
        for(i = 0; i < d.length; i++) {
            System.out.print(d[i] + " ");
	}
        System.out.println();

        DipInject dipinject = new DipInject(new DipMsg());
        dipinject.sendDipDataMsg(k, v, d);
    }
}
Index: Makefile
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/apps/tests/TestDIP/Makefile,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Makefile	24 Jan 2008 07:28:27 -0000	1.1
--- Makefile	16 Feb 2008 10:55:33 -0000	1.2
***************
*** 1,3 ****
--- 1,4 ----
  COMPONENT=TestDIPC
+ BUILD_EXTRA_DEPS = DipMsg.py DipDataMsg.py DipMsg.class DipDataMsg.class DipData.class DipInject.class
  CFLAGS += -I$(TOSDIR)/lib/net
  CFLAGS += -I$(TOSDIR)/lib/net/dip -I$(TOSDIR)/lib/net/dip/interfaces
***************
*** 6,8 ****
--- 7,47 ----
  CONSTANTS += -DTOSH_DATA_LENGTH=32
  CFLAGS += $(CONSTANTS)
+ 
+ DipMsg.py:
+ 	mig python -target=$(PLATFORM) -python-classname=DipMsg $(CFLAGS) $(TOSDIR)/lib/net/dip/Dip.h dip_msg -o $@
+ 
+ DipDataMsg.py:
+ 	mig python -target=$(PLATFORM) -python-classname=DipDataMsg -python-extends=DipMsg $(CFLAGS) $(TOSDIR)/lib/net/dip/Dip.h dip_data_msg -o $@
+ 
+ DipData.py:
+ 	mig python -target=$(PLATFORM) -python-classname=DipData -python-extends=DipDataMsg $(CFLAGS) $(TOSDIR)/lib/net/dip/Dip.h dip_data -o $@
+ 
+ 
+ DipMsg.class: DipMsg.java
+ 	javac -target 1.4 -source 1.4 DipMsg.java
+ 
+ DipDataMsg.class: DipDataMsg.java
+ 	javac -target 1.4 -source 1.4 DipDataMsg.java
+ 
+ DipData.class: DipData.java
+ 	javac -target 1.4 -source 1.4 DipData.java
+ 
+ DipMsg.java:
+ 	mig java -target=$(PLATFORM) -java-classname=DipMsg $(CFLAGS) $(TOSDIR)/lib/net/dip/Dip.h dip_msg -o $@
+ 
+ DipDataMsg.java:
+ 	mig java -target=$(PLATFORM) -java-classname=DipDataMsg -java-extends=DipMsg $(CFLAGS) $(TOSDIR)/lib/net/dip/Dip.h dip_data_msg -o $@
+ 
+ DipData.java:
+ 	mig java -target=$(PLATFORM) -java-classname=DipData -java-extends=DipDataMsg $(CFLAGS) $(TOSDIR)/lib/net/dip/Dip.h dip_data -o $@
+ 
+ DipInject.class:
+ 	javac -target 1.4 -source 1.4 DipInject.java
+ 
+ #clean-inject:
+ #	rm -f DipMsg.py DipDataMsg.py DipData.py
+ #	rm -f DipMsg.java DipDataMsg.java DipData.java
+ #	rm -f DipMsg.class DipDataMsg.class DipData.class
+ #	rm -f DipInject.class
+ 
  include $(MAKERULES)

Index: README
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/apps/tests/TestDIP/README,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** README	26 Jan 2008 08:30:59 -0000	1.2
--- README	16 Feb 2008 10:55:33 -0000	1.3
***************
*** 11,15 ****
  are random are chosen randomly.
  
! If you want 128 total items and 96 new items, you would type:
  
  python gentest.py 128 96
--- 11,16 ----
  are random are chosen randomly.
  
! If you want 128 total items in the dissemination set, where 96 of
! those 128 items are new, you would type:
  
  python gentest.py 128 96
***************
*** 38,42 ****
  isOk will be true if the data value was as expected
  
! 4. TIMING
  
  With a single sender and single receiver on a table using TelosB
--- 39,62 ----
  isOk will be true if the data value was as expected
  
! 4. PACKET INJECTOR
! 
! You can also use the injector to send data packets via a
! basestation. The syntax to do that is:
! 
! java DipInject [key] [version] [data in quotes delimited by space]
! 
! key is the data key in hexadecimal
! version is the version number in decimal
! data is the actual data in quotes delimited by space
! 
! For example, if you want to send key 10, version 2, and data "ab cd
! ef". You would type:
! 
! java DipInject 0a 2 "ab cd ef"
! 
! For this specific test application, your data needs to be "ef be". You
! will need a SerialForwarder running for this work.
! 
! 5. TIMING
  
  With a single sender and single receiver on a table using TelosB



More information about the Tinyos-2-commits mailing list