-
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: 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 feature.
- Loading branch information
Showing
1 changed file
with
36 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,36 @@ | ||
local ser_driver = serial:find_serial(0) | ||
local ser_device = serial:get_device_port(1) | ||
|
||
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() |