diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-01-29 04:13:25 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-01-29 04:13:25 -0600 |
commit | e1d8854d7d5e789ed84e8948f17fb0dac0d44da6 (patch) | |
tree | ab84d7edaead85e03950102e091da51952635159 /shared/src/commonMain/kotlin/mx/trackermap/TrackerMap | |
parent | 64c4a58e644229b9d94233b3dd18b7805ffbb8d7 (diff) | |
download | etbsa-trackermap-mobile-e1d8854d7d5e789ed84e8948f17fb0dac0d44da6.tar.gz etbsa-trackermap-mobile-e1d8854d7d5e789ed84e8948f17fb0dac0d44da6.tar.bz2 etbsa-trackermap-mobile-e1d8854d7d5e789ed84e8948f17fb0dac0d44da6.zip |
Initial implementation of device list, and added getStatus() and getEngineStop() methods to UnitInformation
Diffstat (limited to 'shared/src/commonMain/kotlin/mx/trackermap/TrackerMap')
-rw-r--r-- | shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt | 33 |
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 |