From e1d8854d7d5e789ed84e8948f17fb0dac0d44da6 Mon Sep 17 00:00:00 2001 From: Iván Ávalos Date: Sat, 29 Jan 2022 04:13:25 -0600 Subject: Initial implementation of device list, and added getStatus() and getEngineStop() methods to UnitInformation --- .../TrackerMap/client/models/UnitInformation.kt | 33 +++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'shared/src/commonMain/kotlin') diff --git a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt index edebff0..47134a6 100644 --- a/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt +++ b/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt @@ -3,4 +3,35 @@ package mx.trackermap.TrackerMap.client.models data class UnitInformation( val device: Device, val position: Position? -) \ No newline at end of file +) { + enum class Status { + ONLINE, OFFLINE, UNKNOWN + } + + enum class EngineStop { + ON, OFF, UNKNOWN + } + + /** + * Status is calculated from speed, because status based on + * the actual connection to the server is useless for our clients. + */ + fun getStatus() = position?.speed?.let { + if (it >= 2) { + Status.ONLINE + } else { + Status.OFFLINE + } + } ?: Status.UNKNOWN + + /* Many GPS devices reserve pin 1 for engine stop */ + fun getEngineStop() = if (position?.attributes?.containsKey("out1") == true) { + position.attributes["out1"]?.toString()?.let { + when (it) { + "true" -> EngineStop.ON + "false" -> EngineStop.OFF + else -> EngineStop.UNKNOWN + } + } ?: EngineStop.UNKNOWN + } else EngineStop.UNKNOWN +} \ No newline at end of file -- cgit v1.2.3