110 likes | 216 Views
Programming Assignment 2. CSE535: Mobile Computing (Fall 2010). Environmental Setup Issues. Go to your home directory. Open .bash_profile or .bashrc Add necessary environmental variables Ex) export TOSROOT=“/opt/tinyos-2.x”
E N D
Programming Assignment 2 CSE535: Mobile Computing (Fall 2010)
Environmental Setup Issues • Go to your home directory. Open .bash_profile or .bashrc • Add necessary environmental variables Ex) export TOSROOT=“/opt/tinyos-2.x” • Important! You need to add the current directory (.) into CLASSPATH • Check these variables using “echo” command. ex) echo $TOSROOT • Run “tos-check-env” to check all other environments.
Multiple JRE installation Issues • Check the location of Java library tos-locate-jre --jni • Copy toscomm.dll and getenv.dll from \lib\tinyos into the directory you found using tos-locate-jre --jni
Compile and Install a code • make telosb • Compile an application • make telosb install.(node id) bsl,(Comport) • Ex) make telosb install.5 bsl,/dev/ttyUSB0 • Type “motelist “ to check the com port number
Overall System Architecture PC (Java App) TelosB (Sensing) Id = 1 USB Zigbee TelosB (BaseStation) TelosB (Sensing) Id = 2 EXAMPLE: see TestSerial.java under $TOSROOT/apps/tests/TestSerial EXAMPLE: $TOSROOT/apps/Oscilloscope Sampler.zip in google group EXAMPLE: $TOSROOT/apps/BaseStation
Header file typedef nx_struct SenseMsg { nx_uint16_t sourceMoteID; // Queried mote id nx_uint16_t datatype; // Data type = temperature, humidity, // or light nx_uint16_t data; // Sensingdata } SenseMsg; enum { AM_SENSEMSG = 100, };
AM (Active Message) format • Destination address (2 bytes) • Link source address (2 bytes) • Message length (1 byte) • Group ID (1 byte) • Active Message handler type (1 byte) • Payload (up to 28 bytes): • Use SenseMsg structure Call AMSend.getPayload(……)
AM_SENSEMSG = 100 In configuration file (~AppC.nc) components new AMSenderC(AM_SENSEMSG); components new AMReceiverC(AM_SENSEMSG); In java file (~Msg.java) /** The Active Message type associated with this message. */ public static final int AM_TYPE = 100;
Getting multiple packets for one request • You might get multiple packets after sending one request • Check the sender id and data type whether they match with the request you sent. • Check whether there are other telosb motes with the same ID. • Check whether you create multiple listeners. public TestSerial(MoteIF moteIF) { this.moteIF = moteIF; this.moteIF.registerListener(new TestSerialMsg(), this); } // Invoked when a message arrives public void messageReceived(int toaddr, Message msg) { ... }
Creating multiple listeners MoteIF mif = new MoteIF(phoenix); TestSerial serial = new TestSerial(mif); While (!quit) { …….. serial.sendPackets(); …….. } MoteIF mif = new MoteIF(phoenix); While (!quit) { TestSerial serial = new TestSerial(mif); ……… serial.sendPackets(); ……… } Create listener
Tips for using TestSerial.java • Change the header file (TestSerial.h) • Type “make telosb” • Makefile includes TestSerialMsg.java: mig java -target=null $(CFLAGS) -java-classname=TestSerialMsg TestSerial.h test_serial_msg -o $@ • Check TestSerialMsg.java You will see set_sourceMoteID(), get_sourceMoteID() etc.