Skip to content

Commit

Permalink
Add separate textview for local wifi
Browse files Browse the repository at this point in the history
  • Loading branch information
skilurius committed Sep 3, 2024
1 parent 9d43b8b commit 7794d8c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 69 deletions.
22 changes: 11 additions & 11 deletions app/mavlink/src/main/cpp/mavlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "mavlink/common/mavlink.h"
#include "mavlink.h"

#define TAG "pixelpilot"

long distance_meters_between(double lat1, double lon1, double lat2, double lon2) {
double delta = (lon1 - lon2) * 0.017453292519;
double sdlong = sin(delta);
Expand Down Expand Up @@ -55,28 +57,26 @@ long distance_meters_between(double lat1, double lon1, double lat2, double lon2)
int mavlink_thread_signal = 0;
std::atomic<bool> latestMavlinkDataChange = false;

void onMavlinkChanged();

void *listen(int mavlink_port) {
__android_log_print(ANDROID_LOG_DEBUG, "mavlink.cpp", "Starting mavlink thread...");
__android_log_print(ANDROID_LOG_DEBUG, TAG, "Starting mavlink thread...");
// Create socket
int fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
__android_log_print(ANDROID_LOG_DEBUG, "mavlink.cpp",
__android_log_print(ANDROID_LOG_DEBUG, TAG,
"ERROR: Unable to create MavLink socket: %s", strerror(errno));
return 0;
}

// Bind port
__android_log_print(ANDROID_LOG_DEBUG, "mavlink.cpp", "Mavlink listening on %d", mavlink_port);
__android_log_print(ANDROID_LOG_DEBUG, TAG, "Mavlink listening on %d", mavlink_port);
struct sockaddr_in addr = {};
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
inet_pton(AF_INET, "0.0.0.0", &(addr.sin_addr));
addr.sin_port = htons(mavlink_port);

if (bind(fd, (struct sockaddr *) (&addr), sizeof(addr)) != 0) {
__android_log_print(ANDROID_LOG_ERROR, "mavlink.cpp", "Unable to bind MavLink port %d: %s",
__android_log_print(ANDROID_LOG_ERROR, TAG, "Unable to bind MavLink port %d: %s",
mavlink_port, strerror(errno));
return 0;
}
Expand All @@ -86,7 +86,7 @@ void *listen(int mavlink_port) {
tv.tv_sec = 0;
tv.tv_usec = 100000;
if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
__android_log_print(ANDROID_LOG_ERROR, "mavlink.cpp",
__android_log_print(ANDROID_LOG_ERROR, TAG,
"Unable to bind MavLink rx timeout: %s", strerror(errno));
return 0;
}
Expand All @@ -99,7 +99,7 @@ void *listen(int mavlink_port) {
continue;
} else if (ret == 0) {
// peer has done an orderly shutdown
__android_log_print(ANDROID_LOG_ERROR, "mavlink.cpp", "Shutting down mavlink: ret=0");
__android_log_print(ANDROID_LOG_ERROR, TAG, "Shutting down mavlink: ret=0");
return 0;
}

Expand Down Expand Up @@ -299,16 +299,16 @@ void *listen(int mavlink_port) {
break;

default:
// printf("> MavLink msgMav %d from %d/%d\n",
// msgMav.msgid, msgMav.sysid, msgMav.compid);
//printf("mavlink msg %d from %d/%d\n",
//msgMav.msgid, msgMav.sysid, msgMav.compid);
break;
}
}
}
usleep(1);
}

__android_log_print(ANDROID_LOG_DEBUG, "mavlink.cpp", "Mavlink thread done.");
__android_log_print(ANDROID_LOG_DEBUG, TAG, "Mavlink thread done.");
return 0;
}

Expand Down
46 changes: 8 additions & 38 deletions app/mavlink/src/main/java/com/openipc/mavlink/MavlinkData.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.openipc.mavlink;


