Programming with Mundo

In this assignment you will learn how to use the MundoCore communication middleware and how to write and simulate a small context-aware application.

1. Installing and Configuring MundoCore

Now compile and run the chat sample program:

Start two instances of the chat program and check that they communicate with each other. The program can be exited by entering only . on a line.

Note: More information about MundoCore can be found here: http://leda.tk.informatik.tu-darmstadt.de/cgi-bin/twiki/view/Mundo

2. Installing WorldView

Now create a map with three rooms, add a Ubisense controller, and three tags:

Now you can simulate the Ubisense system with one instance of WorldView and monitor it with another one.

3. Receiving Ubisense Messages

In this exercise you will learn how to receive messages using the publish/subscribe system. Write a small console program that receives and prints Ubisense messages, sent by WorldView. To create a new project in Eclipse, perform the following steps:

Complete the following program, compile, and run it:

public class UbisenseTest extends DefaultApplication implements IReceiver
{
  @Override
  public void init()
  {
    super.init();
    session.subscribe("lan", "ubisense", this);
  }
  public void received(Message msg, MessageContext ctx) // IReceiver
  {
    TypedMap m = msg.getMap("main", "passive").getMap("object");
    System.out.println(m);
  }
  public static void main(String args[])
  {
    start(new UbisenseTest());
  }
}

When you now simulate the Ubisense system with WorldView, your program should print coordinates to the console.

Next, extend this program with formatted output. Use the method getString of TypedMap to obtain the tag name. Use getMap to obtain the nested map p and then read the coordinates x and y from it with getDouble.

4. Controlling a Lamp

In this exercise you will learn how to make Remote Method Calls (RMCs) to services using MundoCore. Write a small console program that reads input from the console and controls a lamp, simulated by WorldView. When you type 0 on the console, the lamp should be turned off, and when you type 1 on the console, then the lamp should be turned on.

Create a new project:

Add the following import statement to your program. The @mcImport tag will instruct the precompiler (mcc) to generate the lamp interface and client stub from the WSDL interface description of the Lamp-Service:

//@mcImport
import org.mundo.bas.ILamp;
import org.mundo.bas.DoILamp;

Now run the ant buildfile by selecting Run As > Ant Build. ILamp and DoILamp should appear in the subdirectory prep.

In the init method, create a distributed object and connect it:

doLamp = new DoILamp(); 
Signal.connect(doLamp, session.publish("lan", channelName));

You can now use the setState method to switch the lamp on or off. Hint: You can look at the source code of the chat example program to see how to read input from the console.

Next, model a lamp in WorldView and test your application:

5. Context-Aware Lightswitch

In WorldView, put a lamp into each of your three rooms. Write a program that controls these lamps. If at least one tag is located inside a room, then automatically turn the corresponding light on. If a room is empty, then turn the light off.

Note: In this step you can hardcode the coordinates of the rooms in your program.

6. Context-Aware Lightswitch 2.0

Extend your program to use the World Model Store Service to obtain the coordinates of rooms.

Starting the WMStore service:

Call select("MapRect") on WMStoreService to obtain all rectangles in the map.





Dr. Erwin Aitenbichler, 26.08.2009