dbus-java for Bluetooth HDP
Jim Connors
james.connors at oracle.com
Thu Jul 14 14:21:46 PDT 2011
Hello,
I'm trying to use dbus-java to communicate with a bluetooth Heathcare
Device Profile (HDP) cpmpliant pulse oxymiter. There has been some work
demonstrating this capability with the Python dbus binding, but next to
nothing on the Java front from what I see. Not being a Python
aficionado, trying to map the Python stuff over to Java isn't working
out too well. The example below attempts to make a remote invocation
on a method called CreateApplication() as specified by the following
interface:
package org.bluez;
import java.util.Map;
import org.freedesktop.dbus.DBusInterface;
import org.freedesktop.dbus.Variant;
public interface HealthManager extends DBusInterface
{
public DBusInterface CreateApplication(Map<String,Variant> a);
public void DestroyApplication(DBusInterface a);
}
The simple application below throws a DBusExecution exception when
reaching the CreateApplication() method call:
package testhdp;
import java.util.Map;
import java.util.HashMap;
import org.freedesktop.DBus;
import org.freedesktop.dbus.DBusConnection;
import org.freedesktop.dbus.DBusInterface;
import org.freedesktop.dbus.Variant;
import org.freedesktop.dbus.UInt16;
import org.bluez.Manager;
import org.bluez.HealthManager;
import org.freedesktop.DBus.Introspectable;
class TestHDP {
public static void main(String[] args) throws
org.freedesktop.dbus.exceptions.DBusException {
DBusConnection conn =
DBusConnection.getConnection(DBusConnection.SYSTEM);
DBus dbus = conn.getRemoteObject(
"org.freedesktop.DBus", "/org/freedesktop/DBus",
DBus.class);
String ORG_BLUEZ = "org.bluez";
System.out.print("Searching dbus.ListNames() return for " +
"\"" + ORG_BLUEZ + "\": ");
String[] names = dbus.ListNames();
boolean bluezFound = false;
for (String name: names)
if (name.equals(ORG_BLUEZ)) {
bluezFound = true;
break;
}
if (bluezFound)
System.out.println(ORG_BLUEZ + " found.");
else
System.out.println(ORG_BLUEZ + " not found.");
Manager m = (Manager) conn.getRemoteObject("org.bluez", "/",
Manager.class);
System.out.println(m.toString());
Map<String, Variant> props = m.GetProperties();
HealthManager hm = (HealthManager) conn.getRemoteObject(
"org.bluez", "/org/bluez", HealthManager.class);
System.out.println(hm.toString());
Map<String, Variant> config = new HashMap<String, Variant>();
config.put("DataType", new Variant<UInt16>(new UInt16(0x1004)));
config.put("Role", new Variant<String>("Sink"));
config.put("Description", new Variant<String>("Oximeter Sink"));
DBusInterface app = hm.CreateApplication(config);
conn.disconnect();
}
}
Output is as follows:
Searching dbus.ListNames() return for "org.bluez": org.bluez found.
org.bluez:/:interface org.bluez.Manager
org.bluez:/org/bluez:interface org.bluez.HealthManager
Exception in thread "main"
org.freedesktop.dbus.exceptions.DBusExecutionException: Wrong return
type (failed to de-serialize correct types: Failed to create proxy
object for /org/bluez/health_app_30 exported by :1.51. Reason: Could not
find an interface to cast to )
at org.freedesktop.dbus.RemoteInvocationHandler.convertRV(Unknown
Source)
at
org.freedesktop.dbus.RemoteInvocationHandler.executeRemoteMethod(Unknown
Source)
at org.freedesktop.dbus.RemoteInvocationHandler.invoke(Unknown Source)
at $Proxy2.CreateApplication(Unknown Source)
at testhdp.TestHDP.main(TestHDP.java:66)
Any guidance would be greatly appreciated.
Thanks,
Jim Connors
More information about the dbus
mailing list