From b40e44c653b94baebc383e5719babbe03f87122a Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Mon, 24 Aug 2026 23:24:07 +0300 Subject: [PATCH] =?UTF-8?q?DebugHttpServer:=20Mercury=20BLE-=D1=8D=D0=BD?= =?UTF-8?q?=D0=B4=D0=BF=D0=BE=D0=B8=D0=BD=D1=82=D1=8B=20(/mercury/status|c?= =?UTF-8?q?onnect|disconnect|screen/off|screen/on)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../binom/viewmate/phone/DebugHttpServer.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app-phone/src/main/kotlin/pw/binom/viewmate/phone/DebugHttpServer.kt b/app-phone/src/main/kotlin/pw/binom/viewmate/phone/DebugHttpServer.kt index e4a2e5c..0a26f60 100644 --- a/app-phone/src/main/kotlin/pw/binom/viewmate/phone/DebugHttpServer.kt +++ b/app-phone/src/main/kotlin/pw/binom/viewmate/phone/DebugHttpServer.kt @@ -115,6 +115,32 @@ object DebugHttpServer { code = 400 } } + // --- Mercury BLE (полевой тест либы rayneo-mercury) --- + method == "GET" && path.startsWith("/mercury/status") -> { + val s = MercuryBridge.state.value + response = """{"connected":${s.connected},"glasses":${s.glassesName?.let { "\"$it\"" } ?: "null"},"status":${jsonEscape(s.statusText)},"error":${s.lastError?.let { jsonEscape(it) } ?: "null"}}""" + code = 200 + } + method == "POST" && path.startsWith("/mercury/connect") -> { + val ok = kotlinx.coroutines.runBlocking { MercuryBridge.connectFirst() } + response = """{"ok":$ok,"connected":${MercuryBridge.state.value.connected},"status":${jsonEscape(MercuryBridge.state.value.statusText)}}""" + code = 200 + } + method == "POST" && path.startsWith("/mercury/disconnect") -> { + kotlinx.coroutines.runBlocking { MercuryBridge.disconnect() } + response = """{"ok":true}""" + code = 200 + } + method == "POST" && path.startsWith("/mercury/screen/off") -> { + val ok = kotlinx.coroutines.runBlocking { MercuryBridge.screenOff() } + response = """{"ok":$ok,"status":${jsonEscape(MercuryBridge.state.value.statusText)}}""" + code = 200 + } + method == "POST" && path.startsWith("/mercury/screen/on") -> { + val ok = kotlinx.coroutines.runBlocking { MercuryBridge.screenOn() } + response = """{"ok":$ok,"status":${jsonEscape(MercuryBridge.state.value.statusText)}}""" + code = 200 + } else -> { response = """{"error":"нет такого пути: $method $path"}""" code = 404 @@ -139,6 +165,9 @@ object DebugHttpServer { return regex.find(body)?.groupValues?.get(1) } + private fun jsonEscape(s: String): String = + s.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n") + private fun reason(code: Int): String = when (code) { 200 -> "OK" 400 -> "Bad Request"