[Interest] How to send OBEX messages with QBluetoothSocket?

Edward Sutton edward.sutton at subsite.com
Tue Jun 14 14:59:08 CEST 2016


Hi Steve,
QBluetoothTransferManager Class
http://doc.qt.io/qt-5/qbluetoothtransfermanager.html


Since Qt runs on both laptops and smartphones, I was not clear which target was running Qt.

I use this to send firmware file updates to an embedded  Bluetooth device


/////////////////////////////////////////////////////////////////////////

/// \brief Implements OBEX file transfer using Qt framework supporting

///

///  Qt 5.6 framework QBluetoothTransferManager supports platforms:

///     - Linux

///     - OS X

///

/// Android has QBluetooth support, however does *not* have QBluetoothTransferManager support

///     - The Android implementation uses JNI to launch an Intent to Bluetooth Share.

///     - While this appraoch works it confuses users:

///         1. On updating a TK, the TSR app disappears.

///         2. A file share window appears with list of *every* device that had *ever* been paired.

///         3. User must quickly select the correct TK_000X destination within about 15 seconds.

///

void ConnectionPrivate::sendFileObex(const QString& pathToFileToSend,

                                            const QString& destinationPath)

{

    Q_UNUSED(destinationPath);


    // - Qt OSX can show send file progress

    // - Qt Android has no file progress feeback

    // - Windows 32 feet code has no file progress feeback

    TrackerConnectionPrivateData::stateTransition(TrackerConnection::TrackerStateFileSending);


    QBluetoothServiceInfo bluetoothServiceInfoDestination = m_mapServiceClassUuidToService[this->fileToSendBluetoothServiceClassUuidDestination];


    qDebug("OBEX push to: %s", bluetoothServiceInfoDestination.device().address().toString().toLatin1().data());


    QFileInfo fileInfoFileToSend(pathToFileToSend);

    qDebug("file.......: %s", fileInfoFileToSend.absoluteFilePath().toLatin1().data());

    qDebug("file size..: %i bytes", (int) fileInfoFileToSend.size());

    qDebug("isReadable.: %s", fileInfoFileToSend.isReadable() ? "true" : "false" );


    Q_ASSERT_X(fileInfoFileToSend.exists(),

               Q_FUNC_INFO,

               "Expected m_pdfPrinter == 0");


    // QBluetoothTransferManager is not supported on Android

    // QBluetoothTransferManager works for OSX and Linux

    QBluetoothTransferManager bluetoothTransferManager;

    QBluetoothTransferRequest bluetoothTransferRequest(bluetoothServiceInfoDestination.device().address());


    QFile* fileToSend = new QFile(pathToFileToSend);

    QBluetoothTransferReply *bluetoothTransferReply = bluetoothTransferManager.put(bluetoothTransferRequest, fileToSend);


    //bluetoothTransferManager is default parent

    //ensure that bluetoothTransferManager doesn't take reply down when leaving scope ( not sure why I did this or if needed )

    bluetoothTransferReply->setParent(this);


    if (bluetoothTransferReply->error())

    {

        this->bluetoothTransferReplyFinishedHandler(bluetoothTransferReply);

        bluetoothTransferReply->deleteLater();

        return;

    }


    connect(bluetoothTransferReply, SIGNAL(transferProgress(qint64,qint64)),

            this, SLOT(bluetoothTransferReplyUploadProgressHandler(qint64,qint64)));


    connect(bluetoothTransferReply, SIGNAL(finished(QBluetoothTransferReply*)),

            this, SLOT(bluetoothTransferReplyFinishedHandler(QBluetoothTransferReply*)));

}



On Jun 14, 2016, at 12:42 AM, Steffen Hollenbach <SteffenHollenbach at web.de<mailto:SteffenHollenbach at web.de>> wrote:


Hi,
I hope i am right here. I want to send OBEX messages from my laptop to my smartphone. The main goal is to get the contacts of my smartphone per PBAP (phonebook access profile).

For this I created in QT a QBluetoothSocket which opens a RFCOMM connection to my smartphone and connected it to the PBAP service of my smartphone.

Now i need to send a GET request and a message with headers and data. I know (I hope so) which header and belonging data I need, but I do not know how to send it to the socket.

The socket expects a const char *data parameter. What i need to send:

GET Request with Headers:

Header ID: Connection Id
Value: 1

Header ID: Name
Value: telecom/pb

Header ID: Type
Value: x-bt/vcard-listing


Can someone please help me how to create this data message and send it through the socket to my smartphone?
I use wireshark to check the data, but all i get is a malformed OBEX package or the laptop just sends an OBEX fragement, but no OBEX message.

Thank you.

_______________________________________________
Interest mailing list
Interest at qt-project.org<mailto:Interest at qt-project.org>
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.qt-2Dproject.org_mailman_listinfo_interest&d=CwICAg&c=G4BpsyPyB19LB50bn2swXw&r=cAG2c-SQES5P2qb8IW-uwnBOCX_f2qYJIlzenFnoHUc&m=PfOQ6pQpWi5ENKgWgtU-q42If3x5CSNMuSaptDpD3yQ&s=LZLSvcIxFOM1Z9eLri0av1OcWwAZ9Szvtf3Au03IowU&e=

This email and any files transmitted with it from The Charles Machine Works, Inc. are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error please notify the sender. Our company accepts no liability for the contents of this email, or for the consequences of any actions taken on the basis of the information provided, unless that information is subsequently confirmed in writing. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Finally, the recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160614/57e8706d/attachment.html>


More information about the Interest mailing list