Add a V2X data logger to Settings > Developer
Records every received V2X message (CAM, DENM, SPATEM, MAPEM, VAM) into one SQLite file per run, with a timestamp, the phone's GNSS fix, the OBU's GNSS fix where there is one (CiT One), and RSSI where the hardware reports it (ESP32-C5). Works on both hardware paths: V2X_RX frames from the ESP32 link, and the raw v2x/rx plus processed v2x-uca topics over MQTT. The UPER bytes are stored untouched; CAM, DENM and SPATEM also get a few decoded columns. A foreground service keeps it recording with the screen locked. Subscribes to v2x/rx/mapem so MAPEM is received on the CiT One. The current ESP32-C5 firmware forwards only BTP ports 2001, 2002 and 2004, so MAPEM and VAM appear in an ESP32 log only once it accepts 2003 and 2018. Checked on a Pixel 9 Pro against a simulated car and an RSU: 10 minutes with the screen locked and forced deep Doze, no gaps, files pass integrity_check.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package com.hawhamburg.micr0bu.viewmodel
|
||||
|
||||
import android.app.Application
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.hawhamburg.micr0bu.data.log.V2xLogFile
|
||||
import com.hawhamburg.micr0bu.data.log.V2xLogState
|
||||
import com.hawhamburg.micr0bu.data.log.V2xLogger
|
||||
import com.hawhamburg.micr0bu.service.V2xLogService
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
/** Backs Settings > Developer > V2X data logger. */
|
||||
@HiltViewModel
|
||||
class V2xLogViewModel @Inject constructor(
|
||||
application: Application,
|
||||
private val logger: V2xLogger,
|
||||
) : AndroidViewModel(application) {
|
||||
|
||||
val state: StateFlow<V2xLogState> = logger.state
|
||||
val files: StateFlow<List<V2xLogFile>> = logger.files
|
||||
|
||||
init {
|
||||
logger.refreshFiles()
|
||||
// The running file grows between state updates, so keep the list's sizes current while a
|
||||
// log is on screen.
|
||||
viewModelScope.launch {
|
||||
while (true) {
|
||||
delay(2_000L)
|
||||
if (logger.state.value.active) logger.refreshFiles()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun start() = V2xLogService.start(getApplication())
|
||||
|
||||
fun stop() = V2xLogService.stop(getApplication())
|
||||
|
||||
fun delete(log: V2xLogFile) {
|
||||
logger.delete(log)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user