dbus-java for Bluetooth HDP

Jim Connors james.connors at oracle.com
Fri Jul 15 10:33:36 PDT 2011


Santiago,

Thank you very much for your reply.  I've already spent a decent amount 
of time on this; the thought of digging deep into DBus and dbus-java 
isn't very appealing, not to mention my qualifications to do so.   The 
requirement for Java comes from the ability to seamlessly integrate with 
the wealth of Java back-end software.   Just curious if you or anyone on 
this alias has an opinion on the notion of taking the Python HDP code 
and running it in a Jython environment.  This would rehost the software 
to a Java Virtual Machine and make Java back-end integration 
straightforward.

Thanks,
-- Jim C

On 7/15/2011 3:38 AM, Santiago Perez wrote:
> Hi Jim.
> I have tried to develop a X73 Manager for a Blood Pressure Monitor 
> with BT HDP and Java, but nowadays the Java binding doesn't support 
> the datatype "File Descriptor".
>
> A file descriptor is needed because is the way in which the device 
> sends data to the manager. It is defined in the "health API" doc of 
> bluez, the org.bluez.HealthChannel interface has the method "fd 
> Acquire()" (fd: file descriptor).
>
> The Java binding's author (Matthew Johnson dbus at matthew.ath.cx 
> <mailto:dbus at matthew.ath.cx>) said to me that he cannot to incorporate 
> that datatype at the moment. I tried it, but it isn't easy...
>
> Anyway, related to your code I see a few things:
> - You have to work with a dBus connection for the current Session, no 
> with the dBus system... way? I don't know. I just know that the 
> Bluetooth HDP only creates the HealthManager in the dBus Session, not 
> in the dBus System...
> - You don't need to get the remote object for the dBus connection!
>
> This is my code and it works, I hope it is useful for you:
>
> Cheers,
> Santiago
>
> -------------
>
>
> *//Getting a DBus connection
> *try {
>  dbusConn = DBusConnection.getConnection(*DBusConnection.SESSION*);
> } catch (DBusException e) {
>  throw new 
> BusinessRuleException(BusinessRuleError.ERROR_CONNECTION_DBUS, 
> errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_CONNECTION_DBUS)));
> }
> if(dbusConn == null)
> {
>  throw new 
> BusinessRuleException(BusinessRuleError.ERROR_CONNECTION_DBUS, 
> errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_CONNECTION_DBUS))); 
>
> }
>
> *//Getting the HealthManager object
> *try {
>  bluezHealthManager = dbusConn.getRemoteObject("org.bluez", 
> "/org/bluez", org.bluez.HealthManager.class);
> } catch (DBusException e) {
>  throw new 
> BusinessRuleException(BusinessRuleError.ERROR_HEALTHMANAGER_BLUEZ, 
> errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_HEALTHMANAGER_BLUEZ)));
> }
> if(bluezHealthManager == null)
> {
>  throw new 
> BusinessRuleException(BusinessRuleError.ERROR_HEALTHMANAGER_BLUEZ, 
> errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_HEALTHMANAGER_BLUEZ))); 
>
> }
>
> *//Registering the X73 Manager for a Blood Pressure Monitor in dBus
> *Map<String, Variant> dictionary = new HashMap<String, Variant>();
>
> UInt16 managerType = new UInt16(0x1007);
> dictionary.put("DataType", new Variant(managerType));
> dictionary.put("Role",new Variant(strRole));
> dictionary.put("Description",new Variant(strDescription));
> dictionary.put("ChannelType",new Variant(strChannelType));
>
> Path managerPath = null;
> managerPath = bluezHealthManager.CreateApplication(dictionary);
> if(managerPath == null)
> {
>  throw new 
> BusinessRuleException(BusinessRuleError.ERROR_REGISTER_X73MANAGER_DBUS, errorBundle.getString(Integer.toString(BusinessRuleError.ERROR_REGISTER_X73MANAGER_DBUS))); 
>
> }
>
>
>
> *The HealthManager interface in Java is defined as:*
>
> package org.bluez;
> import java.util.Map;
>
> import org.freedesktop.dbus.DBusInterface;
> import org.freedesktop.dbus.Path;
> import org.freedesktop.dbus.Variant;
>
> public interface HealthManager extends DBusInterface
> {
>   public Path CreateApplication(Map<String,Variant> dic);
>   public void DestroyApplication(Path o);
> }
>
>
>
> ---------------
>
>
> > Date: Thu, 14 Jul 2011 17:21:46 -0400
> > From: james.connors at oracle.com
> > To: dbus at lists.freedesktop.org
> > Subject: dbus-java for Bluetooth HDP
> >
> > 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
> >
> > _______________________________________________
> > dbus mailing list
> > dbus at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/dbus
>
>
> _______________________________________________
> dbus mailing list
> dbus at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dbus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20110715/fe5a62f8/attachment.html>


More information about the dbus mailing list