rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Data Structures | Functions
rusefi_lua.h File Reference

Data Structures

class  LuaHandle
 

Functions

void startLua ()
 
expected< floattestLuaReturnsNumberOrNil (const char *script)
 
float testLuaReturnsNumber (const char *script)
 
int testLuaReturnsInteger (const char *script)
 
void testLuaExecString (const char *script)
 
void initLuaCanRx ()
 
int doLuaCanRx (LuaHandle &ls)
 
void processLuaCan (const size_t busIndex, const CANRxFrame &frame)
 
size_t getLuaCanRxDropped ()
 

Function Documentation

◆ doLuaCanRx()

int doLuaCanRx ( LuaHandle ls)

Definition at line 170 of file lua_can_rx.cpp.

170 {
172 int counter = 0;
173 // While it processed a frame, continue checking
174 while (doOneLuaCanRx(ls)) {
175 counter++;
176 }
177 return counter;
178}
static bool doOneLuaCanRx(LuaHandle &ls)
@ LuaAllCanRxFunction

Referenced by runOneLua().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLuaCanRxDropped()

size_t getLuaCanRxDropped ( )

Definition at line 187 of file lua_can_rx.cpp.

187 {
188 return dropRxCount;
189}
static size_t dropRxCount

Referenced by configureRusefiLuaHooks(), and startLua().

Here is the caller graph for this function:

◆ initLuaCanRx()

void initLuaCanRx ( )

Definition at line 180 of file lua_can_rx.cpp.

180 {
181 // Push all CAN frames in to the free buffer
182 for (size_t i = 0; i < LUA_canFrameCount; i++) {
183 freeBuffers.post(&canFrames[i], TIME_INFINITE);
184 }
185}
static CanFrameData canFrames[LUA_canFrameCount]
static chibios_rt::Mailbox< CanFrameData *, LUA_canFrameCount > freeBuffers

Referenced by startLua().

Here is the caller graph for this function:

◆ processLuaCan()

void processLuaCan ( const size_t  busIndex,
const CANRxFrame frame 
)

Definition at line 38 of file lua_can_rx.cpp.

38 {
39 auto filter = getFilterForId(busIndex, CAN_ID(frame));
40
41 // Filter the frame if we aren't listening for it
42 if (!filter) {
43 return;
44 }
45
46 CanFrameData* frameBuffer;
47 msg_t msg;
48
49 {
50 // Acquire a buffer under lock
51 chibios_rt::CriticalSectionLocker csl;
52 msg = freeBuffers.fetchI(&frameBuffer);
53 }
54
55 if (msg != MSG_OK) {
56 // all buffers are already in use, this frame will be dropped!
58 return;
59 }
60
61 // Copy the frame in to the buffer
62 frameBuffer->BusIndex = busIndex;
63 frameBuffer->Frame = frame;
64 frameBuffer->Callback = filter->Callback;
65
66 {
67 // Push the frame in to the queue under lock
68 chibios_rt::CriticalSectionLocker csl;
69 filledBuffers.postI(frameBuffer);
70 }
71}
CanFilter * getFilterForId(size_t busIndex, int Id)
static chibios_rt::Mailbox< CanFrameData *, LUA_canFrameCount > filledBuffers

Referenced by processCanRxMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ startLua()

void startLua ( )

Definition at line 281 of file lua.cpp.

