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

Function lua_mavlink_init

libraries/AP_Scripting/lua_bindings.cpp:52–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50
51#if HAL_GCS_ENABLED
52int lua_mavlink_init(lua_State *L) {
53
54 // Allow : and . access
55 const int arg_offset = (luaL_testudata(L, 1, "mavlink") != NULL) ? 1 : 0;
56
57 binding_argcheck(L, 2+arg_offset);
58 // get the depth of receive queue
59 const uint32_t queue_size = get_uint32(L, 1+arg_offset, 0, 25);
60 // get number of msgs to accept
61 const uint32_t num_msgs = get_uint32(L, 2+arg_offset, 0, 25);
62
63 struct AP_Scripting::mavlink &data = AP::scripting()->mavlink_data;
64 bool failed = false;
65 {
66 WITH_SEMAPHORE(data.sem);
67 if (data.rx_buffer == nullptr) {
68 data.rx_buffer = NEW_NOTHROW ObjectBuffer<struct AP_Scripting::mavlink_msg>(queue_size);
69 }
70 if (data.accept_msg_ids == nullptr) {
71 data.accept_msg_ids = NEW_NOTHROW uint32_t[num_msgs];
72 }
73 if ((data.rx_buffer == nullptr) || (data.accept_msg_ids == nullptr)) {
74 delete data.rx_buffer;
75 delete[] data.accept_msg_ids;
76 data.rx_buffer = nullptr;
77 data.accept_msg_ids = nullptr;
78 data.accept_msg_ids_size = 0;
79 failed = true;
80 } else {
81 data.accept_msg_ids_size = num_msgs;
82 memset(data.accept_msg_ids, UINT32_MAX, sizeof(int) * num_msgs);
83 }
84 } // release semaphore here as luaL_error will NOT do that!
85
86 if (failed) {
87 return luaL_error(L, "out of memory");
88 }
89
90 return 0;
91}
92
93int lua_mavlink_receive_chan(lua_State *L) {
94

Callers

nothing calls this directly

Calls 4

luaL_testudataFunction · 0.85
scriptingFunction · 0.85
memsetFunction · 0.85
luaL_errorFunction · 0.85

Tested by

no test coverage detected