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
0c251d79
Commit
0c251d79
authored
Oct 18, 2015
by
Don Gagne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix native function setting
parent
9fcdda7b
Changes
6
Show 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 @
0c251d79
...
@@ -79,7 +79,6 @@ public class UsbDeviceJNI extends QtActivity
...
@@ -79,7 +79,6 @@ public class UsbDeviceJNI extends QtActivity
}
}
};
};
// NATIVE C++ FUNCTION THAT WILL BE CALLED IF THE DEVICE IS UNPLUGGED
// NATIVE C++ FUNCTION THAT WILL BE CALLED IF THE DEVICE IS UNPLUGGED
private
static
native
void
nativeDeviceHasDisconnected
(
int
userDataA
);
private
static
native
void
nativeDeviceHasDisconnected
(
int
userDataA
);
private
static
native
void
nativeDeviceException
(
int
userDataA
,
String
messageA
);
private
static
native
void
nativeDeviceException
(
int
userDataA
,
String
messageA
);
...
...
libs/qtandroidserialport/src/qserialport.cpp
View file @
0c251d79
...
@@ -1370,6 +1370,12 @@ void QSerialPort::setError(QSerialPort::SerialPortError serialPortError, const Q
...
@@ -1370,6 +1370,12 @@ void QSerialPort::setError(QSerialPort::SerialPortError serialPortError, const Q
emit
error
(
serialPortError
);
emit
error
(
serialPortError
);
}
}
void
QSerialPort
::
setNativeMethods
(
void
)
{
QSerialPortPrivate
::
setNativeMethods
();
}
#include "moc_qserialport.cpp"
#include "moc_qserialport.cpp"
QT_END_NAMESPACE
QT_END_NAMESPACE
libs/qtandroidserialport/src/qserialport.h
View file @
0c251d79
...
@@ -247,6 +247,8 @@ public:
...
@@ -247,6 +247,8 @@ public:
Handle
handle
()
const
;
Handle
handle
()
const
;
static
void
setNativeMethods
(
void
);
Q_SIGNALS:
Q_SIGNALS:
void
baudRateChanged
(
qint32
baudRate
,
QSerialPort
::
Directions
directions
);
void
baudRateChanged
(
qint32
baudRate
,
QSerialPort
::
Directions
directions
);
void
dataBitsChanged
(
QSerialPort
::
DataBits
dataBits
);
void
dataBitsChanged
(
QSerialPort
::
DataBits
dataBits
);
...
...
libs/qtandroidserialport/src/qserialport_android.cpp
View file @
0c251d79
...
@@ -106,7 +106,6 @@ QSerialPortPrivate::QSerialPortPrivate(QSerialPort *q)
...
@@ -106,7 +106,6 @@ QSerialPortPrivate::QSerialPortPrivate(QSerialPort *q)
,
isCustomBaudRateSupported
(
false
)
,
isCustomBaudRateSupported
(
false
)
,
emittedBytesWritten
(
false
)
,
emittedBytesWritten
(
false
)
,
pendingBytesWritten
(
0
)
,
pendingBytesWritten
(
0
)
,
hasRegisteredFunctions
(
false
)
,
jniDataBits
(
8
)
,
jniDataBits
(
8
)
,
jniStopBits
(
1
)
,
jniStopBits
(
1
)
,
jniParity
(
0
)
,
jniParity
(
0
)
...
@@ -115,34 +114,10 @@ QSerialPortPrivate::QSerialPortPrivate(QSerialPort *q)
...
@@ -115,34 +114,10 @@ QSerialPortPrivate::QSerialPortPrivate(QSerialPort *q)
{
{
}
}
bool
QSerialPortPrivate
::
open
(
QIODevice
::
OpenMode
mode
)
void
QSerialPortPrivate
::
setNativeMethods
(
void
)
{
{
rwMode
=
mode
;
__android_log_print
(
ANDROID_LOG_INFO
,
kJTag
,
"Opening %s"
,
systemLocation
.
toLatin1
().
data
());
__android_log_print
(
ANDROID_LOG_INFO
,
kJTag
,
"Calling Java Open"
);
QAndroidJniObject
jnameL
=
QAndroidJniObject
::
fromString
(
systemLocation
);
cleanJavaException
();
deviceId
=
QAndroidJniObject
::
callStaticMethod
<
jint
>
(
kJniClassName
,
"open"
,
"(Ljava/lang/String;I)I"
,
jnameL
.
object
<
jstring
>
(),
(
jint
)
this
);
cleanJavaException
();
isReadStopped
=
false
;
if
(
deviceId
==
BAD_PORT
)
{
__android_log_print
(
ANDROID_LOG_ERROR
,
kJTag
,
"Error opening %s"
,
systemLocation
.
toLatin1
().
data
());
q_ptr
->
setError
(
QSerialPort
::
DeviceNotFoundError
);
return
false
;
}
if
(
!
hasRegisteredFunctions
)
{
__android_log_print
(
ANDROID_LOG_INFO
,
kJTag
,
"Registering Native Functions"
);
__android_log_print
(
ANDROID_LOG_INFO
,
kJTag
,
"Registering Native Functions"
);
// REGISTER THE C++ FUNCTION WITH JNI
// REGISTER THE C++ FUNCTION WITH JNI
JNINativeMethod
javaMethods
[]
{
JNINativeMethod
javaMethods
[]
{
{
"nativeDeviceHasDisconnected"
,
"(I)V"
,
reinterpret_cast
<
void
*>
(
jniDeviceHasDisconnected
)},
{
"nativeDeviceHasDisconnected"
,
"(I)V"
,
reinterpret_cast
<
void
*>
(
jniDeviceHasDisconnected
)},
...
@@ -156,15 +131,14 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
...
@@ -156,15 +131,14 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
jniEnv
->
ExceptionClear
();
jniEnv
->
ExceptionClear
();
}
}
QAndroidJniObject
java
Class
(
kJniClassName
);
jclass
objectClass
=
jniEnv
->
Find
Class
(
kJniClassName
);
if
(
!
javaClass
.
isValid
()
)
{
if
(
!
objectClass
)
{
__android_log_print
(
ANDROID_LOG_ERROR
,
kJTag
,
"Java class %s not valid
"
,
kJniClassName
);
__android_log_print
(
ANDROID_LOG_ERROR
,
kJTag
,
"Couldn't find class: %s
"
,
kJniClassName
);
return
false
;
return
;
}
}
jclass
objectClass
=
jniEnv
->
GetObjectClass
(
javaClass
.
object
<
jobject
>
());
jint
val
=
jniEnv
->
RegisterNatives
(
objectClass
,
javaMethods
,
sizeof
(
javaMethods
)
/
sizeof
(
javaMethods
[
0
]));
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"
);
__android_log_print
(
ANDROID_LOG_INFO
,
kJTag
,
"Native Functions Registered"
);
if
(
jniEnv
->
ExceptionCheck
())
{
if
(
jniEnv
->
ExceptionCheck
())
{
...
@@ -172,11 +146,34 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
...
@@ -172,11 +146,34 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
jniEnv
->
ExceptionClear
();
jniEnv
->
ExceptionClear
();
}
}
if
(
val
<
0
)
{
if
(
val
<
0
)
{
__android_log_print
(
ANDROID_LOG_ERROR
,
kJTag
,
"Error registering methods"
);
__android_log_print
(
ANDROID_LOG_ERROR
,
kJTag
,
"Error registering methods"
);
q_ptr
->
setError
(
QSerialPort
::
OpenError
);
return
false
;
}
}
}
bool
QSerialPortPrivate
::
open
(
QIODevice
::
OpenMode
mode
)
{
rwMode
=
mode
;
__android_log_print
(
ANDROID_LOG_INFO
,
kJTag
,
"Opening %s"
,
systemLocation
.
toLatin1
().
data
());
__android_log_print
(
ANDROID_LOG_INFO
,
kJTag
,
"Calling Java Open"
);
QAndroidJniObject
jnameL
=
QAndroidJniObject
::
fromString
(
systemLocation
);
cleanJavaException
();
deviceId
=
QAndroidJniObject
::
callStaticMethod
<
jint
>
(
kJniClassName
,
"open"
,
"(Ljava/lang/String;I)I"
,
jnameL
.
object
<
jstring
>
(),
(
jint
)
this
);
cleanJavaException
();
isReadStopped
=
false
;
if
(
deviceId
==
BAD_PORT
)
{
__android_log_print
(
ANDROID_LOG_ERROR
,
kJTag
,
"Error opening %s"
,
systemLocation
.
toLatin1
().
data
());
q_ptr
->
setError
(
QSerialPort
::
DeviceNotFoundError
);
return
false
;
}
}
__android_log_print
(
ANDROID_LOG_INFO
,
kJTag
,
"Calling Java getDeviceHandle"
);
__android_log_print
(
ANDROID_LOG_INFO
,
kJTag
,
"Calling Java getDeviceHandle"
);
...
...
libs/qtandroidserialport/src/qserialport_android_p.h
View file @
0c251d79
...
@@ -108,10 +108,11 @@ public:
...
@@ -108,10 +108,11 @@ public:
qint64
pendingBytesWritten
;
qint64
pendingBytesWritten
;
static
void
setNativeMethods
(
void
);
private:
private:
QIODevice
::
OpenMode
rwMode
;
QIODevice
::
OpenMode
rwMode
;
int
deviceId
;
int
deviceId
;
bool
hasRegisteredFunctions
;
int
jniDataBits
;
int
jniDataBits
;
int
jniStopBits
;
int
jniStopBits
;
int
jniParity
;
int
jniParity
;
...
...
src/main.cc
View file @
0c251d79
...
@@ -86,6 +86,25 @@ int WindowsCrtReportHook(int reportType, char* message, int* returnValue)
...
@@ -86,6 +86,25 @@ int WindowsCrtReportHook(int reportType, char* message, int* returnValue)
#endif
#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
* @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