diff --git a/src/BeagleBone/BeagleBone.jl b/src/BeagleBone/BeagleBone.jl index e7d2e6e419215234404f056ab0449623f674c61e..adb09efd7effe8f88f7506b93f5a13afbcbf6ce0 100644 --- a/src/BeagleBone/BeagleBone.jl +++ b/src/BeagleBone/BeagleBone.jl @@ -53,15 +53,31 @@ function bbparse(l::Tuple) end end +global __waiting_first_connection__ = false """ run_server(port=2001) Run a server on `port` that listens for commands from computer +Optional debug keyword disables blinking system leds """ -function run_server(port=2001) +function run_server(port=2001; debug=false) + global __waiting_first_connection__ = true server = listen(port) @async while isopen(server) try + @async while __waiting_first_connection__ && !debug + #Blink SysLED 2 when waiting for first connection to signal availability + led = SysLED() + write!(led, 2, true) + sleep(0.4) + write!(led, 2, false) + sleep(0.2) + write!(led, 2, true) + sleep(0.4) + write!(led, 2, false) + sleep(0.8) + end sock = accept(server) + __waiting_first_connection__ = false @async while isopen(sock) try l = deserialize(sock); diff --git a/src/BeagleBone/precompile.jl b/src/BeagleBone/precompile.jl index bf714ec3fbede44bfe021ca0d9ebda58de76e3af..f142352ad70a1c8ebfa7dae40c272f6f34f07feb 100644 --- a/src/BeagleBone/precompile.jl +++ b/src/BeagleBone/precompile.jl @@ -1,17 +1,20 @@ function precompile_bb() #Start server - server = run_server(3001) + server = run_server(3001, debug=true) #Pretend to be Computer clientside = connect(3001) #Precompile serialize - serialize(clientside, (true, Int32(1), ("debug", Int32(1), true), ("debug", Int32(1), (1,2.0,"asd")))) + serialize(clientside, (true, Int32(2), ("debug", Int32(1), true), ("debug", Int32(1), (1,2.0,"asd")))) serialize(clientside, (true, Int32(2), ("debug", Int32(1), Int32(1)), ("debug", Int32(1), 1.0))) serialize(clientside, (false, Int32(2), ("debug", Int32(1)), ("debug", Int32(1)))) - + serialize(clientside, (true, Int32(1), ("debug", Int32(1), true))) + serialize(clientside, (false, Int32(1), ("debug", Int32(1)))) + serialize(clientside, (true, Int32(4), ("debug", Int32(1), true), ("debug", Int32(2), false), + ("debug", Int32(3), true), ("debug", Int32(4), false))) close(clientside) #Close server @@ -23,14 +26,29 @@ function precompile_bb() write!(led, Int32(1), true, debug) read(led, Int32(1), debug) + ind = 1 + println("False: $(ind ∉ [1,2,3,4])") + # Precompile GPIO gpio = GPIO() write!(gpio, Int32(1), ("value", "1"), debug) #read(gpio, ind, args, debug) -#TODO write/read + #Do read/write to file + val = true + testfile = joinpath(@__DIR__,"startup/testfile.txt") + file = open(testfile, "r+") + write(file, val ? "1" : "0") + close(file) + + file = open(testfile, "r") + l = readline(file) + close(file) + println("Read from file: $l") try getdev("nonexistent") catch end try bbparse("Invalid input") catch end try bbparse(("Invalid input")) catch end + + println("Internal Precompile Finished") end diff --git a/src/BeagleBone/startup/README.md b/src/BeagleBone/startup/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8e11bdc3b559d62f98f9c0e0756d538b7715f845 --- /dev/null +++ b/src/BeagleBone/startup/README.md @@ -0,0 +1,12 @@ +To setup automatic start of julia server on the beagle bone +1. Make sure that julia is installed in `/home/debian/julia-903644385b/bin/julia` on the BeagleBone or edit `juliaserver.service` accordingly +2. Create the folder `/home/debian/juliapackages/` on the BeagleBone +3. On the computer, go to `LabConnections/util` and run `./copyfoldertobb.sh` + - If this failes, make sure that there is not already a folder `/home/debian/juliapackages/LabConnections` +1. Copy `LabConnections/src/BeagleBone/startup/juliaserver.service` to `/lib/systemd/system/juliaserver.service` on the BeagleBone. +2. Run: `sudo systemctl enable juliaserver` on BeagleBone +3. Run: `sudo systemctl start juliaserver` on BeagleBone + +After a while, the BeagleBone should start blinking on SysLED 2: on-off-on-sleep-repeat + +The server should now start automatically on restart of the BeagleBone. diff --git a/src/BeagleBone/startup/juliaserver.service b/src/BeagleBone/startup/juliaserver.service new file mode 100644 index 0000000000000000000000000000000000000000..c5f8411f6c3e22a9fbab77ed1dbdcaeb9932f3c8 --- /dev/null +++ b/src/BeagleBone/startup/juliaserver.service @@ -0,0 +1,9 @@ +[Unit] +Description=JuliaServer service + +[Service] +ExecStart=/home/debian/julia-903644385b/bin/julia -i -e 'include("/home/debian/juliapackages/LabConnections/src/BeagleBone/startup/startup.jl")' & + + +[Install] +WantedBy=multi-user.target diff --git a/src/BeagleBone/startup/startup.jl b/src/BeagleBone/startup/startup.jl new file mode 100644 index 0000000000000000000000000000000000000000..6240433f2fe912dc531a5df36e69ae6f98ba82da --- /dev/null +++ b/src/BeagleBone/startup/startup.jl @@ -0,0 +1,8 @@ +push!(LOAD_PATH, "/home/debian/juliapackages") +using LabConnections.BeagleBone +BeagleBone.precompile_bb() +server = run_server() +while isopen(server) + #To keep julia from returning, thus killing the process + sleep(10) +end diff --git a/src/BeagleBone/startup/testfile.txt b/src/BeagleBone/startup/testfile.txt new file mode 100644 index 0000000000000000000000000000000000000000..56a6051ca2b02b04ef92d5150c9ef600403cb1de --- /dev/null +++ b/src/BeagleBone/startup/testfile.txt @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/util/copyfoldertobb.sh b/util/copyfoldertobb.sh index a9c9d052e2c51ae0a9374063353baf822b871591..0bc0ec6e1b0a2948d27788a4b236a16acbc85cb5 100755 --- a/util/copyfoldertobb.sh +++ b/util/copyfoldertobb.sh @@ -17,7 +17,7 @@ if [ "{flag}"=true ]; then { printf "${GREEN}Transferring /${project}...${NC}\n" printf "scp -r ../../${project} debian@192.168.7.2:/home/debian" - scp -r ../../${project} debian@192.168.7.2:/home/debian + scp -r ../../${project} debian@192.168.7.2:/home/debian/juliapackages } || { # catch # save log for exception flag=false