programming assignment 2 cse535: mobile computing (fall 2010)

11

Upload: alison-terry

Post on 04-Jan-2016

220 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Programming Assignment 2 CSE535: Mobile Computing (Fall 2010)
Page 2: Programming Assignment 2 CSE535: Mobile Computing (Fall 2010)

Environmental Setup IssuesEnvironmental 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.

Page 3: Programming Assignment 2 CSE535: Mobile Computing (Fall 2010)

Multiple JRE installation IssuesMultiple 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

Page 4: Programming Assignment 2 CSE535: Mobile Computing (Fall 2010)

Compile and Install a codeCompile 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

Page 5: Programming Assignment 2 CSE535: Mobile Computing (Fall 2010)

Overall System ArchitectureOverall System Architecture

TelosB(BaseStation)

PC(Java App)

TelosB(Sensing)

Id = 1

TelosB(Sensing)

Id = 2

USB

EXAMPLE: see TestSerial.java under $TOSROOT/apps/tests/TestSerial

EXAMPLE: $TOSROOT/apps/BaseStation

EXAMPLE: $TOSROOT/apps/OscilloscopeSampler.zip in google group

Zigbee

Page 6: Programming Assignment 2 CSE535: Mobile Computing (Fall 2010)

Header fileHeader 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,

};

Page 7: Programming Assignment 2 CSE535: Mobile Computing (Fall 2010)

AM (Active Message) formatAM (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(……)

Page 8: Programming Assignment 2 CSE535: Mobile Computing (Fall 2010)

AM_SENSEMSG = 100AM_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;

Page 9: Programming Assignment 2 CSE535: Mobile Computing (Fall 2010)

Getting multiple packets for one Getting multiple packets for one requestrequest

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) { ... }

Page 10: Programming Assignment 2 CSE535: Mobile Computing (Fall 2010)

Creating multiple listenersCreating 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

Page 11: Programming Assignment 2 CSE535: Mobile Computing (Fall 2010)

Tips for using TestSerial.javaTips 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.