From 54c8a349659b0618da96e8ac3349a6fa250afeb5 Mon Sep 17 00:00:00 2001 From: dogmaphobic Date: Thu, 23 Apr 2015 15:34:52 -0400 Subject: [PATCH] Android SerialPort work. Still not working right... --- .../usbserial/driver/UsbSerialProber.java | 4 +- .../qgchelper/UsbDeviceJNI.java | 14 +--- libs/qtandroidserialport/src/qserialport.cpp | 12 +-- libs/qtandroidserialport/src/qserialport.h | 12 +-- .../src/qserialport_android.cpp | 82 +++++++++---------- libs/qtandroidserialport/src/qserialport_p.h | 12 +-- .../src/qserialportinfo.cpp | 12 +-- .../qtandroidserialport/src/qserialportinfo.h | 12 +-- .../src/qserialportinfo_android.cpp | 70 ++++++++-------- .../src/qserialportinfo_p.h | 12 +-- .../src/qtandroidserialport.pri | 2 - src/comm/SerialLink.cc | 28 ++++++- 12 files changed, 137 insertions(+), 135 deletions(-) diff --git a/android/src/com/hoho/android/usbserial/driver/UsbSerialProber.java b/android/src/com/hoho/android/usbserial/driver/UsbSerialProber.java index 0cfb366e4..2e25a761e 100644 --- a/android/src/com/hoho/android/usbserial/driver/UsbSerialProber.java +++ b/android/src/com/hoho/android/usbserial/driver/UsbSerialProber.java @@ -162,10 +162,10 @@ public enum UsbSerialProber { */ public static List findAllDevices(final UsbManager usbManager) { final List result = new ArrayList(); - Log.i("QGC_UsbSerialProber", "Looking for USB devices"); + //Log.i("QGC_UsbSerialProber", "Looking for USB devices"); // For each UsbDevice, call probe() for each prober. for (final UsbDevice usbDevice : usbManager.getDeviceList().values()) { - Log.i("QGC_UsbSerialProber", "Probing device: " + usbDevice.getDeviceName() + " mid: " + usbDevice.getVendorId() + " pid: " + usbDevice.getDeviceId()); + //Log.i("QGC_UsbSerialProber", "Probing device: " + usbDevice.getDeviceName() + " mid: " + usbDevice.getVendorId() + " pid: " + usbDevice.getDeviceId()); result.addAll(probeSingleDevice(usbManager, usbDevice)); } return result; diff --git a/android/src/org/qgroundcontrol/qgchelper/UsbDeviceJNI.java b/android/src/org/qgroundcontrol/qgchelper/UsbDeviceJNI.java index 79d2597a1..cd43b1442 100644 --- a/android/src/org/qgroundcontrol/qgchelper/UsbDeviceJNI.java +++ b/android/src/org/qgroundcontrol/qgchelper/UsbDeviceJNI.java @@ -199,7 +199,7 @@ public class UsbDeviceJNI extends QtActivity tempL = tempL + Integer.toString(deviceL.getVendorId()) + ":"; listL[countL] = tempL; countL++; - Log.i(TAG, "Found " + tempL); + //Log.i(TAG, "Found " + tempL); } } @@ -260,6 +260,7 @@ public class UsbDeviceJNI extends QtActivity if (m_instance.m_UsbReceiver == null) { + Log.i(TAG, "Creating new broadcast receiver"); m_instance.m_UsbReceiver= new BroadcastReceiver() { public void onReceive(Context contextA, Intent intentA) @@ -273,7 +274,6 @@ public class UsbDeviceJNI extends QtActivity { if (m_userData.containsKey(deviceL.getDeviceId())) { -// UsbDeviceJNI.close(deviceL.getDeviceId()); nativeDeviceHasDisconnected(m_userData.get(deviceL.getDeviceId())); } } @@ -294,6 +294,7 @@ public class UsbDeviceJNI extends QtActivity Log.e(TAG, "UsbIoManager instance is null"); m_ioManager.put(idL, managerL); m_Executor.submit(managerL); + Log.i(TAG, "Port open successfull"); return idL; } } @@ -312,13 +313,11 @@ public class UsbDeviceJNI extends QtActivity m_ioManager.remove(idL); } - + Log.e(TAG, "Port open exception"); return BAD_PORT; } } - - public static void startIoManager(int idA) { if (m_ioManager.get(idA) != null) @@ -334,8 +333,6 @@ public class UsbDeviceJNI extends QtActivity m_Executor.submit(managerL); } - - public static void stopIoManager(int idA) { if(m_ioManager.get(idA) == null) @@ -345,9 +342,6 @@ public class UsbDeviceJNI extends QtActivity m_ioManager.remove(idA); } - - - /////////////////////////////////////////////////////////////////////////////////////////////////////// // // Sets the parameters on an open port. diff --git a/libs/qtandroidserialport/src/qserialport.cpp b/libs/qtandroidserialport/src/qserialport.cpp index 992f06bfc..54cbee2e2 100644 --- a/libs/qtandroidserialport/src/qserialport.cpp +++ b/libs/qtandroidserialport/src/qserialport.cpp @@ -4,7 +4,7 @@ ** Copyright (C) 2011 Sergey Belyashov ** Copyright (C) 2012 Laszlo Papp ** Copyright (C) 2012 Andre Hartmann -** Contact: http://www.qt-project.org/legal +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialPort module of the Qt Toolkit. ** @@ -13,9 +13,9 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -26,8 +26,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/libs/qtandroidserialport/src/qserialport.h b/libs/qtandroidserialport/src/qserialport.h index c637a3f79..e1b6aea92 100644 --- a/libs/qtandroidserialport/src/qserialport.h +++ b/libs/qtandroidserialport/src/qserialport.h @@ -2,7 +2,7 @@ ** ** Copyright (C) 2012 Denis Shienkov ** Copyright (C) 2013 Laszlo Papp -** Contact: http://www.qt-project.org/legal +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialPort module of the Qt Toolkit. ** @@ -11,9 +11,9 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -24,8 +24,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/libs/qtandroidserialport/src/qserialport_android.cpp b/libs/qtandroidserialport/src/qserialport_android.cpp index 53b64440d..e422fd60a 100644 --- a/libs/qtandroidserialport/src/qserialport_android.cpp +++ b/libs/qtandroidserialport/src/qserialport_android.cpp @@ -3,40 +3,32 @@ ** Copyright (C) 2012 Denis Shienkov ** Copyright (C) 2012 Laszlo Papp ** Copyright (C) 2012 Andre Hartmann -** Contact: http://www.qt-project.org/legal +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialPort module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -119,29 +111,6 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) rwMode = mode; __android_log_print(ANDROID_LOG_INFO, V_TAG, "Opening %s", systemLocation.toLatin1().data()); - QAndroidJniObject jnameL = QAndroidJniObject::fromString(systemLocation); - deviceId = QAndroidJniObject::callStaticMethod( - V_jniClassName, - "open", - "(Ljava/lang/String;I)I", - jnameL.object(), - (jint)this); - - isReadStopped = false; - - if (deviceId == BAD_PORT) - { - __android_log_print(ANDROID_LOG_ERROR, V_TAG, "Error opening %s", systemLocation.toLatin1().data()); - q_ptr->setError(QSerialPort::DeviceNotFoundError); - return false; - } - - descriptor = QAndroidJniObject::callStaticMethod( - V_jniClassName, - "getDeviceHandle", - "(I)I", - deviceId); - if (!hasRegisteredFunctions) { // REGISTER THE C++ FUNCTION WITH JNI @@ -155,7 +124,7 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) QAndroidJniObject javaClassL(V_jniClassName); jclass objectClassL = envL->GetObjectClass(javaClassL.object()); - jint valL = envL->RegisterNatives(objectClassL, methodsL, sizeof(methodsL) / sizeof(methodsL[0])); + jint valL = envL->RegisterNatives(objectClassL, methodsL, sizeof(methodsL) / sizeof(JNINativeMethod)); envL->DeleteLocalRef(objectClassL); hasRegisteredFunctions = true; @@ -169,6 +138,29 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) } } + QAndroidJniObject jnameL = QAndroidJniObject::fromString(systemLocation); + deviceId = QAndroidJniObject::callStaticMethod( + V_jniClassName, + "open", + "(Ljava/lang/String;I)I", + jnameL.object(), + (jint)this); + + isReadStopped = false; + + if (deviceId == BAD_PORT) + { + __android_log_print(ANDROID_LOG_ERROR, V_TAG, "Error opening %s", systemLocation.toLatin1().data()); + q_ptr->setError(QSerialPort::DeviceNotFoundError); + return false; + } + + descriptor = QAndroidJniObject::callStaticMethod( + V_jniClassName, + "getDeviceHandle", + "(I)I", + deviceId); + if (rwMode == QIODevice::WriteOnly) stopReadThread(); diff --git a/libs/qtandroidserialport/src/qserialport_p.h b/libs/qtandroidserialport/src/qserialport_p.h index 3ba91b9b2..7bbdaaa7c 100644 --- a/libs/qtandroidserialport/src/qserialport_p.h +++ b/libs/qtandroidserialport/src/qserialport_p.h @@ -3,7 +3,7 @@ ** Copyright (C) 2011-2012 Denis Shienkov ** Copyright (C) 2011 Sergey Belyashov ** Copyright (C) 2012 Laszlo Papp -** Contact: http://www.qt-project.org/legal +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialPort module of the Qt Toolkit. ** @@ -12,9 +12,9 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -25,8 +25,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/libs/qtandroidserialport/src/qserialportinfo.cpp b/libs/qtandroidserialport/src/qserialportinfo.cpp index 26b275d6d..be3eed17c 100644 --- a/libs/qtandroidserialport/src/qserialportinfo.cpp +++ b/libs/qtandroidserialport/src/qserialportinfo.cpp @@ -3,7 +3,7 @@ ** Copyright (C) 2011-2012 Denis Shienkov ** Copyright (C) 2011 Sergey Belyashov ** Copyright (C) 2012 Laszlo Papp -** Contact: http://www.qt-project.org/legal +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialPort module of the Qt Toolkit. ** @@ -12,9 +12,9 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -25,8 +25,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/libs/qtandroidserialport/src/qserialportinfo.h b/libs/qtandroidserialport/src/qserialportinfo.h index 6fe1662e8..099656a5b 100644 --- a/libs/qtandroidserialport/src/qserialportinfo.h +++ b/libs/qtandroidserialport/src/qserialportinfo.h @@ -2,7 +2,7 @@ ** ** Copyright (C) 2012 Denis Shienkov ** Copyright (C) 2012 Laszlo Papp -** Contact: http://www.qt-project.org/legal +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialPort module of the Qt Toolkit. ** @@ -11,9 +11,9 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -24,8 +24,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/libs/qtandroidserialport/src/qserialportinfo_android.cpp b/libs/qtandroidserialport/src/qserialportinfo_android.cpp index 50db905fc..fe711088a 100644 --- a/libs/qtandroidserialport/src/qserialportinfo_android.cpp +++ b/libs/qtandroidserialport/src/qserialportinfo_android.cpp @@ -3,40 +3,32 @@ ** Copyright (C) 2011-2012 Denis Shienkov ** Copyright (C) 2011 Sergey Belyashov ** Copyright (C) 2012 Laszlo Papp -** Contact: http://www.qt-project.org/legal +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialPort module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL$ +** $QT_BEGIN_LICENSE:LGPL21$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** ** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -56,11 +48,11 @@ QT_BEGIN_NAMESPACE static const char V_jniClassName[] {"org/qgroundcontrol/qgchelper/UsbDeviceJNI"}; static const char V_TAG[] {"QGC_QSerialPortInfo"}; -QList availablePortsByFiltersOfDevices() +QList availablePortsByFiltersOfDevices(bool &ok) { QList serialPortInfoList; - __android_log_print(ANDROID_LOG_INFO, V_TAG, "Collecting device list"); + //__android_log_print(ANDROID_LOG_INFO, V_TAG, "Collecting device list"); QAndroidJniObject resultL = QAndroidJniObject::callStaticObjectMethod( V_jniClassName, "availableDevicesInfo", @@ -68,6 +60,7 @@ QList availablePortsByFiltersOfDevices() if (!resultL.isValid()) { __android_log_print(ANDROID_LOG_ERROR, V_TAG, "Error from availableDevicesInfo"); + ok = false; return serialPortInfoList; } @@ -75,24 +68,24 @@ QList availablePortsByFiltersOfDevices() jobjectArray objArrayL = resultL.object(); int countL = envL->GetArrayLength(objArrayL); - for (int iL=0; iLGetObjectArrayElement(objArrayL, iL)); const char *rawStringL = envL->GetStringUTFChars(stringL, 0); - __android_log_print(ANDROID_LOG_INFO, V_TAG, "Adding device: %s", rawStringL); + //__android_log_print(ANDROID_LOG_INFO, V_TAG, "Adding device: %s", rawStringL); QStringList strListL = QString::fromUtf8(rawStringL).split(QStringLiteral(":")); envL->ReleaseStringUTFChars(stringL, rawStringL); - infoL.d_ptr->portName = strListL[0]; - infoL.d_ptr->device = strListL[0]; - infoL.d_ptr->manufacturer = strListL[1]; - infoL.d_ptr->productIdentifier = strListL[2].toInt(); - infoL.d_ptr->hasProductIdentifier = (infoL.d_ptr->productIdentifier != 0) ? true: false; - infoL.d_ptr->vendorIdentifier = strListL[3].toInt(); - infoL.d_ptr->hasVendorIdentifier = (infoL.d_ptr->vendorIdentifier != 0) ? true: false; + priv.portName = strListL[0]; + priv.device = strListL[0]; + priv.manufacturer = strListL[1]; + priv.productIdentifier = strListL[2].toInt(); + priv.hasProductIdentifier = (priv.productIdentifier != 0) ? true: false; + priv.vendorIdentifier = strListL[3].toInt(); + priv.hasVendorIdentifier = (priv.vendorIdentifier != 0) ? true: false; - serialPortInfoList.append(infoL); + serialPortInfoList.append(priv); } return serialPortInfoList; @@ -100,17 +93,20 @@ QList availablePortsByFiltersOfDevices() QList availablePortsBySysfs() { - return availablePortsByFiltersOfDevices(); + bool ok; + return availablePortsByFiltersOfDevices(ok); } QList availablePortsByUdev() { - return availablePortsByFiltersOfDevices(); + bool ok; + return availablePortsByFiltersOfDevices(ok); } QList QSerialPortInfo::availablePorts() { - return availablePortsByFiltersOfDevices(); + bool ok; + return availablePortsByFiltersOfDevices(ok); } QList QSerialPortInfo::standardBaudRates() diff --git a/libs/qtandroidserialport/src/qserialportinfo_p.h b/libs/qtandroidserialport/src/qserialportinfo_p.h index c9f108638..5a15dcfeb 100644 --- a/libs/qtandroidserialport/src/qserialportinfo_p.h +++ b/libs/qtandroidserialport/src/qserialportinfo_p.h @@ -3,7 +3,7 @@ ** Copyright (C) 2011-2012 Denis Shienkov ** Copyright (C) 2011 Sergey Belyashov ** Copyright (C) 2012 Laszlo Papp -** Contact: http://www.qt-project.org/legal +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtSerialPort module of the Qt Toolkit. ** @@ -12,9 +12,9 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -25,8 +25,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ diff --git a/libs/qtandroidserialport/src/qtandroidserialport.pri b/libs/qtandroidserialport/src/qtandroidserialport.pri index 9bf07c0ad..d3d98a0ba 100644 --- a/libs/qtandroidserialport/src/qtandroidserialport.pri +++ b/libs/qtandroidserialport/src/qtandroidserialport.pri @@ -21,8 +21,6 @@ android { CONFIG += mobility - INCLUDEPATH += $$PWD/qt4support/include - HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS } diff --git a/src/comm/SerialLink.cc b/src/comm/SerialLink.cc index 9cd1f2b3f..d998badb0 100644 --- a/src/comm/SerialLink.cc +++ b/src/comm/SerialLink.cc @@ -93,6 +93,7 @@ bool SerialLink::_isBootloader() **/ void SerialLink::run() { +#ifndef __android__ // Initialize the connection if (!_hardwareConnect(_type)) { // Need to error out here. @@ -103,6 +104,7 @@ void SerialLink::run() _emitLinkError("Error connecting: " + err); return; } +#endif qint64 msecs = QDateTime::currentMSecsSinceEpoch(); qint64 initialmsecs = QDateTime::currentMSecsSinceEpoch(); @@ -255,10 +257,13 @@ bool SerialLink::_disconnect(void) _stopp = true; } wait(); // This will terminate the thread and close the serial port - return true; + } else { + _transmitBuffer.clear(); //clear the output buffer to avoid sending garbage at next connect + qCDebug(SerialLinkLog) << "Already disconnected"; } - _transmitBuffer.clear(); //clear the output buffer to avoid sending garbage at next connect - qCDebug(SerialLinkLog) << "Already disconnected"; +#ifdef __android__ + LinkManager::instance()->suspendConfigurationUpdates(false); +#endif return true; } @@ -276,6 +281,19 @@ bool SerialLink::_connect(void) QMutexLocker locker(&this->_stoppMutex); _stopp = false; } +#ifdef __android__ + LinkManager::instance()->suspendConfigurationUpdates(true); + // Initialize the connection + if (!_hardwareConnect(_type)) { + // Need to error out here. + QString err("Could not create port."); + if (_port) { + err = _port->errorString(); + } + _emitLinkError("Error connecting: " + err); + return false; + } +#endif start(HighPriority); return true; } @@ -338,6 +356,9 @@ bool SerialLink::_hardwareConnect(QString &type) // After the bootloader times out, it still can take a second or so for the Pixhawk USB driver to come up and make // the port available for open. So we retry a few times to wait for it. +#ifdef __android__ + _port->open(QIODevice::ReadWrite); +#else for (int openRetries = 0; openRetries < 4; openRetries++) { if (!_port->open(QIODevice::ReadWrite)) { qCDebug(SerialLinkLog) << "Port open failed, retrying"; @@ -346,6 +367,7 @@ bool SerialLink::_hardwareConnect(QString &type) break; } } +#endif if (!_port->isOpen() ) { emit communicationUpdate(getName(),"Error opening port: " + _port->errorString()); _port->close(); -- 2.22.0