Исправить порядок слов BALZAM CAN и добавить поддержку пульта МПУ

This commit is contained in:
2026-10-02 16:41:25 +03:00
parent a63c1dd7d8
commit 025a3fde28
7 changed files with 74 additions and 21 deletions
@@ -104,7 +104,7 @@ object BalsamCanProtocol {
}
val padded = values + List(3 - values.size) { 0 }
val header = (mask shl 13) or startAddress
val data = listOf(header, padded[0], padded[1], padded[2])
val data = listOf(padded[1], padded[2], header, padded[0])
.flatMap { listOf((it ushr 8).toByte(), it.toByte()) }
.toByteArray()
val node = nodes[device - 1]
@@ -131,13 +131,13 @@ object BalsamCanProtocol {
private fun fallbackDecode(canId: Long, data: ByteArray): IntArray {
val relative = (canId and 0x1FFF_FFFFL) - BASE_ID
val header = u16be(data, 0)
val header = u16be(data, 4)
return intArrayOf(
((relative and 0x0F) + 1).toInt(),
if (relative >= 0x10) 1 else 0,
(header ushr 13) and 7,
header and 0x1FFF,
u16be(data, 2), u16be(data, 4), u16be(data, 6),
u16be(data, 6), u16be(data, 0), u16be(data, 2),
)
}
@@ -9,7 +9,7 @@ class BalsamCanProtocolTest {
fun decodesThreeNamedSensorRegisters() {
val frame = requireNotNull(BalsamCanProtocol.decode(
0x00BA_0010L,
byteArrayOf(0xE0.toByte(), 0x18, 0x00, 0x29, 0xFF.toByte(), 0xFE.toByte(), 0x12, 0x34),
byteArrayOf(0xFF.toByte(), 0xFE.toByte(), 0x12, 0x34, 0xE0.toByte(), 0x18, 0x00, 0x29),
))
assertEquals(1, frame.device)
assertEquals(0x18, frame.startAddress)
@@ -28,7 +28,7 @@ class BalsamCanProtocolTest {
)
assertEquals(0x00BA_0002L, wire.canId)
assertEquals(
listOf(0xC0, 0x28, 0x12, 0x34, 0xFE, 0xDC, 0x00, 0x00),
listOf(0xFE, 0xDC, 0x00, 0x00, 0xC0, 0x28, 0x12, 0x34),
wire.data.map { it.toInt() and 0xFF },
)
val decoded = requireNotNull(BalsamCanProtocol.decode(wire.canId, wire.data))