Changeset 3cde4f5 in subsurface


Ignore:
Timestamp:
Jul 4, 2017, 7:46:07 AM (6 months ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
2693735
Parents:
709c1df
git-author:
Jan Mulder <jlmulder@…> (07/04/17 07:40:33)
git-committer:
Dirk Hohndel <dirk@…> (07/04/17 07:46:07)
Message:

Address code review

Addresses code review by Dirk. No functional changes.

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

Location:
core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • core/qt-ble.cpp

    r709c1df r3cde4f5  
    2323#define BLE_TIMEOUT 12000 // 12 seconds seems like a very long time to wait
    2424
     25#define IS_HW(_d) same_string((_d)->vendor, "Heinrichs Weikamp")
     26#define IS_SHEARWATER(_d) same_string((_d)->vendor, "Shearwater")
     27
    2528extern "C" {
    26 
    27 static int device_is_hw(dc_user_device_t *device);
    2829
    2930void waitFor(int ms) {
     
    5859void BLEObject::characteristcStateChanged(const QLowEnergyCharacteristic &c, const QByteArray &value)
    5960{
    60         if (device_is_hw(device)) {
     61        if (IS_HW(device)) {
    6162                if (c.uuid() == hwAllCharacteristics[HW_OSTC_BLE_DATA_TX]) {
    6263                        receivedPackets.append(value);
     
    6566                }
    6667        } else {
    67             receivedPackets.append(value);
     68                receivedPackets.append(value);
    6869        }
    6970        //qDebug() << ".. incoming packet count" << receivedPackets.length();
     
    7273void BLEObject::characteristicWritten(const QLowEnergyCharacteristic &c, const QByteArray &value)
    7374{
    74         if (device_is_hw(device)) {
     75        if (IS_HW(device)) {
    7576                if (c.uuid() == hwAllCharacteristics[HW_OSTC_BLE_CREDITS_RX]) {
    7677                        qDebug() << "HW_OSTC_BLE_CREDITS_RX confirmed" << c.uuid() << value.toHex();
     
    9596        bool isStandardUuid = false;
    9697        newService.toUInt16(&isStandardUuid);
    97         if (device_is_hw(device)) {
     98        if (IS_HW(device)) {
    9899                /* The HW BT/BLE piece or hardware uses, what we
    99100                 * call here, "a Standard UUID. It is standard because the Telit/Stollmann
     
    132133}
    133134
    134 /* Yeah, I could do the C++ inline member thing */
    135 static int device_is_shearwater(dc_user_device_t *device)
    136 {
    137         return !strcmp(device->vendor, "Shearwater");
    138 }
    139 
    140 static int device_is_hw(dc_user_device_t *device)
    141 {
    142         return !strcmp(device->vendor, "Heinrichs Weikamp");
    143 }
    144 
    145135dc_status_t BLEObject::write(const void *data, size_t size, size_t *actual)
    146136{
     
    162152                        QLowEnergyService::WriteWithResponse;
    163153
    164                 if (device_is_shearwater(device))
     154                if (IS_SHEARWATER(device))
    165155                        bytes.prepend("\1\0", 2);
    166156
     
    193183        int offset = 0;
    194184        while (!receivedPackets.isEmpty()) {
     185                /*
     186                 * Yes, to while loops with same condition seems strange. The inner one
     187                 * does the real work, but it prevents the QtEventloop to do its thing.
     188                 * As the incoming packets arrive based on signals and slots, that
     189                 * stuff is not handeled during the inner loop. So, add a short waitFor
     190                 * between the inner and outer while loop.
     191                 */
    195192                while (!receivedPackets.isEmpty()) {
    196193                        QByteArray packet = receivedPackets.takeFirst();
    197194
    198                         if (device_is_shearwater(device))
     195                        if (IS_SHEARWATER(device))
    199196                                packet.remove(0,2);
    200197
     
    215212}
    216213
    217 int BLEObject::setupHwTerminalIo(QList<QLowEnergyCharacteristic> allC)
     214dc_status_t BLEObject::setupHwTerminalIo(QList<QLowEnergyCharacteristic> allC)
    218215{       /* This initalizes the Terminal I/O client as described in
    219216         * http://www.telit.com/fileadmin/user_upload/products/Downloads/sr-rf/BlueMod/TIO_Implementation_Guide_r04.pdf
     
    258255
    259256        /* And give to OSTC some time to get initialized */
    260         int msec = 5000;
     257        int msec = BLE_TIMEOUT;
    261258        while (msec > 0 && !isCharacteristicWritten) {
    262259                waitFor(100);
     
    291288        qDebug() << "qt_ble_open(" << devaddr << ")";
    292289
    293         if (device_is_shearwater(io->user_device))
     290        if (IS_SHEARWATER(io->user_device))
    294291                controller->setRemoteAddressType(QLowEnergyController::RandomAddress);
    295292
     
    363360                const QLowEnergyCharacteristic &c = list.constLast();
    364361
    365                 if (device_is_hw(io->user_device)) {
    366                         ble->setupHwTerminalIo(list);
     362                if (IS_HW(io->user_device)) {
     363                        dc_status_t r = ble->setupHwTerminalIo(list);
     364                        if (r != DC_STATUS_SUCCESS)
     365                                return r;
    367366                } else {
    368367                        QList<QLowEnergyDescriptor> l = c.descriptors();
  • core/qt-ble.h

    rd6b17fe r3cde4f5  
    3232        void characteristicWritten(const QLowEnergyCharacteristic &c, const QByteArray &value);
    3333        void writeCompleted(const QLowEnergyDescriptor &d, const QByteArray &value);
    34         int setupHwTerminalIo(QList<QLowEnergyCharacteristic>);
     34        dc_status_t setupHwTerminalIo(QList<QLowEnergyCharacteristic>);
    3535private:
    3636        QVector<QLowEnergyService *> services;
Note: See TracChangeset for help on using the changeset viewer.