generated from Grigo/AndroidTemplate
added refference point
This commit is contained in:
@@ -6,6 +6,7 @@ import android.util.Log;
|
||||
|
||||
import com.grigowashere.loratester.api.ServerApi;
|
||||
import com.grigowashere.loratester.location.GeoUtils;
|
||||
import com.grigowashere.loratester.model.RadioSnapshot;
|
||||
import com.grigowashere.loratester.net.NetworkMonitor;
|
||||
import com.grigowashere.loratester.telnet.StatsExtractor;
|
||||
|
||||
@@ -46,8 +47,12 @@ public class ReferencePointRecorder {
|
||||
private final List<Map<String, Object>> buffer = new ArrayList<>();
|
||||
|
||||
private volatile boolean recording;
|
||||
private volatile boolean rotating;
|
||||
private volatile long sessionId = -1;
|
||||
private volatile int sampleCount;
|
||||
private volatile int segmentIndex = 1;
|
||||
private volatile String baseLabel;
|
||||
private volatile String lastParamSignature;
|
||||
private ScheduledFuture<?> sampleTask;
|
||||
private ScheduledFuture<?> flushTask;
|
||||
private Listener listener;
|
||||
@@ -111,6 +116,10 @@ public class ReferencePointRecorder {
|
||||
}
|
||||
sessionId = id;
|
||||
sampleCount = 0;
|
||||
segmentIndex = 1;
|
||||
baseLabel = label;
|
||||
lastParamSignature = null;
|
||||
rotating = false;
|
||||
recording = true;
|
||||
startTimers();
|
||||
notifyState();
|
||||
@@ -173,6 +182,16 @@ public class ReferencePointRecorder {
|
||||
return;
|
||||
}
|
||||
StatsExtractor.ExtractedStats stats = uploader.getLastStats();
|
||||
String signature = paramSignature(stats);
|
||||
if (signature != null) {
|
||||
String prev = lastParamSignature;
|
||||
if (prev == null) {
|
||||
lastParamSignature = signature;
|
||||
} else if (!prev.equals(signature)) {
|
||||
requestRotate(signature);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Double lat = validLat();
|
||||
Double lon = validLon();
|
||||
if (stats == null && (lat == null || lon == null)) {
|
||||
@@ -194,6 +213,77 @@ public class ReferencePointRecorder {
|
||||
notifyState();
|
||||
}
|
||||
|
||||
private void requestRotate(String newSignature) {
|
||||
if (rotating || !recording) {
|
||||
return;
|
||||
}
|
||||
rotating = true;
|
||||
executor.execute(() -> rotateSession(newSignature));
|
||||
}
|
||||
|
||||
private void rotateSession(String newSignature) {
|
||||
if (!recording) {
|
||||
rotating = false;
|
||||
return;
|
||||
}
|
||||
flush();
|
||||
try {
|
||||
if (sessionId > 0) {
|
||||
serverApi.finishReferencePointSession(sessionId);
|
||||
}
|
||||
Double lat = validLat();
|
||||
Double lon = validLon();
|
||||
segmentIndex++;
|
||||
String nextLabel = (baseLabel == null || baseLabel.isBlank()
|
||||
? "Репер"
|
||||
: baseLabel) + " #" + segmentIndex;
|
||||
long nextId = serverApi.startReferencePointSession(deviceId, nextLabel, lat, lon);
|
||||
synchronized (buffer) {
|
||||
buffer.clear();
|
||||
}
|
||||
sessionId = nextId;
|
||||
sampleCount = 0;
|
||||
lastParamSignature = newSignature;
|
||||
notifyState();
|
||||
} catch (Exception e) {
|
||||
Log.w(TAG, "rotate reference point failed", e);
|
||||
notifyError(e.getMessage() != null ? e.getMessage() : "reference rotate failed");
|
||||
} finally {
|
||||
rotating = false;
|
||||
}
|
||||
}
|
||||
|
||||
private static String paramSignature(StatsExtractor.ExtractedStats stats) {
|
||||
if (stats == null || stats.metaJson == null) {
|
||||
return null;
|
||||
}
|
||||
RadioSnapshot snap = RadioSnapshot.fromExtracted(stats);
|
||||
if (snap.frequencyMhz == null
|
||||
&& snap.sf == null
|
||||
&& snap.bwKhz == null
|
||||
&& snap.powerDbm == null
|
||||
&& snap.codeRate == null
|
||||
&& snap.preambleLength == null
|
||||
&& snap.txTimeoutMs == null
|
||||
&& snap.crcEnabled == null
|
||||
&& snap.role == null) {
|
||||
return null;
|
||||
}
|
||||
return "role=" + value(snap.role)
|
||||
+ "|fq=" + value(snap.frequencyMhz)
|
||||
+ "|sf=" + value(snap.sf)
|
||||
+ "|bw=" + value(snap.bwKhz)
|
||||
+ "|pw=" + value(snap.powerDbm)
|
||||
+ "|cr=" + value(snap.codeRate)
|
||||
+ "|pl=" + value(snap.preambleLength)
|
||||
+ "|tm=" + value(snap.txTimeoutMs)
|
||||
+ "|crc=" + value(snap.crcEnabled);
|
||||
}
|
||||
|
||||
private static String value(Object value) {
|
||||
return value != null ? String.valueOf(value) : "";
|
||||
}
|
||||
|
||||
private void flush() {
|
||||
if (sessionId <= 0 || networkMonitor != null && !networkMonitor.isOnline()) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user