motorolaMagicFromDbc(17, 10)

only:we have a problem?
This commit is contained in:
rusefillc 2024-11-06 23:01:49 -05:00
parent 99e4a593f2
commit 5c82315569
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,38 @@
#include "pch.h"
#include "rusefi_lua.h"
#include "lua_lib.h"
static int motorolaMagicFromDbc(int b, int length) {
// https://github.com/ebroecker/canmatrix/wiki/signal-Byteorder
// convert from lsb0 bit numbering to msb0 bit numbering (or msb0 to lsb0)
b = b - (b % 8) + 7 - (b % 8);
// convert from lsbit of signal data to msbit of signal data, when bit numbering is msb0
b = b + length - 1;
// convert from msbit of signal data to lsbit of signal data, when bit numbering is msb0
b = b - (b % 8) + 7 - (b % 8);
return b;
}
TEST(dbcMotorola, testFromDbc) {
ASSERT_EQ(24, motorolaMagicFromDbc(27, 4));
ASSERT_EQ(24, motorolaMagicFromDbc(30, 7));
ASSERT_EQ(24, motorolaMagicFromDbc(31, 8));
ASSERT_EQ(24, motorolaMagicFromDbc(17, 10));
ASSERT_EQ(24, motorolaMagicFromDbc(17, 10));
}
TEST(dbcMotorola, testFromIntelIntoMotorolaDbc) {
// todo?!
}
TEST(dbcMotorola, accessRange) {
uint8_t data[] = { 0x00, 0x00, 0x03, 0xFF, 0x00, 0x00, 0x00, 0x00};
EXPECT_NEAR_M3(getBitRangeMsb(data, motorolaMagicFromDbc(17, 10), 10), 0x03FF);
EXPECT_NEAR_M3(getBitRangeLsb(data, 16, 2), 3);
EXPECT_NEAR_M3(getBitRangeLsb(data, 24, 8), 0xFF);
}

View File

@ -71,6 +71,7 @@ TESTS_SRC_CPP = \
tests/shift_torque_reduction/test_shift_torque_reduction_angle_advance.cpp \
tests/test_fft.cpp \
tests/lua/test_lua_basic.cpp \
tests/lua/test_lua_dbc.cpp \
tests/lua/test_lookup.cpp \
tests/lua/test_lua_e38.cpp \
tests/lua/test_lua_canam.cpp \