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

Method thread

libraries/AP_Scripting/AP_Scripting.cpp:303–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

301#pragma GCC optimize ("O0")
302
303void AP_Scripting::thread(void) {
304 while (true) {
305 // reset flags
306 _stop = false;
307 _restart = false;
308 _init_failed = false;
309
310 lua_scripts *lua = NEW_NOTHROW lua_scripts(_script_vm_exec_count, _script_heap_size, _debug_options);
311 if (lua == nullptr || !lua->heap_allocated()) {
312 GCS_SEND_TEXT(MAV_SEVERITY_CRITICAL, "Scripting: %s", "Unable to allocate memory");
313 _init_failed = true;
314 } else {
315#if AP_SCRIPTING_SERIALDEVICE_ENABLED
316 // clear data in serial buffers that the script wasn't ready to
317 // receive
318 _serialdevice.clear();
319#endif
320 // run won't return while scripting is still active
321 lua->run();
322
323 // only reachable if the lua backend has died for any reason
324 GCS_SEND_TEXT(MAV_SEVERITY_CRITICAL, "Scripting: %s", "stopped");
325 }
326 delete lua;
327 lua = nullptr;
328
329 // clear allocated i2c devices
330 for (uint8_t i=0; i<SCRIPTING_MAX_NUM_I2C_DEVICE; i++) {
331 delete _i2c_dev[i];
332 _i2c_dev[i] = nullptr;
333 }
334 num_i2c_devices = 0;
335
336 // clear allocated PWM sources
337 for (uint8_t i=0; i<SCRIPTING_MAX_NUM_PWM_SOURCE; i++) {
338 if (_pwm_source[i] != nullptr) {
339 delete _pwm_source[i];
340 _pwm_source[i] = nullptr;
341 }
342 }
343 num_pwm_source = 0;
344
345#if AP_NETWORKING_ENABLED
346 // clear allocated sockets
347 for (uint8_t i=0; i<SCRIPTING_MAX_NUM_NET_SOCKET; i++) {
348 if (_net_sockets[i] != nullptr) {
349 delete _net_sockets[i];
350 _net_sockets[i] = nullptr;
351 }
352 }
353#endif // AP_NETWORKING_ENABLED
354
355#if AP_SCRIPTING_SERIALDEVICE_ENABLED
356 // clear data in serial buffers that hasn't been transmitted
357 _serialdevice.clear();
358#endif
359
360 // Clear blocked commands

Callers

nothing calls this directly

Calls 4

heap_allocatedMethod · 0.80
clearMethod · 0.45
runMethod · 0.45
delayMethod · 0.45

Tested by

no test coverage detected