only:vincpy
This commit is contained in:
parent
f5c1501b04
commit
950f0d4525
|
@ -632,6 +632,18 @@ int lua_canRxAddMask(lua_State* l) {
|
|||
}
|
||||
#endif // EFI_CAN_SUPPORT
|
||||
|
||||
static int lua_vincpy(lua_State* l) {
|
||||
luaL_checktype(l, 1, LUA_TTABLE);
|
||||
size_t sourceIndex = luaL_checknumber(l, 2);
|
||||
size_t destinationIndex = luaL_checknumber(l, 3);
|
||||
size_t size = luaL_checknumber(l, 4);
|
||||
for (int i = 0;i<size;i++) {
|
||||
lua_pushnumber(l, engineConfiguration->vinNumber[sourceIndex + i]);
|
||||
lua_rawseti(l, 1, destinationIndex + i);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void configureRusefiLuaHooks(lua_State* lState) {
|
||||
LuaClass<Timer> luaTimer(lState, "Timer");
|
||||
luaTimer
|
||||
|
@ -658,6 +670,7 @@ void configureRusefiLuaHooks(lua_State* lState) {
|
|||
|
||||
lua_register(lState, "readPin", lua_readpin);
|
||||
lua_register(lState, "vin", lua_vin);
|
||||
lua_register(lState, "vincpy", lua_vincpy);
|
||||
lua_register(lState, "getAuxAnalog", lua_getAuxAnalog);
|
||||
lua_register(lState, "getSensorByIndex", lua_getSensorByIndex);
|
||||
lua_register(lState, "getSensor", lua_getSensorByName);
|
||||
|
|
|
@ -13,7 +13,7 @@ TEST(LuaVin, Test) {
|
|||
|
||||
strcpy(engineConfiguration->vinNumber, "GM123");
|
||||
|
||||
const char* realdata = TWO_BYTES_MSB R"(
|
||||
const char* realdata = R"(
|
||||
|
||||
function testFunc()
|
||||
return vin(0)
|
||||
|
@ -21,3 +21,21 @@ TEST(LuaVin, Test) {
|
|||
|
||||
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 0x47);
|
||||
}
|
||||
|
||||
TEST(LuaVinCpy, Test) {
|
||||
EngineTestHelper eth(engine_type_e::TEST_CRANK_ENGINE);
|
||||
|
||||
strcpy(engineConfiguration->vinNumber, "GM123");
|
||||
|
||||
const char* realdata = ARRAY_EQUALS PRINT_ARRAY R"(
|
||||
|
||||
function testFunc()
|
||||
data = {0, 0, 0, 0, 0}
|
||||
vincpy(data, 2, 1, 3);
|
||||
print(arrayToString(data))
|
||||
expected = { 0x31, 0x32, 0x33, 0x00, 0x00 }
|
||||
return equals(data, expected)
|
||||
end)";
|
||||
|
||||
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue