Skip to content
Snippets Groups Projects
Commit 55f09f2d authored by Marcus Greiff's avatar Marcus Greiff
Browse files

Tested and wrote new tests for the SysLED (dummy file systems not yet included)

parent 53025c26
No related branches found
No related tags found
1 merge request!2Rewrote devices on Beaglebone. Passes precompile, but needs proper testing.
......@@ -5,7 +5,7 @@ i ∈ [1,2,3,4].
"""
type SysLED <: IO_Object
i::Int32
brightness_filestream::IOStream
filestream::IOStream
function SysLED(i::Int32)
i [1,2,3,4] && error("Invalid SysLED index: $i")
#Note, in the future we should interface to config and retrieve IOStream from there
......@@ -18,10 +18,11 @@ end
write!(led::SysLED, val::Bool, debug::Bool=false)
Turns the LED 'SysLed' on/off for val = true/false respectively.
"""
function write!(led::SysLED, val::Bool, debug::Bool=false)
function write!(led::SysLED, entry::String, debug::Bool=false)
debug && return
write(led.brightness_filestream, val ? "1" : "0")
seekstart(led.brightness_filestream)
entry ["0", "1"] && error("Invalid SysLED entry $(entry), valid options are 0 and 1 (string)")
write(led.filestream, entry)
seekstart(led.filestream)
end
"""
......@@ -30,9 +31,9 @@ Reads the current brightness value from the LED 'SysLED'.
"""
function read(led::SysLED, debug::Bool=false)
debug && return
l = read(led.brightness_filestream, Char)
l = read(filestream, Char)
(l != '1' && l != '0') && error("Invalid value \"$l\" read from SysLed")
seekstart(led.brightness_filestream)
seekstart(led.filestream)
return l
end
......@@ -42,5 +43,5 @@ Closes all open filestreams for the SysLED 'led'.
"""
function teardown(led::SysLED, debug::Bool=false)
debug && return
close(led.brightness_filestream)
close(led.filestream)
end
......@@ -24,7 +24,7 @@ function precompile_bb()
debug = true
#Precompile SysLED
led = initdev("sysled",Int32(1))
write!(led, true, debug)
write!(led, "1", debug)
read(led, debug)
ind = 1
......
using LabConnections.BeagleBone
import LabConnections.BeagleBone: getdev, write!
import LabConnections.BeagleBone: getdev, write!, closedev, read, initdev
using Base.Test
#Fixture
device = getdev("sysled")
ledon = true
@testset "SYS LED Tests" begin
@testset "Error Handling" begin
# Attempt to initialize faulty device
@test_throws ErrorException getdev("wrong_device_name")
# Test that an exception is thrown when a faulty ID is given
@test_throws ErrorException write!(device, 5, ledon)
device = initdev("sysled", 1)
# Test that an exception is thrown when a faulty ID is given
@test_throws ErrorException write!(device, 0, ledon)
@test_throws ErrorException write!(device, "bad_entry")
# Close device
closedev("sysled", 1)
end
@testset "IO Communication" begin
# Instanciate all possible leds and perform 10 read/write commands
device1 = initdev("sysled", 1)
device2 = initdev("sysled", 2)
device3 = initdev("sysled", 3)
device4 = initdev("sysled", 4)
for i = 1:10
for j = 1:4
write!(device, j, ledon)
end
sleep(0.001)
for j = 1:4
val = read(device, j)
@test val == ledon
end
ledon = !ledon
state =
write!(device1, "$(i%2)")
write!(device2, "$((i+1)%2)")
write!(device3, "$(i%2)")
write!(device4, "$((i+1)%2)")
sleep(0.1)
end
closedev("sysled", 1)
closedev("sysled", 2)
closedev("sysled", 3)
closedev("sysled", 4)
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment