-
Notifications
You must be signed in to change notification settings - Fork 18k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AP_Scripting: added example script that causes a hard fault
this exercises rapid fault handling
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--[[ | ||
example script to test fault handling with pcall | ||
--]] | ||
|
||
local MAV_SEVERITY = {EMERGENCY=0, ALERT=1, CRITICAL=2, ERROR=3, WARNING=4, NOTICE=5, INFO=6, DEBUG=7} | ||
|
||
gcs:send_text(MAV_SEVERITY.INFO, "Loading fault test") | ||
|
||
local test_count = 0 | ||
|
||
--[[ | ||
evaluate some lua code and return as a string | ||
--]] | ||
local function evaluate(code) | ||
local eval_code = "function eval_func()\n" .. code .. "\nend\n" | ||
local f, errloc, err = load(eval_code, "eval_func", "t", _ENV) | ||
if not f then | ||
gcs:send_text(MAV_SEVERITY.info, string.format("load failed: err=%s errloc=%s", err, errloc)) | ||
return nil | ||
end | ||
local success, err2 = pcall(f) | ||
if not success then | ||
gcs:send_text(MAV_SEVERITY.DEBUG,string.format("pcall failed: err=%s", err2)) | ||
return nil | ||
end | ||
local ok, s2 = pcall(eval_func) | ||
eval_func = nil | ||
if ok then | ||
return s2 | ||
end | ||
return nil | ||
end | ||
|
||
local function run_test() | ||
evaluate("local loc = nil; loc:get_lat()") | ||
end | ||
|
||
local function update() | ||
test_count = test_count + 1 | ||
if test_count % 100 == 0 then | ||
gcs:send_text(MAV_SEVERITY.INFO,string.format("Test %u", test_count)) | ||
end | ||
run_test() | ||
return update,1 | ||
end | ||
|
||
gcs:send_text(MAV_SEVERITY.INFO, "Starting fault test in 2 seconds") | ||
|
||
-- wait a while for GCS to connect | ||
return update,2000 |