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 | |
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')
-rw-r--r-- | shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/client/models/UnitInformation.kt | 33 | ||||
-rw-r--r-- | shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/utils/Serialization.kt | 12 |
2 files changed, 44 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 diff --git a/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/utils/Serialization.kt b/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/utils/Serialization.kt new file mode 100644 index 0000000..be26416 --- /dev/null +++ b/shared/src/iosMain/kotlin/mx/trackermap/TrackerMap/utils/Serialization.kt @@ -0,0 +1,12 @@ +package mx.trackermap.TrackerMap.utils + +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.longOrNull + +class Serialization { + companion object { + fun longOrNull(json: JsonPrimitive) = json.longOrNull + + fun toString(json: JsonPrimitive) = json.toString() + } +}
\ No newline at end of file |