Skip to content
Merged
Show file tree
Hide file tree
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
66 changes: 47 additions & 19 deletions app/src/main/java/com/openipc/pixelpilot/VideoActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,9 @@ private void setupPieChart() {
chart.getDescription().setEnabled(false);
chart.setDrawHoleEnabled(true);
chart.setHoleColor(Color.WHITE);
chart.setTransparentCircleColor(Color.WHITE);
chart.setTransparentCircleAlpha(110);
chart.setHoleRadius(58f);
chart.setTransparentCircleRadius(61f);
chart.setHoleRadius(75f);
chart.setCenterTextSize(12);
chart.setCenterText("RSSI");
chart.setHighlightPerTapEnabled(false);
chart.setRotationEnabled(false);
chart.setClickable(false);
Expand Down Expand Up @@ -803,19 +802,34 @@ private void showFecThresholdsDialog() {
.setView(layout)
.setPositiveButton("OK", (dialog, which) -> {
SharedPreferences.Editor editor = prefs.edit();
try { editor.putInt("fec_lost_to_5", Integer.parseInt(edits[0].getText().toString())); } catch (Exception ignored) {}
try { editor.putInt("fec_recovered_to_4", Integer.parseInt(edits[1].getText().toString())); } catch (Exception ignored) {}
try { editor.putInt("fec_recovered_to_3", Integer.parseInt(edits[2].getText().toString())); } catch (Exception ignored) {}
try { editor.putInt("fec_recovered_to_2", Integer.parseInt(edits[3].getText().toString())); } catch (Exception ignored) {}
try { editor.putInt("fec_recovered_to_1", Integer.parseInt(edits[4].getText().toString())); } catch (Exception ignored) {}
try {
editor.putInt("fec_lost_to_5", Integer.parseInt(edits[0].getText().toString()));
} catch (Exception ignored) {
}
try {
editor.putInt("fec_recovered_to_4", Integer.parseInt(edits[1].getText().toString()));
} catch (Exception ignored) {
}
try {
editor.putInt("fec_recovered_to_3", Integer.parseInt(edits[2].getText().toString()));
} catch (Exception ignored) {
}
try {
editor.putInt("fec_recovered_to_2", Integer.parseInt(edits[3].getText().toString()));
} catch (Exception ignored) {
}
try {
editor.putInt("fec_recovered_to_1", Integer.parseInt(edits[4].getText().toString()));
} catch (Exception ignored) {
}
editor.apply();
setFecThresholdsFromPrefs();
})
.setNegativeButton("Cancel", null)
.show();
}

void initDefaultOptions(){
void initDefaultOptions() {
SharedPreferences prefs = getSharedPreferences("general", MODE_PRIVATE);
boolean adaptiveEnabled = prefs.getBoolean("adaptive_link_enabled", true);
int adaptiveTxPower = prefs.getInt("adaptive_tx_power", 20);
Expand Down Expand Up @@ -1211,8 +1225,7 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
// VPN permission not granted
Log.e(TAG, "VPN permission was not granted by the user.");
}
}
else {
} else {
Log.w(TAG, "onActivityResult: unknown request code " + requestCode);
}
}
Expand Down Expand Up @@ -1423,6 +1436,7 @@ public void onWfbNgStatsChanged(WfbNGStats data) {
if (data.count_p_all > 0) {
binding.tvMessage.setVisibility(View.INVISIBLE);
binding.tvMessage.setText("");

if (data.count_p_dec_err > 0) {
binding.tvLinkStatus.setText("Waiting for session key.");
} else {
Expand All @@ -1432,23 +1446,36 @@ public void onWfbNgStatsChanged(WfbNGStats data) {
entries.add(new PieEntry((float) data.count_p_dec_ok / data.count_p_all));
entries.add(new PieEntry((float) data.count_p_fec_recovered / data.count_p_all));
entries.add(new PieEntry((float) data.count_p_lost / data.count_p_all));

PieDataSet dataSet = new PieDataSet(entries, "Link Status");
dataSet.setDrawIcons(false);
dataSet.setDrawValues(false);

ArrayList<Integer> colors = new ArrayList<>();
colors.add(getColor(R.color.colorGreen));
colors.add(getColor(R.color.colorYellow));
colors.add(getColor(R.color.colorRed));
dataSet.setColors(colors);

PieData pieData = new PieData(dataSet);
pieData.setValueFormatter(new PercentFormatter());
pieData.setValueTextSize(11f);
pieData.setValueTextColor(Color.WHITE);

int rssiColor = getColor(R.color.colorGreenBg);
if (data.avg_rssi < 60 && 30 <= data.avg_rssi) {
rssiColor = getColor(R.color.colorYellow);
} else if (data.avg_rssi < 30) {
rssiColor = getColor(R.color.colorRed);
}

binding.pcLinkStat.setData(pieData);
binding.pcLinkStat.setCenterText("" + data.count_p_fec_recovered);
binding.pcLinkStat.setCenterTextSize(22);
binding.pcLinkStat.setCenterText("" + data.avg_rssi);
binding.pcLinkStat.setCenterTextColor(rssiColor);
binding.pcLinkStat.invalidate();

// Set link icon tint color.
int color = getColor(R.color.colorGreenBg);
if ((float) data.count_p_fec_recovered / data.count_p_all > 0.2) {
color = getColor(R.color.colorYellowBg);
Expand All @@ -1457,14 +1484,15 @@ public void onWfbNgStatsChanged(WfbNGStats data) {
color = getColor(R.color.colorRedBg);
}
binding.imgLinkStatus.setImageTintList(ColorStateList.valueOf(color));
binding.tvLinkStatus.setText(String.format("O%sD%sR%sL%s",
paddedDigits(data.count_p_outgoing, 6),
paddedDigits(data.count_p_dec_ok, 6),
paddedDigits(data.count_p_fec_recovered, 6),
paddedDigits(data.count_p_lost, 6)));

binding.tvLinkStatus.setText(String.format("Outgoing %3d Decoded %3d Recovered %3d Lost %3d",
data.count_p_outgoing,
data.count_p_dec_ok,
data.count_p_fec_recovered,
data.count_p_lost));
}
} else {
binding.tvLinkStatus.setText("No wfb-ng data.");
binding.tvLinkStatus.setText("No Video Link");
}
});
}
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/openipc/pixelpilot/osd/OSDManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public void onFinish() {
listOSDItems.add(new OSDElement("Timer", binding.itemTimer));
listOSDItems.add(new OSDElement("Total Distance", binding.itemTotDis));
listOSDItems.add(new OSDElement("Video Decoding", binding.itemVideoStats));
listOSDItems.add(new OSDElement("Video Link Txt", binding.itemLinkStatus));
listOSDItems.add(new OSDElement("Video Link Graph", binding.itemLinkStatusChart));
listOSDItems.add(new OSDElement("Video Link Status", binding.itemLinkStatus));
listOSDItems.add(new OSDElement("Video Link Status Graph", binding.itemLinkStatusChart));
restoreOSDConfig();
}

