You are on page 1of 5

MoteIF

http://www.tinyos.net/dist-2.0.0/tinyos-2.0.0/doc/j...

Overview Package Class Tree Serialized Deprecated Index Help


PREV CLASS NEXT CLASS SUMMARY: NESTED | FIELD | CONSTR | METHOD FRAMES NO FRAMES All Classes DETAIL: FIELD | CONSTR | METHOD

net.tinyos.message

Class MoteIF
java.lang.Object net.tinyos.message.MoteIF

public class MoteIF extends java.lang.Object MoteIF provides an application-level Java interface for receiving messages from, and sending messages to, a mote through a serial port, TCP connection, or some other means of connectivity. Generally this is used to write Java programs that connect over a TCP or serial port to communicate with a TOSBase or GenericBase mote. The default way to use MoteIF is to create an instance of this class and then register one or more MessageListener objects that will be invoked when messages arrive. For example:
MoteIF mif = new MoteIF(); mif.registerListener(new FooMsg(), this); // Invoked when a message arrives public void messageReceived(int toaddr, Message msg) { ... }

The default MoteIF constructor uses the MOTECOM environment variable to determine how the Java application connects to the mote. For example, a MOTECOM setting of "serial@COM1" connects to a base station using the serial port on COM1. You can also send messages through the base station mote using MoteIF.send(). See Also:
BuildSource

Field Summary
protected Receiver protected Sender

receiver

sender

1 of 5

03-08-2011 12:34

MoteIF

http://www.tinyos.net/dist-2.0.0/tinyos-2.0.0/doc/j...

protected PhoenixSource static int

source

TOS_BCAST_ADDR

The destination address for a broadcast.

Constructor Summary
MoteIF()

Create a new mote interface to packet source specied using the MOTECOM environment variable.
MoteIF(Messenger messages)

Create a new mote interface to packet source specied using the MOTECOM environment variable.
MoteIF(PhoenixSource source)

Create a new mote interface to an arbitrary packet source.

Method Summary
void

deregisterListener(Message m, MessageListener l)

Deregister a listener for a given message type.


PhoenixSource

getSource()

void

registerListener(Message m, MessageListener l)

Register a listener for given messages type.


void

send(int moteId, Message m)

Send m to moteId via this mote interface Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail
TOS_BCAST_ADDR
public static final int TOS_BCAST_ADDR

The destination address for a broadcast.

2 of 5

03-08-2011 12:34

MoteIF

http://www.tinyos.net/dist-2.0.0/tinyos-2.0.0/doc/j...

See Also: Constant Field Values

source
protected PhoenixSource source

sender
protected Sender sender

receiver
protected Receiver receiver

Constructor Detail
MoteIF
public MoteIF()

Create a new mote interface to packet source specied using the MOTECOM environment variable. Status and error messages will be printed to System.err.

MoteIF
public MoteIF(Messenger messages)

Create a new mote interface to packet source specied using the MOTECOM environment variable. Status and error messages will be printed to 'messages'. Parameters: messages - where to send status messages (null means no messages)

MoteIF
public MoteIF(PhoenixSource source)

3 of 5

03-08-2011 12:34

MoteIF

http://www.tinyos.net/dist-2.0.0/tinyos-2.0.0/doc/j...

Create a new mote interface to an arbitrary packet source. The packet source is started if necessary. Parameters: source - packet source to use

Method Detail
getSource
public PhoenixSource getSource()

Returns: this MoteIF's source

send
public void send(int moteId, Message m) throws java.io.IOException

Send m to moteId via this mote interface Parameters: moteId - message destination m - message Throws: java.io.IOException - thrown if message could not be sent

registerListener
public void registerListener(Message m, MessageListener l)

Register a listener for given messages type. The message m should be an instance of a subclass of Message (generated by mig). When a message of the corresponding type is received, a new instance of m's class is created with the received message as data. This message is then passed to the given MessageListener. Note that multiple MessageListeners can be registered for the same message type, and in fact each listener can use a dierent template type if it wishes (the only requirement is that m.getType() matches the received message).

4 of 5

03-08-2011 12:34

MoteIF

http://www.tinyos.net/dist-2.0.0/tinyos-2.0.0/doc/j...

Parameters: m - message template specifying which message to receive l - listener to which received messages are dispatched

deregisterListener
public void deregisterListener(Message m, MessageListener l)

Deregister a listener for a given message type. Parameters: m - message template specifying which message to receive l - listener to which received messages are dispatched Overview Package Class Tree Serialized Deprecated Index Help
PREV CLASS NEXT CLASS SUMMARY: NESTED | FIELD | CONSTR | METHOD FRAMES NO FRAMES All Classes DETAIL: FIELD | CONSTR | METHOD

5 of 5

03-08-2011 12:34

You might also like