things are turning nasty

This commit is contained in:
rusefillc 2024-02-16 00:31:00 -05:00
parent fa68d54687
commit 29a83d222a
2 changed files with 5 additions and 1 deletions

View File

@ -99,6 +99,7 @@ public class DbcField {
public static int getBitRange(byte[] data, int bitIndex, int bitWidth, boolean isBigEndian) {
if (bitIndex < 0)
throw new IllegalArgumentException("Huh? " + bitIndex + " " + bitWidth);
int byteIndex = bitIndex >> 3;
int shift = bitIndex - byteIndex * 8;
if (byteIndex >= data.length)

View File

@ -24,8 +24,11 @@ public class GetValueFromTrcTest {
@Test
public void testBigEndian() {
byte[] rpm = {(byte) 0x70, 0x04, 0x1F};
assertEquals(0x41f, DbcField.getBitRange(rpm, 16, 16, true));
byte[] data = {(byte) 0xAB, 0x56, 0x34};
// hmmm
assertEquals(0x56AB, DbcField.getBitRange(data, 0, 16, false));
assertEquals(0xAB56, DbcField.getBitRange(data, 8, 16, true));