2

Bluetooth Health Device Profile (具体的には、Nonin Onyx II 9560BT) を使用して、デバイスから測定値を取得しようとしています。このガイドを使用して、dbus 経由で python を使用してこれを行うことができました。現在、これを C++ に移植しようとしています。すでにアプリケーションで QT を使用しているため、QT DBus バインディングを使用しています。

これまでのところ、この APIに基づいてテストするための次の短いプログラムにたどり着きました。

#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtCore/QStringList>
#include <QtDBus/QtDBus>

int main(int argc, char **argv)
{
    QCoreApplication app(argc, argv);

    if (!QDBusConnection::sessionBus().isConnected()) {
        fprintf(stderr, "Cannot connect to the D-Bus session bus.\n"
                "To start it, run:\n"
                "\teval `dbus-launch --auto-syntax`\n");
        return 1;
    }

    QDBusInterface iface("org.bluez","/org/bluez","org.bluez.HealthManager",QDBusConnection::systemBus(),0);

    QVariantMap map;
    map.insert("DataType",ushort(1004));//same result with simply 1004
    map.insert("Role","Sink");
    map.insert("Description","HDP Test Manager"); //Optional
    //map.insert("ChannelType","Reliable");//Optional, same result with or without
    //QList<QVariant> argumentList;
    //argumentList.append(map);

    QDBusPendingReply<> r = iface.call("CreateApplication",map);

    qDebug() << r.reply();
    qDebug() << r.error();
    return 0;
}

私が知る限り、「CreateApplication」によって取得された dict オブジェクトは、QT では QVariantMap に対応する a{sv} に対応します。ただし、次のエラーが発生し続けます。

QDBusMessage(type=Error, service="", error name="org.bluez.Error.InvalidArguments", error message="Invalid arguments in method call", signature="", contents=([]) )

質問: 何が間違っていますか? freedesktop.org のガイド、qt ドキュメント、強力な google に基づいて、これは私が得た限りです。

助けてくれてありがとう!

/Keyz182

4

1 に答える 1

1

今は動作します。ushort(0x1004)がQVariantによってintにキャストされていたため、bluezコードによってuint32として取得されていたようですが、これは予期されていたものではありません。

それを修正するために、私は次のことをしました(別の方法があるかもしれませんが、これは私にとってはうまくいきました)。

ushortのメタタイプ宣言を追加して登録しました。次に、値を含むQVariantを作成し、QVariants convertメソッドを使用して、メタタイプをushort(またはdbusに公開されている場合はuint16)として設定しました。

#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtCore/QStringList>
#include <QtDBus/QtDBus>

Q_DECLARE_METATYPE(ushort); //Added this to declare ushort as a metatype

int main(int argc, char **argv)
{
    QCoreApplication app(argc, argv);

    int ushorttype = qDBusRegisterMetaType<ushort>(); //Register the ushort metatype and get it's id

    if (!QDBusConnection::sessionBus().isConnected()) {
        fprintf(stderr, "Cannot connect to the D-Bus session bus.\n"
                "To start it, run:\n"
                "\teval `dbus-launch --auto-syntax`\n");
        return 1;
    }

    QDBusInterface iface("org.bluez","/org/bluez","org.bluez.HealthManager",QDBusConnection::systemBus(),0);

    QVariant dt(0x1004);
    dt.convert((QVariant::Type)ushorttype); //convert to the new type

    QVariantMap map;
    map.insert("DataType",dt);
    map.insert("Role","Sink");
    map.insert("Description","HDP Test Manager"); //Optional

    QDBusPendingReply<> r = iface.call("CreateApplication",map);

    qDebug() << r.isValid();
    qDebug() << r.reply();
    return 0;
}
于 2011-02-18T13:51:57.987 に答える