@SuppressWarnings("WeakerAccess")
public class MavlinkData {
public final float telemetryAltitude;
public final float telemetryPitch;
Expand All @@ -16,9 +14,9 @@ public class MavlinkData {
public final double telemetryLonBase;
public final double telemetryHdg;
public final double telemetryDistance;
public final float telemetrySats;
public final float telemetryGspeed;
public final float telemetryVspeed;
public final float telemetrySat;
public final float telemetryGSpeed;
public final float telemetryVSpeed;
public final float telemetryThrottle;
public final byte telemetryArm;
public final byte flight_mode;
Expand All @@ -28,37 +26,11 @@ public class MavlinkData {
public final byte heading;
public String status_text;

public MavlinkData() {
this.telemetryAltitude = 0;
this.telemetryPitch = 0;
this.telemetryRoll = 0;
this.telemetryYaw = 0;
this.telemetryBattery = 0;
this.telemetryCurrent = 0;
this.telemetryCurrentConsumed = 0;
this.telemetryLat = 0;
this.telemetryLon = 0;
this.telemetryLatBase = 0;
this.telemetryLonBase = 0;
this.telemetryHdg = 0;
this.telemetryDistance = 0;
this.telemetrySats = 0;
this.telemetryGspeed = 0;
this.telemetryVspeed = 0;
this.telemetryThrottle = 0;
this.telemetryArm = 0;
this.flight_mode = 0;
this.gps_fix_type = 0;
this.hdop = 0;
this.rssi = 0;
this.heading = 0;
}

public MavlinkData(float telemetryAltitude, float telemetryPitch, float telemetryRoll, float telemetryYaw,
float telemetryBattery, float telemetryCurrent, float telemetryCurrentConsumed,
double telemetryLat, double telemetryLon, double telemetryLatBase, double telemetryLonBase,
double telemetryHdg, double telemetryDistance, float telemetrySats, float telemetryGspeed,
float telemetryVspeed, float telemetryThrottle, byte telemetryArm, byte flight_mode,
double telemetryHdg, double telemetryDistance, float telemetrySat, float telemetryGSpeed,
float telemetryVSpeed, float telemetryThrottle, byte telemetryArm, byte flight_mode,
byte gps_fix_type, byte hdop, byte rssi, byte heading, String status) {
this.telemetryAltitude = telemetryAltitude;
this.telemetryPitch = telemetryPitch;
Expand All @@ -73,9 +45,9 @@ public MavlinkData(float telemetryAltitude, float telemetryPitch, float telemetr
this.telemetryLonBase = telemetryLonBase;
this.telemetryHdg = telemetryHdg;
this.telemetryDistance = telemetryDistance;
this.telemetrySats = telemetrySats;
this.telemetryGspeed = telemetryGspeed;
this.telemetryVspeed = telemetryVspeed;
this.telemetrySat = telemetrySat;
this.telemetryGSpeed = telemetryGSpeed;
this.telemetryVSpeed = telemetryVSpeed;
this.telemetryThrottle = telemetryThrottle;
this.telemetryArm = telemetryArm;
this.flight_mode = flight_mode;
Expand All @@ -84,7 +56,5 @@ public MavlinkData(float telemetryAltitude, float telemetryPitch, float telemetr
this.rssi = rssi;
this.heading = heading;
this.status_text = status;


}
}
7 changes: 4 additions & 3 deletions app/src/main/java/com/openipc/pixelpilot/VideoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
// Into an Android Surface View
public class VideoActivity extends AppCompatActivity implements IVideoParamsChanged,
WfbNGStatsChanged, MavlinkUpdate, SettingsChanged {
private static final String TAG = "pixelpilot";
private static final int PICK_KEY_REQUEST_CODE = 1;
private static final int PICK_DVR_REQUEST_CODE = 2;
private static final String TAG = "VideoActivity";
private static WifiManager wifiManager;
final Handler handler = new Handler(Looper.getMainLooper());
final Runnable runnable = new Runnable() {
Expand Down Expand Up @@ -516,7 +516,8 @@ public void onDecodingInfoChanged(final DecodingInfo decodingInfo) {
videoPlayer.start();
}
if (decodingInfo.currentFPS > 0) {
binding.tvMessage.setVisibility(View.INVISIBLE);
binding.tvMessage.setVisibility(View.GONE);
binding.wifiMessage.setVisibility(View.GONE);
}
String info = "%dx%d@%.0f " + (decodingInfo.nCodec == 1 ? " H265 " : " H264 ")
+ (decodingInfo.currentKiloBitsPerSecond > 1000 ? " %.1fMbps " : " %.1fKpbs ")
Expand Down Expand Up @@ -594,7 +595,7 @@ private void copyGSKey() {
out = new FileOutputStream(file);
out.write(keyBytes, 0, keyBytes.length);
} catch (IOException e) {
Log.e("tag", "Failed to copy asset", e);
Log.e(TAG, "Failed to copy asset", e);
} finally {
if (out != null) {
try {
Expand Down
21 changes: 10 additions & 11 deletions app/src/main/java/com/openipc/pixelpilot/WfbLinkManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ public synchronized void refreshAdapters() {
missingPermissions = true;
}
}

if (missingPermissions) {
return;
}


// Stops newly detached adapters.
Iterator<Map.Entry<String, UsbDevice>> iterator = activeWifiAdapters.entrySet().iterator();
while (iterator.hasNext()) {
Expand All @@ -132,12 +132,15 @@ public synchronized void refreshAdapters() {

if (activeWifiAdapters.isEmpty()) {
String text = "No compatible wifi adapter found.";
binding.tvMessage.setText(text);
binding.tvMessage.setVisibility(View.VISIBLE);

String wifi = VideoActivity.wirelessInfo();
if (wifi != null) {
text += "\n(udp://" + wifi + ":5600)";
String local = "udp://" + wifi + ":5600";
binding.wifiMessage.setText(local);
binding.wifiMessage.setVisibility(View.VISIBLE);
}
binding.tvMessage.setVisibility(View.VISIBLE);
binding.tvMessage.setText(text);
}
}

Expand Down Expand Up @@ -171,13 +174,9 @@ public synchronized void startAdapters(int channel) {

public synchronized boolean startAdapter(UsbDevice dev) {
binding.tvMessage.setVisibility(View.VISIBLE);
String name = String.format("%04X", dev.getVendorId()) + ":" + String.format("%04X", dev.getProductId());
if (binding.tvMessage.getText().toString().startsWith("Starting")
&& !binding.tvMessage.getText().toString().endsWith(name)) {
binding.tvMessage.setText(binding.tvMessage.getText() + ", " + name);
} else {
binding.tvMessage.setText("Starting wfb-ng on channel " + wifiChannel + " with " + name);
}
String text = "Starting wfb-ng channel " + wifiChannel + " with " + String.format(
"[%04X", dev.getVendorId()) + ":" + String.format("%04X]", dev.getProductId());
binding.tvMessage.setText(text);
wfbLink.start(wifiChannel, dev);
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/openipc/pixelpilot/osd/OSDManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ public void render(MavlinkData data) {
}

binding.tvGndSpeed.setText(formatFloat((float)
((data.telemetryGspeed / 100.0f - 1000.0) * 3.6f), "Km/h", ""));
((data.telemetryGSpeed / 100.0f - 1000.0) * 3.6f), "Km/h", ""));
binding.tvAirSpeed.setText(formatFloat((float)
(data.telemetryVspeed / 100.0f - 1000.0), "m/s", ""));
binding.tvSat.setText(formatFloat(data.telemetrySats, "", ""));
(data.telemetryVSpeed / 100.0f - 1000.0), "m/s", ""));
binding.tvSat.setText(formatFloat(data.telemetrySat, "", ""));
binding.tvLat.setText(String.format("%.7f", (float) (data.telemetryLat / 10000000.0f)));
binding.tvLon.setText(String.format("%.7f", (float) (data.telemetryLon / 10000000.0f)));

Expand Down
16 changes: 13 additions & 3 deletions app/src/main/res/layout/activity_video.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,20 @@
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5" />
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/wifi_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorWhite"
android:translationY="28dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<FrameLayout
android:id="@+id/osdLayout"
Expand Down

0 comments on commit 7794d8c

Please sign in to comment.