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

Function lua_get_CAN_device2

libraries/AP_Scripting/lua_bindings.cpp:720–748  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

718}
719
720int lua_get_CAN_device2(lua_State *L) {
721
722 // Allow : and . access
723 const int arg_offset = (luaL_testudata(L, 1, "CAN") != NULL) ? 1 : 0;
724
725 binding_argcheck(L, 1 + arg_offset);
726
727 const uint32_t raw_buffer_len = get_uint32(L, 1 + arg_offset, 1, 25);
728 const uint32_t buffer_len = static_cast<uint32_t>(raw_buffer_len);
729
730 auto *scripting = AP::scripting();
731
732 if (scripting->_CAN_dev2 == nullptr) {
733 scripting->_CAN_dev2 = NEW_NOTHROW ScriptingCANSensor(AP_CAN::Protocol::Scripting2);
734 if (scripting->_CAN_dev2 == nullptr) {
735 return luaL_argerror(L, 1, "CAN device nullptr");
736 }
737 }
738
739 if (!scripting->_CAN_dev2->initialized()) {
740 // Driver not initialized, probably because there is no can driver set to scripting 2
741 // Return nil
742 return 0;
743 }
744
745 *new_ScriptingCANBuffer(L) = scripting->_CAN_dev2->add_buffer(buffer_len);
746
747 return 1;
748}
749#endif // AP_SCRIPTING_CAN_SENSOR_ENABLED
750
751#if AP_SERIALMANAGER_ENABLED

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