Hi Nicole,
You can register multiple listeners. In Java there is a feature called
anonymous class, which might be useful in this case. I haven't tested
the following code, it should just give you an idea of how this could be
done:
-------
public void init() {
// ...
PhoenixSource ps = BuildSource.makePhoenix(comm,
PrintStreamMessenger.err);
MoteIF mif = new MoteIF(ps);
mif.registerListener(new MsgType1(), new MessageListener() {
public void messageReceived(int to, Message msg) {
handlerType1(to, msg);
}
});
mif.registerListener(new MsgType2(), new MessageListener() {
public void messageReceived(int to, Message msg) {
handlerType2(to, msg);
}
});
// ...
}
// handler for the first message type
private void handlerType1(int to, Message msg) {
// handler code here
}
// handler for the second message type
private void handlerType2(int to, Message msg) {
// handler code here
}
-------
As you can see, two MessageListeners are registered for two different
message types. Instead of explicitly having two different classes
implementing the MessageListener interface (which is also possible), an
anonymous class (because it doesn't have a name) is created from the
interface definition. It is a subclass of the current class, therefore
it can call the current class' methods.
Cheers,
Urs
Nicole Neureiter wrote:
Hi,
i'm trying to create a java program to communicate with my motes on which a
protocol is implemented. Till now I only used to send and receive one message
type between pc and motes which was no problem at all. But I need to send a
second message type from the mote to the pc in the same programm and that is my
problem.
I tried to create a second modeIF but it did not work. Anyone an idea?
Thanks
Nicole
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help