Skip to content

Commit

Permalink
Android SerialPort work.
Browse files Browse the repository at this point in the history
Still not working right...
  • Loading branch information
dogmaphobic committed Apr 23, 2015
1 parent c3c6d32 commit 54c8a34
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 135 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ public static UsbSerialDriver findFirstDevice(final UsbManager usbManager) {
*/
public static List<UsbSerialDriver> findAllDevices(final UsbManager usbManager) {
final List<UsbSerialDriver> result = new ArrayList<UsbSerialDriver>();
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;
Expand Down
14 changes: 4 additions & 10 deletions android/src/org/qgroundcontrol/qgchelper/UsbDeviceJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ else if (driverL instanceof ProlificSerialDriver)
tempL = tempL + Integer.toString(deviceL.getVendorId()) + ":";
listL[countL] = tempL;
countL++;
Log.i(TAG, "Found " + tempL);
//Log.i(TAG, "Found " + tempL);
}
}

Expand Down Expand Up @@ -260,6 +260,7 @@ public static int open(String nameA, int userDataA)

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)
Expand All @@ -273,7 +274,6 @@ public void onReceive(Context contextA, Intent intentA)
{
if (m_userData.containsKey(deviceL.getDeviceId()))
{
// UsbDeviceJNI.close(deviceL.getDeviceId());
nativeDeviceHasDisconnected(m_userData.get(deviceL.getDeviceId()));
}
}
Expand All @@ -294,6 +294,7 @@ public void onReceive(Context contextA, Intent intentA)
Log.e(TAG, "UsbIoManager instance is null");
m_ioManager.put(idL, managerL);
m_Executor.submit(managerL);
Log.i(TAG, "Port open successfull");
return idL;
}
}
Expand All @@ -312,13 +313,11 @@ public void onReceive(Context contextA, Intent intentA)

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)
Expand All @@ -334,8 +333,6 @@ public static void startIoManager(int idA)
m_Executor.submit(managerL);
}



public static void stopIoManager(int idA)
{
if(m_ioManager.get(idA) == null)
Expand All @@ -345,9 +342,6 @@ public static void stopIoManager(int idA)
m_ioManager.remove(idA);
}




///////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Sets the parameters on an open port.
Expand Down
12 changes: 6 additions & 6 deletions libs/qtandroidserialport/src/qserialport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
** Copyright (C) 2011 Sergey Belyashov <[email protected]>
** Copyright (C) 2012 Laszlo Papp <[email protected]>
** Copyright (C) 2012 Andre Hartmann <[email protected]>
** 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.
**
Expand All @@ -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
Expand All @@ -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$
Expand Down
12 changes: 6 additions & 6 deletions libs/qtandroidserialport/src/qserialport.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
**
** Copyright (C) 2012 Denis Shienkov <[email protected]>
** Copyright (C) 2013 Laszlo Papp <[email protected]>
** 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.
**
Expand All @@ -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
Expand All @@ -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$
Expand Down
82 changes: 37 additions & 45 deletions libs/qtandroidserialport/src/qserialport_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,32 @@
** Copyright (C) 2012 Denis Shienkov <[email protected]>
** Copyright (C) 2012 Laszlo Papp <[email protected]>
** Copyright (C) 2012 Andre Hartmann <[email protected]>
** 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$
**
****************************************************************************/
Expand Down Expand Up @@ -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<jint>(
V_jniClassName,
"open",
"(Ljava/lang/String;I)I",
jnameL.object<jstring>(),
(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<jint>(
V_jniClassName,
"getDeviceHandle",
"(I)I",
deviceId);

if (!hasRegisteredFunctions)
{
// REGISTER THE C++ FUNCTION WITH JNI
Expand All @@ -155,7 +124,7 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)

QAndroidJniObject javaClassL(V_jniClassName);
jclass objectClassL = envL->GetObjectClass(javaClassL.object<jobject>());
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;

Expand All @@ -169,6 +138,29 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
}
}

QAndroidJniObject jnameL = QAndroidJniObject::fromString(systemLocation);
deviceId = QAndroidJniObject::callStaticMethod<jint>(
V_jniClassName,
"open",
"(Ljava/lang/String;I)I",
jnameL.object<jstring>(),
(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<jint>(
V_jniClassName,
"getDeviceHandle",
"(I)I",
deviceId);

if (rwMode == QIODevice::WriteOnly)
stopReadThread();

Expand Down
12 changes: 6 additions & 6 deletions libs/qtandroidserialport/src/qserialport_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** Copyright (C) 2011-2012 Denis Shienkov <[email protected]>
** Copyright (C) 2011 Sergey Belyashov <[email protected]>
** Copyright (C) 2012 Laszlo Papp <[email protected]>
** 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.
**
Expand All @@ -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
Expand All @@ -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$
Expand Down
12 changes: 6 additions & 6 deletions libs/qtandroidserialport/src/qserialportinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
** Copyright (C) 2011-2012 Denis Shienkov <[email protected]>
** Copyright (C) 2011 Sergey Belyashov <[email protected]>
** Copyright (C) 2012 Laszlo Papp <[email protected]>
** 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.
**
Expand All @@ -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
Expand All @@ -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$
Expand Down
12 changes: 6 additions & 6 deletions libs/qtandroidserialport/src/qserialportinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
**
** Copyright (C) 2012 Denis Shienkov <[email protected]>
** Copyright (C) 2012 Laszlo Papp <[email protected]>
** 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.
**
Expand All @@ -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
Expand All @@ -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$
Expand Down
Loading

0 comments on commit 54c8a34

Please sign in to comment.