fix: critical bug in PiezoPacketCollector processEndPacket

CRITICAL: In multi-channel mode, "ree:" packets between channels
were silently dropped instead of saving the current channel data.
This caused channel data loss when channels are separated by "ree:".

Fixed: Added missing isMultiChannel + ree: branch that calls
saveCurrentChannel() — matching Swift behavior exactly.

Found via line-by-line Swift vs Kotlin verification.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
dwjang
2026-04-21 16:21:43 +09:00
parent c1c6dfc16a
commit 444aa6280f
@@ -130,12 +130,19 @@ class PiezoPacketCollector {
private fun processEndPacket(prefix: String, bytes: ByteArray) {
if (isMultiChannel && prefix == "raa:") {
// Final completion marker — save last channel and finish
if (hasFirstPacket && rawData.isNotEmpty()) saveCurrentChannel()
isComplete = true
val validChannels = channelResults.filterNotNull()
onLog?.invoke("raa: multi-channel complete — ${validChannels.size} channels")
onMultiChannelComplete?.invoke(validChannels)
} else if (!isMultiChannel) {
} else if (isMultiChannel) {
// ree: in multi-channel = channel separator, save and continue
if (hasFirstPacket && rawData.isNotEmpty()) {
saveCurrentChannel()
}
} else {
// Single-channel complete (ree:)
finishSingleChannel()
}
}