diff --git a/gradle.properties b/gradle.properties index 6aeb63b..78acc19 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/commonMain/kotlin/io/rebble/libpebblecommon/packets/LogDump.kt b/src/commonMain/kotlin/io/rebble/libpebblecommon/packets/LogDump.kt new file mode 100644 index 0000000..b6e5be9 --- /dev/null +++ b/src/commonMain/kotlin/io/rebble/libpebblecommon/packets/LogDump.kt @@ -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() + } +} \ No newline at end of file diff --git a/src/commonMain/kotlin/io/rebble/libpebblecommon/protocolhelpers/PacketRegistry.kt b/src/commonMain/kotlin/io/rebble/libpebblecommon/protocolhelpers/PacketRegistry.kt index 1b7a72e..5e3b238 100644 --- a/src/commonMain/kotlin/io/rebble/libpebblecommon/protocolhelpers/PacketRegistry.kt +++ b/src/commonMain/kotlin/io/rebble/libpebblecommon/protocolhelpers/PacketRegistry.kt @@ -29,6 +29,7 @@ object PacketRegistry { screenshotPacketsRegister() appLogPacketsRegister() phoneControlPacketsRegister() + logDumpPacketsRegister() } /** diff --git a/src/commonMain/kotlin/io/rebble/libpebblecommon/services/LogDumpService.kt b/src/commonMain/kotlin/io/rebble/libpebblecommon/services/LogDumpService.kt new file mode 100644 index 0000000..26c7f9d --- /dev/null +++ b/src/commonMain/kotlin/io/rebble/libpebblecommon/services/LogDumpService.kt @@ -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(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) + } +} \ No newline at end of file