Expand Down Expand Up @@ -218,6 +218,7 @@ public void render(MavlinkData data) {
};
binding.tvFlightMode.setText(flightMode);

// Video status
if (!Objects.equals(currentFCStatus, data.status_text)) {
currentFCStatus = data.status_text;
binding.tvStatus.setVisibility(View.VISIBLE);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_video.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
android:layout_height="38dp"
android:layout_marginStart="5dp"
android:gravity="start|center_vertical"
android:text="Video Stats"
android:text="Video Decoding Stats"
android:textColor="@color/colorWhite"
android:textSize="14sp" />
</com.openipc.pixelpilot.osd.MovableLayout>
Expand Down
2 changes: 1 addition & 1 deletion app/wfbngrtl8812/src/main/cpp/SignalQualityCalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ SignalQualityCalculator::SignalQuality SignalQualityCalculator::calculate_signal

// __android_log_print(ANDROID_LOG_DEBUG, TAG, "avg_rssi: %f", avg_rssi);

// Map the RSSI from range 10..80 to -1024..1024
// Map the RSSI from range 0..80 to -1024..1024
avg_rssi = map_range(avg_rssi, 0.f, 80.f, -1024.f, 1024.f);
avg_rssi = std::max(-1024.f, std::min(1024.f, avg_rssi));

Expand Down
13 changes: 11 additions & 2 deletions app/wfbngrtl8812/src/main/cpp/WfbngLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,10 @@ extern "C" JNIEXPORT void JNICALL Java_com_openipc_wfbngrtl8812_WfbNgLink_native
native(wfbngLinkN)->stop(env, androidContext, fd);
}

float map_range(float value, float inputMin, float inputMax, float outputMin, float outputMax) {
return outputMin + ((value - inputMin) * (outputMax - outputMin) / (inputMax - inputMin));
}

extern "C" JNIEXPORT void JNICALL Java_com_openipc_wfbngrtl8812_WfbNgLink_nativeCallBack(JNIEnv *env,
jclass clazz,
jobject wfbStatChangedI,
Expand All @@ -363,12 +367,16 @@ extern "C" JNIEXPORT void JNICALL Java_com_openipc_wfbngrtl8812_WfbNgLink_native
if (jcStats == nullptr) {
return;
}
jmethodID jcStatsConstructor = env->GetMethodID(jcStats, "<init>", "(IIIIIIII)V");
jmethodID jcStatsConstructor = env->GetMethodID(jcStats, "<init>", "(IIIIIIIII)V");
if (jcStatsConstructor == nullptr) {
return;
}
SignalQualityCalculator::get_instance().add_fec_data(
aggregator->count_p_all, aggregator->count_p_fec_recovered, aggregator->count_p_lost);

auto quality = SignalQualityCalculator::get_instance().calculate_signal_quality();
uint32_t avg_rssi_int = round(map_range(quality.quality, -1024.f, 1024.f, 0.f, 100.f));

auto stats = env->NewObject(jcStats,
jcStatsConstructor,
(jint)aggregator->count_p_all,
Expand All @@ -378,7 +386,8 @@ extern "C" JNIEXPORT void JNICALL Java_com_openipc_wfbngrtl8812_WfbNgLink_native
(jint)aggregator->count_p_lost,
(jint)aggregator->count_p_bad,
(jint)aggregator->count_p_override,
(jint)aggregator->count_p_outgoing);
(jint)aggregator->count_p_outgoing,
(jint)avg_rssi_int);
if (stats == nullptr) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ public class WfbNGStats {
public final int count_p_bad;
public final int count_p_override;
public final int count_p_outgoing;
public final int avg_rssi;

public WfbNGStats(int cntPall, int cntDecErr, int cntDecOk, int cntFecRec,
int cntLost, int cntBad, int cntOverride, int cntOutgoing) {
int cntLost, int cntBad, int cntOverride, int cntOutgoing, int avgRssi) {
count_p_all = cntPall;
count_p_dec_err = cntDecErr;
count_p_dec_ok = cntDecOk;
Expand All @@ -23,5 +24,6 @@ public WfbNGStats(int cntPall, int cntDecErr, int cntDecOk, int cntFecRec,
count_p_bad = cntBad;
count_p_override = cntOverride;
count_p_outgoing = cntOutgoing;
avg_rssi = avgRssi;
}
}