fix: mls LED 명령 Big Endian 파라미터로 변경 (테스터 exe와 동일)

테스터 코드 분석 결과:
  exe: mls? + [0x00, 0x05] (16비트 Big Endian) → LED 바뀜
  앱: mls? + [0x05, 0x00] (16비트 Little Endian) → LED 안 바뀜

CRC16.buildCommandBE() 추가: 파라미터를 Big Endian으로 직렬화
sendLedMode(): buildCommandBE("mls", [state]) 사용

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-24 16:38:35 +09:00
parent 3cebaff6a0
commit fdc4047c5c
2 changed files with 12 additions and 1 deletions
@@ -354,7 +354,7 @@ class BleManager private constructor(private val context: Context) {
} }
fun sendLedMode(state: Int) { fun sendLedMode(state: Int) {
sendRaw(CRC16.buildCommandASCII("mls", " $state")) sendRaw(CRC16.buildCommandBE("mls", intArrayOf(state)))
} }
fun sendImuQuery() { fun sendImuQuery() {
@@ -54,6 +54,17 @@ object CRC16 {
return appendCRC("$cmd?$asciiParams".toByteArray(Charsets.UTF_8)) return appendCRC("$cmd?$asciiParams".toByteArray(Charsets.UTF_8))
} }
/** 파라미터를 16비트 Big Endian으로 추가 (펌웨어 테스터와 동일 포맷) */
fun buildCommandBE(cmd: String, params: IntArray = intArrayOf()): ByteArray {
val cmdBytes = "$cmd?".toByteArray(Charsets.UTF_8)
val paramBytes = ByteArray(params.size * 2)
for (i in params.indices) {
paramBytes[i * 2] = ((params[i] shr 8) and 0xFF).toByte() // High byte first
paramBytes[i * 2 + 1] = (params[i] and 0xFF).toByte() // Low byte
}
return appendCRC(cmdBytes + paramBytes)
}
fun buildSimpleCommand(cmd: String): ByteArray { fun buildSimpleCommand(cmd: String): ByteArray {
return appendCRC(cmd.toByteArray(Charsets.UTF_8)) return appendCRC(cmd.toByteArray(Charsets.UTF_8))
} }