Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
48417668
Commit
48417668
authored
Oct 18, 2015
by
Don Gagne
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2034 from DonLakeFlyer/AndroidSerial
Fix native function setting in android serial port
parents
736a861f
0c251d79
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
42 deletions
+66
-42
UsbDeviceJNI.java
android/src/org/qgroundcontrol/qgchelper/UsbDeviceJNI.java
+0
-1
qserialport.cpp
libs/qtandroidserialport/src/qserialport.cpp
+6
-0
qserialport.h
libs/qtandroidserialport/src/qserialport.h
+2
-0
qserialport_android.cpp
libs/qtandroidserialport/src/qserialport_android.cpp
+37
-40
qserialport_android_p.h
libs/qtandroidserialport/src/qserialport_android_p.h
+2
-1
main.cc
src/main.cc
+19
-0
No files found.
android/src/org/qgroundcontrol/qgchelper/UsbDeviceJNI.java
View file @
48417668
...
...
@@ -79,7 +79,6 @@ public class UsbDeviceJNI extends QtActivity
}
};
// NATIVE C++ FUNCTION THAT WILL BE CALLED IF THE DEVICE IS UNPLUGGED
private
static
native
void
nativeDeviceHasDisconnected
(
int
userDataA
);
private
static
native
void
nativeDeviceException
(
int
userDataA
,
String
messageA
);
...
...
libs/qtandroidserialport/src/qserialport.cpp
View file @
48417668
...
...
@@ -1370,6 +1370,12 @@ void QSerialPort::setError(QSerialPort::SerialPortError serialPortError, const Q
emit
error
(
serialPortError
);
}
void
QSerialPort
::
setNativeMethods
(
void
)
{
QSerialPortPrivate
::
setNativeMethods
();
}
#include "moc_qserialport.cpp"
QT_END_NAMESPACE
libs/qtandroidserialport/src/qserialport.h
View file @
48417668
...
...
@@ -247,6 +247,8 @@ public:
Handle
handle
()
const
;
static
void
setNativeMethods
(
void
);
Q_SIGNALS:
void
baudRateChanged
(
qint32
baudRate
,
QSerialPort
::
Directions
directions
);
void
dataBitsChanged
(
QSerialPort
::
DataBits
dataBits
);
...
...
libs/qtandroidserialport/src/qserialport_android.cpp
View file @
48417668
...
...
@@ -106,7 +106,6 @@ QSerialPortPrivate::QSerialPortPrivate(QSerialPort *q)
,
isCustomBaudRateSupported
(
false
)
,
emittedBytesWritten
(
false
)
,
pendingBytesWritten
(
0
)
,
hasRegisteredFunctions
(
false
)
,
jniDataBits
(
8
)
,
jniStopBits
(
1
)
,
jniParity
(
0
)
...
...
@@ -115,6 +114,43 @@ QSerialPortPrivate::QSerialPortPrivate(QSerialPort *q)
{
}
void
QSerialPortPrivate
::
setNativeMethods
(
void
)
{
__android_log_print
(
ANDROID_LOG_INFO
,
kJTag
,
"Registering Native Functions"
);
// REGISTER THE C++ FUNCTION WITH JNI
JNINativeMethod
javaMethods
[]
{
{
"nativeDeviceHasDisconnected"
,
"(I)V"
,
reinterpret_cast
<
void
*>
(
jniDeviceHasDisconnected
)},
{
"nativeDeviceNewData"
,
"(I[B)V"
,
reinterpret_cast
<
void
*>
(
jniDeviceNewData
)},
{
"nativeDeviceException"
,
"(ILjava/lang/String;)V"
,
reinterpret_cast
<
void
*>
(
jniDeviceException
)}
};
QAndroidJniEnvironment
jniEnv
;
if
(
jniEnv
->
ExceptionCheck
())
{
jniEnv
->
ExceptionDescribe
();
jniEnv
->
ExceptionClear
();
}
jclass
objectClass
=
jniEnv
->
FindClass
(
kJniClassName
);
if
(
!
objectClass
)
{
__android_log_print
(
ANDROID_LOG_ERROR
,
kJTag
,
"Couldn't find class: %s"
,
kJniClassName
);
return
;
}
jint
val
=
jniEnv
->
RegisterNatives
(
objectClass
,
javaMethods
,
sizeof
(
javaMethods
)
/
sizeof
(
javaMethods
[
0
]));
__android_log_print
(
ANDROID_LOG_INFO
,
kJTag
,
"Native Functions Registered"
);
if
(
jniEnv
->
ExceptionCheck
())
{
jniEnv
->
ExceptionDescribe
();
jniEnv
->
ExceptionClear
();
}
if
(
val
<
0
)
{
__android_log_print
(
ANDROID_LOG_ERROR
,
kJTag
,
"Error registering methods"
);
}
}
bool
QSerialPortPrivate
::
open
(
QIODevice
::
OpenMode
mode
)
{
rwMode
=
mode
;
...
...
@@ -140,45 +176,6 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
return
false
;
}
if
(
!
hasRegisteredFunctions
)
{
__android_log_print
(
ANDROID_LOG_INFO
,
kJTag
,
"Registering Native Functions"
);
// REGISTER THE C++ FUNCTION WITH JNI
JNINativeMethod
javaMethods
[]
{
{
"nativeDeviceHasDisconnected"
,
"(I)V"
,
reinterpret_cast
<
void
*>
(
jniDeviceHasDisconnected
)},
{
"nativeDeviceNewData"
,
"(I[B)V"
,
reinterpret_cast
<
void
*>
(
jniDeviceNewData
)},
{
"nativeDeviceException"
,
"(ILjava/lang/String;)V"
,
reinterpret_cast
<
void
*>
(
jniDeviceException
)}
};
QAndroidJniEnvironment
jniEnv
;
if
(
jniEnv
->
ExceptionCheck
())
{
jniEnv
->
ExceptionDescribe
();
jniEnv
->
ExceptionClear
();
}
QAndroidJniObject
javaClass
(
kJniClassName
);
if
(
!
javaClass
.
isValid
())
{
__android_log_print
(
ANDROID_LOG_ERROR
,
kJTag
,
"Java class %s not valid"
,
kJniClassName
);
return
false
;
}
jclass
objectClass
=
jniEnv
->
GetObjectClass
(
javaClass
.
object
<
jobject
>
());
jint
val
=
jniEnv
->
RegisterNatives
(
objectClass
,
javaMethods
,
sizeof
(
javaMethods
)
/
sizeof
(
javaMethods
[
0
]));
jniEnv
->
DeleteLocalRef
(
objectClass
);
hasRegisteredFunctions
=
true
;
__android_log_print
(
ANDROID_LOG_INFO
,
kJTag
,
"Native Functions Registered"
);
if
(
jniEnv
->
ExceptionCheck
())
{
jniEnv
->
ExceptionDescribe
();
jniEnv
->
ExceptionClear
();
}
if
(
val
<
0
)
{
__android_log_print
(
ANDROID_LOG_ERROR
,
kJTag
,
"Error registering methods"
);
q_ptr
->
setError
(
QSerialPort
::
OpenError
);
return
false
;
}
}
__android_log_print
(
ANDROID_LOG_INFO
,
kJTag
,
"Calling Java getDeviceHandle"
);
cleanJavaException
();
descriptor
=
QAndroidJniObject
::
callStaticMethod
<
jint
>
(
...
...
libs/qtandroidserialport/src/qserialport_android_p.h
View file @
48417668
...
...
@@ -108,10 +108,11 @@ public:
qint64
pendingBytesWritten
;
static
void
setNativeMethods
(
void
);
private:
QIODevice
::
OpenMode
rwMode
;
int
deviceId
;
bool
hasRegisteredFunctions
;
int
jniDataBits
;
int
jniStopBits
;
int
jniParity
;
...
...
src/main.cc
View file @
48417668
...
...
@@ -86,6 +86,25 @@ int WindowsCrtReportHook(int reportType, char* message, int* returnValue)
#endif
#ifdef __android__
#include <jni.h>
#include "qserialport.h"
jint
JNI_OnLoad
(
JavaVM
*
vm
,
void
*
reserved
)
{
Q_UNUSED
(
reserved
);
JNIEnv
*
env
;
if
(
vm
->
GetEnv
(
reinterpret_cast
<
void
**>
(
&
env
),
JNI_VERSION_1_6
)
!=
JNI_OK
)
{
return
-
1
;
}
QSerialPort
::
setNativeMethods
();
return
JNI_VERSION_1_6
;
}
#endif
/**
* @brief Starts the application
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment