net.tinyos.message
Class MoteIF

java.lang.Object
  extended bynet.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 receiver
           
protected  Sender sender
           
protected  PhoenixSource source
           
static int TOS_BCAST_ADDR
          The destination address for a broadcast.
 
Constructor Summary
MoteIF()
          Create a new mote interface to packet source specified using the MOTECOM environment variable.
MoteIF(Messenger messages)
          Create a new mote interface to packet source specified 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.

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 specified 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 specified 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)
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 different template type if it wishes (the only requirement is that m.getType() matches the received message).

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