Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/mavlink/src/main/cpp/mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void *listen(int mavlink_port) {
if (bind(fd, (struct sockaddr *) (&addr), sizeof(addr)) != 0) {
__android_log_print(ANDROID_LOG_ERROR, TAG, "Unable to bind MavLink port %d: %s",
mavlink_port, strerror(errno));
close(fd);
return 0;
}

Expand All @@ -88,6 +89,7 @@ void *listen(int mavlink_port) {
if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
__android_log_print(ANDROID_LOG_ERROR, TAG,
"Unable to bind MavLink rx timeout: %s", strerror(errno));
close(fd);
return 0;
}

Expand All @@ -102,11 +104,13 @@ void *listen(int mavlink_port) {
continue;
} else {
__android_log_print(ANDROID_LOG_ERROR, TAG, "Error receiving mavlink: %s", strerror(errno));
close(fd);
return 0;
}
} else if (ret == 0) {
// peer has done an orderly shutdown
__android_log_print(ANDROID_LOG_ERROR, TAG, "Shutting down mavlink: ret=0");
close(fd);
return 0;
}

Expand Down Expand Up @@ -315,6 +319,7 @@ void *listen(int mavlink_port) {
usleep(1);
}

close(fd);
__android_log_print(ANDROID_LOG_DEBUG, TAG, "Mavlink thread done.");
return 0;
}
Expand Down Expand Up @@ -375,6 +380,11 @@ Java_com_openipc_mavlink_MavlinkNative_nativeCallBack(JNIEnv *env, jclass clazz,
extern "C"
JNIEXPORT void JNICALL
Java_com_openipc_mavlink_MavlinkNative_nativeStart(JNIEnv *env, jclass clazz, jobject context) {
// mavlink_thread_signal is how a previous listen() loop was told to exit;
// it has to be cleared here or a restart (e.g. toggling streaming mode off
// again) would see it already set and exit its loop before ever reading a
// packet.
mavlink_thread_signal = 0;
Comment thread
josephnef marked this conversation as resolved.
Comment thread
josephnef marked this conversation as resolved.
auto threadFunction = []() {
listen(14550);
};
Expand Down
Loading