Skip to content

Commit

Permalink
log dump endpoint support
Browse files Browse the repository at this point in the history
  • Loading branch information
crc-32 committed Sep 9, 2024
1 parent ba7c0d4 commit 4f2c586
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kotlin.code.style=official

group=io.rebble.libpebblecommon
version=0.1.21
version=0.1.22
org.gradle.jvmargs=-Xms128M -Xmx1G -XX:ReservedCodeCacheSize=200M
kotlin.native.binary.memoryModel=experimental
kotlin.mpp.androidSourceSetLayoutVersion=2
Expand Down
61 changes: 61 additions & 0 deletions src/commonMain/kotlin/io/rebble/libpebblecommon/packets/LogDump.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.rebble.libpebblecommon.packets

import io.rebble.libpebblecommon.protocolhelpers.PacketRegistry
import io.rebble.libpebblecommon.protocolhelpers.PebblePacket
import io.rebble.libpebblecommon.protocolhelpers.ProtocolEndpoint
import io.rebble.libpebblecommon.structmapper.*

open class LogDump(val message: Message): PebblePacket(ProtocolEndpoint.LOG_DUMP) {
val command = SUByte(m, message.value)

init {
type = command.get()
}

enum class Message(val value: UByte) {
RequestLogDump(0x10u),
LogLine(0x80u),
Done(0x81u),
NoLogs(0x82u)
}

class RequestLogDump(logGeneration: UByte, cookie: UInt): LogDump(Message.RequestLogDump) {
val generation = SUByte(m, logGeneration)
val cookie = SUInt(m, cookie)
}

open class ReceivedLogDumpMessage(message: Message): LogDump(message) {
val cookie = SUInt(m)
}

class LogLine: ReceivedLogDumpMessage(Message.LogLine) {
val timestamp = SUInt(m)
val level = SUByte(m)
val length = SUByte(m)
val line = SUShort(m)
val filename = SFixedString(m, 16)
val messageText = SFixedString(m, 0)

init {
messageText.linkWithSize(length)
}
}

class Done: ReceivedLogDumpMessage(Message.Done)

class NoLogs: ReceivedLogDumpMessage(Message.NoLogs)
}

fun logDumpPacketsRegister() {
PacketRegistry.register(ProtocolEndpoint.LOG_DUMP, LogDump.Message.NoLogs.value) {
LogDump.NoLogs()
}

PacketRegistry.register(ProtocolEndpoint.LOG_DUMP, LogDump.Message.Done.value) {
LogDump.Done()
}

PacketRegistry.register(ProtocolEndpoint.LOG_DUMP, LogDump.Message.LogLine.value) {
LogDump.LogLine()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ object PacketRegistry {
screenshotPacketsRegister()
appLogPacketsRegister()
phoneControlPacketsRegister()
logDumpPacketsRegister()
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.rebble.libpebblecommon.services

import io.rebble.libpebblecommon.ProtocolHandler
import io.rebble.libpebblecommon.packets.LogDump
import io.rebble.libpebblecommon.protocolhelpers.PebblePacket
import io.rebble.libpebblecommon.protocolhelpers.ProtocolEndpoint
import kotlinx.coroutines.channels.Channel

class LogDumpService(private val protocolHandler: ProtocolHandler) : ProtocolService {
val receivedMessages = Channel<LogDump>(Channel.BUFFERED)

init {
protocolHandler.registerReceiveCallback(ProtocolEndpoint.LOG_DUMP, this::receive)
}

suspend fun send(packet: LogDump) {
protocolHandler.send(packet)
}

fun receive(packet: PebblePacket) {
if (packet !is LogDump) {
throw IllegalStateException("Received invalid packet type: $packet")
}

receivedMessages.trySend(packet)
}
}

0 comments on commit 4f2c586

Please sign in to comment.