AP_Scripting: add serial loopback test script
Tests that data can flow both ways with one end using protocol 28 (Scripting) and the other using the serial device simulation feature.
This commit is contained in:
parent
46e204dd6c
commit
f9b138724c
36
libraries/AP_Scripting/tests/serial_loopback.lua
Normal file
36
libraries/AP_Scripting/tests/serial_loopback.lua
Normal file
@ -0,0 +1,36 @@
|
||||
local ser_driver = serial:find_serial(0)
|
||||
local ser_device = serial:find_simulated_device(28, 0)
|
||||
|
||||
if ser_driver == nil or ser_device == nil then
|
||||
error("bad config")
|
||||
end
|
||||
|
||||
ser_driver:begin(115200) -- baud rate does not matter
|
||||
|
||||
function test_driver_to_device()
|
||||
local msg_send = "hello device"
|
||||
local num_sent = 0
|
||||
for ci = 1,#msg_send do
|
||||
num_sent = num_sent + ser_driver:write(msg_send:byte(ci, ci)):toint()
|
||||
end
|
||||
local msg_recv = ser_device:readstring(#msg_send)
|
||||
if msg_send == msg_recv and num_sent == #msg_send then
|
||||
gcs:send_text(6, "driver -> device good")
|
||||
end
|
||||
end
|
||||
|
||||
function test_device_to_driver()
|
||||
local msg_send = "hello driver"
|
||||
local num_sent = ser_device:writestring(msg_send)
|
||||
local msg_recv = ser_driver:readstring(#msg_send)
|
||||
if msg_send == msg_recv and num_sent == #msg_send then
|
||||
gcs:send_text(6, "device -> driver good")
|
||||
end
|
||||
end
|
||||
|
||||
function update()
|
||||
test_driver_to_device()
|
||||
test_device_to_driver()
|
||||
end
|
||||
|
||||
return update()
|
Loading…
Reference in New Issue
Block a user