diff --git a/Examples/testLED.jl b/Examples/testLED.jl index 66d634dfc9b8e6ca32f4ca63fa1810e71054baff..d61d0e74027429ad9bd3d9d7d2e13ca0aaa34cbc 100644 --- a/Examples/testLED.jl +++ b/Examples/testLED.jl @@ -1,9 +1,10 @@ #On beaglebone, run: # include("LabConnections/src/LabConnections.jl") -# using LabConnections.BeagleBone -# run_server() +# using Main.LabConnections.BeagleBone +# srv = run_server() using LabConnections.Computer +using Sockets stream = BeagleBoneStream(ip"192.168.7.2") led1 = SysLED(1) @@ -16,6 +17,7 @@ led4 = SysLED(4) init_devices!(stream, led1, led2, led3, led4) ledon = true for i = 1:100 + global ledon put!(led1, ledon) put!(led2, !ledon) put!(led3, ledon) diff --git a/Manifest.toml b/Manifest.toml new file mode 100644 index 0000000000000000000000000000000000000000..7d0d0bf2fe7d8163dbb57c2731e66f0a248a6645 --- /dev/null +++ b/Manifest.toml @@ -0,0 +1,5 @@ +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" diff --git a/Project.toml b/Project.toml new file mode 100644 index 0000000000000000000000000000000000000000..221164a87621cc6c674cd10b4ca493fbea6e6c49 --- /dev/null +++ b/Project.toml @@ -0,0 +1,14 @@ +name = "LabConnections" +uuid = "e9ebaa62-f26d-11e8-0a59-692f6511a9a1" +authors = ["Mattias Fält <mattiasf@control.lth.se>", "Marcus Greiff", "Marcus Thelander Andrén"] +version = "0.1.0" + +[deps] +Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" +Sockets = "6462fe0b-24de-5631-8697-dd941f90decc" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/REQUIRE b/REQUIRE index 137767a42af4a6bc4e8d823feb3bedec27ee23b2..05b5ab4c7d81a3e977876f720ae2f433d944114c 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1 @@ -julia 0.6 +julia 1.0 diff --git a/src/BeagleBone/BeagleBone.jl b/src/BeagleBone/BeagleBone.jl index 9aa402b155546dbaddf4cb17c7b1b7f82eed6629..aca8a1cbace4c45d3fa292bdc8487f0d4e205b49 100644 --- a/src/BeagleBone/BeagleBone.jl +++ b/src/BeagleBone/BeagleBone.jl @@ -125,8 +125,8 @@ function bbparse(l::Tuple, sock) return else #TODO fix to have at least partial type stability - vals = Array{Any,1}(ndev) - timestamps = Array{UInt64,1}(ndev) + vals = Array{Any,1}(undef,ndev) + timestamps = Array{UInt64,1}(undef,ndev) for i = 1:ndev command = l[2+i]::Tuple dev = getdev(command[1], command[2]) @@ -146,7 +146,7 @@ Optional debug keyword disables blinking system leds. """ function run_server(port=2001; debug=false) global __waiting_first_connection__ = true - server = listen(port) + server = listen(IPv4(0), port) # IPv4(0) means listen from any ip @async while isopen(server) try @async while __waiting_first_connection__ && !debug @@ -173,7 +173,7 @@ function run_server(port=2001; debug=false) println("Connection to server closed") else println("error: $(typeof(err))") - throw(err) + rethrow() end end end @@ -181,7 +181,7 @@ function run_server(port=2001; debug=false) if isa(err,Base.UVError) && err.prefix == "accept" println("Server closed successfully") else - throw(err) + rethrow() end end end diff --git a/src/BeagleBone/Debug.jl b/src/BeagleBone/Debug.jl index e2fd3693b9f4e921a609da4fd6025f844f070306..5c7f84b804c251491dd9db305b05a8ed99a8de2d 100644 --- a/src/BeagleBone/Debug.jl +++ b/src/BeagleBone/Debug.jl @@ -2,7 +2,7 @@ Debug(i::Int32) Type for debugging and precompile. """ -type Debug <: IO_Object +struct Debug <: IO_Object i::Int32 end write!(::Debug, val, debug::Bool=false) = nothing diff --git a/src/BeagleBone/GPIO.jl b/src/BeagleBone/GPIO.jl index cc03657f6f81630a3eea0c6ab8249184b95e1fb0..88a1879f361fbbf95b272d008f393fb6171332f1 100644 --- a/src/BeagleBone/GPIO.jl +++ b/src/BeagleBone/GPIO.jl @@ -15,7 +15,7 @@ The operation of reading the current output value of the GPIO is done by See the test/BeagleBone/GPIO_test.jl for more examples. """ -type GPIO <: IO_Object +struct GPIO <: IO_Object i::Int32 basedir::String filestreams::Array{IOStream,1} @@ -79,7 +79,8 @@ function teardown(gpio::GPIO, debug::Bool=false) end #Unexport filestructure - if isdefined(:RUNNING_TESTS) + global RUNNING_TESTS + if RUNNING_TESTS # Remove the dummy file system for testing basedir = "$(pwd())/testfilesystem/gpio" try @@ -100,7 +101,8 @@ end Export the GPIO file system, either for real-time or testing usecases. """ function export_gpio(i::Int32) - if isdefined(:RUNNING_TESTS) + global RUNNING_TESTS + if RUNNING_TESTS # Export a dummy file system for testing basedir = "$(pwd())/testfilesystem/gpio" try diff --git a/src/BeagleBone/PWM.jl b/src/BeagleBone/PWM.jl index 33fa9c473e22602917026da0d0a781f5849bd9f1..c554de5918d64c9119bc51536c443dca77b33036 100644 --- a/src/BeagleBone/PWM.jl +++ b/src/BeagleBone/PWM.jl @@ -5,7 +5,7 @@ dictionary pwm_pins relates to memory adresses in of the AM3359 chip, see p.182 in www.ti.com/product/AM3359/technicaldocuments. """ -type PWM <: IO_Object +struct PWM <: IO_Object i::Int32 pin::String chip::String @@ -95,7 +95,8 @@ function teardown(pwm::PWM, debug::Bool=false) close(stream) end - if isdefined(:RUNNING_TESTS) + global RUNNING_TESTS + if RUNNING_TESTS # Remove the dummy file system for testing try rm("$(pwm.basedir)/$(pwm_pins[pwm.pin][2])/pwm$(pwm_pins[pwm.pin][3])"; recursive=true) @@ -120,7 +121,8 @@ function export_pwm(i::Int32) pin = pins[i] chip = pwm_pins[pin][2] - if isdefined(:RUNNING_TESTS) + global RUNNING_TESTS + if RUNNING_TESTS # Export a dummy file system for testing basedir = "$(pwd())/testfilesystem/pwm" complete_path = "$(basedir)/$(pwm_pins[pin][2])/pwm$(pwm_pins[pin][3])" diff --git a/src/BeagleBone/SysLED.jl b/src/BeagleBone/SysLED.jl index 03cca51cafc65897a903464b4d78b61031bc502f..71680bc8c802d6f0d41f4735832377477410ed17 100644 --- a/src/BeagleBone/SysLED.jl +++ b/src/BeagleBone/SysLED.jl @@ -3,7 +3,7 @@ Type representing the system LEDs on the BeagleBone. The LEDs are indexed by i ∈ [1,2,3,4]. """ -type SysLED <: IO_Object +struct SysLED <: IO_Object i::Int32 basedir::String filestream::IOStream @@ -49,7 +49,8 @@ function teardown(led::SysLED, debug::Bool=false) debug && return close(led.filestream) - if isdefined(:RUNNING_TESTS) + global RUNNING_TESTS + if RUNNING_TESTS # Remove the dummy file system for testing try #println("$(led.basedir)/beaglebone:green:usr$(led.i-1)") @@ -67,7 +68,8 @@ Exports a dummy filesystem for testing the LED implementation function export_led(i::Int32, debug::Bool=false) debug && return - if isdefined(:RUNNING_TESTS) + global RUNNING_TESTS + if RUNNING_TESTS # Export a dummy file system for testing basedir = "$(pwd())/testfilesystem/leds" try diff --git a/src/BeagleBone/config/config_library.jl b/src/BeagleBone/config/config_library.jl index 72fac56dc887fe1458a9f06ced30b1dcf313108b..55842b4a6cca920eb506ff899ae835984fb01e98 100644 --- a/src/BeagleBone/config/config_library.jl +++ b/src/BeagleBone/config/config_library.jl @@ -2,7 +2,7 @@ import YAML abstract type IO_Object end -type GPIO <: IO_Object +struct GPIO <: IO_Object ID::Int32 pins::Array{String, 1} InOut::String @@ -11,7 +11,7 @@ end GPIO(ID, pins, InOut; file_handles=[])=GPIO(ID, pins, InOut, file_handles) # The PWM type -type PWM <: IO_Object +struct PWM <: IO_Object ID::Int32 pins::Array{String, 1} file_handles::Array{IOStream} @@ -19,7 +19,7 @@ end PWM(ID, pins; file_handles=[])=PWM(ID, pins, file_handles) # The analog to digital converter type -type ADC <: IO_Object +struct ADC <: IO_Object ID::Int32 pins::Array{String, 1} channel::String @@ -28,7 +28,7 @@ end ADC(ID, pins, channel; file_handles=[])=ADC(ID, pins, channel, file_handles) # The quadrature encoder type -type QEP <: IO_Object +struct QEP <: IO_Object ID::Int32 pins::Array{String, 1} file_handles::Array{IOStream} diff --git a/src/Computer/10V.jl b/src/Computer/10V.jl index 4c84a4914a7a46a053e4e4057da6bd0ea333171a..ae2e9820ab08f6d8d295d7f3f50c77d539bc924c 100644 --- a/src/Computer/10V.jl +++ b/src/Computer/10V.jl @@ -17,7 +17,7 @@ initialize(::AnalogInput10V) = nothing initialize(::AnalogOutput10V) = nothing close(::AnalogInput10V) = nothing -close(input::AnalogOutput10V) = ccall((:comedi_write_zero, comedipath), Void, (Int32, Int32, Int32), Int32(0), Int32(1), input.i) +close(input::AnalogOutput10V) = ccall((:comedi_write_zero, comedipath), Cvoid, (Int32, Int32, Int32), Int32(0), Int32(1), input.i) getwritecommand(stream::LabStream, input::AnalogInput10V, val) = error("Can't write to device $input") getreadcommand(stream::LabStream, output::AnalogOutput10V, val) = error("Can't read from device $output") diff --git a/src/LabConnections.jl b/src/LabConnections.jl index 0b631489882871da15f88a7a471089ed480f6271..10e9c6b39d35f107d5ee83baf9afac3d2013de2e 100644 --- a/src/LabConnections.jl +++ b/src/LabConnections.jl @@ -2,6 +2,11 @@ __precompile__() module LabConnections module BeagleBone + RUNNING_TESTS = false # TODO Can we make this constant? + function running_test(val) + global RUNNING_TESTS = val + end + using Sockets, Serialization export run_server import Base: read println("Initializing BB") @@ -13,7 +18,10 @@ module LabConnections end module Computer - import Base: read, send, close, get, put!, serialize + using Sockets, Serialization + import Base: read, close, get, put! + import Sockets: send + import Serialization: serialize println("Initializing Computer") include(joinpath("Computer","Computer.jl")) end diff --git a/test/BeagleBone/GPIO_test.jl b/test/BeagleBone/GPIO_test.jl index 07ca2d51130efc6b8c3b06f3d85a55c8c4b59bfb..ad0d1188fbd2491003b8cc2b93f8ace01ed25272 100644 --- a/test/BeagleBone/GPIO_test.jl +++ b/test/BeagleBone/GPIO_test.jl @@ -1,7 +1,7 @@ using LabConnections.BeagleBone import LabConnections.BeagleBone: initdev, listdev, closedev, printdev, write!, read, gpio_channels -using Base.Test +using Test @testset "GPIO tests" begin diff --git a/test/BeagleBone/PWM_test.jl b/test/BeagleBone/PWM_test.jl index 7a61d005011e9bfc3ad42fce339f63ee868f1fd2..dcd6fa929c573a04c3165383420467e072bdf1f5 100644 --- a/test/BeagleBone/PWM_test.jl +++ b/test/BeagleBone/PWM_test.jl @@ -1,7 +1,7 @@ using LabConnections.BeagleBone import LabConnections.BeagleBone: initdev, listdev, closedev, printdev, write!, read, pwm_pins -using Base.Test +using Test @testset "PWM tests" begin diff --git a/test/BeagleBone/SYS_LED_test.jl b/test/BeagleBone/SYS_LED_test.jl index d513ddfbafc8bf0691064688b068821bb5c35fa9..fb3ed90fbd690efff0c4e76c5038c30ecae6fb0e 100644 --- a/test/BeagleBone/SYS_LED_test.jl +++ b/test/BeagleBone/SYS_LED_test.jl @@ -1,7 +1,7 @@ using LabConnections.BeagleBone import LabConnections.BeagleBone: getdev, write!, closedev, read, initdev, printdev, listdev -using Base.Test +using Test @testset "SYS LED Tests" begin diff --git a/test/runtests.jl b/test/runtests.jl index 66269ccc59ac606d46ea0e557442bcd529d3572d..cdeb529d1dafc44c6d4411676935ace5ea1ec3e0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,10 +1,10 @@ using LabConnections.BeagleBone -using Base.Test +using Test # This flag is enabled if a dummy filesystem should be used for testing (for online testing) # disabling the flag allows the BBB to be run in the loop, in this case blinking LEDS -RUNNING_TESTS = true +BeagleBone.running_test(true) # Run tests include("BeagleBone/SYS_LED_test.jl") diff --git a/test/testBB.jl b/test/testBB.jl index f0499b3b50a86c1275fa5a305bbc84a674a8e8c8..078ae46364139a2898bd8ee18fefed6cde613ec0 100644 --- a/test/testBB.jl +++ b/test/testBB.jl @@ -1,5 +1,5 @@ using LabConnections -using Base.Test +using Test # This flag is enabled if a dummy filesystem should be used for testing (for online testing) # disabling the flag allows the BBB to be run in the loop, in this case blinking LEDS diff --git a/test/testConenction.jl b/test/testConenction.jl index 9344e0b1d6db597606d48a99fc5c58c3f132a67d..47c46e3189a139b5631787fe56c1495f6273af1d 100644 --- a/test/testConenction.jl +++ b/test/testConenction.jl @@ -1,3 +1,4 @@ +using Sockets, Serialization #BB side function startbb() @async begin