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

Function lua_mavlink_send_chan

libraries/AP_Scripting/lua_bindings.cpp:157–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155}
156
157int lua_mavlink_send_chan(lua_State *L) {
158
159 // Allow : and . access
160 const int arg_offset = (luaL_testudata(L, 1, "mavlink") != NULL) ? 1 : 0;
161
162 binding_argcheck(L, 3+arg_offset);
163
164 const mavlink_channel_t chan = (mavlink_channel_t)get_uint32(L, 1+arg_offset, 0, MAVLINK_COMM_NUM_BUFFERS - 1);
165
166 const uint32_t msgid = get_uint32(L, 2+arg_offset, 0, (1 << 24) - 1);
167
168 const char *packet = luaL_checkstring(L, 3+arg_offset);
169
170 // FIXME: The data that's in this mavlink_msg_entry_t should be provided from the script, which allows
171 // sending entirely new messages as outputs. At the moment we can only encode messages that
172 // are known at compile time. This is fine as a starting point as this is symmetrical to the
173 // decoding side of the scripting support
174 const mavlink_msg_entry_t *entry = mavlink_get_msg_entry(msgid);
175 if (entry == nullptr) {
176 return luaL_error(L, "Unknown MAVLink message ID (%d)", msgid);
177 }
178
179 WITH_SEMAPHORE(comm_chan_lock(chan));
180 if (comm_get_txspace(chan) >= (GCS_MAVLINK::packet_overhead_chan(chan) + entry->max_msg_len)) {
181 _mav_finalize_message_chan_send(chan,
182 entry->msgid,
183 packet,
184 entry->min_msg_len,
185 entry->max_msg_len,
186 entry->crc_extra);
187
188 lua_pushboolean(L, true);
189 } else {
190 lua_pushboolean(L, false);
191 }
192
193 return 1;
194}
195
196int lua_mavlink_block_command(lua_State *L) {
197

Callers

nothing calls this directly

Calls 4

luaL_testudataFunction · 0.85
luaL_errorFunction · 0.85
comm_get_txspaceFunction · 0.85
lua_pushbooleanFunction · 0.85

Tested by

no test coverage detected