Friday, April 22, 2011

Mobile Device Capabilities / Simple Device Discovery / Alien

  • I'm testing what kind of characteristics do the virtual devices provided in the J2ME framework have.

[sourcecode language="java"]

package org.rene;

import javax.microedition.midlet.*;

* @author rene
import javax.microedition.midlet.*;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.util.Resources;
import javax.bluetooth.BluetoothConnectionException;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.DiscoveryAgent;

public class DeviceProps extends MIDlet {

public void startApp() {
//init the LWUIT Display
try {
Resources r ="/LWUITtheme.res");
} catch ( e) {
System.out.println("Theme not found");
Form f = new Form();
f.setTitle("Local Device Props");
f.setLayout(new BoxLayout(BoxLayout.Y_AXIS));

public void pauseApp() {

public void destroyApp(boolean unconditional) {

* Displays the bluetooth device information on the screen
* @param f the form to display the information on
private void getBluetoothInfo(Form f) {
LocalDevice local = null;
//Retrieve the local bluetooth device object
try {
local = LocalDevice.getLocalDevice();

} catch (BluetoothStateException e) {
f.addComponent(new Label("Failed to retrieve the local device ("
+ e.getMessage() + ")"));
//Retrieve the bluetooth address
f.addComponent(new Label("Address: " + local.getBluetoothAddress()));
//watch out -> could be null
f.addComponent(new Label("Name: " + local.getFriendlyName()));
f.addComponent(new Label("API version: " + local.getProperty("bluetooth.api.version")));
int mode = local.getDiscoverable();
StringBuffer text = new StringBuffer("Discoverable Mode: ");
switch (mode) {
case DiscoveryAgent.GIAC:
case DiscoveryAgent.LIAC:
case DiscoveryAgent.NOT_DISCOVERABLE:
text.append("Not Discoverable");
text.append(Integer.toString(mode, 16));
f.addComponent(new Label(text.toString()));
f.addComponent(new Label("Master Switch Supported : "
+ local.getProperty("bluetooth.master.switch")));
f.addComponent(new Label("Max Attributes : "
+ local.getProperty("")));
f.addComponent(new Label("Max Connected Devices : "
+ local.getProperty("bluetooth.connected.devices.max")));
f.addComponent(new Label("Max Receive MTU : "
+ local.getProperty("bluetooth.l2cap.receiveMTU.max")));
f.addComponent(new Label("Max Service Discovery Transactions : "
+ local.getProperty("")));
f.addComponent(new Label("Connection options: "));
f.addComponent(new Label("Inquiry Scan Supported : "
+ local.getProperty("bluetooth.connected.inquiry.scan")));
f.addComponent(new Label("Page Scan Supported : "
+ local.getProperty("")));
f.addComponent(new Label("Inquiry Supported : "
+ local.getProperty("bluetooth.connected.inquiry")));
f.addComponent(new Label("Page Supported : "
+ local.getProperty("")));



[caption id="attachment_236" align="aligncenter" width="138" caption="Virtual Device Capabilities"][/caption]

  1. Discoverable mode: General. It means that this device responds only to general inquiries. (Whilst limited mode enabled devices respond to both general and limited inquiries)

  2. Master Switch Supported: true. The application can ask the device to change from master to slave and vice versa within a connection. Why does this matter?  Well, once defined a master it could form what's called a piconet (a small network) with up to 7 slaves which share the master's clock. This magic number suits me very well as I'm planing to support up to eight players.

  3. Max Attributes: 10. This has to do with service records. I'll find out more when I study service discovery.

  4. Max Connected Devices : 7. Reference to the piconet.

  5. Max Receive MTU: 512. Maximum Transmission Unit. In some forums talk about setting this size, I need to do some research latter related to the option of living it alone or tweaking it for performance of possible.

  6. Max Service Discovery Transactions : 5. keyword -> Concurrent, which is not bad at all.

  7. Inquiry Scan Supported: false. This device cannot respond to an inquiry request while it has established a link to another device.

  8. Page Scan Supported: false. It cannot accept a connection from a new remote device if it is already connected to another remote device.

  9. Inquiry Supported: false. It cannot start an inquiry while it's connected to another device.

  10. Page Supported: false. It cannot establish a connection to a remote device if it's already connected to another device.

  • So this device is very limited in the connectivity aspect. I'm adopting the pessimistic approach  and I will consider that all devices are like this, in order to aim for a fail-prove communication architecture. This is where the engineering stuff comes into play, in the designing and implementation of  subtle workarounds.

  • Some concepts on establishing communication:

[caption id="attachment_237" align="aligncenter" width="300" caption="SimpleDeviceDiscovery"][/caption]

This is just an introduction, the real thing comes with inquiries but it's ok for  warming up.

  • I like xmind very much to make brainmaps and conceptual maps but it's only available on its prepackage from in .deb format. I could build it from source, but I wanted to use an utility called alien to transform deb packages into rpm packages and conversely.
this does the trick:
[sourcecode language="bash"]

alien -r -c xmind-


and then you just install the generated rpm package as usual.

No comments:

Post a Comment