Debuging added
This commit is contained in:
parent
5f46f6ab21
commit
d009a9fcd4
@ -20,7 +20,7 @@ import com.dumon.plugin.geolocation.imu.ImuData
|
||||
import com.dumon.plugin.geolocation.imu.ImuSensorManager
|
||||
import com.dumon.plugin.geolocation.wifi.WifiPositioningManager
|
||||
import com.dumon.plugin.geolocation.wifi.WifiScanResult
|
||||
import com.dumon.plugin.geolocation.fusion.SensorFusionManager
|
||||
//import com.dumon.plugin.geolocation.fusion.SensorFusionManager
|
||||
import com.dumon.plugin.geolocation.utils.PermissionUtils
|
||||
import com.getcapacitor.annotation.PermissionCallback
|
||||
import org.json.JSONArray
|
||||
@ -44,7 +44,6 @@ class DumonGeolocation : Plugin() {
|
||||
private var gpsManager: GpsStatusManager? = null
|
||||
private var imuManager: ImuSensorManager? = null
|
||||
private var wifiManager: WifiPositioningManager? = null
|
||||
private var fusionManager: SensorFusionManager? = null
|
||||
|
||||
private var latestLatitude = 0.0
|
||||
private var latestLongitude = 0.0
|
||||
@ -90,7 +89,6 @@ class DumonGeolocation : Plugin() {
|
||||
latestSource = if (isMocked) "MOCK" else "GNSS"
|
||||
isMockedLocation = isMocked
|
||||
latestTimestamp = location.time
|
||||
fusionManager?.updateGpsPosition(latestLatitude, latestLongitude)
|
||||
emitPositionUpdate()
|
||||
}
|
||||
)
|
||||
@ -100,7 +98,6 @@ class DumonGeolocation : Plugin() {
|
||||
onImuUpdate = {
|
||||
latestImu = it
|
||||
emitPositionUpdate()
|
||||
fusionManager?.updateMotionEstimate(it.speed.toDouble(), it.directionRad.toDouble())
|
||||
}
|
||||
)
|
||||
|
||||
@ -111,15 +108,6 @@ class DumonGeolocation : Plugin() {
|
||||
emitPositionUpdate()
|
||||
}
|
||||
)
|
||||
|
||||
fusionManager = SensorFusionManager { lat, lon ->
|
||||
latestLatitude = lat
|
||||
latestLongitude = lon
|
||||
latestAccuracy = 3.0
|
||||
latestSource = "FUSED"
|
||||
latestTimestamp = System.currentTimeMillis()
|
||||
emitPositionUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
@ -252,44 +240,8 @@ class DumonGeolocation : Plugin() {
|
||||
call.resolve(result)
|
||||
}
|
||||
|
||||
// private fun emitPositionUpdate() {
|
||||
// /*val now = System.currentTimeMillis()
|
||||
// if (now - lastEmitTimestamp < emitIntervalMs) return
|
||||
// lastEmitTimestamp = now
|
||||
// notifyListeners("onPositionUpdate", buildPositionData())*/
|
||||
//
|
||||
// val now = System.currentTimeMillis()
|
||||
// if (now - lastEmitTimestamp < emitIntervalMs) return
|
||||
//
|
||||
// val distance = calculateDistance(latestLatitude, latestLongitude, prevLatitude, prevLongitude)
|
||||
// val isSignificantChange = distance >= significantChangeThreshold
|
||||
// val speedChanged = abs((latestImu?.speed ?: 0f) - prevSpeed) > speedChangeThreshold
|
||||
// val directionChanged = abs((latestImu?.directionRad ?: 0f) - prevDirection) > directionChangeThreshold
|
||||
//
|
||||
// if (isSignificantChange || speedChanged || directionChanged) {
|
||||
// prevLatitude = latestLatitude
|
||||
// prevLongitude = latestLongitude
|
||||
// prevSpeed = latestImu?.speed ?: 0f
|
||||
// prevDirection = latestImu?.directionRad ?: 0f
|
||||
// lastEmitTimestamp = now
|
||||
//
|
||||
// notifyListeners("onPositionUpdate", buildPositionData())
|
||||
// }
|
||||
//
|
||||
// // Fallback prediksi jika tidak ada GNSS update > 1.5 detik
|
||||
// if (System.currentTimeMillis() - latestTimestamp > 1500 && latestImu != null) {
|
||||
// val (predLat, predLon) = fusionManager?.predictForwardPosition(1.0) ?: return
|
||||
// latestLatitude = predLat
|
||||
// latestLongitude = predLon
|
||||
// latestAccuracy = 10.0
|
||||
// latestSource = "PREDICTED"
|
||||
// latestTimestamp = System.currentTimeMillis()
|
||||
//
|
||||
// Log.d("DUMON_PREDICTION", "Predicted position: $predLat, $predLon")
|
||||
// notifyListeners("onPositionUpdate", buildPositionData())
|
||||
// }
|
||||
// }
|
||||
private fun emitPositionUpdate() {
|
||||
|
||||
val now = System.currentTimeMillis()
|
||||
if (now - lastEmitTimestamp < emitIntervalMs) return
|
||||
|
||||
@ -318,32 +270,6 @@ class DumonGeolocation : Plugin() {
|
||||
lastEmitTimestamp = now
|
||||
|
||||
notifyListeners("onPositionUpdate", buildPositionData())
|
||||
return
|
||||
}
|
||||
|
||||
maybeEmitPredictedPosition(now, speedNow)
|
||||
}
|
||||
|
||||
private fun maybeEmitPredictedPosition(now: Long, speedNow: Float) {
|
||||
val timeSinceFix = now - latestTimestamp
|
||||
|
||||
val shouldPredict = (motionState == "driving") && timeSinceFix > 3000
|
||||
|
||||
if (!shouldPredict) return
|
||||
|
||||
val (predLat, predLon) = fusionManager?.predictForwardPosition(1.5) ?: return
|
||||
val predictedDistance = calculateDistance(latestLatitude, latestLongitude, predLat, predLon)
|
||||
|
||||
if (predictedDistance > significantChangeThreshold) {
|
||||
latestLatitude = predLat
|
||||
latestLongitude = predLon
|
||||
latestAccuracy = 10.0
|
||||
latestSource = "PREDICTED"
|
||||
latestTimestamp = now
|
||||
lastEmitTimestamp = now
|
||||
|
||||
Log.d("DUMON_PREDICTION", "Predicted position: $predLat, $predLon")
|
||||
notifyListeners("onPositionUpdate", buildPositionData())
|
||||
}
|
||||
}
|
||||
|
||||
@ -382,46 +308,6 @@ class DumonGeolocation : Plugin() {
|
||||
|
||||
obj.put("predicted", latestSource == "PREDICTED")
|
||||
|
||||
// === Full Detail (commented out for future use) ===
|
||||
/*
|
||||
satelliteStatus?.let {
|
||||
val gnss = JSObject()
|
||||
gnss.put("satellitesInView", it.satellitesInView)
|
||||
gnss.put("usedInFix", it.usedInFix)
|
||||
val constellations = JSObject()
|
||||
it.constellationCounts.forEach { (k, v) -> constellations.put(k, v) }
|
||||
gnss.put("constellationCounts", constellations)
|
||||
obj.put("gnssData", gnss)
|
||||
}
|
||||
|
||||
latestImu?.let {
|
||||
val imu = JSObject()
|
||||
imu.put("accelX", it.accelX)
|
||||
imu.put("accelY", it.accelY)
|
||||
imu.put("accelZ", it.accelZ)
|
||||
imu.put("gyroX", it.gyroX)
|
||||
imu.put("gyroY", it.gyroY)
|
||||
imu.put("gyroZ", it.gyroZ)
|
||||
imu.put("speed", it.speed)
|
||||
imu.put("acceleration", it.acceleration)
|
||||
imu.put("directionRad", it.directionRad)
|
||||
obj.put("imuData", imu)
|
||||
}
|
||||
|
||||
wifiScanResult?.let {
|
||||
val wifi = JSArray()
|
||||
it.aps.forEach { ap ->
|
||||
val a = JSObject()
|
||||
a.put("ssid", ap.ssid)
|
||||
a.put("bssid", ap.bssid)
|
||||
a.put("rssi", ap.rssi)
|
||||
ap.distance?.let { d -> a.put("distance", d) }
|
||||
wifi.put(a)
|
||||
}
|
||||
obj.put("wifiData", wifi)
|
||||
}
|
||||
*/
|
||||
|
||||
return obj
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user