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 2024-05-01 03:27:23 +01:00 committed by Andrew Tridgell
parent 632d0a93c1
commit 95a5169439
2 changed files with 16 additions and 4 deletions

View File

@ -344,14 +344,14 @@ function efi:get_backend(instance) end
---@class CAN
CAN = {}
-- get a CAN bus device handler first scripting driver
-- get a CAN bus device handler first scripting driver, will return nil if no driver with protocol Scripting is configured
---@param buffer_len uint32_t_ud -- buffer length 1 to 25
---@return ScriptingCANBuffer_ud
---@return ScriptingCANBuffer_ud|nil
function CAN:get_device(buffer_len) end
-- get a CAN bus device handler second scripting driver
-- get a CAN bus device handler second scripting driver, will return nil if no driver with protocol Scripting2 is configured
---@param buffer_len uint32_t_ud -- buffer length 1 to 25
---@return ScriptingCANBuffer_ud
---@return ScriptingCANBuffer_ud|nil
function CAN:get_device2(buffer_len) end
-- Auto generated binding

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);