mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
Partial support for Rayneo iO
This commit is contained in:
1 parent
742a5a3f81
commit
4d101eefe1
23 files changed
+1954
-69
No files matched your search
@@ -64,3 +64,17 @@ test('Full Screen is offered only with a bottom or popup app switcher', () => {
|
||||
assert.deepEqual(Array.from(api.DISPLAY_LAYOUT_VALUES, (value) => api.displayLayoutLabel(value)),
|
||||
['Band · Top', 'Band · High', 'Band · Middle', 'Band · Low', 'Band · Bottom', 'Tall', 'Full Screen']);
|
||||
});
|
||||
|
||||
test('a RayNeo iO pins the band to the top and the switcher to the right, leaving the stored choice alone', () => {
|
||||
const store = new Map([['display.layout', 'band-middle'], ['display.appSwitcherPosition', 'bottom']]);
|
||||
const api = settingsFixture(store);
|
||||
assert.equal(api.displayLayoutSetting.get(), 'band-middle');
|
||||
assert.equal(api.appSwitcherPositionSetting.get(), 'bottom');
|
||||
api.glassesTypeSetting.set('rayneo-io');
|
||||
assert.equal(api.displayLayoutSetting.get(), 'band-top');
|
||||
assert.equal(api.appSwitcherPositionSetting.get(), 'right');
|
||||
assert.equal(store.get('display.layout'), 'band-middle');
|
||||
api.glassesTypeSetting.set('g2');
|
||||
assert.equal(api.displayLayoutSetting.get(), 'band-middle');
|
||||
assert.equal(api.appSwitcherPositionSetting.get(), 'bottom');
|
||||
});
|
||||
@@ -162,3 +162,21 @@ test("a bare R1 substring is not a ring — only the stock EVEN R1 prefix is", (
|
||||
const ad = classifyAdvertisement(raw({ address: "DA:7F:D2:B5:6E:E2", name: "EVEN R1_B56EE2", manufacturerData: "" }));
|
||||
assert.equal(ad.role, "ring");
|
||||
});
|
||||
|
||||
// RayNeo iO-2229 as captured 2026-11-01: company 0x5716 + [07][MAC]; pairing mode omits the data.
|
||||
test("RayNeo iO advertisements classify as one device with its MAC", () => {
|
||||
const io = classifyAdvertisement(raw({
|
||||
address: "00:6A:5E:5F:33:C2",
|
||||
name: "RayNeo iO-2229",
|
||||
manufacturerData: "1657" + "07006a5e5f33c2130000000000000001",
|
||||
}));
|
||||
assert.equal(io.role, "rayneo-io");
|
||||
assert.equal(io.embeddedMac, "00:6A:5E:5F:33:C2");
|
||||
assert.equal(io.embeddedMacMismatch, false);
|
||||
assert.equal(io.serial, null);
|
||||
const pairing = classifyAdvertisement(raw({ address: "00:6A:5E:5F:33:C2", name: "RayNeo iO-2229", manufacturerData: "" }));
|
||||
assert.equal(pairing.role, "rayneo-io");
|
||||
assert.equal(pairing.embeddedMac, null);
|
||||
// G2 advertisements are untouched
|
||||
assert.equal(classifyAdvertisement(raw({})).role, "left");
|
||||
});
|
||||
@@ -0,0 +1,152 @@
|
||||
package com.faceclaw.app
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
/** Vectors are bytes captured from a RayNeo iO (Strix OS 1.0.5.12 / 1.0.4.12 + CFW) on 2026-11-01. */
|
||||
class RayNeoIoProtocolTest {
|
||||
private fun hex(value: String) = value.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
|
||||
|
||||
private val phoneId = hex("fac582dfa91e")
|
||||
private val glassesId = hex("006a5e5f33c2")
|
||||
|
||||
@Test
|
||||
fun crcAndFrames() {
|
||||
assertEquals(0x31c3, RayNeoIoProtocol.crc16Xmodem("123456789".encodeToByteArray()))
|
||||
val payload = hex("100001")
|
||||
val frame = RayNeoIoProtocol.encodeFrame(0x1234, RayNeoIoProtocol.BUSINESS_CFW, payload)
|
||||
assertEquals(13, frame.size)
|
||||
assertContentEquals(hex("aa55000712340" + "0f0100001"), frame.copyOfRange(0, 11))
|
||||
val decoded = RayNeoIoProtocol.decodeFrame(frame)!!
|
||||
assertEquals(0x1234, decoded.messageNumber)
|
||||
assertEquals(0xf0, decoded.business)
|
||||
assertContentEquals(payload, decoded.payload)
|
||||
frame[9] = 9
|
||||
assertNull(RayNeoIoProtocol.decodeFrame(frame))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun reassemblerSpansNotificationsAndSkipsJunk() {
|
||||
val a = RayNeoIoProtocol.encodeFrame(1, 15, ByteArray(300) { it.toByte() })
|
||||
val b = RayNeoIoProtocol.encodeFrame(2, 0xf0, hex("0195000001070024cf"))
|
||||
val stream = hex("0102") + a + b
|
||||
val r = RayNeoIoProtocol.FrameReassembler()
|
||||
val frames = RayNeoIoProtocol.writes(stream, 23).flatMap { r.ingest(it) }
|
||||
assertEquals(listOf(1, 2), frames.map { it.messageNumber })
|
||||
assertEquals(300, frames[0].payload.size)
|
||||
assertEquals(0, r.pendingBytes)
|
||||
// a corrupt head is skipped, the next good frame still decodes
|
||||
val bad = a.copyOf().also { it[20] = (it[20] + 1).toByte() }
|
||||
assertEquals(listOf(2), r.ingest(bad + b).map { it.messageNumber })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun handshakeMatchesCapture() {
|
||||
// the Mac harness's request (iOS platform byte, name "Amoli", model "Mac")
|
||||
assertContentEquals(
|
||||
hex("11002810000101110006fac582dfa91e120005416d6f6c69130001011600066950686f6e651700034d6163"),
|
||||
RayNeoIoProtocol.versionRequest(phoneId, "Amoli", "iPhone", "Mac", RayNeoIoProtocol.PLATFORM_IOS),
|
||||
)
|
||||
val reply = RayNeoIoProtocol.parseVersionReply(
|
||||
hex("11004a10000102110006006a5e5f33c212000e5261794e656f20694f2d323232391300010514000f3030364135453546333343323232391500010518000f303036413545354633334332323239"),
|
||||
)!!
|
||||
assertContentEquals(glassesId, reply.glassesId)
|
||||
assertEquals(2, reply.protocolVersion)
|
||||
assertEquals("006A5E5F33C2229", reply.serial)
|
||||
assertFalse(reply.accountBound)
|
||||
assertContentEquals(
|
||||
hex("18002a100004875e2013110020efed651a6aacd1834e8023891eaf80ec4a25814db5222e42655b71fdd373ab96"),
|
||||
RayNeoIoProtocol.guestAuthRequest(hex("875e2013"), phoneId, glassesId),
|
||||
)
|
||||
val authReply = hex("19002a1000042316e62111002082289251b37c1ddb76694d5a4bb4e911a79ad8f2867d7379bb8125f36ae6acac")
|
||||
assertTrue(RayNeoIoProtocol.isGuestAuthReply(authReply))
|
||||
assertTrue(RayNeoIoProtocol.verifyGuestAuthReply(authReply, phoneId, glassesId))
|
||||
assertFalse(RayNeoIoProtocol.verifyGuestAuthReply(authReply, hex("fac582dfa91f"), glassesId))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun envelopes() {
|
||||
assertContentEquals(
|
||||
hex("080110011a027b7d"),
|
||||
RayNeoIoProtocol.encodeEnvelope(RayNeoIoProtocol.Envelope(RayNeoIoProtocol.OTA_VERSION, "{}")),
|
||||
)
|
||||
val status = RayNeoIoProtocol.decodeEnvelope(hex(GENERAL_STATUS))!!
|
||||
assertEquals(1, status.type)
|
||||
assertEquals(98, RayNeoIoProtocol.batteryFromLauncherJson(status.json))
|
||||
assertEquals(100, RayNeoIoProtocol.batteryFromLauncherJson("""{"cmd":"battery_change","payload":{"value":100,"mode":1}}"""))
|
||||
assertEquals(-1, RayNeoIoProtocol.batteryFromLauncherJson("""{"cmd":"screen_status","payload":{"value":1}}"""))
|
||||
val request = RayNeoIoProtocol.Envelope(1, RayNeoIoProtocol.GENERAL_STATUS_REQUEST, sequence = 300, mode = RayNeoIoProtocol.MODE_REQUEST)
|
||||
val back = RayNeoIoProtocol.decodeEnvelope(RayNeoIoProtocol.encodeEnvelope(request))!!
|
||||
assertEquals(300, back.sequence)
|
||||
assertEquals(RayNeoIoProtocol.MODE_REQUEST, back.mode)
|
||||
assertEquals(request.json, back.json)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun cfwLink() {
|
||||
assertContentEquals(hex("100001"), RayNeoIoProtocol.controlPacket(RayNeoIoProtocol.CTRL_QUERY))
|
||||
val record = ByteArray(500) { it.toByte() }
|
||||
val packets = RayNeoIoProtocol.cfwPackets(record, 0x95, 240)
|
||||
assertEquals(listOf(0x81, 0x01, 0x41), packets.map { it[0].toInt() and 255 })
|
||||
assertTrue(packets.all { it[1] == 0x95.toByte() })
|
||||
assertContentEquals(record, packets.flatMap { it.drop(2) }.toByteArray())
|
||||
assertEquals(0xc1, RayNeoIoProtocol.cfwPackets(ByteArray(5), 1)[0][0].toInt() and 255)
|
||||
|
||||
val ack = RayNeoIoProtocol.parseCfwAck(hex("0195000001070024cf"))!!
|
||||
assertFalse(ack.nack)
|
||||
assertEquals(0x95, ack.streamId)
|
||||
assertEquals(0, ack.messageId)
|
||||
assertEquals(1, ack.lens)
|
||||
assertEquals(7, ack.size)
|
||||
assertEquals(0xcf24, ack.checksum)
|
||||
assertTrue(RayNeoIoProtocol.parseCfwAck(hex("0395000002070024cf"))!!.nack)
|
||||
assertNull(RayNeoIoProtocol.parseCfwAck(hex("0195000003070024cf")))
|
||||
|
||||
// Glassly v13 IDENT, then the Faceclaw fork's with the revision string appended
|
||||
val v13 = RayNeoIoProtocol.parseIdent(hex("110d1c02dc00f00000010d007f474c4153534c594346572d494f2f31330019"))!!
|
||||
assertEquals(540, v13.width)
|
||||
assertEquals(220, v13.height)
|
||||
assertEquals(240, v13.maxChunk)
|
||||
assertEquals(13, v13.revision)
|
||||
assertEquals("GLASSLYCFW-IO/13", v13.name)
|
||||
assertFalse(v13.faceclaw)
|
||||
val fc = RayNeoIoProtocol.parseIdent(hex("110d1c02dc00f00000010d00ff474c4153534c594346572d494f2f3133001946616365636c61772f333800"))!!
|
||||
assertTrue(fc.faceclaw)
|
||||
assertEquals(38, fc.faceclawRevision)
|
||||
|
||||
assertEquals(1, RayNeoIoProtocol.parsePageState(hex("130100")))
|
||||
val g = RayNeoIoProtocol.parseGesture(hex("0703010a000000"))!!
|
||||
assertEquals(3, g.eventType)
|
||||
assertEquals(1, g.source)
|
||||
assertEquals(10L, g.tick)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun recordsShareTheG2Encoder() {
|
||||
// the G2 envelope is unchanged by the record/packet split
|
||||
val g2 = CfwTransport.frame("123456789abcdef".encodeToByteArray(), 255, 3, 23)
|
||||
assertContentEquals(hex("aa21ff0c0101f000830b0f0078c331323334862b"), g2[0])
|
||||
// an iO record carries the same flags/length/CRC header
|
||||
val t = CfwTransport(testPlatform())
|
||||
val message = ByteArray(64) { (it % 7).toByte() }
|
||||
val rec = t.encodeRecord(message, CfwTransport.BOTH)
|
||||
assertEquals(CfwTransport.BOTH or CfwTransport.COMPRESSED or CfwTransport.RESET_CONTEXT, rec[0].toInt())
|
||||
assertEquals(CfwTransport.crc(message), (rec[3].toInt() and 255) or ((rec[4].toInt() and 255) shl 8))
|
||||
assertContentEquals(message, inflateRecords(listOf(rec))[0])
|
||||
// the next record continues the same compression context
|
||||
val second = t.encodeRecord(message, CfwTransport.BOTH)
|
||||
assertEquals(CfwTransport.BOTH or CfwTransport.COMPRESSED, second[0].toInt())
|
||||
t.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun advertisement() {
|
||||
assertEquals("00:6A:5E:5F:33:C2", RayNeoIoBle.macFromManufacturerData(hex("07006a5e5f33c2130000000000000001")))
|
||||
assertNull(RayNeoIoBle.macFromManufacturerData(hex("0800")))
|
||||
assertTrue(RayNeoIoBle.matchesName("RayNeo iO-2229"))
|
||||
assertFalse(RayNeoIoBle.matchesName("Even G2_32_L_693CCB"))
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val GENERAL_STATUS = "080110011aa6037b2267656e6572616c537461747573223a7b226175746f6d617469634272696768746e657373223a66616c73652c2262617474657279223a39382c22626174745f74656d70223a33342c22626c7565746f6f746841646472657373223a2230303a36413a35453a35463a33333a4332222c226272696768746e657373223a312c226465766963654e616d65223a225261794e656f20694f2d32323239222c2269734368617267696e67223a747275652c2263686172676554797065223a302c2273637265656e537461747573223a312c2268616c6c537461747573223a302c226d6963537461747573223a302c22666f6375734d6f6465223a7b22656e61626c65223a302c22656e61626c65476c617373436c6f7365223a312c22706f6c696379223a7b226175746f223a312c22626567696e223a2230393a3030222c22656e64223a2231383a3030222c227765656b646179223a5b302c312c322c332c342c352c365d7d7d2c22707265736372697074696f6e223a7b22656e61626c65223a312c22646567726565223a222d332c302c2d322e37352c30222c227064223a223633227d7d7d"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
package com.faceclaw.app
|
||||
|
||||
import kotlin.concurrent.Volatile
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
private const val IO = "00:6A:5E:5F:33:C2"
|
||||
private val PHONE_ID = byteArrayOf(1, 2, 3, 4, 5, 6)
|
||||
|
||||
private class IoClock(private val base: ProtocolPlatform) : ProtocolPlatform by base {
|
||||
@Volatile var offsetMs = 0L
|
||||
|
||||
override fun elapsedRealtimeMs(): Long = base.elapsedRealtimeMs() + offsetMs
|
||||
}
|
||||
|
||||
private fun awaitTrue(timeoutMs: Long, condition: () -> Boolean): Boolean {
|
||||
val platform = testPlatform()
|
||||
val deadline = platform.elapsedRealtimeMs() + timeoutMs
|
||||
while (platform.elapsedRealtimeMs() < deadline) {
|
||||
if (condition()) return true
|
||||
sleepMs(10)
|
||||
}
|
||||
return condition()
|
||||
}
|
||||
|
||||
/**
|
||||
* A RayNeo iO running faceclaw-rayneo-cfw, as the phone sees it over GATT: answers the
|
||||
* handshake, guest auth, launcher status, OS version, QUERY and page controls, reassembles
|
||||
* and inflates CFW records, and ACKs each lens of every record whose CRC checks out.
|
||||
*/
|
||||
private class FakeIoGlasses(platform: ProtocolPlatform) : SessionLink {
|
||||
lateinit var core: GlassesSessionCore
|
||||
private val lock = platform.createLock()
|
||||
val glassesId = byteArrayOf(0x00, 0x6a, 0x5e, 0x5f, 0x33, 0xc2.toByte())
|
||||
/** The phone id the glasses accept; null = pairing mode (they bind to the next one). */
|
||||
@Volatile var boundTo: ByteArray? = null
|
||||
@Volatile var faceclaw = true
|
||||
@Volatile var pageOpen = false
|
||||
@Volatile var hangUps = 0
|
||||
private val controlsList = ArrayList<Int>()
|
||||
private val messagesList = ArrayList<ByteArray>()
|
||||
private val launcherList = ArrayList<String>()
|
||||
val launcher: List<String> get() = lock.withLock { launcherList.toList() }
|
||||
private val records = ArrayList<ByteArray>()
|
||||
private var current = ByteArray(0)
|
||||
private val inbound = RayNeoIoProtocol.FrameReassembler()
|
||||
private var number = 1
|
||||
|
||||
val controls: List<Int> get() = lock.withLock { controlsList.toList() }
|
||||
val messages: List<ByteArray> get() = lock.withLock { messagesList.toList() }
|
||||
|
||||
fun notify(business: Int, payload: ByteArray) {
|
||||
val frame = lock.withLock { RayNeoIoProtocol.encodeFrame(number++, business, payload) }
|
||||
core.onNotification(IO, RayNeoIoBle.NOTIFY_CHAR_UUID, frame)
|
||||
}
|
||||
|
||||
fun page(state: Int, reason: Int) = notify(0xf0, byteArrayOf(0x13, state.toByte(), reason.toByte()))
|
||||
|
||||
override fun connect(address: String, timeoutMs: Int): Boolean = true
|
||||
|
||||
override fun isConnected(address: String): Boolean = true
|
||||
|
||||
override fun requestHighPriority(address: String) {}
|
||||
|
||||
override fun requestMtu(address: String, mtu: Int, timeoutMs: Int): Boolean = true
|
||||
|
||||
override fun negotiatedMtu(address: String): Int = 185
|
||||
|
||||
override fun discoverServices(address: String, timeoutMs: Int): Boolean = true
|
||||
|
||||
override fun enableNotifications(address: String, characteristicUuid: String, enable: Boolean, timeoutMs: Int): Boolean =
|
||||
characteristicUuid == RayNeoIoBle.NOTIFY_CHAR_UUID
|
||||
|
||||
override fun writeFrames(address: String, characteristicUuid: String, frames: List<ByteArray>, mode: GattWriteMode, timeoutMs: Int): Boolean {
|
||||
assertEquals(RayNeoIoBle.WRITE_CHAR_UUID, characteristicUuid)
|
||||
assertTrue(frames.all { it.size <= 185 - 3 }, "writes must fit the MTU")
|
||||
val decoded = lock.withLock { frames.flatMap { inbound.ingest(it) } }
|
||||
for (frame in decoded) handle(frame)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun handle(frame: RayNeoIoProtocol.Frame) {
|
||||
val p = frame.payload
|
||||
when (frame.business) {
|
||||
0x10 -> {
|
||||
val tlvs = RayNeoIoProtocol.decodeTlvs(p)!!
|
||||
val version = tlvs.firstOrNull { it.tag == 0x11 }
|
||||
val auth = tlvs.firstOrNull { it.tag == 0x18 }
|
||||
if (version != null) {
|
||||
val phone = RayNeoIoProtocol.decodeTlvs(version.value)!!.first { it.tag == 0x11 }.value
|
||||
val bound = boundTo
|
||||
if (bound != null && !bound.contentEquals(phone)) {
|
||||
hangUps++
|
||||
core.onConnectionStateChange(IO, false)
|
||||
return
|
||||
}
|
||||
notify(0x10, RayNeoIoProtocol.tlv(0x11, RayNeoIoProtocol.tlv(0x10, byteArrayOf(2)) +
|
||||
RayNeoIoProtocol.tlv(0x11, glassesId) + RayNeoIoProtocol.tlv(0x14, "006A5E5F33C2229".encodeToByteArray())))
|
||||
} else if (auth != null) {
|
||||
val fields = RayNeoIoProtocol.decodeTlvs(auth.value)!!
|
||||
val phoneRandom = fields.first { it.tag == 0x10 }.value
|
||||
val phone = PHONE_ID
|
||||
assertTrue(RayNeoIoProtocol.authProof(phoneRandom, phone, glassesId).contentEquals(fields.first { it.tag == 0x11 }.value))
|
||||
boundTo = phone
|
||||
val random = byteArrayOf(9, 8, 7, 6)
|
||||
notify(0x10, RayNeoIoProtocol.tlv(0x19, RayNeoIoProtocol.tlv(0x10, random) +
|
||||
RayNeoIoProtocol.tlv(0x11, RayNeoIoProtocol.authProof(random, phone, glassesId))))
|
||||
}
|
||||
}
|
||||
15 -> {
|
||||
lock.withLock { launcherList.add(RayNeoIoProtocol.decodeEnvelope(p)!!.json) }
|
||||
notify(15, RayNeoIoProtocol.encodeEnvelope(RayNeoIoProtocol.Envelope(1,
|
||||
"""{"generalStatus":{"battery":77,"isCharging":false}}""", sequence = RayNeoIoProtocol.decodeEnvelope(p)!!.sequence, mode = 2)))
|
||||
}
|
||||
9 -> notify(9, RayNeoIoProtocol.encodeEnvelope(RayNeoIoProtocol.Envelope(1, """{"OsVersion":"Strix OS 1.0.4.12"}""")))
|
||||
0xf0 -> cfw(p)
|
||||
}
|
||||
}
|
||||
|
||||
private fun cfw(p: ByteArray) {
|
||||
val opt = p[0].toInt() and 255
|
||||
val stream = p[1].toInt() and 255
|
||||
if (opt and RayNeoIoProtocol.OPT_CONTROL != 0) {
|
||||
val ctrl = p[2].toInt() and 255
|
||||
lock.withLock { controlsList.add(ctrl) }
|
||||
when (ctrl) {
|
||||
RayNeoIoProtocol.CTRL_QUERY -> if (faceclaw) notify(0xf0, ident())
|
||||
RayNeoIoProtocol.CTRL_PAGE_OPEN, RayNeoIoProtocol.CTRL_KEEPALIVE -> { pageOpen = true; page(1, 0) }
|
||||
RayNeoIoProtocol.CTRL_PAGE_CLOSE -> { pageOpen = false; page(0, 0) }
|
||||
}
|
||||
return
|
||||
}
|
||||
val complete = lock.withLock {
|
||||
if (opt and RayNeoIoProtocol.OPT_RESET != 0) current = ByteArray(0)
|
||||
current += p.copyOfRange(2, p.size)
|
||||
val len = if (current.size >= 5) (current[1].toInt() and 255) or ((current[2].toInt() and 255) shl 8) else -1
|
||||
if (len >= 0 && current.size == 5 + len) current.also { records.add(it); current = ByteArray(0) } else null
|
||||
} ?: return
|
||||
val message = lock.withLock { inflateRecords(records).last() }
|
||||
val crc = (complete[3].toInt() and 255) or ((complete[4].toInt() and 255) shl 8)
|
||||
val ok = pageOpen && CfwTransport.crc(message) == crc && ioSupportsCfwType(message[0].toInt() and 255)
|
||||
if (ok) lock.withLock { messagesList.add(message) }
|
||||
for (lens in 1..2) {
|
||||
notify(0xf0, byteArrayOf(if (ok) 1 else 3, stream.toByte(), 0, 0, lens.toByte(),
|
||||
message.size.toByte(), (message.size ushr 8).toByte(), crc.toByte(), (crc ushr 8).toByte()))
|
||||
}
|
||||
}
|
||||
|
||||
private fun ident(): ByteArray {
|
||||
val name = "GLASSLYCFW-IO/13".encodeToByteArray()
|
||||
return byteArrayOf(0x11, 13, 0x1c, 0x02, 0xdc.toByte(), 0x00, 0xf0.toByte(), 0x00, 0x00, 0x01, 0x0d, 0x00, 0xff.toByte()) +
|
||||
name + byteArrayOf(0, 25) + "Faceclaw/38".encodeToByteArray() + byteArrayOf(0)
|
||||
}
|
||||
|
||||
override fun disconnect(address: String) {}
|
||||
|
||||
override fun close() {}
|
||||
|
||||
override fun isBonded(address: String): Boolean = false
|
||||
|
||||
override fun prepareBenchmarkLink(address: String, mode: Int) {}
|
||||
|
||||
override fun recordDisplayFrameSent() {}
|
||||
}
|
||||
|
||||
private class IoListener : FaceclawBleCommunicatorListener {
|
||||
val phases = ArrayList<String>()
|
||||
@Volatile var lastStatus = ""
|
||||
val events = ArrayList<String>()
|
||||
val batteries = ArrayList<String>()
|
||||
val firmware = ArrayList<String>()
|
||||
|
||||
override fun onStateChange(phase: String?, status: String?) {
|
||||
phases.add(phase ?: "")
|
||||
lastStatus = status ?: ""
|
||||
}
|
||||
|
||||
override fun onRingEvent(kind: String?, containerName: String?, eventType: Int, eventSource: Int, systemExitReasonCode: Int, frameId: Int, ringTick: Long, ringType: Int, ringAux: Int, ringSpeed: Int) {
|
||||
events.add("$kind:$eventType:$eventSource")
|
||||
}
|
||||
|
||||
override fun onBatteryState(headsetBattery: Int, headsetCharging: Int, ringBattery: Int, ringCharging: Int) {
|
||||
batteries.add("$headsetBattery/$headsetCharging")
|
||||
}
|
||||
|
||||
override fun onSilentMode(silent: Boolean) {}
|
||||
|
||||
override fun onWearState(wearing: Boolean) {}
|
||||
|
||||
override fun onPhoneLockState(locked: Boolean) {}
|
||||
|
||||
override fun onEvenAppConflict(message: String?) {}
|
||||
|
||||
override fun onFrameMetrics(paintMs: Int, transmitMs: Int, tileCount: Int) {}
|
||||
|
||||
override fun onFrameFinished(frameId: Int, outcome: String?) {}
|
||||
|
||||
override fun onFirmwareInfo(leftVersion: String?, rightVersion: String?, extension: String?) {
|
||||
firmware.add("$leftVersion|$extension")
|
||||
}
|
||||
}
|
||||
|
||||
private class IoSession {
|
||||
val platform = IoClock(testPlatform())
|
||||
val glasses = FakeIoGlasses(platform)
|
||||
private val host = object : SessionHost {
|
||||
private val lock = platform.createLock()
|
||||
private val lines = ArrayList<String>()
|
||||
private var done: Latch? = null
|
||||
|
||||
fun logs(): List<String> = lock.withLock { lines.toList() }
|
||||
|
||||
override fun postToMain(action: () -> Unit) = action()
|
||||
|
||||
override fun currentThreadDispatcher(): SessionDispatcher = SessionDispatcher { it() }
|
||||
|
||||
override fun isPhoneLocked(): Boolean = false
|
||||
|
||||
override fun setScreenWakeLock(on: Boolean) {}
|
||||
|
||||
override fun isEvenAppActive(): Boolean = false
|
||||
|
||||
override fun startWorker(body: () -> Unit) {
|
||||
val latch = Latch(1, platform)
|
||||
done = latch
|
||||
startThread("io-test-session", true) {
|
||||
try {
|
||||
body()
|
||||
} finally {
|
||||
latch.countDown()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun joinWorker(timeoutMs: Long) {
|
||||
done?.await(timeoutMs)
|
||||
}
|
||||
|
||||
override fun log(level: SessionLogLevel, tag: String, message: String, error: Throwable?) {
|
||||
lock.withLock { lines.add("$level $tag: $message") }
|
||||
}
|
||||
}
|
||||
val listener = IoListener()
|
||||
val core = GlassesSessionCore(glasses, host, FrameTimingsCore(platform), platform, IO, IO, "")
|
||||
|
||||
init {
|
||||
glasses.core = core
|
||||
core.setListener(listener)
|
||||
core.setRequiredFirmwareRevision(38)
|
||||
core.useRayNeoIo(PHONE_ID, "Pixel", "Google", "Pixel 11")
|
||||
}
|
||||
|
||||
fun pageUp(): Boolean = core.monitor.withLock { core.sessionReady && core.fixedLayoutCreated }
|
||||
|
||||
fun displayedMatchesDesired(): Boolean = core.monitor.withLock {
|
||||
core.desiredTilesLock.locked { core.desiredFingerprint.isNotEmpty() && core.desiredFingerprint == core.displayedFingerprint }
|
||||
}
|
||||
|
||||
fun submitFrame(value: Byte, frameId: Int) {
|
||||
val pixels = ByteArray(64 * 32) { if (it % 7 == 0) value else 0 }
|
||||
core.submitSurfaceFrame(ArrayByteReader(pixels), "s", 0, 0, 64, 32, "content-$value", 0, frameId, null)
|
||||
}
|
||||
|
||||
fun tail(): String = host.logs().takeLast(25).joinToString("\n")
|
||||
}
|
||||
|
||||
class RayNeoIoSessionTest {
|
||||
@Test
|
||||
fun connectsAuthenticatesOpensThePageAndPresentsFrames() {
|
||||
val s = IoSession()
|
||||
s.core.configureBrightness(false, 70, 2, 100, "0:0,1000:100", 280)
|
||||
s.core.configureCompositorScreen(540, 220)
|
||||
s.core.configureSurface("s", 0, 0, 64, 32, 0, SurfaceCompositor.TRANSPARENCY_OPAQUE)
|
||||
try {
|
||||
assertTrue(s.core.start())
|
||||
assertTrue(awaitTrue(5_000) { s.pageUp() }, "page never opened:\n" + s.tail())
|
||||
assertTrue(s.core.isRayNeoIo())
|
||||
assertTrue(s.listener.firmware.contains("Strix OS 1.0.4.12|Faceclaw/38"), s.listener.firmware.toString())
|
||||
assertTrue(awaitTrue(2_000) { s.listener.batteries.contains("77/0") }, s.listener.batteries.toString())
|
||||
assertEquals(listOf(RayNeoIoProtocol.CTRL_QUERY, RayNeoIoProtocol.CTRL_PAGE_OPEN), s.glasses.controls.take(2))
|
||||
|
||||
s.submitFrame(0x7f, 1)
|
||||
assertTrue(awaitTrue(5_000) { s.displayedMatchesDesired() }, "frame never displayed:\n" + s.tail())
|
||||
val types = s.glasses.messages.map { it[0].toInt() and 255 }
|
||||
assertTrue(types.contains(CFW_MSG_PRESENT), types.toString())
|
||||
// nothing G2-only (brightness 30, ENTER_EVENHUB 31, debug flags 7, ...) reaches the iO
|
||||
assertTrue(types.all { ioSupportsCfwType(it) }, types.toString())
|
||||
// a visible frame wakes the screen through the launcher's brightness (70% -> level 6)
|
||||
assertTrue(awaitTrue(3_000) { s.glasses.launcher.any { it.contains("brightness_change") && it.contains("\"value\":6") } },
|
||||
s.glasses.launcher.toString())
|
||||
|
||||
// a second, different frame goes out as an update
|
||||
val before = s.glasses.messages.size
|
||||
s.submitFrame(0x30, 2)
|
||||
assertTrue(awaitTrue(5_000) { s.displayedMatchesDesired() && s.glasses.messages.size > before })
|
||||
} finally {
|
||||
s.core.close()
|
||||
}
|
||||
// disconnect closes the page so the glasses go back to their own UI at once
|
||||
assertEquals(RayNeoIoProtocol.CTRL_PAGE_CLOSE, s.glasses.controls.last())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun refusalAsksForPairingModeAndConnectsOnceItIsOn() {
|
||||
val s = IoSession()
|
||||
s.glasses.boundTo = byteArrayOf(9, 9, 9, 9, 9, 9)
|
||||
try {
|
||||
assertTrue(s.core.start())
|
||||
assertTrue(awaitTrue(5_000) { s.glasses.hangUps >= 1 && s.listener.lastStatus.contains("pairing mode") },
|
||||
"no pairing-mode prompt:\n" + s.tail())
|
||||
assertFalse(s.pageUp())
|
||||
s.glasses.boundTo = null // the wearer held the button
|
||||
s.platform.offsetMs += 5_000
|
||||
s.core.interruptibleSleep.interrupt()
|
||||
assertTrue(awaitTrue(5_000) { s.pageUp() }, "never connected after pairing mode:\n" + s.tail())
|
||||
assertTrue(s.glasses.boundTo!!.contentEquals(PHONE_ID))
|
||||
} finally {
|
||||
s.core.close()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun stockFirmwareIsIncompatible() {
|
||||
val s = IoSession()
|
||||
s.glasses.faceclaw = false
|
||||
try {
|
||||
assertTrue(s.core.start())
|
||||
assertTrue(awaitTrue(8_000) { s.listener.phases.contains("incompatible-firmware") }, "not halted:\n" + s.tail())
|
||||
assertTrue(s.listener.firmware.contains("Strix OS 1.0.4.12|"))
|
||||
assertFalse(s.glasses.controls.contains(RayNeoIoProtocol.CTRL_PAGE_OPEN))
|
||||
} finally {
|
||||
s.core.close()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun gesturesPageLossAndKeepalive() {
|
||||
val s = IoSession()
|
||||
s.core.configureCompositorScreen(540, 220)
|
||||
try {
|
||||
assertTrue(s.core.start())
|
||||
assertTrue(awaitTrue(5_000) { s.pageUp() }, s.tail())
|
||||
// taps/crown arrive as G2 sys-events from the right temple; head up wakes; head down is dropped
|
||||
s.glasses.notify(0xf0, byteArrayOf(7, 3, 1, 0, 0, 0, 0))
|
||||
s.glasses.notify(0xf0, byteArrayOf(7, 1, 0, 0, 0, 0, 0))
|
||||
s.glasses.notify(0xf0, byteArrayOf(7, 12, 2, 0, 0, 0, 0))
|
||||
s.glasses.notify(0xf0, byteArrayOf(7, 15, 2, 0, 0, 0, 0))
|
||||
assertEquals(listOf("sys-event:3:1", "sys-event:1:1", "display-wake:12:1"), s.listener.events)
|
||||
|
||||
// the lease ran out on the glasses: the session reopens the page
|
||||
s.glasses.pageOpen = false
|
||||
s.glasses.page(0, 3)
|
||||
assertFalse(s.pageUp())
|
||||
s.platform.offsetMs += 4_000
|
||||
s.core.interruptibleSleep.interrupt()
|
||||
assertTrue(awaitTrue(5_000) { s.pageUp() }, "page not reopened:\n" + s.tail())
|
||||
|
||||
// keepalives well inside the 120 s lease
|
||||
val keepalives = s.glasses.controls.count { it == RayNeoIoProtocol.CTRL_KEEPALIVE }
|
||||
s.platform.offsetMs += 31_000
|
||||
s.core.interruptibleSleep.interrupt()
|
||||
assertTrue(awaitTrue(5_000) { s.glasses.controls.count { it == RayNeoIoProtocol.CTRL_KEEPALIVE } > keepalives })
|
||||
|
||||
// the wearer closed it: stay closed until they touch the glasses again
|
||||
s.glasses.pageOpen = false
|
||||
s.glasses.page(0, 4)
|
||||
s.platform.offsetMs += 4_000
|
||||
s.core.interruptibleSleep.interrupt()
|
||||
sleepMs(300)
|
||||
assertFalse(s.pageUp())
|
||||
s.glasses.notify(0xf0, byteArrayOf(7, 0, 1, 0, 0, 0, 0))
|
||||
s.core.interruptibleSleep.interrupt()
|
||||
assertTrue(awaitTrue(5_000) { s.pageUp() }, "touch did not reopen:\n" + s.tail())
|
||||
} finally {
|
||||
s.core.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ const {
|
||||
isPreviouslyPaired,
|
||||
glassesRow,
|
||||
ringRow,
|
||||
rayneoRow,
|
||||
DEFAULT_STALE_AFTER_MS,
|
||||
} = require("../.test-build/app/g2/pairing-candidates.js");
|
||||
const { requiredArtworkFileNames, glassesImagePath, GENERIC_G2_IMAGE_PATH } = require("../.test-build/app/g2/glasses-artwork.js");
|
||||
@@ -289,3 +290,19 @@ test("every artwork file the resolver claims is bundled exists on disk", () => {
|
||||
assert.ok(fs.existsSync(path.join(dir, name)), `missing app/images/glasses/${name}`);
|
||||
}
|
||||
});
|
||||
|
||||
test("a RayNeo iO is its own candidate, never half of a G2 pair", () => {
|
||||
const aggregator = new DiscoveryAggregator();
|
||||
aggregator.ingest({
|
||||
address: "00:6A:5E:5F:33:C2", name: "RayNeo iO-2229", manufacturerData: "1657" + "07006a5e5f33c2130000000000000001",
|
||||
rssi: -50, txPower: null, connectable: true, bonded: false, source: "scan", seenAtMs: 1000,
|
||||
});
|
||||
assert.equal(aggregator.pairs().length, 0);
|
||||
assert.equal(aggregator.rings().length, 0);
|
||||
const found = aggregator.rayneos();
|
||||
assert.equal(found.length, 1);
|
||||
const row = rayneoRow(found[0], { pairedAddress: "00:6a:5e:5f:33:c2" });
|
||||
assert.equal(row.kind, "rayneo-io");
|
||||
assert.equal(row.canSelect, true);
|
||||
assert.equal(row.isPreviouslyPaired, true);
|
||||
});
|
||||
Reference in new issue
Block a user