Commit cc0ac5b4 authored by Mattias Fält's avatar Mattias Fält

Working startup script on BB

parent 60830c95
......@@ -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);
......
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
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.
[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
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
1
\ No newline at end of file
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment