Classes | |
| struct | JniMethodCache |
| struct | JniPortInfoFields |
| class | PortListener |
| class | DeviceWatcher |
| struct | JavaBinding |
| struct | JavaBindingList |
| The Java methods or fields that C++ binds, in the order in which they are declared. More... | |
| struct | JavaMethod |
| struct | JavaField |
| A field of QGCUsbSerialPortInfo.java, declared by its JNI type, from which its signature is derived. More... | |
Typedefs | |
| using | PortHandle = qint64 |
| Names an open port in every call to Java and in Java's callbacks. registerPort() makes one. | |
Enumerations | |
| enum class | FlowControl { None = 0 , RtsCts , DtrDsr , XonXoff , XonXoffInline } |
| enum class | Result : int { Ok = 0 , Failed = -1 , IoError = -2 , Unsupported = -3 , NotOpen = -4 , DeviceNotFound = -5 , PermissionDenied = -6 , AlreadyOpen = -7 , PermissionRequested = -8 , PermissionPending = -9 , PermissionAwaitsAndroid = -10 , PermissionAwaitsFocus = -11 , AmbiguousName = -12 } |
| enum class | ResourceErrorReason : int { DeviceDetached = 1 , ReadFailed = 2 , WriteFailed = 3 } |
| Why a port can no longer transfer data. QGCUsbSerialResourceError.java lists the same values. More... | |
Functions | |
| static void | cacheMethodIds (JNIEnv *env, jclass javaClass) |
| static void | cachePortInfoFieldIds (QJniEnvironment &env) |
| static jclass | getSerialManagerClass () |
| The serial manager class, or null until setNativeMethods() has found it. | |
| static bool | resolveSerialManagerClass (QJniEnvironment &env) |
| static jboolean | jniDeviceNewData (JNIEnv *env, jclass javaClass, jlong token, jbyteArray data, jint length) |
| static void | jniDeviceBytesWritten (JNIEnv *env, jclass javaClass, jlong token, jint count) |
| static void | jniDeviceResourceError (JNIEnv *env, jclass javaClass, jlong token, jint reason, jstring detail) |
| static void | jniDevicesChanged (JNIEnv *env, jclass javaClass) |
| bool | setNativeMethods () |
| static bool | javaThrew (QJniEnvironment &env, const char *methodName) |
| static jclass | findJavaMethod (QJniEnvironment &env, const JavaBinding< jmethodID > &method) |
| Returns the serial manager class, or null after a warning if it or the method is unavailable. | |
| template<typename Ret, typename... Args> | |
| static Ret | callJava (QJniEnvironment &env, const JavaMethod< Ret, Args... > &method, std::type_identity_t< Ret > fallback, Args... args) |
| template<typename Ret, typename... Args> | |
| static auto | callJavaObject (QJniEnvironment &env, const JavaMethod< Ret, Args... > &method, Args... args) |
| template<typename... Args> | |
| static Result | callJavaCommand (const JavaMethod< jint, Args... > &method, Args... args) |
| Calls a static Java method that returns a QGCUsbSerialResult. | |
| static jboolean | toJava (bool value) |
| static jint | toJava (std::chrono::milliseconds timeout) |
| static bool | callJavaBool (const JavaMethod< jboolean, jlong > &method, PortHandle handle) |
| static bool | callJavaBool (const JavaMethod< jboolean, jstring > &method, const QString &portName) |
| static QList< int > | callJavaIntArray (const JavaMethod< jintArray, jlong > &method, PortHandle handle) |
| static AndroidInterface::JniLocalRef< jbyteArray > | toJavaBytes (QJniEnvironment &env, const char *data, int length, const char *caller) |
| static QString | stringField (JNIEnv *env, jobject object, const JavaField< jstring > &field) |
| static quint16 | usbIdField (JNIEnv *env, jobject object, const JavaField< jint > &field) |
| QList< QSerialPortInfo > | availablePorts () |
| QList< QSerialPortInfo > | portsAwaitingPermission () |
| The ports of attached devices that still need USB permission. | |
| bool | hasPermission (const QString &portName) |
| Whether QGC may open the device of this port. | |
| bool | requestPermission (const QString &portName) |
| bool | isPermissionDenied (const QString &portName) |
| bool | isPortNameValid (const QString &portName) |
| Whether an attached device has a port with this name. | |
| bool | isPortOpen (const QString &portName) |
| PortHandle | getPortHandle (const QString &portName) |
| The handle of the open port with this name, or kNoPort. | |
| QString | getLastErrorDetail () |
| int | open (const QString &portName, PortHandle handle) |
| Result | close (PortHandle handle) |
| Result | startReading (PortHandle handle) |
| Result | stopReading (PortHandle handle) |
| Stops delivering the port's input until startReading(); what arrives meanwhile is dropped. | |
| bool | isReading (PortHandle handle) |
| QByteArray | read (PortHandle handle, int length, std::chrono::milliseconds timeout) |
| template<typename... Args> | |
| static int | callJavaWrite (const JavaMethod< jint, jlong, jbyteArray, jint, Args... > &method, PortHandle handle, const char *data, int length, Args... args) |
| int | write (PortHandle handle, const char *data, int length, std::chrono::milliseconds timeout) |
| Returns length, or a Result: Failed if the write timed out, otherwise what writeWithProgress() reports. | |
| int | writeWithProgress (PortHandle handle, const char *data, int length, std::chrono::milliseconds timeout) |
| int | writeAsync (PortHandle handle, const char *data, int length) |
| static std::optional< jint > | toJavaDataBits (QSerialPort::DataBits dataBits) |
| static std::optional< jint > | toJavaStopBits (QSerialPort::StopBits stopBits) |
| static std::optional< jint > | toJavaParity (QSerialPort::Parity parity) |
| static std::optional< FlowControl > | toJavaFlowControl (QSerialPort::FlowControl flowControl) |
| static std::optional< FlowControl > | fromJavaFlowControl (jint code) |
| Result | setParameters (PortHandle handle, qint32 baudRate, QSerialPort::DataBits dataBits, QSerialPort::StopBits stopBits, QSerialPort::Parity parity) |
| FlowControl | getFlowControl (PortHandle handle) |
| None also if the port cannot be asked. | |
| Result | setFlowControl (PortHandle handle, QSerialPort::FlowControl flowControl) |
| QList< FlowControl > | getSupportedFlowControl (PortHandle handle) |
| The flow control the port's driver has. | |
| bool | getXon (PortHandle handle) |
| Under XON/XOFF flow control, false while the device has paused transmission. | |
| Result | setLatencyTimer (PortHandle handle, int milliseconds) |
| Sets how long an FTDI chip holds back a partly filled packet, 1 to 255 ms. No other chip supports it. | |
| Result | setBreak (PortHandle handle, bool set) |
| Result | purgeBuffers (PortHandle handle, QSerialPort::Directions directions) |
| Result | setDataTerminalReady (PortHandle handle, bool set) |
| Result | setRequestToSend (PortHandle handle, bool set) |
| static QSerialPort::PinoutSignals | callJavaControlLines (const JavaMethod< jintArray, jlong > &method, PortHandle handle) |
| QSerialPort::PinoutSignals | getControlLines (PortHandle handle) |
| The control lines that are active. | |
| bool | isControlLineActive (PortHandle handle, QSerialPort::PinoutSignal line) |
| Whether this one of the control lines is active. | |
| QSerialPort::PinoutSignals | getSupportedControlLines (PortHandle handle) |
| The control lines the port has at all. None also if the port cannot be asked. | |
| bool | isControlLineSupported (PortHandle handle, QSerialPort::PinoutSignal line) |
| Whether the port has this one of the control lines. | |
| Result | echoToCallbacks (PortHandle handle, const char *data, int length, int deliveredLength, int written, ResourceErrorReason reason, const QString &detail) |
| template<typename Id> | |
| static void | appendUnbound (QStringList &names, const char *kind, const JavaBindingList< Id > &bindings) |
| Adds each method or field of the list that JNI did not find in Java to the names. | |
| QStringList | unboundJavaNames () |
| PortHandle | registerPort (PortListener *listener) |
| Returns a handle under which Java's callbacks reach the listener until unregisterPort() has returned. | |
| void | unregisterPort (PortHandle handle) |
| bool | deliverNewData (PortHandle handle, const char *bytes, int length) |
| void | deliverBytesWritten (PortHandle handle, int count) |
| void | deliverResourceError (PortHandle handle, ResourceErrorReason reason, const QString &detail) |
| bool | selfTest () |
Variables | |
| static JniMethodCache | s_methods |
| static std::atomic< jclass > | s_serialManagerClass {nullptr} |
| static JniPortInfoFields | s_portInfoFields |
| static QString | t_exceptionDetail |
| constexpr const char * | kJniUsbSerialManagerClassName = "org/mavlink/qgroundcontrol/serial/QGCUsbSerialManager" |
| constexpr PortHandle | kNoPort = 0 |
| static QReadWriteLock | s_listenersLock |
| static QHash< PortHandle, PortListener * > | s_listeners |
| static PortHandle | s_lastHandle = kNoPort |
| JavaBindingList< jmethodID > | s_javaMethods |
| JavaBindingList< jfieldID > | s_javaFields |
The USB serial ports of the Android device, as QGCUsbSerialManager.java provides them. A function that calls a Java method has the name of that method.
What the app itself uses of AndroidSerial, the USB serial ports of the Android device as Java provides them: it binds Java's callbacks as the library loads, tests that binding at boot, and hears when the devices change. AndroidSerialJni.h declares the rest of the namespace, which is private to the serial port library.
| using AndroidSerial::PortHandle = qint64 |
Names an open port in every call to Java and in Java's callbacks. registerPort() makes one.
Definition at line 63 of file AndroidSerialJni.h.
|
strong |
The flow control a USB serial driver may have, by the code that flowControlCode() in QGCUsbSerialManager.java gives it. QSerialPort::FlowControl names only three of them.
| Enumerator | |
|---|---|
| None | |
| RtsCts | |
| DtrDsr | |
| XonXoff | |
| XonXoffInline | |
Definition at line 21 of file AndroidSerialJni.h.
|
strong |
Why a port can no longer transfer data. QGCUsbSerialResourceError.java lists the same values.
| Enumerator | |
|---|---|
| DeviceDetached | The device was unplugged. |
| ReadFailed | A read from the device failed. |
| WriteFailed | A write to the device failed. |
Definition at line 55 of file AndroidSerialJni.h.
|
strong |
How an operation on a port went. QGCUsbSerialResult.java lists the same values. A function that returns a count or a descriptor as an int returns one of the negative values instead when it fails.
| Enumerator | |
|---|---|
| Ok | |
| Failed | The call could not be made, or failed for a reason not listed here. |
| IoError | The device did not carry it out, and may be gone. |
| Unsupported | The port or its driver cannot do this. |
| NotOpen | No port is open under this handle. |
| DeviceNotFound | Opening: there is no such device. |
| PermissionDenied | Opening: QGC may not use the device, and the user denied the request to allow it. |
| AlreadyOpen | Opening: the port is already open. |
| PermissionRequested | This open has asked the user to allow it. |
| PermissionPending | The user was asked before, and has not answered yet. |
| PermissionAwaitsAndroid | The device was just attached, and Android asks the user first. |
| PermissionAwaitsFocus | The user is not asked while another window has the focus. |
| AmbiguousName | Opening: several attached devices share this stable name, so it opens none. |
Definition at line 34 of file AndroidSerialJni.h.
|
static |
Adds each method or field of the list that JNI did not find in Java to the names.
Definition at line 945 of file AndroidSerialJni.cc.
References appendUnbound(), and AndroidSerial::JavaBindingList< Id >::first.
Referenced by appendUnbound(), and unboundJavaNames().
| QList< QSerialPortInfo > AndroidSerial::availablePorts | ( | ) |
The ports of the attached USB serial devices, also of those that still need USB permission. Android withholds the serial number of such a device, so its ports have no stable name either.
Definition at line 504 of file AndroidSerialJni.cc.
References availablePorts(), callJavaObject(), QSerialPortInfo::Data::description, AndroidInterface::JniLocalRef< T >::get(), QSerialPortInfo::Data::hasHardwareFlowControl, QSerialPortInfo::Data::hasProductIdentifier, QSerialPortInfo::Data::hasVendorIdentifier, AndroidSerial::JavaBinding< Id >::id, QSerialPortInfo::Data::manufacturer, QSerialPortInfo::Data::portName, QSerialPortInfo::portNameFromSystemLocation(), QSerialPortInfo::Data::productIdentifier, s_methods, s_portInfoFields, QSerialPortInfo::Data::serialNumber, QSerialPortInfo::Data::stableName, stringField(), QSerialPortInfo::Data::systemLocation, usbIdField(), and QSerialPortInfo::Data::vendorIdentifier.
Referenced by availablePorts(), QSerialPortInfo::availablePorts(), and portsAwaitingPermission().
|
static |
Definition at line 67 of file AndroidSerialJni.cc.
References cacheMethodIds(), and s_javaMethods.
Referenced by cacheMethodIds(), and resolveSerialManagerClass().
|
static |
Definition at line 97 of file AndroidSerialJni.cc.
References cachePortInfoFieldIds(), and s_javaFields.
Referenced by cachePortInfoFieldIds(), and resolveSerialManagerClass().
|
static |
Calls a static Java method that returns an int, a long or a boolean. Returns fallback, after a warning, if the method is unavailable or throws. The arguments have the JNI types that the method declares.
Definition at line 340 of file AndroidSerialJni.cc.
References AndroidSerial::JavaMethod< Ret, Args >::call(), callJava(), findJavaMethod(), javaThrew(), and AndroidSerial::JavaBinding< Id >::name.
Referenced by callJava(), callJavaBool(), callJavaBool(), callJavaCommand(), callJavaWrite(), getFlowControl(), getPortHandle(), and open().
|
static |
Definition at line 412 of file AndroidSerialJni.cc.
References callJava(), and callJavaBool().
Referenced by callJavaBool(), callJavaBool(), getXon(), hasPermission(), isPermissionDenied(), isPortNameValid(), isReading(), and requestPermission().
|
static |
Definition at line 418 of file AndroidSerialJni.cc.
References callJava(), callJavaBool(), and AndroidSerial::JavaBinding< Id >::name.
|
static |
Calls a static Java method that returns a QGCUsbSerialResult.
Definition at line 382 of file AndroidSerialJni.cc.
References AmbiguousName, callJava(), callJavaCommand(), Failed, AndroidSerial::JavaBinding< Id >::name, and Ok.
Referenced by callJavaCommand(), close(), echoToCallbacks(), purgeBuffers(), setBreak(), setDataTerminalReady(), setFlowControl(), setLatencyTimer(), setParameters(), setRequestToSend(), startReading(), and stopReading().
|
static |
Definition at line 882 of file AndroidSerialJni.cc.
References callJavaControlLines(), callJavaIntArray(), QSerialPort::ClearToSendSignal, QSerialPort::DataCarrierDetectSignal, QSerialPort::DataSetReadySignal, QSerialPort::DataTerminalReadySignal, QSerialPort::RequestToSendSignal, and QSerialPort::RingIndicatorSignal.
Referenced by callJavaControlLines(), getControlLines(), and getSupportedControlLines().
|
static |
Definition at line 430 of file AndroidSerialJni.cc.
References callJavaIntArray(), callJavaObject(), and AndroidSerial::JavaBinding< Id >::name.
Referenced by callJavaControlLines(), callJavaIntArray(), and getSupportedFlowControl().
|
static |
Calls a static Java method that returns an object, such as an array. The reference is null, after a warning, if the method is unavailable, throws or returns null.
Definition at line 361 of file AndroidSerialJni.cc.
References AndroidSerial::JavaMethod< Ret, Args >::call(), callJavaObject(), findJavaMethod(), javaThrew(), and AndroidSerial::JavaBinding< Id >::name.
Referenced by availablePorts(), callJavaIntArray(), callJavaObject(), getLastErrorDetail(), and read().
|
static |
Calls one of the Java write methods with the data as a Java array. Returns what the method returns, or Result::Failed if the call cannot be made.
Definition at line 687 of file AndroidSerialJni.cc.
References callJava(), callJavaWrite(), Failed, AndroidSerial::JavaBinding< Id >::name, and toJavaBytes().
Referenced by callJavaWrite(), writeAsync(), and writeWithProgress().
| Result AndroidSerial::close | ( | PortHandle | handle | ) |
Ok also if no port is open under the handle. IoError if the device did not close cleanly; Java has given the port up all the same.
Definition at line 635 of file AndroidSerialJni.cc.
References callJavaCommand(), close(), and s_methods.
Referenced by close().
| void AndroidSerial::deliverBytesWritten | ( | PortHandle | handle, |
| int | count ) |
Definition at line 54 of file AndroidSerialRegistry.cc.
References AndroidSerial::PortListener::bytesWritten(), s_listeners, and s_listenersLock.
Referenced by jniDeviceBytesWritten().
| bool AndroidSerial::deliverNewData | ( | PortHandle | handle, |
| const char * | bytes, | ||
| int | length ) |
Pass what Java reports for the port with this handle to its listener, or drop it if no port is registered under the handle any more. Java's callbacks call these on Java's threads; a test calls them in Java's place. deliverNewData() returns what the listener answers, or true if there is none.
Definition at line 42 of file AndroidSerialRegistry.cc.
References AndroidSerial::PortListener::newDataArrived(), s_listeners, and s_listenersLock.
Referenced by jniDeviceNewData().
| void AndroidSerial::deliverResourceError | ( | PortHandle | handle, |
| ResourceErrorReason | reason, | ||
| const QString & | detail ) |
Definition at line 66 of file AndroidSerialRegistry.cc.
References AndroidSerial::PortListener::resourceErrorArrived(), s_listeners, and s_listenersLock.
Referenced by jniDeviceResourceError().
| Result AndroidSerial::echoToCallbacks | ( | PortHandle | handle, |
| const char * | data, | ||
| int | length, | ||
| int | deliveredLength, | ||
| int | written, | ||
| ResourceErrorReason | reason, | ||
| const QString & | detail ) |
Has Java call each of its callbacks once, on the calling thread: the listener of the handle gets the first deliveredLength of the length bytes of data, a report of this many written bytes and a resource error with this reason and detail, and DeviceWatcher emits its signal.
Definition at line 928 of file AndroidSerialJni.cc.
References callJavaCommand(), echoToCallbacks(), Failed, s_methods, and toJavaBytes().
Referenced by echoToCallbacks(), and selfTest().
|
static |
Returns the serial manager class, or null after a warning if it or the method is unavailable.
Definition at line 316 of file AndroidSerialJni.cc.
References findJavaMethod(), getSerialManagerClass(), AndroidSerial::JavaBinding< Id >::id, and AndroidSerial::JavaBinding< Id >::name.
Referenced by callJava(), callJavaObject(), and findJavaMethod().
|
static |
Definition at line 788 of file AndroidSerialJni.cc.
References fromJavaFlowControl(), None, and XonXoffInline.
Referenced by fromJavaFlowControl(), getFlowControl(), and getSupportedFlowControl().
| QSerialPort::PinoutSignals AndroidSerial::getControlLines | ( | PortHandle | handle | ) |
The control lines that are active.
Definition at line 904 of file AndroidSerialJni.cc.
References callJavaControlLines(), getControlLines(), and s_methods.
Referenced by getControlLines(), and isControlLineActive().
| FlowControl AndroidSerial::getFlowControl | ( | PortHandle | handle | ) |
None also if the port cannot be asked.
Definition at line 813 of file AndroidSerialJni.cc.
References callJava(), fromJavaFlowControl(), getFlowControl(), None, and s_methods.
Referenced by getFlowControl().
| QString AndroidSerial::getLastErrorDetail | ( | ) |
What the failure of this thread's last call to Java says of itself beyond its Result, such as the message of Java's exception, or nothing. Ask only right after a call that returned a failure, on its thread: a later call replaces the detail, and a call that fails before it reaches Java leaves that of the one before.
Definition at line 601 of file AndroidSerialJni.cc.
References callJavaObject(), getLastErrorDetail(), s_methods, and t_exceptionDetail.
Referenced by getLastErrorDetail().
| PortHandle AndroidSerial::getPortHandle | ( | const QString & | portName | ) |
The handle of the open port with this name, or kNoPort.
Definition at line 585 of file AndroidSerialJni.cc.
References callJava(), getPortHandle(), kNoPort, and s_methods.
Referenced by getPortHandle(), and isPortOpen().
|
static |
The serial manager class, or null until setNativeMethods() has found it.
Definition at line 122 of file AndroidSerialJni.cc.
References getSerialManagerClass(), and s_serialManagerClass.
Referenced by findJavaMethod(), getSerialManagerClass(), and unboundJavaNames().
| QSerialPort::PinoutSignals AndroidSerial::getSupportedControlLines | ( | PortHandle | handle | ) |
The control lines the port has at all. None also if the port cannot be asked.
Definition at line 914 of file AndroidSerialJni.cc.
References callJavaControlLines(), getSupportedControlLines(), and s_methods.
Referenced by getSupportedControlLines(), and isControlLineSupported().
| QList< FlowControl > AndroidSerial::getSupportedFlowControl | ( | PortHandle | handle | ) |
The flow control the port's driver has.
Definition at line 832 of file AndroidSerialJni.cc.
References callJavaIntArray(), fromJavaFlowControl(), getSupportedFlowControl(), and s_methods.
Referenced by getSupportedFlowControl().
| bool AndroidSerial::getXon | ( | PortHandle | handle | ) |
Under XON/XOFF flow control, false while the device has paused transmission.
Definition at line 846 of file AndroidSerialJni.cc.
References callJavaBool(), getXon(), and s_methods.
Referenced by getXon().
| bool AndroidSerial::hasPermission | ( | const QString & | portName | ) |
Whether QGC may open the device of this port.
Definition at line 560 of file AndroidSerialJni.cc.
References callJavaBool(), hasPermission(), and s_methods.
Referenced by hasPermission(), AndroidSerialAccess::hasUsbPermission(), and AndroidSerialAccess::requestUsbPermission().
| bool AndroidSerial::isControlLineActive | ( | PortHandle | handle, |
| QSerialPort::PinoutSignal | line ) |
Whether this one of the control lines is active.
Definition at line 909 of file AndroidSerialJni.cc.
References getControlLines(), and isControlLineActive().
Referenced by isControlLineActive().
| bool AndroidSerial::isControlLineSupported | ( | PortHandle | handle, |
| QSerialPort::PinoutSignal | line ) |
Whether the port has this one of the control lines.
Definition at line 919 of file AndroidSerialJni.cc.
References getSupportedControlLines(), and isControlLineSupported().
Referenced by isControlLineSupported().
| bool AndroidSerial::isPermissionDenied | ( | const QString & | portName | ) |
Whether the user has denied QGC the device of this port, and has not been asked again since. DeviceWatcher tells of a denial, as it does of a grant.
Definition at line 570 of file AndroidSerialJni.cc.
References callJavaBool(), isPermissionDenied(), and s_methods.
Referenced by isPermissionDenied(), and AndroidSerialAccess::isUsbPermissionDenied().
| bool AndroidSerial::isPortNameValid | ( | const QString & | portName | ) |
Whether an attached device has a port with this name.
Definition at line 575 of file AndroidSerialJni.cc.
References callJavaBool(), isPortNameValid(), and s_methods.
Referenced by isPortNameValid().
| bool AndroidSerial::isPortOpen | ( | const QString & | portName | ) |
Definition at line 580 of file AndroidSerialJni.cc.
References getPortHandle(), isPortOpen(), and kNoPort.
Referenced by isPortOpen().
| bool AndroidSerial::isReading | ( | PortHandle | handle | ) |
Definition at line 654 of file AndroidSerialJni.cc.
References callJavaBool(), isReading(), and s_methods.
Referenced by isReading().
|
static |
Returns whether the call into Java that this thread has just made threw, after a warning. What the exception says of itself is kept for getLastErrorDetail().
Definition at line 298 of file AndroidSerialJni.cc.
References AndroidInterface::JniLocalRef< T >::get(), javaThrew(), and t_exceptionDetail.
Referenced by callJava(), callJavaObject(), and javaThrew().
|
static |
Definition at line 238 of file AndroidSerialJni.cc.
References deliverBytesWritten(), and jniDeviceBytesWritten().
Referenced by jniDeviceBytesWritten(), and setNativeMethods().
|
static |
Definition at line 199 of file AndroidSerialJni.cc.
References deliverNewData(), and jniDeviceNewData().
Referenced by jniDeviceNewData(), and setNativeMethods().
|
static |
Definition at line 249 of file AndroidSerialJni.cc.
References deliverResourceError(), and jniDeviceResourceError().
Referenced by jniDeviceResourceError(), and setNativeMethods().
|
static |
Definition at line 280 of file AndroidSerialJni.cc.
References AndroidSerial::DeviceWatcher::devicesChanged(), AndroidSerial::DeviceWatcher::instance(), and jniDevicesChanged().
Referenced by jniDevicesChanged(), and setNativeMethods().
| int AndroidSerial::open | ( | const QString & | portName, |
| PortHandle | handle ) |
Opens the port under a handle from registerPort(). Returns the file descriptor of the port's USB connection, which is not negative, or a Result. For a device that still needs USB permission the result is one of the five Permission results, which tells what has become of the permission, and getLastErrorDetail() has nothing to add to it. Such an open also asks the user for the permission, who answers later; DeviceWatcher tells of the answer. Callers open ports without being told to and try again every few seconds, so the open asks once for each time the device is attached, not in the first seconds after that, which Android's own prompt for the device takes to appear, and only while QGC's window has the focus. It asks once more if Android closes the dialog without an answer. After a denial, the user is asked again once the device has been replugged, or by requestPermission(). A stable name that no device with permission has stands for the only attached device with its vendor and product IDs that still needs permission, if there is exactly one.
Definition at line 617 of file AndroidSerialJni.cc.
References callJava(), Failed, kNoPort, open(), and s_methods.
Referenced by open(), and selfTest().
| QList< QSerialPortInfo > AndroidSerial::portsAwaitingPermission | ( | ) |
The ports of attached devices that still need USB permission.
Definition at line 552 of file AndroidSerialJni.cc.
References availablePorts(), and portsAwaitingPermission().
Referenced by portsAwaitingPermission().
| Result AndroidSerial::purgeBuffers | ( | PortHandle | handle, |
| QSerialPort::Directions | directions ) |
Discards what the device has buffered in the given directions. With Output, it also stops the write thread from sending what is left of the data handed to writeAsync() so far, also where the driver has no purge command. The listener's bytesWritten() still follows for all of that data.
Definition at line 861 of file AndroidSerialJni.cc.
References callJavaCommand(), QSerialPort::Input, QSerialPort::Output, purgeBuffers(), s_methods, and toJava().
Referenced by purgeBuffers().
| QByteArray AndroidSerial::read | ( | PortHandle | handle, |
| int | length, | ||
| std::chrono::milliseconds | timeout ) |
Reads up to length bytes from the device, waiting no longer than timeout. Usable only before startReading() has first run on the port, which QSerialPort does as it opens a port for reading: from then on input arrives through the port instead, and this returns nothing. A negative timeout waits 1 ms.
Definition at line 659 of file AndroidSerialJni.cc.
References callJavaObject(), read(), s_methods, and toJava().
Referenced by read().
| PortHandle AndroidSerial::registerPort | ( | PortListener * | listener | ) |
Returns a handle under which Java's callbacks reach the listener until unregisterPort() has returned.
Definition at line 22 of file AndroidSerialRegistry.cc.
References kNoPort, s_lastHandle, s_listeners, and s_listenersLock.
Referenced by selfTest().
| bool AndroidSerial::requestPermission | ( | const QString & | portName | ) |
Asks the user to let QGC open the device of this port, unless it already may. The user answers later. Unlike open(), this asks whenever it is called, also after the user has denied the permission. Returns false if there is no such device.
Definition at line 565 of file AndroidSerialJni.cc.
References callJavaBool(), requestPermission(), and s_methods.
Referenced by requestPermission(), and AndroidSerialAccess::requestUsbPermission().
|
static |
Finds the serial manager class and the methods and fields that C++ binds. Returns false if Java has no such class.
Definition at line 129 of file AndroidSerialJni.cc.
References cacheMethodIds(), cachePortInfoFieldIds(), kJniUsbSerialManagerClassName, resolveSerialManagerClass(), and s_serialManagerClass.
Referenced by resolveSerialManagerClass(), and setNativeMethods().
|
nodiscard |
Proves, for QGC's boot test, that C++ and Java reach each other in the app as it is packaged: Java has every method and field that C++ binds, passes arguments that C++ gave it to each callback, and answers calls about a port that does not exist. Returns false after it has logged what failed, as critical messages of the category Android.AndroidSerial.SelfTest.
Definition at line 18 of file AndroidSerialSelfTest.cc.
References AndroidSerial::PortListener::bytesWritten(), DeviceNotFound, AndroidSerial::DeviceWatcher::devicesChanged(), echoToCallbacks(), AndroidSerial::DeviceWatcher::instance(), AndroidSerial::PortListener::newDataArrived(), NotOpen, Ok, open(), registerPort(), AndroidSerial::PortListener::resourceErrorArrived(), selfTest(), unboundJavaNames(), unregisterPort(), writeAsync(), and WriteFailed.
Referenced by QGCApplication::init(), and selfTest().
| Result AndroidSerial::setBreak | ( | PortHandle | handle, |
| bool | set ) |
Definition at line 856 of file AndroidSerialJni.cc.
References callJavaCommand(), s_methods, setBreak(), and toJava().
Referenced by setBreak().
| Result AndroidSerial::setDataTerminalReady | ( | PortHandle | handle, |
| bool | set ) |
Definition at line 872 of file AndroidSerialJni.cc.
References callJavaCommand(), s_methods, setDataTerminalReady(), and toJava().
Referenced by setDataTerminalReady().
| Result AndroidSerial::setFlowControl | ( | PortHandle | handle, |
| QSerialPort::FlowControl | flowControl ) |
Definition at line 821 of file AndroidSerialJni.cc.
References callJavaCommand(), s_methods, setFlowControl(), toJavaFlowControl(), and Unsupported.
Referenced by setFlowControl().
| Result AndroidSerial::setLatencyTimer | ( | PortHandle | handle, |
| int | milliseconds ) |
Sets how long an FTDI chip holds back a partly filled packet, 1 to 255 ms. No other chip supports it.
Definition at line 851 of file AndroidSerialJni.cc.
References callJavaCommand(), s_methods, and setLatencyTimer().
Referenced by setLatencyTimer().
|
nodiscard |
Registers the callbacks that Java calls on its threads, and finds the Java methods that C++ calls: call it as the library loads, before anything else of the namespace. Returns false, after a warning, if Java does not declare the callbacks as they are registered here: a callback would then throw on its Java thread.
Definition at line 161 of file AndroidSerialJni.cc.
References jniDeviceBytesWritten(), jniDeviceNewData(), jniDeviceResourceError(), jniDevicesChanged(), kJniUsbSerialManagerClassName, resolveSerialManagerClass(), and setNativeMethods().
Referenced by JNI_OnLoad(), and setNativeMethods().
| Result AndroidSerial::setParameters | ( | PortHandle | handle, |
| qint32 | baudRate, | ||
| QSerialPort::DataBits | dataBits, | ||
| QSerialPort::StopBits | stopBits, | ||
| QSerialPort::Parity | parity ) |
Definition at line 798 of file AndroidSerialJni.cc.
References callJavaCommand(), s_methods, setParameters(), toJavaDataBits(), toJavaParity(), toJavaStopBits(), and Unsupported.
Referenced by setParameters().
| Result AndroidSerial::setRequestToSend | ( | PortHandle | handle, |
| bool | set ) |
Definition at line 877 of file AndroidSerialJni.cc.
References callJavaCommand(), s_methods, setRequestToSend(), and toJava().
Referenced by setRequestToSend().
| Result AndroidSerial::startReading | ( | PortHandle | handle | ) |
Starts delivering the port's input to its listener, or has Java's read thread read on after the listener answered that the port had no room for more.
Definition at line 644 of file AndroidSerialJni.cc.
References callJavaCommand(), s_methods, and startReading().
Referenced by startReading().
| Result AndroidSerial::stopReading | ( | PortHandle | handle | ) |
Stops delivering the port's input until startReading(); what arrives meanwhile is dropped.
Definition at line 649 of file AndroidSerialJni.cc.
References callJavaCommand(), s_methods, and stopReading().
Referenced by stopReading().
|
static |
Definition at line 481 of file AndroidSerialJni.cc.
References AndroidInterface::JniLocalRef< T >::get(), AndroidSerial::JavaBinding< Id >::id, and stringField().
Referenced by availablePorts(), and stringField().
|
static |
Definition at line 395 of file AndroidSerialJni.cc.
References toJava().
Referenced by purgeBuffers(), read(), setBreak(), setDataTerminalReady(), setRequestToSend(), toJava(), toJava(), and writeWithProgress().
|
static |
Java takes a timeout as a count of milliseconds in an int, and zero as no limit. A negative timeout is that of a deadline that has passed, so it becomes the shortest wait there is, not zero.
Definition at line 402 of file AndroidSerialJni.cc.
References toJava().
|
static |
Definition at line 452 of file AndroidSerialJni.cc.
References AndroidInterface::JniLocalRef< T >::get(), AndroidInterface::JniLocalRef< T >::reset(), and toJavaBytes().
Referenced by callJavaWrite(), echoToCallbacks(), and toJavaBytes().
|
static |
Definition at line 729 of file AndroidSerialJni.cc.
References QSerialPort::Data5, QSerialPort::Data6, QSerialPort::Data7, QSerialPort::Data8, and toJavaDataBits().
Referenced by setParameters(), and toJavaDataBits().
|
static |
Definition at line 774 of file AndroidSerialJni.cc.
References QSerialPort::HardwareControl, QSerialPort::NoFlowControl, None, RtsCts, QSerialPort::SoftwareControl, toJavaFlowControl(), and XonXoff.
Referenced by setFlowControl(), and toJavaFlowControl().
|
static |
Definition at line 756 of file AndroidSerialJni.cc.
References QSerialPort::EvenParity, QSerialPort::MarkParity, QSerialPort::NoParity, QSerialPort::OddParity, QSerialPort::SpaceParity, and toJavaParity().
Referenced by setParameters(), and toJavaParity().
|
static |
Definition at line 742 of file AndroidSerialJni.cc.
References QSerialPort::OneAndHalfStop, QSerialPort::OneStop, toJavaStopBits(), and QSerialPort::TwoStop.
Referenced by setParameters(), and toJavaStopBits().
| QStringList AndroidSerial::unboundJavaNames | ( | ) |
What C++ binds and JNI did not find in Java, each by its kind, name and JNI signature: the class alone if that is missing, else every such method and field. Nothing if all is bound.
Definition at line 956 of file AndroidSerialJni.cc.
References appendUnbound(), getSerialManagerClass(), kJniUsbSerialManagerClassName, s_javaFields, s_javaMethods, and unboundJavaNames().
Referenced by selfTest(), and unboundJavaNames().
| void AndroidSerial::unregisterPort | ( | PortHandle | handle | ) |
Definition at line 36 of file AndroidSerialRegistry.cc.
References s_listeners, and s_listenersLock.
Referenced by selfTest().
|
static |
Definition at line 499 of file AndroidSerialJni.cc.
References AndroidSerial::JavaBinding< Id >::id, and usbIdField().
Referenced by availablePorts(), and usbIdField().
| int AndroidSerial::write | ( | PortHandle | handle, |
| const char * | data, | ||
| int | length, | ||
| std::chrono::milliseconds | timeout ) |
Returns length, or a Result: Failed if the write timed out, otherwise what writeWithProgress() reports.
Definition at line 705 of file AndroidSerialJni.cc.
References Failed, write(), and writeWithProgress().
Referenced by write().
| int AndroidSerial::writeAsync | ( | PortHandle | handle, |
| const char * | data, | ||
| int | length ) |
Hands the data to the port's write thread and returns length at once, or a Result: Failed if the thread still has too much to write, IoError if the listener's resourceErrorArrived() has been called since startReading() last ran, NotOpen if the port is not open. The listener's bytesWritten() follows for the whole length: once the device has taken the data, however long that takes, or once purgeBuffers() has discarded what was not yet sent. If the device is lost instead, its resourceErrorArrived() follows.
Definition at line 716 of file AndroidSerialJni.cc.
References callJavaWrite(), s_methods, and writeAsync().
Referenced by selfTest(), and writeAsync().
| int AndroidSerial::writeWithProgress | ( | PortHandle | handle, |
| const char * | data, | ||
| int | length, | ||
| std::chrono::milliseconds | timeout ) |
Returns the bytes written, fewer than length on timeout, or a Result: IoError or NotOpen if the port can no longer transfer data, as when its device is unplugged. A zero timeout waits without limit. A negative one is that of a deadline that has passed, and waits 1 ms, the shortest wait that Java takes.
Definition at line 711 of file AndroidSerialJni.cc.
References callJavaWrite(), s_methods, toJava(), and writeWithProgress().
Referenced by write(), and writeWithProgress().
|
constexpr |
Definition at line 30 of file AndroidSerialJni.h.
Referenced by resolveSerialManagerClass(), setNativeMethods(), and unboundJavaNames().
|
constexpr |
Definition at line 64 of file AndroidSerialJni.h.
Referenced by getPortHandle(), isPortOpen(), open(), and registerPort().
|
inline |
Definition at line 49 of file JavaBinding.h.
Referenced by cachePortInfoFieldIds(), AndroidSerial::JavaField< T >::JavaField(), and unboundJavaNames().
|
inline |
Definition at line 48 of file JavaBinding.h.
Referenced by cacheMethodIds(), AndroidSerial::JavaMethod< Ret, Args >::JavaMethod(), and unboundJavaNames().
|
static |
Definition at line 20 of file AndroidSerialRegistry.cc.
Referenced by registerPort().
|
static |
Definition at line 19 of file AndroidSerialRegistry.cc.
Referenced by deliverBytesWritten(), deliverNewData(), deliverResourceError(), registerPort(), and unregisterPort().
|
static |
Definition at line 18 of file AndroidSerialRegistry.cc.
Referenced by deliverBytesWritten(), deliverNewData(), deliverResourceError(), registerPort(), and unregisterPort().
|
static |
Definition at line 62 of file AndroidSerialJni.cc.
Referenced by availablePorts(), close(), echoToCallbacks(), getControlLines(), getFlowControl(), getLastErrorDetail(), getPortHandle(), getSupportedControlLines(), getSupportedFlowControl(), getXon(), hasPermission(), isPermissionDenied(), isPortNameValid(), isReading(), open(), purgeBuffers(), read(), requestPermission(), setBreak(), setDataTerminalReady(), setFlowControl(), setLatencyTimer(), setParameters(), setRequestToSend(), startReading(), stopReading(), writeAsync(), and writeWithProgress().
|
static |
Definition at line 95 of file AndroidSerialJni.cc.
Referenced by availablePorts().
|
static |
Definition at line 65 of file AndroidSerialJni.cc.
Referenced by getSerialManagerClass(), and resolveSerialManagerClass().
|
thread_localstatic |
Definition at line 294 of file AndroidSerialJni.cc.
Referenced by getLastErrorDetail(), and javaThrew().