From 3d329639ea6860fcb2e86116d420638659660ca3 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 4 Oct 2022 21:12:51 -0400 Subject: [PATCH] Mark is asking for VIN number field #3967 --- firmware/controllers/lua/lua_hooks.cpp | 8 ++++++++ unit_tests/tests/lua/test_lua_vin.cpp | 23 +++++++++++++++++++++++ unit_tests/tests/tests.mk | 1 + 3 files changed, 32 insertions(+) create mode 100644 unit_tests/tests/lua/test_lua_vin.cpp diff --git a/firmware/controllers/lua/lua_hooks.cpp b/firmware/controllers/lua/lua_hooks.cpp index 809c1983cb..bb2fe3bb57 100644 --- a/firmware/controllers/lua/lua_hooks.cpp +++ b/firmware/controllers/lua/lua_hooks.cpp @@ -26,6 +26,13 @@ using namespace luaaa; #include "electronic_throttle_impl.h" #endif +static int lua_vin(lua_State* l) { + auto zeroBasedCharIndex = luaL_checkinteger(l, 1); + char value = engineConfiguration->vinNumber[zeroBasedCharIndex]; + lua_pushnumber(l, value); + return 1; +} + static int lua_readpin(lua_State* l) { auto msg = luaL_checkstring(l, 1); #if EFI_PROD_CODE @@ -585,6 +592,7 @@ void configureRusefiLuaHooks(lua_State* l) { configureRusefiLuaUtilHooks(l); lua_register(l, "readPin", lua_readpin); + lua_register(l, "vin", lua_vin); lua_register(l, "getAuxAnalog", lua_getAuxAnalog); lua_register(l, "getSensorByIndex", lua_getSensorByIndex); lua_register(l, "getSensor", lua_getSensorByName); diff --git a/unit_tests/tests/lua/test_lua_vin.cpp b/unit_tests/tests/lua/test_lua_vin.cpp new file mode 100644 index 0000000000..14f862d403 --- /dev/null +++ b/unit_tests/tests/lua/test_lua_vin.cpp @@ -0,0 +1,23 @@ +/* + * test_lua_vin.cpp + * + */ + +#include "pch.h" +#include "rusefi_lua.h" +#include "lua_lib.h" + + +TEST(LuaVin, Test) { + EngineTestHelper eth(TEST_CRANK_ENGINE); + + strcpy(engineConfiguration->vinNumber, "GM123"); + + const char* realdata = TWO_BYTES_MSB R"( + + function testFunc() + return vin(0) + end)"; + + EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 0x47); +} diff --git a/unit_tests/tests/tests.mk b/unit_tests/tests/tests.mk index aaaef707a5..501e94a8eb 100644 --- a/unit_tests/tests/tests.mk +++ b/unit_tests/tests/tests.mk @@ -41,6 +41,7 @@ TESTS_SRC_CPP = \ tests/lua/test_lua_hooks.cpp \ tests/lua/test_lua_Leiderman_Khlystov.cpp \ tests/lua/test_can_filter.cpp \ + tests/lua/test_lua_vin.cpp \ tests/sensor/test_cj125.cpp \ tests/test_change_engine_type.cpp \ tests/util/test_scaled_channel.cpp \