aboutsummaryrefslogtreecommitdiff
path: root/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap
diff options
context:
space:
mode:
Diffstat (limited to 'shared/src/commonMain/kotlin/mx/trackermap/TrackerMap')
-rw-r--r--shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt33
1 files changed, 32 insertions, 1 deletions
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