281 {
282 luaHeapInit();
283
284#if EFI_CAN_SUPPORT
285 initLuaCanRx();
286#endif // EFI_CAN_SUPPORT
287
288 addConsoleActionII("set_lua_setting", [](int index, int value) {
289 engineConfiguration->scriptSetting[index] = value;
290 });
291
292 luaThread.start();
293
294 addConsoleActionS("lua", [](const char* str){
295 if (interactivePending) {
296 return;
297 }
298
299 strncpy(interactiveCmd, str, sizeof(interactiveCmd) - 1);
300 interactiveCmd[sizeof(interactiveCmd) - 1] = '\0';
301
302 interactivePending = true;
303 });
304
305 addConsoleAction("luareset", [](){
306 needsReset = true;
307 });
308
309 addConsoleAction("luamemory", [](){
310 efiPrintf("maxLuaDuration %lu", maxLuaDuration);
311 maxLuaDuration = 0;
312 efiPrintf("rx total/recent/dropped %d %d %d", totalRxCount,
314 efiPrintf("luaCycle %luus including luaRxTime %dus", NT2US(engine->outputChannels.luaLastCycleDuration),
315 NT2US(rxTime));
316
318 });
319}
TunerStudioOutputChannels outputChannels
Definition engine.h:109
void addConsoleActionS(const char *token, VoidCharPtr callback)
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
void addConsoleActionII(const char *token, VoidIntInt callback)
Register a console command with two Integer parameters.
static EngineAccessor engine
Definition engine.h:413
static constexpr engine_configuration_s * engineConfiguration
static LuaThread luaThread
Definition lua.cpp:279
static char interactiveCmd[100]
Definition lua.cpp:111
static int recentRxCount
Definition lua.cpp:19
static int rxTime
Definition lua.cpp:21
static int totalRxCount
Definition lua.cpp:20
static uint32_t maxLuaDuration
Definition lua.cpp:146
static bool needsReset
Definition lua.cpp:196
static bool interactivePending
Definition lua.cpp:110
size_t getLuaCanRxDropped()
void initLuaCanRx()
void luaHeapPrintInfo()
Definition lua_heap.cpp:213
void luaHeapInit()
Definition lua_heap.cpp:109

Referenced by commonEarlyInit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ testLuaExecString()

void testLuaExecString ( const char script)

Definition at line 394 of file lua.cpp.

394 {
395 auto ls = setupLuaState(luaHeapAlloc);
396
397 if (!ls) {
398 throw std::logic_error("Call to setupLuaState failed, returned null");
399 }
400
401 if (!loadScript(ls, script)) {
402 throw std::logic_error("Call to loadScript failed");
403 }
404}
static bool loadScript(LuaHandle &ls, const char *scriptStr)
Definition lua.cpp:90
static LuaHandle setupLuaState(lua_Alloc alloc)
Definition lua.cpp:55
void * luaHeapAlloc(void *, void *optr, size_t osize, size_t nsize)
Definition lua_heap.cpp:138
Here is the call graph for this function:

◆ testLuaReturnsInteger()

int testLuaReturnsInteger ( const char script)

Definition at line 383 of file lua.cpp.

383 {
384 auto ls = runScript(script);
385
386 // pop the return value;
387 if (!lua_isinteger(ls, -1)) {
388 throw std::logic_error("Returned value is not an integer");
389 }
390
391 return lua_tointeger(ls, -1);
392}
static LuaHandle runScript(const char *script)
Definition lua.cpp:328
Here is the call graph for this function:

◆ testLuaReturnsNumber()

float testLuaReturnsNumber ( const char script)

Definition at line 371 of file lua.cpp.

371 {
372 auto ls = runScript(script);
373
374 // check the return value
375 if (!lua_isnumber(ls, -1)) {
376 throw new std::logic_error("Returned value is not a number");
377 }
378
379 // pop the return value
380 return lua_tonumber(ls, -1);
381}
Here is the call graph for this function:

◆ testLuaReturnsNumberOrNil()

expected< float > testLuaReturnsNumberOrNil ( const char script)

Definition at line 354 of file lua.cpp.

354 {
355 auto ls = runScript(script);
356
357 // check nil return first
358 if (lua_isnil(ls, -1)) {
359 return unexpected;
360 }
361
362 // If not nil, it should be a number
363 if (!lua_isnumber(ls, -1)) {
364 throw std::logic_error("Returned value is not a number");
365 }
366
367 // pop the return value
368 return lua_tonumber(ls, -1);
369}
Here is the call graph for this function:

Go to the source code of this file.