MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / lua_get_CAN_device

Function lua_get_CAN_device

libraries/AP_Scripting/lua_bindings.cpp:690–718  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

688
689#if AP_SCRIPTING_CAN_SENSOR_ENABLED
690int lua_get_CAN_device(lua_State *L) {
691
692 // Allow : and . access
693 const int arg_offset = (luaL_testudata(L, 1, "CAN") != NULL) ? 1 : 0;
694
695 binding_argcheck(L, 1 + arg_offset);
696
697 const uint32_t raw_buffer_len = get_uint32(L, 1 + arg_offset, 1, 25);
698 const uint32_t buffer_len = static_cast<uint32_t>(raw_buffer_len);
699
700 auto *scripting = AP::scripting();
701
702 if (scripting->_CAN_dev == nullptr) {
703 scripting->_CAN_dev = NEW_NOTHROW ScriptingCANSensor(AP_CAN::Protocol::Scripting);
704 if (scripting->_CAN_dev == nullptr) {
705 return luaL_argerror(L, 1, "CAN device nullptr");
706 }
707 }
708
709 if (!scripting->_CAN_dev->initialized()) {
710 // Driver not initialized, probably because there is no can driver set to scripting
711 // Return nil
712 return 0;
713 }
714
715 *new_ScriptingCANBuffer(L) = scripting->_CAN_dev->add_buffer(buffer_len);
716
717 return 1;
718}
719
720int lua_get_CAN_device2(lua_State *L) {
721

Callers

nothing calls this directly

Calls 5

luaL_testudataFunction · 0.85
scriptingFunction · 0.85
luaL_argerrorFunction · 0.85
add_bufferMethod · 0.80
initializedMethod · 0.45

Tested by

no test coverage detected