Skip to content

Commit

Permalink
PhoneAppVersion response improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
crc-32 committed May 19, 2020
1 parent 3106e29 commit 7a6245a
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/androidMain/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.rebble.libpebblecommon

@ExperimentalUnsignedTypes
actual fun getPlatform(): PhoneAppVersion.OSType = PhoneAppVersion.OSType.Android
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import io.rebble.libpebblecommon.exceptions.PacketDecodeException
import io.rebble.libpebblecommon.protocol.PacketRegistry
import io.rebble.libpebblecommon.protocol.PebblePacket
import io.rebble.libpebblecommon.protocol.ProtocolEndpoint

import io.rebble.libpebblecommon.PhoneAppVersion.ProtocolCapsFlag
@ExperimentalUnsignedTypes
class ProtocolHandler(private val send: (ByteArray) -> Unit) {
var protocolCaps: UInt = ProtocolCapsFlag.makeFlags(ProtocolCapsFlag.SupportsSendTextApp)

init {
PacketRegistry.setup()
}
Expand All @@ -29,11 +31,13 @@ class ProtocolHandler(private val send: (ByteArray) -> Unit) {

ProtocolEndpoint.PHONE_VERSION -> {
val res = PhoneAppVersion.AppVersionResponse()
res.protocolVersion.set(1u)
res.protocolVersion.set(0xffffffffu)
res.sessionCaps. set(0u)
res.platformFlags. set(0u)
res.majorVersion. set(2u)
res.minorVersion. set(2u)
res.bugfixVersion. set(0u)
//TODO: Platform flags + CAPS
res.platformFlags. set(protocolCaps)
_send(res.serialize().toByteArray(), res)
}

Expand Down
41 changes: 41 additions & 0 deletions src/commonMain/kotlin/io/rebble/libpebblecommon/System.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,47 @@ open class PhoneAppVersion(message: Message) : PebblePacket(endpoint) {
type = command.get()
}

enum class OSType(val value: UInt) {
Unknown(0u),
IOS(1u),
Android(2u),
MacOS(3u),
Linux(4u),
Windows(5u)
}

enum class SessionCapsFlag(val value: UByte) {
Geolocation(1u),
GammaRay(Int.MIN_VALUE.toUByte())
}

enum class ProtocolCapsFlag(val value: UByte) {
SupportsAppRunStateProtocol(0u),
SupportsInfiniteLogDump(1u),
SupportsExtendedMusicProtocol(2u),
SupportsTwoWayDismissal(3u),
SupportsLocalization(4u),
Supports8kAppMessage(5u),
SupportsHealthInsights(6u),
SupportsSendTextApp(8u),
SupportsUnreadCoreDump(10u),
SupportsWeatherApp(11u),
SupportsRemindersApp(12u),
SupportsWorkoutApp(13u),
SupportsFwUpdateAcrossDisconnection(21u),
SupportsSmoothFwInstallProgress(14u);

companion object {
fun makeFlags(vararg flags: ProtocolCapsFlag): UInt {
var ret: UInt = 0u
flags.forEach {flag ->
ret or flag.value.toUInt()
}
return ret
}
}
}

class AppVersionRequest : PhoneAppVersion(Message.AppVersionRequest)
class AppVersionResponse : PhoneAppVersion(Message.AppVersionResponse) {
val protocolVersion = SUInt(m) // Unused as of v3.0
Expand Down
4 changes: 4 additions & 0 deletions src/commonMain/kotlin/io/rebble/libpebblecommon/main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.rebble.libpebblecommon

@ExperimentalUnsignedTypes
expect fun getPlatform(): PhoneAppVersion.OSType
4 changes: 4 additions & 0 deletions src/iosMain/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.rebble.libpebblecommon

@ExperimentalUnsignedTypes
actual fun getPlatform(): PhoneAppVersion.OSType = PhoneAppVersion.OSType.IOS
4 changes: 4 additions & 0 deletions src/jvmMain/kotlin/main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.rebble.libpebblecommon

@ExperimentalUnsignedTypes
actual fun getPlatform(): PhoneAppVersion.OSType = PhoneAppVersion.OSType.Unknown

0 comments on commit 7a6245a

Please sign in to comment.