fix: align NIP-BE chunk format with KoalaSat/samiz reference implementation
Reviewed the samiz BLE implementation and fixed compatibility issues: - Chunk index: changed from 2 bytes to 1 byte (matching samiz/NIP-BE example) - Chunk overhead: 2 bytes total (1 index + 1 total count), not 3 - chunkSize parameter now means payload size (500), not total chunk size - Android: TX power HIGH, advertise timeout indefinite (matching samiz) - Android: request MTU 512 and CONNECTION_PRIORITY_HIGH on connect - Android: discover services after MTU negotiation (samiz flow) - Android: set WRITE_TYPE_DEFAULT on write characteristic - MTU-to-chunkSize: properly accounts for ATT overhead (3) + chunk overhead (2) These changes ensure wire-level compatibility with samiz devices. https://claude.ai/code/session_01Tz5E73Rj7tL48A3qUGS5DT
This commit is contained in:
+8
-4
@@ -48,15 +48,19 @@ class BleMessageChunkerTest {
|
||||
@Test
|
||||
fun chunksHaveCorrectFormat() {
|
||||
val message = """["EVENT",{"id":"abc","kind":1,"content":"hello world"}]"""
|
||||
val chunks = BleMessageChunker.splitIntoChunks(message, chunkSize = 20)
|
||||
val chunkSize = 20
|
||||
val chunks = BleMessageChunker.splitIntoChunks(message, chunkSize = chunkSize)
|
||||
|
||||
for ((i, chunk) in chunks.withIndex()) {
|
||||
// First 2 bytes are the index
|
||||
// First byte is the index
|
||||
assertEquals(i, BleMessageChunker.chunkIndex(chunk))
|
||||
// Last byte is the total count
|
||||
assertEquals(chunks.size, BleMessageChunker.totalChunks(chunk))
|
||||
// Each chunk should be at most chunkSize
|
||||
assertTrue(chunk.size <= 20, "Chunk size ${chunk.size} exceeds max 20")
|
||||
// Each chunk should be at most chunkSize + 2 (overhead)
|
||||
assertTrue(
|
||||
chunk.size <= chunkSize + BleMessageChunker.CHUNK_OVERHEAD,
|
||||
"Chunk size ${chunk.size} exceeds max ${chunkSize + BleMessageChunker.CHUNK_OVERHEAD}",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user