Lua CAN rx data (#3414)

* rx data

* comments

* multi bus
This commit is contained in:
Matthew Kennedy 2021-10-26 13:48:57 -07:00 committed by GitHub
parent 7a4382499d
commit 148dbdeec6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 3 deletions

View File

@ -67,10 +67,22 @@ static void handleCanFrame(LuaHandle& ls, CANRxFrame* frame) {
return;
}
// TODO: push arguments to function!
UNUSED(frame);
auto dlc = frame->DLC;
int status = lua_pcall(ls, 0, 0, 0);
// Push bus, ID and DLC
lua_pushinteger(ls, 1); // TODO: support multiple busses!
lua_pushinteger(ls, CAN_EID(*frame));
lua_pushinteger(ls, dlc);
// Build table for data
lua_newtable(ls);
for (size_t i = 0; i < dlc; i++) {
lua_pushinteger(ls, frame->data8[i]);
lua_rawseti(ls, -2, i);
}
// Perform the actual function call
int status = lua_pcall(ls, 4, 0, 0);
if (0 != status) {
// error calling CAN rx hook function