generated from Grigo/AndroidTemplate
added local api
This commit is contained in:
@@ -4,6 +4,8 @@ import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.grigowashere.loratester.api.DeviceCommand;
|
||||
import com.grigowashere.loratester.api.PairedTrackSession;
|
||||
import com.grigowashere.loratester.api.ServerApi;
|
||||
@@ -120,11 +122,17 @@ public class CommandPoller {
|
||||
}
|
||||
switch (cmd.kind) {
|
||||
case "at" -> {
|
||||
String line = cmd.payload != null && cmd.payload.get("line") != null
|
||||
? String.valueOf(cmd.payload.get("line")) : null;
|
||||
if (line != null) {
|
||||
uploader.sendAtCommand(line, r ->
|
||||
Log.i(TAG, "remote AT " + line + " -> " + r));
|
||||
List<String> lines = extractLines(cmd.payload);
|
||||
if (lines != null && !lines.isEmpty()) {
|
||||
uploader.sendMacroSequence(lines, r ->
|
||||
Log.i(TAG, "remote macro " + lines + " -> " + r));
|
||||
} else {
|
||||
String line = cmd.payload != null && cmd.payload.get("line") != null
|
||||
? String.valueOf(cmd.payload.get("line")) : null;
|
||||
if (line != null) {
|
||||
uploader.sendAtCommand(line, r ->
|
||||
Log.i(TAG, "remote AT " + line + " -> " + r));
|
||||
}
|
||||
}
|
||||
}
|
||||
case "mode" -> {
|
||||
@@ -224,6 +232,33 @@ public class CommandPoller {
|
||||
return o instanceof Number ? ((Number) o).longValue() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static List<String> extractLines(Map<String, Object> payload) {
|
||||
if (payload == null) {
|
||||
return null;
|
||||
}
|
||||
Object raw = payload.get("lines");
|
||||
if (!(raw instanceof List<?> list) || list.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
List<String> lines = new java.util.ArrayList<>();
|
||||
for (Object item : list) {
|
||||
if (item != null) {
|
||||
String line = String.valueOf(item).trim();
|
||||
if (!line.isEmpty()) {
|
||||
lines.add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
return lines.isEmpty() ? null : lines;
|
||||
}
|
||||
|
||||
public void postMacroToPeer(String peerId, List<String> lines) {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
payload.put("lines", lines);
|
||||
postCommandToPeer(peerId, "at", payload);
|
||||
}
|
||||
|
||||
public void postCommandToPeer(String peerId, String kind, Map<String, Object> payload) {
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
|
||||
@@ -11,12 +11,14 @@ import com.grigowashere.loratester.api.UploadQueue;
|
||||
import com.grigowashere.loratester.net.NetworkMonitor;
|
||||
import com.grigowashere.loratester.location.GeoUtils;
|
||||
import com.grigowashere.loratester.telnet.AtCommandFormatter;
|
||||
import com.grigowashere.loratester.telnet.RadioMacroBuilder;
|
||||
import com.grigowashere.loratester.telnet.StatsExtractor;
|
||||
import com.grigowashere.loratester.telnet.TelnetClient;
|
||||
import com.grigowashere.loratester.telnet.TelnetFrameParser;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
@@ -168,6 +170,52 @@ public class TelemetryUploader implements TelnetClient.Listener {
|
||||
});
|
||||
}
|
||||
|
||||
public void sendMacroSequence(List<String> lines, AtSendCallback callback) {
|
||||
telnetExecutor.execute(() -> {
|
||||
TelnetClient.SendResult last = TelnetClient.SendResult.SENT;
|
||||
if (lines != null) {
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
String line = lines.get(i);
|
||||
if (line == null || line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
last = sendLineOnWorker(line);
|
||||
if (last != TelnetClient.SendResult.SENT) {
|
||||
break;
|
||||
}
|
||||
if (i < lines.size() - 1) {
|
||||
try {
|
||||
Thread.sleep(150);
|
||||
} catch (InterruptedException ignored) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback != null) {
|
||||
TelnetClient.SendResult r = last;
|
||||
mainHandler.post(() -> callback.onResult(r));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private TelnetClient.SendResult sendLineOnWorker(String line) {
|
||||
if (RadioMacroBuilder.STOP.equals(line)) {
|
||||
appendConsole(">> S\n");
|
||||
if (telnetClient == null) {
|
||||
appendConsole("!! telnet not started\n");
|
||||
return TelnetClient.SendResult.NOT_CONNECTED;
|
||||
}
|
||||
TelnetClient.SendResult result = telnetClient.sendRawLine(line);
|
||||
if (result != TelnetClient.SendResult.SENT) {
|
||||
appendConsole("!! send failed: " + result + "\n");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return sendAtCommandOnWorker(line);
|
||||
}
|
||||
|
||||
private TelnetClient.SendResult sendAtCommandOnWorker(String command) {
|
||||
String normalized = AtCommandFormatter.normalize(command);
|
||||
appendConsole(">> " + normalized + "\n");
|
||||
|
||||
@@ -20,4 +20,14 @@ public final class GeoUtils {
|
||||
public static boolean isValidCoordinate(Double lat, Double lon) {
|
||||
return lat != null && lon != null && isValidCoordinate(lat.doubleValue(), lon.doubleValue());
|
||||
}
|
||||
|
||||
public static double haversineMeters(double lat1, double lon1, double lat2, double lon2) {
|
||||
final double r = 6_371_000;
|
||||
double dLat = Math.toRadians(lat2 - lat1);
|
||||
double dLon = Math.toRadians(lon2 - lon1);
|
||||
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
|
||||
+ Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2))
|
||||
* Math.sin(dLon / 2) * Math.sin(dLon / 2);
|
||||
return r * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
package com.grigowashere.loratester.model;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.grigowashere.loratester.telnet.StatsExtractor;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/** Normalized radio stats from telemetry meta JSON (no duplicate fields). */
|
||||
public final class RadioSnapshot {
|
||||
|
||||
public final String role;
|
||||
public final String frame;
|
||||
public final Double frequencyMhz;
|
||||
public final Integer sf;
|
||||
public final Integer bwKhz;
|
||||
public final Double powerDbm;
|
||||
public final Double rssiDbm;
|
||||
public final Double snrDb;
|
||||
public final Integer packet;
|
||||
public final String payload;
|
||||
public final Double onAirMs;
|
||||
public final Double txPktPerS;
|
||||
public final Double rxPktPerS;
|
||||
public final Double perPercent;
|
||||
public final Map<String, String> extraFields;
|
||||
|
||||
public RadioSnapshot(
|
||||
String role,
|
||||
String frame,
|
||||
Double frequencyMhz,
|
||||
Integer sf,
|
||||
Integer bwKhz,
|
||||
Double powerDbm,
|
||||
Double rssiDbm,
|
||||
Double snrDb,
|
||||
Integer packet,
|
||||
String payload,
|
||||
Double onAirMs,
|
||||
Double txPktPerS,
|
||||
Double rxPktPerS,
|
||||
Double perPercent,
|
||||
Map<String, String> extraFields
|
||||
) {
|
||||
this.role = role;
|
||||
this.frame = frame;
|
||||
this.frequencyMhz = frequencyMhz;
|
||||
this.sf = sf;
|
||||
this.bwKhz = bwKhz;
|
||||
this.powerDbm = powerDbm;
|
||||
this.rssiDbm = rssiDbm;
|
||||
this.snrDb = snrDb;
|
||||
this.packet = packet;
|
||||
this.payload = payload;
|
||||
this.onAirMs = onAirMs;
|
||||
this.txPktPerS = txPktPerS;
|
||||
this.rxPktPerS = rxPktPerS;
|
||||
this.perPercent = perPercent;
|
||||
this.extraFields = extraFields != null ? extraFields : Map.of();
|
||||
}
|
||||
|
||||
public static RadioSnapshot empty() {
|
||||
return new RadioSnapshot(null, null, null, null, null, null, null, null,
|
||||
null, null, null, null, null, null, Map.of());
|
||||
}
|
||||
|
||||
public static RadioSnapshot fromMeta(String metaJson, String roleFallback, Double rssiFallback) {
|
||||
if (metaJson == null || metaJson.isBlank()) {
|
||||
RadioSnapshot snap = empty();
|
||||
if (roleFallback != null || rssiFallback != null) {
|
||||
return new RadioSnapshot(roleFallback, null, null, null, null, null,
|
||||
rssiFallback, null, null, null, null, null, null, null, Map.of());
|
||||
}
|
||||
return snap;
|
||||
}
|
||||
try {
|
||||
JsonObject o = JsonParser.parseString(metaJson).getAsJsonObject();
|
||||
String role = text(o, "role");
|
||||
if (role == null) {
|
||||
role = roleFallback;
|
||||
}
|
||||
Double rssi = dbl(o, "rssi_dbm");
|
||||
if (rssi == null) {
|
||||
rssi = rssiFallback;
|
||||
}
|
||||
Map<String, String> extra = new LinkedHashMap<>();
|
||||
JsonElement fieldsEl = o.get("fields");
|
||||
if (fieldsEl != null && fieldsEl.isJsonObject()) {
|
||||
for (Map.Entry<String, JsonElement> e : fieldsEl.getAsJsonObject().entrySet()) {
|
||||
String label = e.getKey();
|
||||
if (isKnownFieldLabel(label)) {
|
||||
continue;
|
||||
}
|
||||
extra.put(label, e.getValue().getAsString());
|
||||
}
|
||||
}
|
||||
return new RadioSnapshot(
|
||||
role,
|
||||
text(o, "frame"),
|
||||
hzToMhz(lng(o, "frequency_hz")),
|
||||
integer(o, "spreading_factor"),
|
||||
integer(o, "bandwidth_khz"),
|
||||
dbl(o, "power_dbm"),
|
||||
rssi,
|
||||
dbl(o, "snr_db"),
|
||||
integer(o, "packet"),
|
||||
text(o, "payload"),
|
||||
dbl(o, "on_air_ms"),
|
||||
dbl(o, "tx_pkt_per_s"),
|
||||
dbl(o, "rx_pkt_per_s"),
|
||||
dbl(o, "per_percent"),
|
||||
extra
|
||||
);
|
||||
} catch (Exception ignored) {
|
||||
return new RadioSnapshot(roleFallback, null, null, null, null, null,
|
||||
rssiFallback, null, null, null, null, null, null, null, Map.of());
|
||||
}
|
||||
}
|
||||
|
||||
public static RadioSnapshot fromExtracted(StatsExtractor.ExtractedStats stats) {
|
||||
if (stats == null) {
|
||||
return empty();
|
||||
}
|
||||
return fromMeta(stats.metaJson, stats.role, stats.rssiDbm != null ? stats.rssiDbm : stats.rssi);
|
||||
}
|
||||
|
||||
public Set<String> diff(RadioSnapshot prev) {
|
||||
Set<String> changed = new HashSet<>();
|
||||
if (prev == null) {
|
||||
return changed;
|
||||
}
|
||||
cmp(changed, "role", role, prev.role);
|
||||
cmp(changed, "rssi", rssiDbm, prev.rssiDbm);
|
||||
cmp(changed, "snr", snrDb, prev.snrDb);
|
||||
cmp(changed, "packet", packet, prev.packet);
|
||||
cmp(changed, "payload", payload, prev.payload);
|
||||
cmp(changed, "per", perPercent, prev.perPercent);
|
||||
cmp(changed, "txSpeed", txPktPerS, prev.txPktPerS);
|
||||
cmp(changed, "rxSpeed", rxPktPerS, prev.rxPktPerS);
|
||||
cmp(changed, "frequency", frequencyMhz, prev.frequencyMhz);
|
||||
cmp(changed, "sf", sf, prev.sf);
|
||||
cmp(changed, "bw", bwKhz, prev.bwKhz);
|
||||
cmp(changed, "power", powerDbm, prev.powerDbm);
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static void cmp(Set<String> changed, String key, Object a, Object b) {
|
||||
if (!Objects.equals(a, b)) {
|
||||
changed.add(key);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isKnownFieldLabel(String label) {
|
||||
String n = label.toLowerCase(Locale.ROOT).trim();
|
||||
return n.equals("send") || n.equals("receive")
|
||||
|| n.contains("frequency") || n.equals("power") || n.equals("rssi")
|
||||
|| n.equals("snr") || n.contains("spreading") || n.contains("bandwidth")
|
||||
|| n.equals("packet") || n.contains("packet number") || n.equals("payload")
|
||||
|| n.contains("on air") || n.contains("tx speed") || n.contains("rx speed")
|
||||
|| n.equals("per");
|
||||
}
|
||||
|
||||
private static String text(JsonObject o, String key) {
|
||||
JsonElement e = o.get(key);
|
||||
return e != null && !e.isJsonNull() ? e.getAsString() : null;
|
||||
}
|
||||
|
||||
private static Integer integer(JsonObject o, String key) {
|
||||
JsonElement e = o.get(key);
|
||||
return e != null && e.isJsonPrimitive() ? e.getAsInt() : null;
|
||||
}
|
||||
|
||||
private static Double dbl(JsonObject o, String key) {
|
||||
JsonElement e = o.get(key);
|
||||
return e != null && e.isJsonPrimitive() ? e.getAsDouble() : null;
|
||||
}
|
||||
|
||||
private static Long lng(JsonObject o, String key) {
|
||||
JsonElement e = o.get(key);
|
||||
return e != null && e.isJsonPrimitive() ? e.getAsLong() : null;
|
||||
}
|
||||
|
||||
private static Double hzToMhz(Long hz) {
|
||||
if (hz == null) {
|
||||
return null;
|
||||
}
|
||||
return hz / 1_000_000.0;
|
||||
}
|
||||
}
|
||||
@@ -30,4 +30,12 @@ public final class AtCommandFormatter {
|
||||
String wire = line + "\r\n";
|
||||
return wire.getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/** Literal line (e.g. screen reset "S") without AT prefix. */
|
||||
public static byte[] toWireBytesLiteral(String line) {
|
||||
if (line == null || line.isEmpty()) {
|
||||
return new byte[0];
|
||||
}
|
||||
return (line + "\r\n").getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,33 @@
|
||||
package com.grigowashere.loratester.telnet;
|
||||
|
||||
/** Common AT commands for LoRa modules (via telnet bridge). */
|
||||
/** LoRa module AT commands (telnet bridge). */
|
||||
public final class AtCommands {
|
||||
|
||||
public static final String HELP = "AT+H";
|
||||
public static final String TRANSMIT = "AT+TX";
|
||||
public static final String RECEIVE = "AT+RX";
|
||||
/** Stop TX or RX test. */
|
||||
public static final String STOP = "S";
|
||||
public static final String TIMEOUT_MS = "AT+TM=";
|
||||
public static final String FREQUENCY_HZ = "AT+FQ=";
|
||||
public static final String POWER_DBM = "AT+PW=";
|
||||
public static final String SPREADING_FACTOR = "AT+SF=";
|
||||
public static final String BANDWIDTH = "AT+BW=";
|
||||
public static final String CODE_RATE = "AT+CR=";
|
||||
public static final String PREAMBLE = "AT+PL=";
|
||||
|
||||
/** Legacy / bridge helpers (if supported by firmware). */
|
||||
public static final String HELP = "AT+H";
|
||||
public static final String STATUS = "AT+STATUS";
|
||||
public static final String RESET = "AT+RESET";
|
||||
public static final String BASIC = "AT";
|
||||
|
||||
public static final String[] BW_KHZ = {
|
||||
"7.81", "10.42", "15.63", "20.83", "31.25",
|
||||
"41.67", "62.5", "125", "250", "500"
|
||||
};
|
||||
|
||||
public static final String[] CODE_RATES = {"4/5", "4/6", "4/7", "4/8"};
|
||||
|
||||
private AtCommands() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package com.grigowashere.loratester.telnet;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.grigowashere.loratester.model.RadioSnapshot;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -14,67 +11,56 @@ public final class LoraStatsFormatter {
|
||||
private LoraStatsFormatter() {
|
||||
}
|
||||
|
||||
/** Human-readable lines from telemetry meta JSON (fields first). */
|
||||
@Deprecated
|
||||
public static String formatMeta(String metaJson) {
|
||||
if (metaJson == null || metaJson.isEmpty()) {
|
||||
RadioSnapshot snap = RadioSnapshot.fromMeta(metaJson, null, null);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String dynamic = formatDynamic(snap, Set.of());
|
||||
if (!dynamic.isEmpty()) {
|
||||
sb.append(dynamic);
|
||||
}
|
||||
String stat = formatStatic(snap, Set.of());
|
||||
if (!stat.isEmpty()) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append("\n");
|
||||
}
|
||||
sb.append(stat);
|
||||
}
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
public static String formatDynamic(RadioSnapshot s, Set<String> changed) {
|
||||
if (s == null) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
JsonObject o = JsonParser.parseString(metaJson).getAsJsonObject();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Set<String> shown = new HashSet<>();
|
||||
|
||||
appendFieldsBlock(sb, o.get("fields"), shown);
|
||||
|
||||
String role = text(o, "role");
|
||||
if (role != null) {
|
||||
append(sb, "Роль", roleLabel(role));
|
||||
}
|
||||
append(sb, "Кадр", text(o, "frame"));
|
||||
append(sb, "Мощность TX", dbl(o, "power_dbm"), " dBm");
|
||||
append(sb, "RSSI", dbl(o, "rssi_dbm"), " dBm");
|
||||
append(sb, "SNR", dbl(o, "snr_db"), " dB");
|
||||
append(sb, "Частота", freqMhz(o), " MHz");
|
||||
append(sb, "SF", integer(o, "spreading_factor"));
|
||||
append(sb, "BW", integer(o, "bandwidth_khz"), " kHz");
|
||||
append(sb, "Пакет", integer(o, "packet"));
|
||||
append(sb, "Payload", text(o, "payload"));
|
||||
append(sb, "On Air", dbl(o, "on_air_ms"), " ms");
|
||||
append(sb, "TX Speed", dbl(o, "tx_pkt_per_s"), " pkt/s");
|
||||
append(sb, "RX Speed", dbl(o, "rx_pkt_per_s"), " pkt/s");
|
||||
append(sb, "PER", dbl(o, "per_percent"), " %");
|
||||
return sb.toString().trim();
|
||||
} catch (Exception ignored) {
|
||||
return metaJson;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
appendLine(sb, "RSSI", fmtDbm(s.rssiDbm), "rssi", changed);
|
||||
appendLine(sb, "SNR", fmtSuffix(s.snrDb, " dB"), "snr", changed);
|
||||
appendLine(sb, "Пакет", fmtInt(s.packet), "packet", changed);
|
||||
appendLine(sb, "Payload", s.payload, "payload", changed);
|
||||
appendLine(sb, "PER", fmtSuffix(s.perPercent, " %"), "per", changed);
|
||||
appendLine(sb, "TX Speed", fmtSuffix(s.txPktPerS, " pkt/s"), "txSpeed", changed);
|
||||
appendLine(sb, "RX Speed", fmtSuffix(s.rxPktPerS, " pkt/s"), "rxSpeed", changed);
|
||||
for (Map.Entry<String, String> e : s.extraFields.entrySet()) {
|
||||
append(sb, e.getKey(), e.getValue());
|
||||
}
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
private static void appendFieldsBlock(StringBuilder sb, JsonElement fieldsEl, Set<String> shown) {
|
||||
if (fieldsEl == null || !fieldsEl.isJsonObject()) {
|
||||
return;
|
||||
public static String formatStatic(RadioSnapshot s, Set<String> changed) {
|
||||
if (s == null) {
|
||||
return "";
|
||||
}
|
||||
JsonObject fields = fieldsEl.getAsJsonObject();
|
||||
for (Map.Entry<String, JsonElement> e : fields.entrySet()) {
|
||||
String label = e.getKey();
|
||||
if (isSkippedFieldLabel(label)) {
|
||||
continue;
|
||||
}
|
||||
String norm = normalizeLabel(label);
|
||||
if (shown.contains(norm)) {
|
||||
continue;
|
||||
}
|
||||
shown.add(norm);
|
||||
append(sb, label, e.getValue().getAsString());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (s.role != null) {
|
||||
appendLine(sb, "Роль", roleLabel(s.role), "role", changed);
|
||||
}
|
||||
}
|
||||
|
||||
private static String normalizeLabel(String label) {
|
||||
return label.toLowerCase(Locale.ROOT).replaceAll("\\s+", " ").trim();
|
||||
}
|
||||
|
||||
private static boolean isSkippedFieldLabel(String label) {
|
||||
String l = normalizeLabel(label);
|
||||
return l.equals("send") || l.equals("receive");
|
||||
appendLine(sb, "Частота", fmtSuffix(s.frequencyMhz, " MHz"), "frequency", changed);
|
||||
appendLine(sb, "SF", fmtInt(s.sf), "sf", changed);
|
||||
appendLine(sb, "BW", fmtSuffix(s.bwKhz, " kHz"), "bw", changed);
|
||||
appendLine(sb, "Мощность TX", fmtDbm(s.powerDbm), "power", changed);
|
||||
appendLine(sb, "On Air", fmtSuffix(s.onAirMs, " ms"), "onAir", changed);
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
public static String roleLabel(String role) {
|
||||
@@ -87,12 +73,23 @@ public final class LoraStatsFormatter {
|
||||
return role;
|
||||
}
|
||||
|
||||
private static String freqMhz(JsonObject o) {
|
||||
if (!o.has("frequency_hz")) {
|
||||
return null;
|
||||
private static void appendLine(
|
||||
StringBuilder sb,
|
||||
String label,
|
||||
String value,
|
||||
String changeKey,
|
||||
Set<String> changed
|
||||
) {
|
||||
if (value == null || value.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
long hz = o.get("frequency_hz").getAsLong();
|
||||
return String.format(Locale.US, "%.3f", hz / 1_000_000.0);
|
||||
if (sb.length() > 0) {
|
||||
sb.append("\n");
|
||||
}
|
||||
if (changed != null && changed.contains(changeKey)) {
|
||||
sb.append("▸ ");
|
||||
}
|
||||
sb.append(label).append(": ").append(value);
|
||||
}
|
||||
|
||||
private static void append(StringBuilder sb, String label, String value) {
|
||||
@@ -105,25 +102,19 @@ public final class LoraStatsFormatter {
|
||||
sb.append(label).append(": ").append(value);
|
||||
}
|
||||
|
||||
private static void append(StringBuilder sb, String label, String value, String suffix) {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
append(sb, label, value + suffix);
|
||||
private static String fmtDbm(Double v) {
|
||||
return v != null ? String.format(Locale.US, "%.0f dBm", v) : null;
|
||||
}
|
||||
|
||||
private static String text(JsonObject o, String key) {
|
||||
JsonElement e = o.get(key);
|
||||
return e != null && !e.isJsonNull() ? e.getAsString() : null;
|
||||
private static String fmtInt(Integer v) {
|
||||
return v != null ? String.valueOf(v) : null;
|
||||
}
|
||||
|
||||
private static String integer(JsonObject o, String key) {
|
||||
JsonElement e = o.get(key);
|
||||
return e != null && e.isJsonPrimitive() ? String.valueOf(e.getAsInt()) : null;
|
||||
private static String fmtSuffix(Double v, String suffix) {
|
||||
return v != null ? String.format(Locale.US, "%s%s", v, suffix) : null;
|
||||
}
|
||||
|
||||
private static String dbl(JsonObject o, String key) {
|
||||
JsonElement e = o.get(key);
|
||||
return e != null && e.isJsonPrimitive() ? String.valueOf(e.getAsDouble()) : null;
|
||||
private static String fmtSuffix(Integer v, String suffix) {
|
||||
return v != null ? v + suffix : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.grigowashere.loratester.telnet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** Builds macro: S (stop) then configuration AT commands, then TX/RX if requested. */
|
||||
public final class RadioMacroBuilder {
|
||||
|
||||
/** Stop TX or RX before applying new settings. */
|
||||
public static final String STOP = AtCommands.STOP;
|
||||
|
||||
/** @deprecated use {@link #STOP} */
|
||||
@Deprecated
|
||||
public static final String SCREEN_RESET = STOP;
|
||||
|
||||
public static final class Params {
|
||||
public Long frequencyHz;
|
||||
public Integer powerDbm;
|
||||
public Integer sf;
|
||||
public String bwKhz;
|
||||
public String codeRate;
|
||||
public Integer preamble;
|
||||
public Integer sendTimeoutMs;
|
||||
public String role;
|
||||
}
|
||||
|
||||
private RadioMacroBuilder() {
|
||||
}
|
||||
|
||||
public static List<String> apply(Integer sf, Integer bwKhz, String role) {
|
||||
Params p = new Params();
|
||||
p.sf = sf;
|
||||
if (bwKhz != null) {
|
||||
p.bwKhz = String.valueOf(bwKhz);
|
||||
}
|
||||
p.role = role;
|
||||
return apply(p);
|
||||
}
|
||||
|
||||
public static List<String> apply(Params p) {
|
||||
List<String> lines = new ArrayList<>();
|
||||
lines.add(STOP);
|
||||
if (p == null) {
|
||||
return lines;
|
||||
}
|
||||
if (p.frequencyHz != null && p.frequencyHz >= 430_000_000L && p.frequencyHz <= 470_000_000L) {
|
||||
lines.add(AtCommands.FREQUENCY_HZ + p.frequencyHz);
|
||||
}
|
||||
if (p.powerDbm != null && p.powerDbm >= -9 && p.powerDbm <= 22) {
|
||||
lines.add(AtCommands.POWER_DBM + p.powerDbm);
|
||||
}
|
||||
if (p.sf != null && p.sf >= 5 && p.sf <= 12) {
|
||||
lines.add(AtCommands.SPREADING_FACTOR + p.sf);
|
||||
}
|
||||
if (p.bwKhz != null && !p.bwKhz.isBlank()) {
|
||||
lines.add(AtCommands.BANDWIDTH + p.bwKhz.trim());
|
||||
}
|
||||
if (p.codeRate != null && !p.codeRate.isBlank()) {
|
||||
lines.add(AtCommands.CODE_RATE + p.codeRate.trim());
|
||||
}
|
||||
if (p.preamble != null && p.preamble >= 1 && p.preamble <= 64) {
|
||||
lines.add(AtCommands.PREAMBLE + p.preamble);
|
||||
}
|
||||
if (p.sendTimeoutMs != null && p.sendTimeoutMs >= 0 && p.sendTimeoutMs <= 60_000) {
|
||||
lines.add(AtCommands.TIMEOUT_MS + p.sendTimeoutMs);
|
||||
}
|
||||
if (StatsExtractor.ROLE_TX.equals(p.role)) {
|
||||
lines.add(AtCommands.TRANSMIT);
|
||||
} else if (StatsExtractor.ROLE_RX.equals(p.role)) {
|
||||
lines.add(AtCommands.RECEIVE);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
}
|
||||
@@ -68,10 +68,6 @@ public class StatsExtractor {
|
||||
if (role != null) {
|
||||
meta.put("role", role);
|
||||
}
|
||||
if (!fields.isEmpty()) {
|
||||
meta.put("fields", fields);
|
||||
}
|
||||
|
||||
Double rssiDbm = firstDouble(RSSI, normalized);
|
||||
if (rssiDbm == null) {
|
||||
rssiDbm = matchDouble(rssiPattern, normalized);
|
||||
@@ -103,7 +99,9 @@ public class StatsExtractor {
|
||||
putDouble(meta, "rx_pkt_per_s", matchDouble(RX_SPEED, normalized));
|
||||
putDouble(meta, "per_percent", matchDouble(PER, normalized));
|
||||
|
||||
enrichFieldsFromStructured(meta, fields);
|
||||
if (!fields.isEmpty()) {
|
||||
meta.put("fields", fields);
|
||||
}
|
||||
|
||||
Double rangeM = matchDouble(rangePattern, normalized);
|
||||
Double displayDbm = rssiDbm != null ? rssiDbm : txPower;
|
||||
@@ -128,57 +126,21 @@ public class StatsExtractor {
|
||||
String value = trimmed.substring(colon + 1).trim();
|
||||
if (label.isEmpty()
|
||||
|| label.equalsIgnoreCase("SEND")
|
||||
|| label.equalsIgnoreCase("RECEIVE")) {
|
||||
|| label.equalsIgnoreCase("RECEIVE")
|
||||
|| isStructuredLabel(label)) {
|
||||
continue;
|
||||
}
|
||||
fields.put(label, value);
|
||||
}
|
||||
}
|
||||
|
||||
/** Ensure meta.fields has display lines even when line split missed some rows. */
|
||||
private static void enrichFieldsFromStructured(
|
||||
Map<String, Object> meta,
|
||||
Map<String, String> fields
|
||||
) {
|
||||
putFieldIfAbsent(fields, "Frequency", meta.get("frequency_hz"),
|
||||
v -> v + " Hz");
|
||||
putFieldIfAbsent(fields, "Power", meta.get("power_dbm"),
|
||||
v -> v + " dBm");
|
||||
putFieldIfAbsent(fields, "RSSI", meta.get("rssi_dbm"),
|
||||
v -> String.valueOf(v));
|
||||
putFieldIfAbsent(fields, "SNR", meta.get("snr_db"),
|
||||
v -> String.valueOf(v));
|
||||
putFieldIfAbsent(fields, "Spreading Factor", meta.get("spreading_factor"),
|
||||
String::valueOf);
|
||||
putFieldIfAbsent(fields, "Bandwidth", meta.get("bandwidth_khz"),
|
||||
v -> v + " kHz");
|
||||
Object packet = meta.get("packet");
|
||||
if (packet != null) {
|
||||
putFieldIfAbsent(fields, "Packet", packet, String::valueOf);
|
||||
putFieldIfAbsent(fields, "Packet Number", packet, String::valueOf);
|
||||
}
|
||||
putFieldIfAbsent(fields, "Payload", meta.get("payload"),
|
||||
v -> (String) v);
|
||||
putFieldIfAbsent(fields, "On Air", meta.get("on_air_ms"),
|
||||
v -> v + " ms");
|
||||
putFieldIfAbsent(fields, "TX Speed", meta.get("tx_pkt_per_s"),
|
||||
v -> v + " pkt/s");
|
||||
putFieldIfAbsent(fields, "RX Speed", meta.get("rx_pkt_per_s"),
|
||||
v -> v + " pkt/s");
|
||||
putFieldIfAbsent(fields, "PER", meta.get("per_percent"),
|
||||
v -> v + " %");
|
||||
}
|
||||
|
||||
private static void putFieldIfAbsent(
|
||||
Map<String, String> fields,
|
||||
String label,
|
||||
Object value,
|
||||
java.util.function.Function<Object, String> format
|
||||
) {
|
||||
if (value == null || fields.containsKey(label)) {
|
||||
return;
|
||||
}
|
||||
fields.put(label, format.apply(value));
|
||||
private static boolean isStructuredLabel(String label) {
|
||||
String n = label.toLowerCase(Locale.ROOT).trim();
|
||||
return n.equals("frequency") || n.equals("power") || n.equals("rssi")
|
||||
|| n.equals("snr") || n.contains("spreading factor") || n.equals("bandwidth")
|
||||
|| n.equals("packet") || n.contains("packet number") || n.equals("payload")
|
||||
|| n.contains("on air") || n.contains("tx speed") || n.contains("rx speed")
|
||||
|| n.equals("per");
|
||||
}
|
||||
|
||||
private static ExtractedStats empty(String frame) {
|
||||
|
||||
@@ -74,11 +74,23 @@ public class TelnetClient {
|
||||
/**
|
||||
* Sends an AT command. Adds AT prefix and CR+LF if missing.
|
||||
*/
|
||||
public SendResult sendRawLine(String line) {
|
||||
byte[] wire = AtCommandFormatter.toWireBytesLiteral(line);
|
||||
if (wire.length == 0) {
|
||||
return SendResult.EMPTY;
|
||||
}
|
||||
return writeWire(wire);
|
||||
}
|
||||
|
||||
public SendResult sendAtCommand(String command) {
|
||||
byte[] wire = AtCommandFormatter.toWireBytes(command);
|
||||
if (wire.length == 0) {
|
||||
return SendResult.EMPTY;
|
||||
}
|
||||
return writeWire(wire);
|
||||
}
|
||||
|
||||
private SendResult writeWire(byte[] wire) {
|
||||
Socket socket = activeSocket.get();
|
||||
if (socket == null || socket.isClosed()) {
|
||||
return SendResult.NOT_CONNECTED;
|
||||
|
||||
@@ -29,7 +29,11 @@ public class TrackRecorder {
|
||||
|
||||
public interface Listener {
|
||||
void onStateChanged(boolean recording, int pointCount, long trackId);
|
||||
|
||||
void onError(String message);
|
||||
|
||||
default void onPointRecorded(double lat, double lon) {
|
||||
}
|
||||
}
|
||||
|
||||
private final ServerApi serverApi;
|
||||
@@ -209,6 +213,18 @@ public class TrackRecorder {
|
||||
}
|
||||
totalPoints++;
|
||||
notifyState();
|
||||
notifyPoint(lat, lon);
|
||||
}
|
||||
|
||||
private void notifyPoint(double lat, double lon) {
|
||||
mainHandler.post(() -> {
|
||||
if (listener != null) {
|
||||
listener.onPointRecorded(lat, lon);
|
||||
}
|
||||
if (pairedListener != null) {
|
||||
pairedListener.onPointRecorded(lat, lon);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void flushBuffer() {
|
||||
|
||||
@@ -5,8 +5,10 @@ import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -14,9 +16,8 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.android.material.button.MaterialButtonToggleGroup;
|
||||
import com.google.android.material.chip.Chip;
|
||||
import com.google.android.material.chip.ChipGroup;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.grigowashere.loratester.CommandPoller;
|
||||
import com.grigowashere.loratester.LoraApp;
|
||||
@@ -24,12 +25,15 @@ import com.grigowashere.loratester.PeerDevices;
|
||||
import com.grigowashere.loratester.R;
|
||||
import com.grigowashere.loratester.TelemetryUploader;
|
||||
import com.grigowashere.loratester.api.DeviceInfo;
|
||||
import com.grigowashere.loratester.model.RadioSnapshot;
|
||||
import com.grigowashere.loratester.telnet.AtCommands;
|
||||
import com.grigowashere.loratester.telnet.LoraStatsFormatter;
|
||||
import com.grigowashere.loratester.telnet.RadioMacroBuilder;
|
||||
import com.grigowashere.loratester.telnet.StatsExtractor;
|
||||
import com.grigowashere.loratester.telnet.TelnetClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@@ -40,11 +44,21 @@ public class AtFragment extends Fragment {
|
||||
private TelemetryUploader uploader;
|
||||
private CommandPoller commandPoller;
|
||||
private TextView atStatus;
|
||||
private TextView atConsole;
|
||||
private ScrollView atConsoleScroll;
|
||||
private TextInputEditText atCommandInput;
|
||||
private TextView atCurrentSnapshot;
|
||||
private TextInputEditText atInputFq;
|
||||
private TextInputEditText atInputPw;
|
||||
private TextInputEditText atInputSf;
|
||||
private TextInputEditText atInputPl;
|
||||
private TextInputEditText atInputTm;
|
||||
private Spinner atBwSpinner;
|
||||
private Spinner atCrSpinner;
|
||||
private Spinner atRoleSpinner;
|
||||
private MaterialButtonToggleGroup atTargetGroup;
|
||||
private ScrollView atConsoleScroll;
|
||||
private TextView atConsole;
|
||||
private String lastConsole = "";
|
||||
private boolean consoleVisible;
|
||||
private boolean formInitialized;
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
@@ -67,109 +81,99 @@ public class AtFragment extends Fragment {
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
atStatus = view.findViewById(R.id.atStatus);
|
||||
atConsole = view.findViewById(R.id.atConsole);
|
||||
atConsoleScroll = view.findViewById(R.id.atConsoleScroll);
|
||||
atCommandInput = view.findViewById(R.id.atCommandInput);
|
||||
atCurrentSnapshot = view.findViewById(R.id.atCurrentSnapshot);
|
||||
atInputFq = view.findViewById(R.id.atInputFq);
|
||||
atInputPw = view.findViewById(R.id.atInputPw);
|
||||
atInputSf = view.findViewById(R.id.atInputSf);
|
||||
atInputPl = view.findViewById(R.id.atInputPl);
|
||||
atInputTm = view.findViewById(R.id.atInputTm);
|
||||
atBwSpinner = view.findViewById(R.id.atBwSpinner);
|
||||
atCrSpinner = view.findViewById(R.id.atCrSpinner);
|
||||
atRoleSpinner = view.findViewById(R.id.atRoleSpinner);
|
||||
atTargetGroup = view.findViewById(R.id.atTargetGroup);
|
||||
ChipGroup chips = view.findViewById(R.id.atQuickChips);
|
||||
Button sendBtn = view.findViewById(R.id.atSendBtn);
|
||||
Button clearLog = view.findViewById(R.id.atClearLog);
|
||||
pollHelper = new FragmentPollHelper(this, this::refreshConsole);
|
||||
atConsoleScroll = view.findViewById(R.id.atConsoleScroll);
|
||||
atConsole = view.findViewById(R.id.atConsole);
|
||||
Button applyBtn = view.findViewById(R.id.atApplyBtn);
|
||||
Button stopBtn = view.findViewById(R.id.atStopBtn);
|
||||
MaterialButton consoleToggle = view.findViewById(R.id.atConsoleToggle);
|
||||
pollHelper = new FragmentPollHelper(this, this::refresh);
|
||||
|
||||
if (atTargetGroup != null) {
|
||||
atTargetGroup.check(R.id.atTargetLocal);
|
||||
}
|
||||
atTargetGroup.check(R.id.atTargetLocal);
|
||||
atBwSpinner.setAdapter(new ArrayAdapter<>(
|
||||
requireContext(),
|
||||
android.R.layout.simple_spinner_dropdown_item,
|
||||
AtCommands.BW_KHZ
|
||||
));
|
||||
atCrSpinner.setAdapter(new ArrayAdapter<>(
|
||||
requireContext(),
|
||||
android.R.layout.simple_spinner_dropdown_item,
|
||||
AtCommands.CODE_RATES
|
||||
));
|
||||
atRoleSpinner.setAdapter(new ArrayAdapter<>(
|
||||
requireContext(),
|
||||
android.R.layout.simple_spinner_dropdown_item,
|
||||
new String[]{"—", "TX", "RX"}
|
||||
));
|
||||
|
||||
addQuickChip(chips, "AT+H", AtCommands.HELP);
|
||||
addQuickChip(chips, "AT+TX", AtCommands.TRANSMIT);
|
||||
addQuickChip(chips, "AT+RX", AtCommands.RECEIVE);
|
||||
addQuickChip(chips, "AT+STATUS", AtCommands.STATUS);
|
||||
addQuickChip(chips, "AT", AtCommands.BASIC);
|
||||
|
||||
sendBtn.setOnClickListener(v -> sendFromInput());
|
||||
clearLog.setOnClickListener(v -> {
|
||||
if (uploader != null) {
|
||||
uploader.clearConsoleLog();
|
||||
}
|
||||
lastConsole = "";
|
||||
if (atConsole != null) {
|
||||
atConsole.setText("");
|
||||
}
|
||||
applyBtn.setOnClickListener(v -> applyMacro());
|
||||
stopBtn.setOnClickListener(v -> sendLines(List.of(AtCommands.STOP)));
|
||||
consoleToggle.setOnClickListener(v -> {
|
||||
consoleVisible = !consoleVisible;
|
||||
atConsoleScroll.setVisibility(consoleVisible ? View.VISIBLE : View.GONE);
|
||||
consoleToggle.setText(consoleVisible
|
||||
? getString(R.string.at_console_hide)
|
||||
: getString(R.string.at_console_toggle));
|
||||
});
|
||||
|
||||
if (atCommandInput != null) {
|
||||
atCommandInput.setOnEditorActionListener((textView, actionId, event) -> {
|
||||
sendFromInput();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPeerTarget() {
|
||||
return atTargetGroup != null && atTargetGroup.getCheckedButtonId() == R.id.atTargetPeer;
|
||||
private RadioMacroBuilder.Params buildParams() {
|
||||
RadioMacroBuilder.Params p = new RadioMacroBuilder.Params();
|
||||
Double fqMhz = parseDouble(atInputFq);
|
||||
if (fqMhz != null) {
|
||||
p.frequencyHz = Math.round(fqMhz * 1_000_000L);
|
||||
}
|
||||
p.powerDbm = parseInt(atInputPw);
|
||||
p.sf = parseInt(atInputSf);
|
||||
int bwPos = atBwSpinner != null ? atBwSpinner.getSelectedItemPosition() : -1;
|
||||
if (bwPos >= 0 && bwPos < AtCommands.BW_KHZ.length) {
|
||||
p.bwKhz = AtCommands.BW_KHZ[bwPos];
|
||||
}
|
||||
if (atCrSpinner != null && atCrSpinner.getSelectedItem() != null) {
|
||||
p.codeRate = atCrSpinner.getSelectedItem().toString();
|
||||
}
|
||||
p.preamble = parseInt(atInputPl);
|
||||
p.sendTimeoutMs = parseInt(atInputTm);
|
||||
if (atRoleSpinner != null && atRoleSpinner.getSelectedItem() != null) {
|
||||
String role = atRoleSpinner.getSelectedItem().toString();
|
||||
if (!"—".equals(role)) {
|
||||
p.role = role;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
private void addQuickChip(ChipGroup group, String label, String command) {
|
||||
Chip chip = new Chip(requireContext());
|
||||
chip.setText(label);
|
||||
chip.setCheckable(false);
|
||||
chip.setOnClickListener(v -> sendCommand(command));
|
||||
group.addView(chip);
|
||||
private void applyMacro() {
|
||||
sendLines(RadioMacroBuilder.apply(buildParams()));
|
||||
}
|
||||
|
||||
private void sendFromInput() {
|
||||
if (atCommandInput == null || atCommandInput.getText() == null) {
|
||||
return;
|
||||
}
|
||||
String cmd = atCommandInput.getText().toString().trim();
|
||||
if (cmd.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
sendCommand(cmd);
|
||||
atCommandInput.setText("");
|
||||
}
|
||||
|
||||
private void sendCommand(String command) {
|
||||
if (uploader == null || !isAdded()) {
|
||||
return;
|
||||
}
|
||||
private void sendLines(List<String> lines) {
|
||||
if (isPeerTarget()) {
|
||||
sendToPeer(command);
|
||||
return;
|
||||
sendMacroToPeer(lines);
|
||||
} else {
|
||||
uploader.sendMacroSequence(lines, this::onSendResult);
|
||||
}
|
||||
uploader.sendAtCommand(command, result -> {
|
||||
if (!isAdded()) {
|
||||
return;
|
||||
}
|
||||
Context ctx = getContext();
|
||||
if (ctx == null) {
|
||||
return;
|
||||
}
|
||||
if (result == TelnetClient.SendResult.NOT_CONNECTED) {
|
||||
Toast.makeText(ctx, R.string.at_not_connected, Toast.LENGTH_SHORT).show();
|
||||
} else if (result == TelnetClient.SendResult.IO_ERROR) {
|
||||
Toast.makeText(ctx, R.string.at_send_error, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
updateConsoleView();
|
||||
});
|
||||
}
|
||||
|
||||
private void sendToPeer(String command) {
|
||||
if (commandPoller == null) {
|
||||
return;
|
||||
}
|
||||
private void sendMacroToPeer(List<String> lines) {
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
List<DeviceInfo> devices = uploader.getServerApi().getDevices();
|
||||
PeerDevices.Result peer = PeerDevices.resolve(
|
||||
devices, uploader.getDeviceId());
|
||||
PeerDevices.Result peer = PeerDevices.resolve(devices, uploader.getDeviceId());
|
||||
if (!peer.ok()) {
|
||||
showToast(R.string.at_peer_unavailable);
|
||||
return;
|
||||
}
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
payload.put("line", command);
|
||||
commandPoller.postCommandToPeer(peer.peerId, "at", payload);
|
||||
commandPoller.postMacroToPeer(peer.peerId, lines);
|
||||
showToast(getString(R.string.at_sent_to_peer, peer.peerId));
|
||||
} catch (Exception e) {
|
||||
showToast(R.string.stats_push_failed);
|
||||
@@ -177,78 +181,127 @@ public class AtFragment extends Fragment {
|
||||
});
|
||||
}
|
||||
|
||||
private void showToast(int resId) {
|
||||
if (isAdded()) {
|
||||
requireActivity().runOnUiThread(() ->
|
||||
Toast.makeText(requireContext(), resId, Toast.LENGTH_SHORT).show());
|
||||
private void onSendResult(TelnetClient.SendResult result) {
|
||||
if (!isAdded()) return;
|
||||
if (result == TelnetClient.SendResult.NOT_CONNECTED) {
|
||||
showToast(R.string.at_not_connected);
|
||||
} else if (result == TelnetClient.SendResult.IO_ERROR) {
|
||||
showToast(R.string.at_send_error);
|
||||
}
|
||||
updateConsoleView();
|
||||
}
|
||||
|
||||
private Integer parseInt(TextInputEditText field) {
|
||||
if (field == null || field.getText() == null) return null;
|
||||
String s = field.getText().toString().trim();
|
||||
if (s.isEmpty()) return null;
|
||||
try {
|
||||
return Integer.parseInt(s);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void showToast(String msg) {
|
||||
if (isAdded()) {
|
||||
requireActivity().runOnUiThread(() ->
|
||||
Toast.makeText(requireContext(), msg, Toast.LENGTH_SHORT).show());
|
||||
private Double parseDouble(TextInputEditText field) {
|
||||
if (field == null || field.getText() == null) return null;
|
||||
String s = field.getText().toString().trim();
|
||||
if (s.isEmpty()) return null;
|
||||
try {
|
||||
return Double.parseDouble(s);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshConsole() {
|
||||
if (!isAdded() || uploader == null || atStatus == null) {
|
||||
return;
|
||||
}
|
||||
boolean telnetOn = uploader.isTelnetConnected();
|
||||
private boolean isPeerTarget() {
|
||||
return atTargetGroup != null && atTargetGroup.getCheckedButtonId() == R.id.atTargetPeer;
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
if (!isAdded() || uploader == null || atStatus == null) return;
|
||||
atStatus.setText(getString(
|
||||
R.string.at_status,
|
||||
telnetOn ? getString(R.string.connected) : getString(R.string.disconnected)
|
||||
uploader.isTelnetConnected()
|
||||
? getString(R.string.connected) : getString(R.string.disconnected)
|
||||
));
|
||||
RadioSnapshot snap = RadioSnapshot.fromExtracted(uploader.getLastStats());
|
||||
atCurrentSnapshot.setText(LoraStatsFormatter.formatStatic(snap, java.util.Set.of())
|
||||
+ "\n" + LoraStatsFormatter.formatDynamic(snap, java.util.Set.of()));
|
||||
if (!formInitialized) {
|
||||
if (snap.frequencyMhz != null && isEmpty(atInputFq)) {
|
||||
atInputFq.setText(String.format(Locale.US, "%.3f", snap.frequencyMhz));
|
||||
}
|
||||
if (snap.powerDbm != null && isEmpty(atInputPw)) {
|
||||
atInputPw.setText(String.valueOf(snap.powerDbm.intValue()));
|
||||
}
|
||||
if (snap.sf != null && isEmpty(atInputSf)) {
|
||||
atInputSf.setText(String.valueOf(snap.sf));
|
||||
}
|
||||
if (snap.bwKhz != null) {
|
||||
selectBw(String.valueOf(snap.bwKhz));
|
||||
}
|
||||
if (snap.role != null && atRoleSpinner != null) {
|
||||
atRoleSpinner.setSelection(StatsExtractor.ROLE_RX.equals(snap.role) ? 2 : 1);
|
||||
}
|
||||
formInitialized = true;
|
||||
}
|
||||
updateConsoleView();
|
||||
if (pollHelper != null) {
|
||||
pollHelper.scheduleNext(400);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConsoleView() {
|
||||
if (uploader == null || atConsole == null || atConsoleScroll == null) {
|
||||
return;
|
||||
private static boolean isEmpty(TextInputEditText field) {
|
||||
return field == null || field.getText() == null || field.getText().length() == 0;
|
||||
}
|
||||
|
||||
private void selectBw(String bw) {
|
||||
if (atBwSpinner == null || bw == null) return;
|
||||
for (int i = 0; i < AtCommands.BW_KHZ.length; i++) {
|
||||
if (AtCommands.BW_KHZ[i].equals(bw) || AtCommands.BW_KHZ[i].equals(bw.replace(".0", ""))) {
|
||||
atBwSpinner.setSelection(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConsoleView() {
|
||||
if (uploader == null || atConsole == null || atConsoleScroll == null) return;
|
||||
String log = uploader.getConsoleLog();
|
||||
if (!log.equals(lastConsole)) {
|
||||
lastConsole = log;
|
||||
atConsole.setText(log);
|
||||
atConsoleScroll.post(() -> {
|
||||
if (atConsoleScroll != null) {
|
||||
atConsoleScroll.fullScroll(View.FOCUS_DOWN);
|
||||
}
|
||||
});
|
||||
if (consoleVisible) {
|
||||
atConsoleScroll.post(() -> atConsoleScroll.fullScroll(View.FOCUS_DOWN));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showToast(int resId) {
|
||||
if (isAdded()) Toast.makeText(requireContext(), resId, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private void showToast(String msg) {
|
||||
if (isAdded()) Toast.makeText(requireContext(), msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (pollHelper != null) {
|
||||
pollHelper.start(0);
|
||||
}
|
||||
if (pollHelper != null) pollHelper.start(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
if (pollHelper != null) {
|
||||
pollHelper.stop();
|
||||
}
|
||||
if (pollHelper != null) pollHelper.stop();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (pollHelper != null) {
|
||||
pollHelper.stop();
|
||||
}
|
||||
atStatus = null;
|
||||
atConsole = null;
|
||||
atConsoleScroll = null;
|
||||
atCommandInput = null;
|
||||
atTargetGroup = null;
|
||||
if (pollHelper != null) pollHelper.stop();
|
||||
pollHelper = null;
|
||||
formInitialized = false;
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package com.grigowashere.loratester.ui;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -14,17 +20,37 @@ import com.grigowashere.loratester.api.ChatMessage;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.Holder> {
|
||||
|
||||
private static final int COLOR_SELF_BG = 0xFF16213E;
|
||||
private static final int COLOR_OTHER_BG = 0xFF1A4A6E;
|
||||
private static final int COLOR_NEW_HIGHLIGHT = 0x33E94560;
|
||||
|
||||
private final List<ChatMessage> messages = new ArrayList<>();
|
||||
private final DateFormat timeFormat =
|
||||
DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault());
|
||||
private final Handler handler = new Handler(Looper.getMainLooper());
|
||||
private final Set<Integer> highlightedPositions = new HashSet<>();
|
||||
|
||||
private String selfDeviceId;
|
||||
private double lastSeenTs;
|
||||
|
||||
public void setSelfDeviceId(String selfDeviceId) {
|
||||
this.selfDeviceId = selfDeviceId;
|
||||
}
|
||||
|
||||
public void setLastSeenTs(double lastSeenTs) {
|
||||
this.lastSeenTs = lastSeenTs;
|
||||
}
|
||||
|
||||
public void setMessages(List<ChatMessage> newMessages) {
|
||||
messages.clear();
|
||||
highlightedPositions.clear();
|
||||
messages.addAll(newMessages);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
@@ -35,7 +61,26 @@ public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.Holder> {
|
||||
}
|
||||
int start = messages.size();
|
||||
messages.addAll(more);
|
||||
for (int i = 0; i < more.size(); i++) {
|
||||
if (more.get(i).ts > lastSeenTs) {
|
||||
highlightedPositions.add(start + i);
|
||||
}
|
||||
}
|
||||
notifyItemRangeInserted(start, more.size());
|
||||
for (int i = 0; i < more.size(); i++) {
|
||||
int pos = start + i;
|
||||
if (highlightedPositions.contains(pos)) {
|
||||
scheduleClearHighlight(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleClearHighlight(int position) {
|
||||
handler.postDelayed(() -> {
|
||||
if (highlightedPositions.remove(position)) {
|
||||
notifyItemChanged(position);
|
||||
}
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
public double lastTs() {
|
||||
@@ -56,8 +101,42 @@ public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.Holder> {
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull Holder holder, int position) {
|
||||
ChatMessage m = messages.get(position);
|
||||
boolean self = selfDeviceId != null && selfDeviceId.equals(m.device_id);
|
||||
String time = timeFormat.format(new Date((long) (m.ts * 1000)));
|
||||
holder.text.setText(time + " " + m.device_id + ": " + m.text);
|
||||
|
||||
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) holder.bubble.getLayoutParams();
|
||||
lp.gravity = self ? Gravity.END : Gravity.START;
|
||||
holder.bubble.setLayoutParams(lp);
|
||||
holder.bubble.setBackgroundColor(self ? COLOR_SELF_BG : COLOR_OTHER_BG);
|
||||
|
||||
holder.author.setText(self
|
||||
? holder.itemView.getContext().getString(R.string.chat_self_label)
|
||||
: m.device_id);
|
||||
holder.text.setText(m.text);
|
||||
holder.time.setText(time);
|
||||
|
||||
int bg = self ? COLOR_SELF_BG : COLOR_OTHER_BG;
|
||||
if (highlightedPositions.contains(position)) {
|
||||
holder.bubble.setBackgroundColor(blend(bg, COLOR_NEW_HIGHLIGHT));
|
||||
} else {
|
||||
holder.bubble.setBackgroundColor(bg);
|
||||
}
|
||||
}
|
||||
|
||||
private static int blend(int base, int overlay) {
|
||||
int ba = Color.alpha(base);
|
||||
int br = Color.red(base);
|
||||
int bg = Color.green(base);
|
||||
int bb = Color.blue(base);
|
||||
int oa = Color.alpha(overlay);
|
||||
int or = Color.red(overlay);
|
||||
int og = Color.green(overlay);
|
||||
int ob = Color.blue(overlay);
|
||||
float ratio = oa / 255f;
|
||||
int r = (int) (br * (1 - ratio) + or * ratio);
|
||||
int g = (int) (bg * (1 - ratio) + og * ratio);
|
||||
int b = (int) (bb * (1 - ratio) + ob * ratio);
|
||||
return Color.argb(ba, r, g, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,11 +145,17 @@ public class ChatAdapter extends RecyclerView.Adapter<ChatAdapter.Holder> {
|
||||
}
|
||||
|
||||
static class Holder extends RecyclerView.ViewHolder {
|
||||
final LinearLayout bubble;
|
||||
final TextView author;
|
||||
final TextView text;
|
||||
final TextView time;
|
||||
|
||||
Holder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
text = itemView.findViewById(R.id.chatItemText);
|
||||
bubble = itemView.findViewById(R.id.chatBubble);
|
||||
author = itemView.findViewById(R.id.chatAuthor);
|
||||
text = itemView.findViewById(R.id.chatText);
|
||||
time = itemView.findViewById(R.id.chatTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,9 @@ public class ChatFragment extends Fragment {
|
||||
View inputBar = view.findViewById(R.id.chatInputBar);
|
||||
|
||||
adapter = new ChatAdapter();
|
||||
if (uploader != null) {
|
||||
adapter.setSelfDeviceId(uploader.getDeviceId());
|
||||
}
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(requireContext());
|
||||
recycler.setLayoutManager(layoutManager);
|
||||
recycler.setAdapter(adapter);
|
||||
@@ -161,6 +164,10 @@ public class ChatFragment extends Fragment {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (adapter != null && uploader != null) {
|
||||
adapter.setSelfDeviceId(uploader.getDeviceId());
|
||||
adapter.setLastSeenTs(chatSince);
|
||||
}
|
||||
if (pollHelper != null) {
|
||||
pollHelper.start(0);
|
||||
}
|
||||
|
||||
@@ -61,6 +61,10 @@ import java.util.concurrent.Executors;
|
||||
|
||||
public class MapFragment extends Fragment {
|
||||
|
||||
private static final class MapSessionState {
|
||||
static boolean initialFitDone;
|
||||
}
|
||||
|
||||
private static final int TILE_SIZE_PX = 256;
|
||||
private static final long DEVICE_POLL_MS = 5000;
|
||||
/** Ignore GPS jitter smaller than ~11 m. */
|
||||
@@ -76,6 +80,7 @@ public class MapFragment extends Fragment {
|
||||
DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault());
|
||||
private final Map<String, Marker> deviceMarkers = new HashMap<>();
|
||||
private final List<Layer> trackLayers = new ArrayList<>();
|
||||
private final List<LatLong> liveTrackPoints = new ArrayList<>();
|
||||
|
||||
private FragmentPollHelper pollHelper;
|
||||
private TelemetryUploader uploader;
|
||||
@@ -85,9 +90,14 @@ public class MapFragment extends Fragment {
|
||||
private TileDownloadLayer downloadLayer;
|
||||
private TileCache tileCache;
|
||||
private TextView mapStatus;
|
||||
private TextView mapDistance;
|
||||
private TextView trackStatus;
|
||||
private Button btnTrack;
|
||||
private Button btnPairedTrack;
|
||||
private Button btnCenterMe;
|
||||
private Button btnCenterTx;
|
||||
private Button btnCenterRx;
|
||||
private Button btnCenterBoth;
|
||||
private Spinner trackSpinner;
|
||||
private List<TrackInfo> savedTracks = new ArrayList<>();
|
||||
private boolean mapResumed;
|
||||
@@ -95,8 +105,10 @@ public class MapFragment extends Fragment {
|
||||
private NetworkMonitor networkMonitor;
|
||||
private NetworkMonitor.Listener networkListener;
|
||||
private boolean networkOnline = true;
|
||||
private boolean initialFitDone;
|
||||
private boolean userMovedMap;
|
||||
private List<DeviceInfo> lastDevices = new ArrayList<>();
|
||||
private Polyline liveTrackPolyline;
|
||||
private Marker liveTrackMarker;
|
||||
private boolean suppressTrackSpinner;
|
||||
private Bitmap bitmapTx;
|
||||
private Bitmap bitmapRx;
|
||||
@@ -128,12 +140,30 @@ public class MapFragment extends Fragment {
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
mapView = view.findViewById(R.id.mapView);
|
||||
mapStatus = view.findViewById(R.id.mapStatus);
|
||||
mapDistance = view.findViewById(R.id.mapDistance);
|
||||
trackStatus = view.findViewById(R.id.trackStatus);
|
||||
btnTrack = view.findViewById(R.id.btnTrack);
|
||||
btnPairedTrack = view.findViewById(R.id.btnPairedTrack);
|
||||
btnCenterMe = view.findViewById(R.id.btnCenterMe);
|
||||
btnCenterTx = view.findViewById(R.id.btnCenterTx);
|
||||
btnCenterRx = view.findViewById(R.id.btnCenterRx);
|
||||
btnCenterBoth = view.findViewById(R.id.btnCenterBoth);
|
||||
trackSpinner = view.findViewById(R.id.trackSpinner);
|
||||
pollHelper = new FragmentPollHelper(this, this::refreshDevices);
|
||||
|
||||
if (btnCenterMe != null) {
|
||||
btnCenterMe.setOnClickListener(v -> centerOnSelf());
|
||||
}
|
||||
if (btnCenterTx != null) {
|
||||
btnCenterTx.setOnClickListener(v -> centerOnRole(StatsExtractor.ROLE_TX));
|
||||
}
|
||||
if (btnCenterRx != null) {
|
||||
btnCenterRx.setOnClickListener(v -> centerOnRole(StatsExtractor.ROLE_RX));
|
||||
}
|
||||
if (btnCenterBoth != null) {
|
||||
btnCenterBoth.setOnClickListener(v -> centerOnBoth());
|
||||
}
|
||||
|
||||
networkOnline = networkMonitor != null && networkMonitor.isOnline();
|
||||
networkListener = online -> {
|
||||
networkOnline = online;
|
||||
@@ -263,7 +293,6 @@ public class MapFragment extends Fragment {
|
||||
public void onDestroyView() {
|
||||
mapResumed = false;
|
||||
mapInitialized = false;
|
||||
initialFitDone = false;
|
||||
if (pollHelper != null) {
|
||||
pollHelper.stop();
|
||||
}
|
||||
@@ -276,6 +305,7 @@ public class MapFragment extends Fragment {
|
||||
}
|
||||
removeAllDeviceMarkers();
|
||||
clearTrackLayers();
|
||||
clearLiveTrackLayers();
|
||||
deviceMarkers.clear();
|
||||
if (downloadLayer != null) {
|
||||
downloadLayer.onDestroy();
|
||||
@@ -290,7 +320,12 @@ public class MapFragment extends Fragment {
|
||||
bitmapRx = null;
|
||||
bitmapTrackPoint = null;
|
||||
mapStatus = null;
|
||||
mapDistance = null;
|
||||
trackStatus = null;
|
||||
btnCenterMe = null;
|
||||
btnCenterTx = null;
|
||||
btnCenterRx = null;
|
||||
btnCenterBoth = null;
|
||||
btnTrack = null;
|
||||
trackSpinner = null;
|
||||
pollHelper = null;
|
||||
@@ -332,8 +367,14 @@ public class MapFragment extends Fragment {
|
||||
if (trackStatus != null) {
|
||||
trackStatus.setText(getString(R.string.track_status, pointCount));
|
||||
}
|
||||
if (!recording && trackId > 0) {
|
||||
loadTrackList();
|
||||
if (recording && pointCount <= 1) {
|
||||
clearLiveTrackLayers();
|
||||
}
|
||||
if (!recording) {
|
||||
clearLiveTrackLayers();
|
||||
if (trackId > 0) {
|
||||
loadTrackList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,9 +384,62 @@ public class MapFragment extends Fragment {
|
||||
trackStatus.setText(getString(R.string.track_error, message));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPointRecorded(double lat, double lon) {
|
||||
if (!isAdded() || !mapResumed) {
|
||||
return;
|
||||
}
|
||||
requireActivity().runOnUiThread(() ->
|
||||
runWhenMapReady(() -> appendLiveTrackPoint(lat, lon)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void appendLiveTrackPoint(double lat, double lon) {
|
||||
if (!isMapReady() || !GeoUtils.isValidCoordinate(lat, lon)) {
|
||||
return;
|
||||
}
|
||||
LatLong pos = new LatLong(lat, lon);
|
||||
if (!liveTrackPoints.isEmpty()) {
|
||||
LatLong last = liveTrackPoints.get(liveTrackPoints.size() - 1);
|
||||
if (samePosition(last, pos)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
liveTrackPoints.add(pos);
|
||||
if (liveTrackPolyline == null) {
|
||||
liveTrackPolyline = new Polyline(
|
||||
MapsforgeBitmaps.linePaint(Color.GREEN, 4f),
|
||||
AndroidGraphicFactory.INSTANCE
|
||||
);
|
||||
mapView.getLayerManager().getLayers().add(liveTrackPolyline);
|
||||
}
|
||||
liveTrackPolyline.getLatLongs().clear();
|
||||
liveTrackPolyline.getLatLongs().addAll(liveTrackPoints);
|
||||
if (liveTrackMarker == null) {
|
||||
liveTrackMarker = new Marker(pos, bitmapTrackPoint, 0, 0);
|
||||
mapView.getLayerManager().getLayers().add(liveTrackMarker);
|
||||
} else {
|
||||
liveTrackMarker.setLatLong(pos);
|
||||
}
|
||||
mapView.invalidate();
|
||||
}
|
||||
|
||||
private void clearLiveTrackLayers() {
|
||||
liveTrackPoints.clear();
|
||||
if (mapView != null) {
|
||||
if (liveTrackPolyline != null) {
|
||||
mapView.getLayerManager().getLayers().remove(liveTrackPolyline);
|
||||
}
|
||||
if (liveTrackMarker != null) {
|
||||
mapView.getLayerManager().getLayers().remove(liveTrackMarker);
|
||||
}
|
||||
}
|
||||
liveTrackPolyline = null;
|
||||
liveTrackMarker = null;
|
||||
}
|
||||
|
||||
private void toggleTracking() {
|
||||
if (trackRecorder.isRecording()) {
|
||||
trackRecorder.stop();
|
||||
@@ -562,6 +656,7 @@ public class MapFragment extends Fragment {
|
||||
if (!isMapReady()) {
|
||||
return;
|
||||
}
|
||||
lastDevices = devices != null ? devices : new ArrayList<>();
|
||||
|
||||
int txCount = 0;
|
||||
int rxCount = 0;
|
||||
@@ -611,13 +706,84 @@ public class MapFragment extends Fragment {
|
||||
networkStatusSuffix()
|
||||
));
|
||||
}
|
||||
updateGpsDistance();
|
||||
|
||||
if (!boundsPoints.isEmpty() && !userMovedMap && !initialFitDone) {
|
||||
if (!boundsPoints.isEmpty() && !userMovedMap && !MapSessionState.initialFitDone) {
|
||||
fitBoundsOnce(boundsPoints, onMap == 1, false);
|
||||
initialFitDone = true;
|
||||
MapSessionState.initialFitDone = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateGpsDistance() {
|
||||
if (mapDistance == null) {
|
||||
return;
|
||||
}
|
||||
DeviceInfo tx = null;
|
||||
DeviceInfo rx = null;
|
||||
for (DeviceInfo d : lastDevices) {
|
||||
if (!GeoUtils.isValidCoordinate(d.lat, d.lon)) {
|
||||
continue;
|
||||
}
|
||||
if (StatsExtractor.ROLE_TX.equals(d.role)) {
|
||||
tx = d;
|
||||
} else if (StatsExtractor.ROLE_RX.equals(d.role)) {
|
||||
rx = d;
|
||||
}
|
||||
}
|
||||
if (tx != null && rx != null) {
|
||||
double dist = GeoUtils.haversineMeters(tx.lat, tx.lon, rx.lat, rx.lon);
|
||||
mapDistance.setVisibility(View.VISIBLE);
|
||||
mapDistance.setText(getString(R.string.map_gps_distance, String.format(Locale.US, "%.0f", dist)));
|
||||
} else {
|
||||
mapDistance.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void centerOnSelf() {
|
||||
if (uploader == null) {
|
||||
return;
|
||||
}
|
||||
String myId = uploader.getDeviceId();
|
||||
for (DeviceInfo d : lastDevices) {
|
||||
if (myId.equals(d.device_id) && GeoUtils.isValidCoordinate(d.lat, d.lon)) {
|
||||
centerOnPoint(new LatLong(d.lat, d.lon), (byte) 14);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void centerOnRole(String role) {
|
||||
for (DeviceInfo d : lastDevices) {
|
||||
if (role.equals(d.role) && GeoUtils.isValidCoordinate(d.lat, d.lon)) {
|
||||
centerOnPoint(new LatLong(d.lat, d.lon), (byte) 14);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void centerOnBoth() {
|
||||
List<LatLong> points = new ArrayList<>();
|
||||
for (DeviceInfo d : lastDevices) {
|
||||
if (GeoUtils.isValidCoordinate(d.lat, d.lon)) {
|
||||
points.add(new LatLong(d.lat, d.lon));
|
||||
}
|
||||
}
|
||||
if (!points.isEmpty()) {
|
||||
userMovedMap = false;
|
||||
fitBoundsOnce(points, points.size() == 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void centerOnPoint(LatLong point, byte zoom) {
|
||||
if (!isMapReady()) {
|
||||
return;
|
||||
}
|
||||
MapViewPosition position = (MapViewPosition) mapView.getModel().mapViewPosition;
|
||||
position.setCenter(point);
|
||||
position.setZoomLevel(zoom);
|
||||
mapView.invalidate();
|
||||
}
|
||||
|
||||
/** Adjust camera only on first device load or when user picks a saved track. */
|
||||
private void fitBoundsOnce(List<LatLong> points, boolean singlePoint, boolean force) {
|
||||
if (!isMapReady() || points.isEmpty() || (!force && userMovedMap)) {
|
||||
@@ -630,7 +796,7 @@ public class MapFragment extends Fragment {
|
||||
}
|
||||
if (singlePoint) {
|
||||
position.setCenter(points.get(0));
|
||||
position.setZoomLevel((byte) 13);
|
||||
position.setZoomLevel((byte) 14);
|
||||
return;
|
||||
}
|
||||
double minLat = Double.MAX_VALUE;
|
||||
@@ -654,7 +820,7 @@ public class MapFragment extends Fragment {
|
||||
double lonSpan = Math.max(box.maxLongitude - box.minLongitude, 0.001);
|
||||
double latZoom = Math.log(h / (double) TILE_SIZE_PX / latSpan) / Math.log(2);
|
||||
double lonZoom = Math.log(w / (double) TILE_SIZE_PX / lonSpan) / Math.log(2);
|
||||
byte zoom = (byte) Math.max(8, Math.min(15, Math.floor(Math.min(latZoom, lonZoom))));
|
||||
byte zoom = (byte) Math.max(12, Math.min(16, Math.floor(Math.min(latZoom, lonZoom))));
|
||||
position.setZoomLevel(zoom);
|
||||
};
|
||||
if (mapView.getWidth() > 0 && mapView.getHeight() > 0) {
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
package com.grigowashere.loratester.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TableLayout;
|
||||
import android.widget.TableRow;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.grigowashere.loratester.R;
|
||||
import com.grigowashere.loratester.model.RadioSnapshot;
|
||||
import com.grigowashere.loratester.telnet.LoraStatsFormatter;
|
||||
import com.grigowashere.loratester.telnet.StatsExtractor;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
public class RadioComparePanel extends LinearLayout {
|
||||
|
||||
private static final int COLOR_TX = 0xFFE94560;
|
||||
private static final int COLOR_RX = 0xFF4FC3F7;
|
||||
private static final int COLOR_CHANGED = 0x33E94560;
|
||||
|
||||
private TextView txHeader;
|
||||
private TextView rxHeader;
|
||||
private TableLayout dynamicTable;
|
||||
private TableLayout staticTable;
|
||||
private MaterialButton staticToggle;
|
||||
private boolean staticExpanded;
|
||||
|
||||
public RadioComparePanel(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public RadioComparePanel(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
setOrientation(VERTICAL);
|
||||
LayoutInflater.from(context).inflate(R.layout.view_radio_compare, this, true);
|
||||
txHeader = findViewById(R.id.compareTxHeader);
|
||||
rxHeader = findViewById(R.id.compareRxHeader);
|
||||
dynamicTable = findViewById(R.id.compareDynamicTable);
|
||||
staticTable = findViewById(R.id.compareStaticTable);
|
||||
staticToggle = findViewById(R.id.compareStaticToggle);
|
||||
staticToggle.setOnClickListener(v -> {
|
||||
staticExpanded = !staticExpanded;
|
||||
staticTable.setVisibility(staticExpanded ? VISIBLE : GONE);
|
||||
staticToggle.setText(staticExpanded
|
||||
? getContext().getString(R.string.stats_static_hide)
|
||||
: getContext().getString(R.string.stats_static_toggle));
|
||||
});
|
||||
}
|
||||
|
||||
public void bind(
|
||||
RadioSnapshot txSnap,
|
||||
RadioSnapshot rxSnap,
|
||||
String txDeviceId,
|
||||
String rxDeviceId,
|
||||
Set<String> changedTx,
|
||||
Set<String> changedRx
|
||||
) {
|
||||
txHeader.setText("TX · " + (txDeviceId != null ? txDeviceId : "—"));
|
||||
rxHeader.setText("RX · " + (rxDeviceId != null ? rxDeviceId : "—"));
|
||||
fillTable(dynamicTable, true, txSnap, rxSnap, changedTx, changedRx);
|
||||
fillTable(staticTable, false, txSnap, rxSnap, changedTx, changedRx);
|
||||
}
|
||||
|
||||
private void fillTable(
|
||||
TableLayout table,
|
||||
boolean dynamic,
|
||||
RadioSnapshot tx,
|
||||
RadioSnapshot rx,
|
||||
Set<String> changedTx,
|
||||
Set<String> changedRx
|
||||
) {
|
||||
table.removeAllViews();
|
||||
if (dynamic) {
|
||||
addRow(table, "RSSI", fmtDbm(tx.rssiDbm), fmtDbm(rx.rssiDbm), "rssi", changedTx, changedRx);
|
||||
addRow(table, "SNR", fmtSuffix(tx.snrDb, " dB"), fmtSuffix(rx.snrDb, " dB"), "snr", changedTx, changedRx);
|
||||
addRow(table, "Пакет", fmtInt(tx.packet), fmtInt(rx.packet), "packet", changedTx, changedRx);
|
||||
addRow(table, "Payload", str(tx.payload), str(rx.payload), "payload", changedTx, changedRx);
|
||||
addRow(table, "PER", fmtSuffix(tx.perPercent, " %"), fmtSuffix(rx.perPercent, " %"), "per", changedTx, changedRx);
|
||||
addRow(table, "TX spd", fmtSuffix(tx.txPktPerS, " p/s"), fmtSuffix(rx.txPktPerS, " p/s"), "txSpeed", changedTx, changedRx);
|
||||
addRow(table, "RX spd", fmtSuffix(tx.rxPktPerS, " p/s"), fmtSuffix(rx.rxPktPerS, " p/s"), "rxSpeed", changedTx, changedRx);
|
||||
} else {
|
||||
addRow(table, "Роль", LoraStatsFormatter.roleLabel(tx.role), LoraStatsFormatter.roleLabel(rx.role), "role", changedTx, changedRx);
|
||||
addRow(table, "Частота", fmtMhz(tx.frequencyMhz), fmtMhz(rx.frequencyMhz), "frequency", changedTx, changedRx);
|
||||
addRow(table, "SF", fmtInt(tx.sf), fmtInt(rx.sf), "sf", changedTx, changedRx);
|
||||
addRow(table, "BW", fmtSuffixInt(tx.bwKhz, " kHz"), fmtSuffixInt(rx.bwKhz, " kHz"), "bw", changedTx, changedRx);
|
||||
addRow(table, "Мощн.", fmtDbm(tx.powerDbm), fmtDbm(rx.powerDbm), "power", changedTx, changedRx);
|
||||
}
|
||||
}
|
||||
|
||||
private void addRow(
|
||||
TableLayout table,
|
||||
String label,
|
||||
String txVal,
|
||||
String rxVal,
|
||||
String changeKey,
|
||||
Set<String> changedTx,
|
||||
Set<String> changedRx
|
||||
) {
|
||||
TableRow row = new TableRow(getContext());
|
||||
TextView lbl = cell(label, 0xFFAAAAAA, false);
|
||||
TextView tx = cell(txVal, COLOR_TX, changedTx != null && changedTx.contains(changeKey));
|
||||
TextView rx = cell(rxVal, COLOR_RX, changedRx != null && changedRx.contains(changeKey));
|
||||
row.addView(lbl);
|
||||
row.addView(tx);
|
||||
row.addView(rx);
|
||||
table.addView(row);
|
||||
}
|
||||
|
||||
private TextView cell(String text, int color, boolean changed) {
|
||||
TextView tv = new TextView(getContext());
|
||||
tv.setText(text != null ? text : "—");
|
||||
tv.setTextColor(color);
|
||||
tv.setTextSize(11f);
|
||||
tv.setPadding(4, 2, 4, 2);
|
||||
if (changed) {
|
||||
tv.setBackgroundColor(COLOR_CHANGED);
|
||||
}
|
||||
return tv;
|
||||
}
|
||||
|
||||
/** Assign TX/RX snapshots by device role. */
|
||||
public static void bindByRole(
|
||||
RadioComparePanel panel,
|
||||
RadioSnapshot local,
|
||||
RadioSnapshot peer,
|
||||
String localId,
|
||||
String peerId,
|
||||
Set<String> changedLocal,
|
||||
Set<String> changedPeer
|
||||
) {
|
||||
RadioSnapshot tx = local;
|
||||
RadioSnapshot rx = peer;
|
||||
String txId = localId;
|
||||
String rxId = peerId;
|
||||
Set<String> chTx = changedLocal;
|
||||
Set<String> chRx = changedPeer;
|
||||
if (StatsExtractor.ROLE_RX.equals(local != null ? local.role : null)) {
|
||||
tx = peer;
|
||||
rx = local;
|
||||
txId = peerId;
|
||||
rxId = localId;
|
||||
chTx = changedPeer;
|
||||
chRx = changedLocal;
|
||||
}
|
||||
if (tx == null) tx = RadioSnapshot.empty();
|
||||
if (rx == null) rx = RadioSnapshot.empty();
|
||||
panel.bind(tx, rx, txId, rxId, chTx, chRx);
|
||||
}
|
||||
|
||||
private static String str(String v) {
|
||||
return v != null && !v.isEmpty() ? v : "—";
|
||||
}
|
||||
|
||||
private static String fmtInt(Integer v) {
|
||||
return v != null ? String.valueOf(v) : "—";
|
||||
}
|
||||
|
||||
private static String fmtDbm(Double v) {
|
||||
return v != null ? String.format(Locale.US, "%.0f dBm", v) : "—";
|
||||
}
|
||||
|
||||
private static String fmtMhz(Double v) {
|
||||
return v != null ? String.format(Locale.US, "%.3f MHz", v) : "—";
|
||||
}
|
||||
|
||||
private static String fmtSuffix(Double v, String suffix) {
|
||||
return v != null ? v + suffix : "—";
|
||||
}
|
||||
|
||||
private static String fmtSuffixInt(Integer v, String suffix) {
|
||||
return v != null ? v + suffix : "—";
|
||||
}
|
||||
}
|
||||
@@ -23,15 +23,11 @@ import com.grigowashere.loratester.R;
|
||||
import com.grigowashere.loratester.TelemetryUploader;
|
||||
import com.grigowashere.loratester.api.DeviceInfo;
|
||||
import com.grigowashere.loratester.api.TelemetryHistoryItem;
|
||||
import com.grigowashere.loratester.location.GeoUtils;
|
||||
import com.grigowashere.loratester.telnet.LoraStatsFormatter;
|
||||
import com.grigowashere.loratester.model.RadioSnapshot;
|
||||
import com.grigowashere.loratester.telnet.StatsExtractor;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -41,32 +37,25 @@ public class StatsFragment extends Fragment {
|
||||
private static final long SERVER_POLL_MS = 1000;
|
||||
|
||||
private final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
private final DateFormat timeFormat =
|
||||
DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.getDefault());
|
||||
private FragmentPollHelper pollHelper;
|
||||
private TelemetryUploader uploader;
|
||||
private CommandPoller commandPoller;
|
||||
private PeerStatsCache peerStatsCache;
|
||||
private TextView statsStatus;
|
||||
private TextView statsPeerWarning;
|
||||
private TextView statsLocalDetails;
|
||||
private TextView statsPeerDetails;
|
||||
private RadioComparePanel radioComparePanel;
|
||||
private RecyclerView statsHistoryList;
|
||||
private final HistoryAdapter historyAdapter = new HistoryAdapter();
|
||||
|
||||
private StatsExtractor.ExtractedStats cachedLocal;
|
||||
private DeviceInfo cachedServer;
|
||||
private DeviceInfo cachedPeer;
|
||||
private int cachedDeviceCount;
|
||||
private RadioSnapshot prevLocal = RadioSnapshot.empty();
|
||||
private RadioSnapshot prevPeer = RadioSnapshot.empty();
|
||||
private RadioSnapshot snapLocal = RadioSnapshot.empty();
|
||||
private RadioSnapshot snapPeer = RadioSnapshot.empty();
|
||||
private String cachedPeerId;
|
||||
private String cachedPeerError;
|
||||
private String cachedError;
|
||||
private int cachedDeviceCount;
|
||||
|
||||
private final TelemetryUploader.StatsListener statsListener = stats -> {
|
||||
cachedLocal = stats;
|
||||
cachedError = null;
|
||||
postRender();
|
||||
};
|
||||
private final TelemetryUploader.StatsListener statsListener = stats -> postRender();
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
@@ -91,15 +80,12 @@ public class StatsFragment extends Fragment {
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
statsStatus = view.findViewById(R.id.statsStatus);
|
||||
statsPeerWarning = view.findViewById(R.id.statsPeerWarning);
|
||||
statsLocalDetails = view.findViewById(R.id.statsLocalDetails);
|
||||
statsPeerDetails = view.findViewById(R.id.statsPeerDetails);
|
||||
radioComparePanel = view.findViewById(R.id.radioComparePanel);
|
||||
statsHistoryList = view.findViewById(R.id.statsHistoryList);
|
||||
statsHistoryList.setLayoutManager(new LinearLayoutManager(requireContext()));
|
||||
statsHistoryList.setAdapter(historyAdapter);
|
||||
Button btnSimulate = view.findViewById(R.id.btnSimulate);
|
||||
Button btnPushStats = view.findViewById(R.id.btnPushStats);
|
||||
Button btnModeTx = view.findViewById(R.id.btnModeTxPeer);
|
||||
Button btnModeRx = view.findViewById(R.id.btnModeRxPeer);
|
||||
pollHelper = new FragmentPollHelper(this, this::refresh);
|
||||
|
||||
btnSimulate.setOnClickListener(v -> {
|
||||
@@ -107,18 +93,14 @@ public class StatsFragment extends Fragment {
|
||||
SEND
|
||||
Frequency: 433000000 Hz
|
||||
Power: 22 dBm
|
||||
Spreading Factor: 7
|
||||
Bandwidth: 125 kHz
|
||||
Packet: 1
|
||||
Payload: Sim TX
|
||||
\u001b[2J""";
|
||||
uploader.simulateChunk(chunk);
|
||||
if (pollHelper.canRun()) {
|
||||
statsStatus.setText(R.string.simulate_sent);
|
||||
}
|
||||
});
|
||||
|
||||
btnPushStats.setOnClickListener(v -> pushStatsToPeer());
|
||||
btnModeTx.setOnClickListener(v -> sendModeToPeer("TX"));
|
||||
btnModeRx.setOnClickListener(v -> sendModeToPeer("RX"));
|
||||
}
|
||||
|
||||
private void pushStatsToPeer() {
|
||||
@@ -127,34 +109,18 @@ public class StatsFragment extends Fragment {
|
||||
return;
|
||||
}
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
String meta = pickMetaJson(true);
|
||||
if (meta != null) {
|
||||
payload.put("meta", meta);
|
||||
}
|
||||
Double rssi = pickRssi(true);
|
||||
if (rssi != null) {
|
||||
payload.put("rssi", rssi);
|
||||
}
|
||||
if (cachedLocal != null && cachedLocal.role != null) {
|
||||
payload.put("role", cachedLocal.role);
|
||||
} else if (cachedServer != null && cachedServer.role != null) {
|
||||
payload.put("role", cachedServer.role);
|
||||
StatsExtractor.ExtractedStats localStats = uploader.getLastStats();
|
||||
if (localStats != null && localStats.metaJson != null) {
|
||||
payload.put("meta", localStats.metaJson);
|
||||
}
|
||||
if (snapLocal.role != null) payload.put("role", snapLocal.role);
|
||||
if (snapLocal.rssiDbm != null) payload.put("rssi", snapLocal.rssiDbm);
|
||||
if (snapLocal.sf != null) payload.put("sf", snapLocal.sf);
|
||||
if (snapLocal.bwKhz != null) payload.put("bw", snapLocal.bwKhz);
|
||||
commandPoller.postCommandToPeer(cachedPeerId, "stats_push", payload);
|
||||
toast(R.string.stats_pushed);
|
||||
}
|
||||
|
||||
private void sendModeToPeer(String role) {
|
||||
if (commandPoller == null || cachedPeerId == null) {
|
||||
toast(R.string.at_peer_unavailable);
|
||||
return;
|
||||
}
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
payload.put("role", role);
|
||||
commandPoller.postCommandToPeer(cachedPeerId, "mode", payload);
|
||||
toast(R.string.stats_pushed);
|
||||
}
|
||||
|
||||
private void toast(int resId) {
|
||||
if (isAdded()) {
|
||||
Toast.makeText(requireContext(), resId, Toast.LENGTH_SHORT).show();
|
||||
@@ -166,7 +132,6 @@ public class StatsFragment extends Fragment {
|
||||
super.onResume();
|
||||
if (uploader != null) {
|
||||
uploader.setStatsListener(statsListener);
|
||||
cachedLocal = uploader.getLastStats();
|
||||
postRender();
|
||||
}
|
||||
if (pollHelper != null) {
|
||||
@@ -192,8 +157,7 @@ public class StatsFragment extends Fragment {
|
||||
}
|
||||
statsStatus = null;
|
||||
statsPeerWarning = null;
|
||||
statsLocalDetails = null;
|
||||
statsPeerDetails = null;
|
||||
radioComparePanel = null;
|
||||
statsHistoryList = null;
|
||||
pollHelper = null;
|
||||
super.onDestroyView();
|
||||
@@ -206,10 +170,10 @@ public class StatsFragment extends Fragment {
|
||||
}
|
||||
|
||||
private void postRender() {
|
||||
if (!isAdded() || statsLocalDetails == null) {
|
||||
if (!isAdded() || radioComparePanel == null) {
|
||||
return;
|
||||
}
|
||||
requireActivity().runOnUiThread(this::renderDetails);
|
||||
requireActivity().runOnUiThread(this::render);
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
@@ -217,11 +181,11 @@ public class StatsFragment extends Fragment {
|
||||
return;
|
||||
}
|
||||
String deviceId = uploader.getDeviceId();
|
||||
boolean telnet = uploader.isTelnetConnected();
|
||||
statsStatus.setText(getString(
|
||||
R.string.stats_status,
|
||||
deviceId,
|
||||
telnet ? getString(R.string.connected) : getString(R.string.disconnected)
|
||||
uploader.isTelnetConnected()
|
||||
? getString(R.string.connected) : getString(R.string.disconnected)
|
||||
));
|
||||
|
||||
executor.execute(() -> {
|
||||
@@ -232,19 +196,37 @@ public class StatsFragment extends Fragment {
|
||||
PeerDevices.Result peer = PeerDevices.resolve(devices, deviceId);
|
||||
cachedPeerId = peer.peerId;
|
||||
cachedPeerError = peer.error;
|
||||
cachedPeer = null;
|
||||
cachedServer = null;
|
||||
|
||||
DeviceInfo self = null;
|
||||
DeviceInfo peerDev = null;
|
||||
for (DeviceInfo d : devices) {
|
||||
if (deviceId.equals(d.device_id)) {
|
||||
cachedServer = d;
|
||||
self = d;
|
||||
} else if (peer.peerId != null && peer.peerId.equals(d.device_id)) {
|
||||
cachedPeer = d;
|
||||
peerDev = d;
|
||||
}
|
||||
}
|
||||
cachedError = null;
|
||||
|
||||
StatsExtractor.ExtractedStats localStats = uploader.getLastStats();
|
||||
snapLocal = localStats != null
|
||||
? RadioSnapshot.fromExtracted(localStats)
|
||||
: RadioSnapshot.fromMeta(
|
||||
self != null ? self.meta : null,
|
||||
self != null ? self.role : null,
|
||||
self != null ? self.rssi : null);
|
||||
|
||||
PeerStatsCache.Snapshot push = peerStatsCache != null ? peerStatsCache.get() : null;
|
||||
if (push != null && push.meta != null) {
|
||||
snapPeer = RadioSnapshot.fromMeta(push.meta, push.role, push.rssi);
|
||||
} else {
|
||||
snapPeer = RadioSnapshot.fromMeta(
|
||||
peerDev != null ? peerDev.meta : null,
|
||||
peerDev != null ? peerDev.role : null,
|
||||
peerDev != null ? peerDev.rssi : null);
|
||||
}
|
||||
|
||||
history = uploader.getServerApi().getTelemetryHistory(deviceId, 30);
|
||||
} catch (Exception e) {
|
||||
cachedError = e.getMessage() != null ? e.getMessage() : "error";
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
List<TelemetryHistoryItem> finalHistory = history;
|
||||
if (isAdded()) {
|
||||
@@ -261,11 +243,10 @@ public class StatsFragment extends Fragment {
|
||||
});
|
||||
}
|
||||
|
||||
private void renderDetails() {
|
||||
if (!isAdded() || statsLocalDetails == null || uploader == null) {
|
||||
private void render() {
|
||||
if (!isAdded() || radioComparePanel == null || uploader == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (statsPeerWarning != null) {
|
||||
if (cachedPeerError != null) {
|
||||
statsPeerWarning.setVisibility(View.VISIBLE);
|
||||
@@ -275,105 +256,18 @@ public class StatsFragment extends Fragment {
|
||||
statsPeerWarning.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
statsLocalDetails.setText(formatDeviceBlock(true));
|
||||
statsPeerDetails.setText(formatDeviceBlock(false));
|
||||
}
|
||||
|
||||
private CharSequence formatDeviceBlock(boolean local) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (local) {
|
||||
sb.append(uploader.isTelnetConnected()
|
||||
? getString(R.string.telnet_connected)
|
||||
: getString(R.string.telnet_disconnected));
|
||||
long at = uploader.getLastStatsAtMs();
|
||||
if (at > 0) {
|
||||
sb.append(" · ").append(timeFormat.format(new Date(at)));
|
||||
}
|
||||
sb.append("\n\n");
|
||||
appendStatsBody(sb, pickMetaJson(true), pickRssi(true), cachedServer, true);
|
||||
} else {
|
||||
if (cachedPeerId == null) {
|
||||
sb.append(getString(R.string.stats_peer_absent));
|
||||
return sb;
|
||||
}
|
||||
sb.append(cachedPeerId);
|
||||
if (cachedPeer != null && cachedPeer.role != null) {
|
||||
sb.append(" · ").append(cachedPeer.role);
|
||||
}
|
||||
sb.append("\n\n");
|
||||
PeerStatsCache.Snapshot push = peerStatsCache != null ? peerStatsCache.get() : null;
|
||||
if (push != null && push.meta != null) {
|
||||
appendStatsBody(sb, push.meta, push.rssi, cachedPeer, false);
|
||||
} else if (cachedPeer != null) {
|
||||
appendStatsBody(sb, cachedPeer.meta, cachedPeer.rssi, cachedPeer, false);
|
||||
} else {
|
||||
sb.append(getString(R.string.no_telemetry_yet));
|
||||
}
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
|
||||
private void appendStatsBody(
|
||||
StringBuilder sb,
|
||||
String meta,
|
||||
Double rssi,
|
||||
DeviceInfo gpsSource,
|
||||
boolean local
|
||||
) {
|
||||
if (meta != null && !meta.isEmpty()) {
|
||||
String fields = LoraStatsFormatter.formatMeta(meta);
|
||||
if (!fields.isEmpty()) {
|
||||
sb.append(fields).append("\n");
|
||||
}
|
||||
} else if (local && cachedError != null) {
|
||||
sb.append(getString(R.string.stats_error, cachedError)).append("\n");
|
||||
} else if (local) {
|
||||
sb.append(getString(R.string.no_telemetry_yet)).append("\n");
|
||||
}
|
||||
sb.append("\nСигнал (dBm): ").append(rssi != null ? rssi : "—").append("\n");
|
||||
Double lat = null;
|
||||
Double lon = null;
|
||||
if (gpsSource != null) {
|
||||
lat = gpsSource.lat;
|
||||
lon = gpsSource.lon;
|
||||
}
|
||||
if (GeoUtils.isValidCoordinate(lat, lon)) {
|
||||
sb.append("GPS: ").append(lat).append(", ").append(lon).append("\n");
|
||||
} else {
|
||||
sb.append(getString(R.string.gps_waiting)).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
private String pickMetaJson(boolean local) {
|
||||
if (local) {
|
||||
boolean telnet = uploader.isTelnetConnected();
|
||||
if (telnet && cachedLocal != null && cachedLocal.metaJson != null) {
|
||||
return cachedLocal.metaJson;
|
||||
}
|
||||
if (cachedServer != null && cachedServer.meta != null && !cachedServer.meta.isEmpty()) {
|
||||
return cachedServer.meta;
|
||||
}
|
||||
if (cachedLocal != null && cachedLocal.metaJson != null) {
|
||||
return cachedLocal.metaJson;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Double pickRssi(boolean local) {
|
||||
if (local) {
|
||||
boolean telnet = uploader.isTelnetConnected();
|
||||
if (telnet && cachedLocal != null && cachedLocal.rssi != null) {
|
||||
return cachedLocal.rssi;
|
||||
}
|
||||
if (cachedServer != null && cachedServer.rssi != null) {
|
||||
return cachedServer.rssi;
|
||||
}
|
||||
if (cachedLocal != null) {
|
||||
return cachedLocal.rssi;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
var chLocal = snapLocal.diff(prevLocal);
|
||||
var chPeer = snapPeer.diff(prevPeer);
|
||||
RadioComparePanel.bindByRole(
|
||||
radioComparePanel,
|
||||
snapLocal,
|
||||
snapPeer,
|
||||
uploader.getDeviceId(),
|
||||
cachedPeerId,
|
||||
chLocal,
|
||||
chPeer
|
||||
);
|
||||
prevLocal = snapLocal;
|
||||
prevPeer = snapPeer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,90 +12,209 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<com.google.android.material.button.MaterialButtonToggleGroup
|
||||
android:id="@+id/atTargetGroup"
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
app:singleSelection="true"
|
||||
app:selectionRequired="true">
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:fillViewport="true">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/atTargetLocal"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="0dp"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/at_target_local"
|
||||
android:checked="true" />
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/atTargetPeer"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/at_target_peer" />
|
||||
</com.google.android.material.button.MaterialButtonToggleGroup>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/at_current_values"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<com.google.android.material.chip.ChipGroup
|
||||
android:id="@+id/atQuickChips"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:hint="@string/at_command_hint">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/atCommandInput"
|
||||
<TextView
|
||||
android:id="@+id/atCurrentSnapshot"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="monospace"
|
||||
android:inputType="text"
|
||||
android:singleLine="true" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
android:textSize="11sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/atSendBtn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="8dp"
|
||||
android:text="@string/send" />
|
||||
</LinearLayout>
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:hint="@string/at_hint_fq_mhz">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/atInputFq"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="numberDecimal" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:hint="@string/at_hint_power">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/atInputPw"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="numberSigned" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_weight="1"
|
||||
android:hint="SF">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/atInputSf"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="@string/at_hint_bw"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/atBwSpinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="@string/at_hint_cr"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/atCrSpinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:hint="@string/at_hint_pl">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/atInputPl"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_weight="1"
|
||||
android:hint="@string/at_hint_tm">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/atInputTm"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="@string/at_hint_role"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/atRoleSpinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<com.google.android.material.button.MaterialButtonToggleGroup
|
||||
android:id="@+id/atTargetGroup"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
app:selectionRequired="true"
|
||||
app:singleSelection="true">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/atTargetLocal"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/at_target_local" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/atTargetPeer"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/at_target_peer" />
|
||||
</com.google.android.material.button.MaterialButtonToggleGroup>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="6dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/atApplyBtn"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/at_apply" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/atStopBtn"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="6dp"
|
||||
android:text="S" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/atConsoleToggle"
|
||||
style="@style/Widget.Material3.Button.TextButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/atClearLog"
|
||||
style="@style/Widget.Material3.Button.TextButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/at_clear_log" />
|
||||
</LinearLayout>
|
||||
android:text="@string/at_console_toggle" />
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/atConsoleScroll"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="120dp"
|
||||
android:background="#0D1117"
|
||||
android:padding="8dp">
|
||||
android:padding="8dp"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/atConsole"
|
||||
|
||||
@@ -32,6 +32,65 @@
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="10sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/mapDistance"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"
|
||||
android:textColor="#00FF88"
|
||||
android:textSize="9sp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnCenterMe"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:minHeight="32dp"
|
||||
android:text="@string/map_center_me"
|
||||
android:textSize="10sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnCenterTx"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="2dp"
|
||||
android:layout_weight="1"
|
||||
android:minHeight="32dp"
|
||||
android:text="@string/map_center_tx"
|
||||
android:textSize="10sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnCenterRx"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="2dp"
|
||||
android:layout_weight="1"
|
||||
android:minHeight="32dp"
|
||||
android:text="@string/map_center_rx"
|
||||
android:textSize="10sp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnCenterBoth"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="2dp"
|
||||
android:layout_weight="1"
|
||||
android:minHeight="32dp"
|
||||
android:text="@string/map_center_both"
|
||||
android:textSize="10sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/mapLegend"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -24,6 +24,20 @@
|
||||
android:textSize="12sp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<com.grigowashere.loratester.ui.RadioComparePanel
|
||||
android:id="@+id/radioComparePanel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnPushStats"
|
||||
style="@style/Widget.Material3.Button.TonalButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/stats_push_peer" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnSimulate"
|
||||
android:layout_width="match_parent"
|
||||
@@ -31,90 +45,6 @@
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/simulate_telnet" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:paddingEnd="6dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/stats_local_title"
|
||||
android:textSize="13sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/statsLocalDetails"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:fontFamily="monospace"
|
||||
android:textSize="11sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="6dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/stats_peer_title"
|
||||
android:textSize="13sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/statsPeerDetails"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:fontFamily="monospace"
|
||||
android:textSize="11sp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnPushStats"
|
||||
style="@style/Widget.Material3.Button.TonalButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/stats_push_peer" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnModeTxPeer"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TX→" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnModeRxPeer"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="4dp"
|
||||
android:text="RX→" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -1,7 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/chatItemText"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="6dp"
|
||||
android:textSize="13sp" />
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="4dp">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/chatBubble"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
android:background="#1A4A6E"
|
||||
android:maxWidth="280dp"
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/chatAuthor"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#AAAAAA"
|
||||
android:textSize="10sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/chatText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"
|
||||
android:textColor="#EEEEEE"
|
||||
android:textSize="13sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/chatTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="2dp"
|
||||
android:textColor="#888888"
|
||||
android:textSize="9sp" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingBottom="4dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/compareTxHeader"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textColor="#E94560"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/compareRxHeader"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textColor="#4FC3F7"
|
||||
android:textSize="12sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<TableLayout
|
||||
android:id="@+id/compareDynamicTable"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:stretchColumns="1,2" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/compareStaticToggle"
|
||||
style="@style/Widget.Material3.Button.TextButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="0dp"
|
||||
android:padding="0dp"
|
||||
android:text="@string/stats_static_toggle"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TableLayout
|
||||
android:id="@+id/compareStaticTable"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:stretchColumns="1,2"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -63,4 +63,23 @@
|
||||
<string name="track_paired_start">Старт трека (оба)</string>
|
||||
<string name="track_paired_started">Синхронный старт запланирован</string>
|
||||
<string name="track_paired_need_two">Нужны 2 устройства online</string>
|
||||
<string name="stats_static_toggle">▼ Статика</string>
|
||||
<string name="stats_static_hide">▲ Статика</string>
|
||||
<string name="at_current_values">Текущие значения</string>
|
||||
<string name="at_apply">Применить</string>
|
||||
<string name="at_hint_fq_mhz">Частота MHz (430–470)</string>
|
||||
<string name="at_hint_power">Мощность dBm (-9…22)</string>
|
||||
<string name="at_hint_bw">Bandwidth kHz</string>
|
||||
<string name="at_hint_cr">Code rate</string>
|
||||
<string name="at_hint_pl">Preamble (1–64)</string>
|
||||
<string name="at_hint_tm">Timeout ms (0–60000)</string>
|
||||
<string name="at_hint_role">Роль после настройки</string>
|
||||
<string name="at_console_toggle">▼ Консоль</string>
|
||||
<string name="at_console_hide">▲ Консоль</string>
|
||||
<string name="map_center_me">Я</string>
|
||||
<string name="map_center_tx">TX</string>
|
||||
<string name="map_center_rx">RX</string>
|
||||
<string name="map_center_both">Оба</string>
|
||||
<string name="map_gps_distance">GPS между устройствами: %1$s m</string>
|
||||
<string name="chat_self_label">Вы</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user