AP_Scripting: CAN: get_device and get_device2 return nil if no driver is configure with the correct protocol

This commit is contained in:
Iampete1 authored and Andrew Tridgell committed 2024-05-07 09:48:10 +10:00
1 parent 632d0a93c1
commit 95a5169439
2 files changed
+16 -4

No files matched your search

+12
View File
@@ -682,6 +682,12 @@ int lua_get_CAN_device(lua_State *L) {
}
}
if (!scripting->_CAN_dev->initialized()) {
// Driver not initialized, probably because there is no can driver set to scripting
// Return nil
return 0;
}
new_ScriptingCANBuffer(L);
*((ScriptingCANBuffer**)luaL_checkudata(L, -1, "ScriptingCANBuffer")) = scripting->_CAN_dev->add_buffer(buffer_len);
@@ -707,6 +713,12 @@ int lua_get_CAN_device2(lua_State *L) {
}
}
if (!scripting->_CAN_dev2->initialized()) {
// Driver not initialized, probably because there is no can driver set to scripting 2
// Return nil
return 0;
}
new_ScriptingCANBuffer(L);
*((ScriptingCANBuffer**)luaL_checkudata(L, -1, "ScriptingCANBuffer")) = scripting->_CAN_dev2->add_buffer(buffer_len);