Changeset 6fe0388 in subsurface


Ignore:
Timestamp:
Jul 4, 2017, 7:46:07 AM (2 weeks ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
f6768ced
Parents:
40d85b5
git-author:
Jan Mulder <jlmulder@…> (07/03/17 10:24:39)
git-committer:
Dirk Hohndel <dirk@…> (07/04/17 07:46:07)
Message:

OSTC over BLE: initialize Terminal I/O client

This initalizes the Terminal I/O client as described in paragraph 3 of
http://www.telit.com/fileadmin/user_upload/products/Downloads/sr-rf/BlueMod/TIO_Implementation_Guide_r04.pdf

This is for all Heinrichs Weikamp computers, that use referenced BT/BLE hardware
module from Telit Wireless Solutions (Formerly Stollmann E+V GmbH). The 16 bit
UUID 0xFEFB (or a derived 128 bit UUID starting with 0x0000FEFB is a
clear indication that the OSTC is equipped with this BT/BLE hardware.
Furthermore, most devices equipped with this BT/BLE hardware have BT addresses
starting with 00:80:25:...

Signed-off-by: Jan Mulder <jlmulder@…>

Location:
core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • core/qt-ble.cpp

    rbc1a313 r6fe0388  
    44#include <QtBluetooth/QBluetoothAddress>
    55#include <QLowEnergyController>
     6#include <QLowEnergyService>
    67#include <QCoreApplication>
    78#include <QElapsedTimer>
     
    2324
    2425extern "C" {
     26
     27static int device_is_hw(dc_user_device_t *device);
    2528
    2629void waitFor(int ms) {
     
    107110}
    108111
     112static int device_is_hw(dc_user_device_t *device)
     113{
     114        return !strcmp(device->vendor, "Heinrichs Weikamp");
     115}
     116
    109117dc_status_t BLEObject::write(const void *data, size_t size, size_t *actual)
    110118{
     
    161169        memcpy(data, packet.data(), size);
    162170        *actual = size;
     171        return DC_STATUS_SUCCESS;
     172}
     173
     174int BLEObject::setupHwTerminalIo(QList<QLowEnergyCharacteristic> allC)
     175{       /* This initalizes the Terminal I/O client as described in
     176         * http://www.telit.com/fileadmin/user_upload/products/Downloads/sr-rf/BlueMod/TIO_Implementation_Guide_r04.pdf
     177         * Referenced section numbers below are from that document.
     178         *
     179         * This is for all HW computers, that use referenced BT/BLE hardware module from Telit
     180         * (formerly Stollmann). The 16 bit UUID 0xFEFB (or a derived 128 bit UUID starting with
     181         * 0x0000FEFB is a clear indication that the OSTC is equipped with this BT/BLE hardware.
     182         */
     183
     184        if (allC.length() != 4) {
     185                qDebug() << "This should not happen. HW/OSTC BT/BLE device without 4 Characteristics";
     186                return DC_STATUS_IO;
     187        }
     188
     189        /* The Terminal I/O client subscribes to indications of the UART credits TX
     190         * characteristic (see 6.4).
     191         *
     192         * Notice that indications are subscribed to by writing 0x0200 to its descriptor. This
     193         * can be understood by looking for Client Characteristic Configuration, Assigned
     194         * Number: 0x2902. Enabling/Disabeling is setting the proper bit, and they
     195         * differ for indications and notifications.
     196         */
     197        QLowEnergyDescriptor d = allC[HW_OSTC_BLE_CREDITS_TX].descriptors().first();
     198        preferredService()->writeDescriptor(d, QByteArray::fromHex("0200"));
     199
     200        /* The Terminal I/O client subscribes to notifications of the UART data TX
     201         * characteristic (see 6.2).
     202         */
     203        d = allC[HW_OSTC_BLE_DATA_TX].descriptors().first();
     204        preferredService()->writeDescriptor(d, QByteArray::fromHex("0100"));
     205
     206        /* The Terminal I/O client transmits initial UART credits to the server (see 6.5).
     207         *
     208         * Notice that we have to write to the characteristic here, and not to its
     209         * descriptor as for the enabeling of notifications or indications.
     210         */
     211        isCharacteristicWritten = false;
     212        preferredService()->writeCharacteristic(allC[HW_OSTC_BLE_CREDITS_RX],
     213                                                QByteArray(1, 255),
     214                                                QLowEnergyService::WriteWithResponse);
     215
     216        /* And give to OSTC some time to get initialized */
     217        int msec = 5000;
     218        while (msec > 0 && !isCharacteristicWritten) {
     219                waitFor(100);
     220                msec -= 100;
     221        };
     222        if (!isCharacteristicWritten)
     223                return DC_STATUS_TIMEOUT;
     224
    163225        return DC_STATUS_SUCCESS;
    164226}
     
    257319        if (!list.isEmpty()) {
    258320                const QLowEnergyCharacteristic &c = list.constLast();
    259                 QList<QLowEnergyDescriptor> l = c.descriptors();
    260 
    261                 qDebug() << "Descriptor list with" << l.length() << "elements";
    262 
    263                 QLowEnergyDescriptor d;
    264                 foreach(d, l)
    265                         qDebug() << "Descriptor:" << d.name() << "uuid:" << d.uuid().toString();
    266 
    267 
    268                 if (!l.isEmpty()) {
    269                         d = l.first();
    270                         qDebug() << "now writing \"0x0100\" to the first descriptor";
    271 
    272                         ble->preferredService()->writeDescriptor(d, QByteArray::fromHex("0100"));
     321
     322                if (device_is_hw(io->user_device)) {
     323                        ble->setupHwTerminalIo(list);
     324                } else {
     325                        QList<QLowEnergyDescriptor> l = c.descriptors();
     326
     327                        qDebug() << "Descriptor list with" << l.length() << "elements";
     328
     329                        QLowEnergyDescriptor d;
     330                        foreach(d, l)
     331                                qDebug() << "Descriptor:" << d.name() << "uuid:" << d.uuid().toString();
     332
     333                        if (!l.isEmpty()) {
     334                                d = l.first();
     335                                qDebug() << "now writing \"0x0100\" to the first descriptor";
     336
     337                                ble->preferredService()->writeDescriptor(d, QByteArray::fromHex("0100"));
     338                        }
    273339                }
    274340        }
  • core/qt-ble.h

    r5265956 r6fe0388  
    66#include <QLowEnergyController>
    77#include <QEventLoop>
     8
     9#define HW_OSTC_BLE_DATA_RX     0
     10#define HW_OSTC_BLE_DATA_TX     1
     11#define HW_OSTC_BLE_CREDITS_RX  2
     12#define HW_OSTC_BLE_CREDITS_TX  3
    813
    914class BLEObject : public QObject
     
    2631        void characteristcStateChanged(const QLowEnergyCharacteristic &c, const QByteArray &value);
    2732        void writeCompleted(const QLowEnergyDescriptor &d, const QByteArray &value);
    28 
     33        int setupHwTerminalIo(QList<QLowEnergyCharacteristic>);
    2934private:
    3035        QVector<QLowEnergyService *> services;
     
    3338        QList<QByteArray> receivedPackets;
    3439        QEventLoop waitForPacket;
     40        bool isCharacteristicWritten;
    3541        dc_user_device_t *device;
     42
     43        QList<QUuid> hwAllCharacteristics = {
     44                "{00000001-0000-1000-8000-008025000000}", // HW_OSTC_BLE_DATA_RX
     45                "{00000002-0000-1000-8000-008025000000}", // HW_OSTC_BLE_DATA_TX
     46                "{00000003-0000-1000-8000-008025000000}", // HW_OSTC_BLE_CREDITS_RX
     47                "{00000004-0000-1000-8000-008025000000}"  // HW_OSTC_BLE_CREDITS_TX
     48        };
    3649};
    3750
Note: See TracChangeset for help on using the changeset viewer.