Skip to content

Commit

Permalink
Merge pull request #8 from matejdro/calendar
Browse files Browse the repository at this point in the history
update timeline packet definitions
  • Loading branch information
crc-32 authored Dec 4, 2020
2 parents f175b0d + 027a1a5 commit d9a6015
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import io.rebble.libpebblecommon.structmapper.SBytes
import io.rebble.libpebblecommon.structmapper.SUByte
import io.rebble.libpebblecommon.structmapper.SUShort

open class BlobCommand constructor(message: Message, token: UShort, database: BlobDatabase) : PebblePacket(
endpoint
) {
open class BlobCommand constructor(message: Message, token: UShort, database: BlobDatabase) :
PebblePacket(
endpoint
) {
enum class Message(val value: UByte) {
Insert(0x01u),
Delete(0x04u),
Expand All @@ -29,7 +30,12 @@ open class BlobCommand constructor(message: Message, token: UShort, database: Bl
val token = SUShort(m, token)
val database = SUByte(m, database.id)

open class InsertCommand(token: UShort, database: BlobDatabase, key: UByteArray, value: UByteArray) : BlobCommand(
open class InsertCommand(
token: UShort,
database: BlobDatabase,
key: UByteArray,
value: UByteArray
) : BlobCommand(
Message.Insert, token, database
) {
val keySize = SUByte(m, key.size.toUByte())
Expand Down Expand Up @@ -66,7 +72,10 @@ open class BlobResponse(response: BlobStatus = BlobStatus.GeneralFailure) : Pebb
DataStale(0x08u),
NotSupported(0x09u),
Locked(0xAu),
TryLater(0xBu)
TryLater(0xBu),

// Added status by libpebblecommon to expose watch connection error
WatchDisconnected(0xFFu),
}

class Success : BlobResponse(BlobStatus.Success)
Expand All @@ -84,14 +93,21 @@ open class BlobResponse(response: BlobStatus = BlobStatus.GeneralFailure) : Pebb
val token = SUShort(m)
val response = SUByte(m, response.value)

val responseValue
get() = BlobStatus.values().firstOrNull { it.value == response.get() }
?: error("Unknown blobdb response ${response.get()}")

companion object {
val endpoint = ProtocolEndpoint.BLOBDB_V1
}
}

fun blobDBPacketsRegister() {
PacketRegistry.registerCustomTypeOffset(BlobResponse.endpoint, 4 + UShort.SIZE_BYTES)
PacketRegistry.register(BlobResponse.endpoint, BlobResponse.BlobStatus.Success.value) { BlobResponse.Success() }
PacketRegistry.register(
BlobResponse.endpoint,
BlobResponse.BlobStatus.Success.value
) { BlobResponse.Success() }
PacketRegistry.register(
BlobResponse.endpoint,
BlobResponse.BlobStatus.GeneralFailure.value
Expand All @@ -116,11 +132,20 @@ fun blobDBPacketsRegister() {
BlobResponse.endpoint,
BlobResponse.BlobStatus.DatabaseFull.value
) { BlobResponse.DatabaseFull() }
PacketRegistry.register(BlobResponse.endpoint, BlobResponse.BlobStatus.DataStale.value) { BlobResponse.DataStale() }
PacketRegistry.register(
BlobResponse.endpoint,
BlobResponse.BlobStatus.DataStale.value
) { BlobResponse.DataStale() }
PacketRegistry.register(
BlobResponse.endpoint,
BlobResponse.BlobStatus.NotSupported.value
) { BlobResponse.NotSupported() }
PacketRegistry.register(BlobResponse.endpoint, BlobResponse.BlobStatus.Locked.value) { BlobResponse.Locked() }
PacketRegistry.register(BlobResponse.endpoint, BlobResponse.BlobStatus.TryLater.value) { BlobResponse.TryLater() }
PacketRegistry.register(
BlobResponse.endpoint,
BlobResponse.BlobStatus.Locked.value
) { BlobResponse.Locked() }
PacketRegistry.register(
BlobResponse.endpoint,
BlobResponse.BlobStatus.TryLater.value
) { BlobResponse.TryLater() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ class TimelineItem(
enum class Type(val value: UByte) {
Notification(1u),
Pin(2u),
Reminder(3u)
Reminder(3u);

companion object {
fun fromValue(value: UByte): Type {
return values().firstOrNull { it.value == value }
?: error("Unknown timeline item type: $value")
}
}
}

val itemId = SUUID(m, itemId)
Expand Down Expand Up @@ -90,7 +97,11 @@ class TimelineItem(
val length = SUShort(m, endianness = '<')
val content = SBytes(m, 0)

constructor(attributeId: UByte, content: UByteArray, contentEndianness: Char = '|'): this() {
constructor(
attributeId: UByte,
content: UByteArray,
contentEndianness: Char = '|'
) : this() {
this.attributeId.set(attributeId)

this.length.set(content.size.toUShort())
Expand All @@ -103,6 +114,27 @@ class TimelineItem(
content.linkWithSize(length)
}
}

enum class Flag(val value: Int) {
IS_VISIBLE(0),
IS_FLOATING(1),
IS_ALL_DAY(2),
FROM_WATCH(3),
FROM_ANCS(4),
PERSIST_QUICK_VIEW(5);

companion object {
fun makeFlags(flags: List<Flag>): UShort {
var short: UShort = 0u

for (flag in flags) {
short = (1u shl flag.value).toUShort() or short
}

return short
}
}
}
}

open class TimelineAction(message: Message) : PebblePacket(endpoint) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.rebble.libpebblecommon.services.blobdb

import io.rebble.libpebblecommon.PacketPriority
import io.rebble.libpebblecommon.ProtocolHandler
import io.rebble.libpebblecommon.packets.blobdb.BlobCommand
import io.rebble.libpebblecommon.packets.blobdb.BlobResponse
Expand Down Expand Up @@ -27,13 +28,16 @@ class BlobDBService(private val protocolHandler: ProtocolHandler) : ProtocolServ
*
* @return [BlobResponse] from the watch or *null* if the sending failed
*/
suspend fun send(packet: BlobCommand): BlobResponse? {
suspend fun send(
packet: BlobCommand,
priority: PacketPriority = PacketPriority.NORMAL
): BlobResponse {
val result = CompletableDeferred<BlobResponse>()
pending[packet.token.get()] = result

val sendingResult = protocolHandler.send(packet)
val sendingResult = protocolHandler.send(packet, priority)
if (!sendingResult) {
return null
return BlobResponse(BlobResponse.BlobStatus.WatchDisconnected)
}

return result.await()
Expand Down

0 comments on commit d9a6015

Please sign in to comment.