diff --git a/Examples/testLED.jl b/Examples/testLED.jl index 66d634d..116f15b 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) @@ -25,24 +27,25 @@ for i = 1:100 get(led1) get(led2) get(led3) - #sleep(0.1) - v1,v2,v3 = read(stream) #Sends request to read, reads all inputs for which get! was called - v1 == !v2 == v3 == ledon ? nothing : println("ledon is $ledon, but read v1, v2, v3 = $v1, $v2, $v3") + sleep(0.1) + v1,v2,v3 = .==(read(stream), "1") #Sends request to read, reads all inputs for which get! was called + v1 == !v2 == v3 == ledon ? nothing : println("ledon is $ledon, but read v1, v2, v3 = $v1, $v2, $v3") ledon = !ledon end for i = 1:40 + global ledon send(led1, ledon) #sleep(0.03) - v1 = read(led1) + v1 = read(led1) == "1" send(led2, ledon) #sleep(0.03) - v2 = read(led2) + v2 = read(led2) == "1" send(led3, ledon) #sleep(0.03) - v3 = read(led3) + v3 = read(led3) == "1" send(led4, ledon) #sleep(0.03) - v4 = read(led4) + v4 = read(led4) == "1" v1 == v2 == v3 == v4 == ledon ? nothing : println("ledon is $ledon, but read v1, v2, v3, v4 = $v1, $v2, $v3, $v4") ledon = !ledon end diff --git a/Examples/tetsGPIO.jl b/Examples/tetsGPIO.jl new file mode 100644 index 0000000..76ab897 --- /dev/null +++ b/Examples/tetsGPIO.jl @@ -0,0 +1,12 @@ +using LabConnections.Computer +using Sockets + +stream = BeagleBoneStream(ip"192.168.7.2") + +gpio112 = GPIO(1, true) # Writing P9.30 (according to setup specification on BB) +gpio66 = GPIO(29, false) # Reading P8.7 + +init_devices!(stream, gpio112, gpio66) + +send(gpio112, true) +val = read(gpio112) diff --git a/Manifest.toml b/Manifest.toml new file mode 100644 index 0000000..7d0d0bf --- /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 0000000..a4e5270 --- /dev/null +++ b/Project.toml @@ -0,0 +1,14 @@ +name = "LabConnections" +uuid = "e9ebaa62-f26d-11e8-0a59-692f6511a9a1" +authors = ["Mattias Fält ", "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/README.md b/README.md index 0350b2b..64e80bc 100644 --- a/README.md +++ b/README.md @@ -2,111 +2,136 @@ [![coverage report](https://gitlab.control.lth.se/labdev/LabConnections.jl/badges/master/coverage.svg)](https://gitlab.control.lth.se/labdev/LabConnections.jl/commits/master) # Welcome to LabConnections.jl - the IO-software part of the LabDev project - - -The goal of this project is to develop a software package in [Julia](https://julialang.org/) -for interfacing with lab processes using either the [BeagleBone Black Rev C](http://beagleboard.org/) (BBB) +

+ +

+The goal of this project is to develop a software package in [Julia](https://julialang.org/) +for interfacing with lab processes using either the [BeagleBone Black Rev C](http://beagleboard.org/) (BB) with custom [IO-board cape](https://gitlab.control.lth.se/labdev/ioboards), or the old IO-boxes in the labs using Comedi. -With this package, the user is able to setup a connection between the -host computer and the IO-device, and send and +With this package, the user is able to setup a connection between the +host computer and the IO-device (BB or old IO-box), and send and receive control signals and measurements from the lab process. -The full documentation of the package is available [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/master/docs/build/index.md). +The full documentation of the package is available [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/julia1/docs/build/index.md). ## Package Overview -The `LabConnections.jl` package is subdivided into two main modules; `Computer` -and `BeagleBone`. `Computer` defines the user interface on the host -computer side, while `BeagleBone` defines low-level types and functions meant -to be used locally on the BBB. - -### Computer - - -This module contains the user interface on the host computer side, and defines -types for devices/connections to the lab process, and filestreams between the -host computer and different IO-devices (BBB or Comedi). There are currently 3 +The `LabConnections.jl` package is subdivided into two main modules; `LabConnections.Computer` +and `LabConnections.BeagleBone`. `LabConnections.Computer` defines the user interface on the host +computer side, while `LabConnections.BeagleBone` defines low-level types and functions meant +to be used locally on the BB. + +### LabConnections.Computer +

+ +

+ +The module `LabConnections.Computer` contains the user interface on the host computer side, and defines +types for devices/connections to the lab process, and filestreams between the +host computer and different IO-devices (BB or Comedi). There are currently 3 different device/connection types (each has the abstract super type `AbstractDevice`): * `AnalogInput10V` : Represents ±10V connections from the lab process to the IO-device. Each instance will correspond to a physical ±10V measurement signal from the lab process, whose value can be read. * `AnalogOutput10V` : Represents ±10V connections from the IO-device to the lab process. Each instance will correspond to a physical ±10V input signal to the lab process, whose value can be set. -* `SysLED` : Represents the System LEDs on the BBB. Used for simple testing and debugging from the host computer side. +* `SysLED` : Represents the System LEDs on the BB. Used for simple testing and debugging from the host computer side. There are 2 different filestream types (each has the abstract super type `LabStream`): -* `BeagleBoneStream` : Represents the data stream between the host computer and the BBB. -* `ComediStream` : Represent the data stream between the host computer and the old IO-boxes using Comedi. +* `BeagleBoneStream` : Represents the data stream between the host computer and the BB. +* `ComediStream` : Represent the data stream between the host computer and the old IO-boxes using Comedi. -### BeagleBone - +### LabConnections.BeagleBone +

+ +

-This module defines types representing different pins and LEDs on the BBB, and +The module `LabConnections.BeagleBone` defines types representing different pins and LEDs on the BB, and functions to change their status and behaviour. There are currently 4 different types defined (each has the abstract super type `IO_Object`): -* `GPIO` : Represents the BBB's General Purpose Input Output (GPIO) pins. -Each instance will correspond to a physical GPIO pin on the board, and can be +* `GPIO` : Represents the BB's General Purpose Input Output (GPIO) pins. +Each instance will correspond to a physical GPIO pin on the board, and can be set as an input or output pin, and to output high (1) or low (0). -* `PWM` : Represents the BBB's Pulse Width Modulation (PWM) pins. +* `PWM` : Represents the BB's Pulse Width Modulation (PWM) pins. Each instance will correspond to a physical PWM pin on the board, which can be turned on/off, and whose period, duty cycle and polarity can be specified. -* `SysLED` : Represents the 4 system LEDs on the BBB, and can be turned on/off. -Used to perform simple tests and debugging on the BBB. -* `Debug` : Used for debugging and pre-compilation on the BBB. It does +* `SysLED` : Represents the 4 system LEDs on the BB, and can be turned on/off. +Used to perform simple tests and debugging on the BB. +* `Debug` : Used for debugging and pre-compilation on the BB. It does not represent any physical pin or LED on the board. -**Note:** In addition to GPIO and PWM, the BBB also has pins dedicated for [Serial Peripheral +**Note:** In addition to GPIO and PWM, the BB also has pins dedicated for [Serial Peripheral Interface](https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus) (SPI). -Work to feature this functionality in the module `BeagleBone` is currently ongoing. More -information can be found [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/master/docs/build/man/introduction.md#spi-development) +Work to include this functionality in the module `LabConnections.BeagleBone` is currently ongoing. ## Getting Started ### Installation -Instructions on installing the required software and setting up a connection between -the host computer and the BBB are found [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/master/docs/build/man/installation.md#installation-instructions). +First, you should follow the instructions on how to install the required software and setting up a connection between the host computer and the BB. These instructions are found [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/julia1/docs/build/man/installation.md#installation-instructions). ### A Simple Example -We will here go through a simple example of using the host computer interface to communicate with the BBB and control the onboard system LEDs. - -First make sure that you have followed the installation guide, and that the BBB is running a server and is connected to the host computer. -Then, start the Julia REPL and input - - using LabConnections.Computer -to load the host computer interface. Then define a file stream `stream` and connect to the server running on the BBB by inputting - - stream = BeagleBoneStream(ip"192.168.7.2") -Now, we continue by defining the LED we want to control - - led = SysLED(1) - -The object `led` will now correspond to the first system LED on the BBB. -To tell the BBB that we want to control the LED, we make a call to `init_devices!` - - init_devices!(stream, led) -Now we can start controlling the LED on the BBB. Let's begin by turning it on - - send(led, true) -You should now see the first system LED on the BBB being lit. -The function `send` puts a new command (`true`) to a device (`led`) to the file stream buffer and -sends it immediately to the BBB. +This is a simple example that demonstrates the usage of local devices on the BB via a host computer. The devices that will be used in the example are `SysLED` and `GPIO`. + +First make sure that you have followed the installation guide, and that the BB is running a server connected to the host computer. +Then, start a Julia REPL on the host computer and type +``` +using LabConnections.Computer +using Sockets +``` +to load the host computer interface. Then define a file stream and connect to the server running on the BB by typing +``` +stream = BeagleBoneStream(ip"192.168.7.2") +``` +Now, we continue by defining the onboard LED on the BB we want to control +``` +led = SysLED(1) +``` +The argument `1` means that the object `led` will correspond to the first system LED on the BB. So far, this definition is only known to the host computer. To tell the BB that we want to control the LED, we make a call to `init_devices!` +``` +init_devices!(stream, led) +``` +Now the LED object is defined also on the BB, and we can start controlling it from the host computer. Let's begin by turning it on +``` +send(led, true) +``` +You should now see the first onboard LED on the BB being lit. The function `send` puts a new command (in this case `true`) to a device (in this case `led`) to the file stream buffer and +immediately sends it to the BB. We can read the current status of the LED by calling `read` - - v = read(led) +``` +v = read(led) +``` You should now see a printout saying that the LED is turned on. -We can also stack several commands to the buffer before sending them to the BBB. -We do this with the command `put!`. To turn on 2 LEDS at the same time, we can call - - led2 = SysLED(2) - led3 = SysLED(3) - init_devices!(stream, led2, led3) - put!(led2, true) - put!(led3, true) - send(stream) +We can also stack several commands to the message buffer before sending them to the BB. +We do this with the command `put!`. To turn on 2 LEDS at the same time, we do the following call +``` +led2 = SysLED(2) +led3 = SysLED(3) +init_devices!(stream, led2, led3) +put!(led2, true) +put!(led3, true) +send(stream) +``` Similarly we can read from several devices at the same time by using `get` - - get(led2) - get(led3) - v1, v2 = read(stream) +``` +get(led2) +get(led3) +v1, v2 = read(stream) +``` +We can also manipulate other types of devices on the BB. Let's try manipulating a couple of physical GPIO's on the BB. Similar to the LEDs, we begin by defining two `GPIO`-objects and initializing them on the BB +``` +gpio112 = GPIO(1, true) +gpio66 = GPIO(29,false) +init_devices!(stream, gpio112, gpio66) +``` +When creating the `GPIO`-objects, we input two arguments. The first one is an integer value (1-33) which defines which physical GPIO pin we want to access. The integer corresponds to the index of the physical GPIO in the `gpio_channels`-array defined [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/julia1/src/BeagleBone/IO_Object.jl). Additionally, the pin map of the BB can be found [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/julia1/docs/build/man/development.md#Package-Development-1). The second argument defines if the GPIO should be of output (`true`) or input (`false`) type. + +Now that we have access to two GPIO pins, we can e.g set the output pin's value to high (`true`) +``` +send(gpio112, true) +``` +The physical GPIO pin on the BB will now output a voltage. The other GPIO pin was defined to be of input type, and if we want to read from it we simply type +``` +val = read(gpio66) +``` +where `val` will be either 0 or 1 depending on the voltage value read by the pin. ### More Examples -There are several examples found [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/master/docs/build/examples/examples.md#examples) -which let's you test out the functionality of `LabConnections.jl`. - +More examples for testing out the functionality of `LabConnections.jl` are found [here](https://gitlab.control.lth.se/labdev/LabConnections.jl/blob/master/docs/build/examples/examples.md#examples). +A real-world example using `LabConnections.jl` with the old IO-boxes for controlling the ball and beam process is avaible [here](https://gitlab.control.lth.se/processes/LabProcesses.jl/blob/master/src/interface_implementations/ballandbeam.jl). diff --git a/REQUIRE b/REQUIRE index 137767a..05b5ab4 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1 @@ -julia 0.6 +julia 1.0 diff --git a/docs/build/examples/examples.md b/docs/build/examples/examples.md index eca81f5..0ab33e8 100644 --- a/docs/build/examples/examples.md +++ b/docs/build/examples/examples.md @@ -4,7 +4,7 @@ # Examples -The following examples may be run from the BB, and may require the user to export the the LabConnections module to the LOAD_PATH manually, executing the following line in the Julia prompt +The following examples may be run from the BeagleBone (BB), and may require the user to export the the LabConnections module to the LOAD_PATH manually, executing the following line in the Julia REPL (while SSH:d into the BB) ``` @@ -12,7 +12,7 @@ push!(LOAD_PATH, "/home/debian/juliapackages") ``` -When running the examples with hardware in the loop, take caution not to short the BB ground with any output pin, as this will damage the board. For instance, if connecting a diode to the output pins, always use a resistor of >1000 Ohm in parallel. See the configuration page for information on which functionality specific pins support. +When running the examples with hardware in the loop, take caution not to short the BBB ground with any output pin, as this will damage the board. For instance, if connecting a diode to the output pins, always use a resistor of >1000 Ohm in parallel. @@ -20,7 +20,7 @@ When running the examples with hardware in the loop, take caution not to short t ## Example with LEDs (BB) -To test the system LED functionality of the Julia code from the BBB, open a Julia prompt and run the SYS_LED_test.jl file +To test the system LED functionality of the Julia code from the BBB, open a Julia prompt and run the SYS*LED*test.jl file ``` diff --git a/docs/build/examples/testing.md b/docs/build/examples/testing.md index d6c3c74..41b839d 100644 --- a/docs/build/examples/testing.md +++ b/docs/build/examples/testing.md @@ -1,27 +1,26 @@ - + -# Tests +# Testing -The BeagleBone tests can be run on any computer, regrdless of their file-syste. By setting the flag RUNNING_TESTS to true, a dummy file-system is exported in which the tests are run operate. This has the advantage of enabling testing of the code run on the BB free from the BB itself, without building the Debian FS, thereby enabling the automatic testing through Travis. +Scripts for testing the code in `LabConnections.jl` are found under `/test`. The test-sets under `/test/BeagleBone` can be run on any computer (i.e not only on a real BeagleBone (BB)), regardless of their file system. By setting the flag RUNNING_TESTS to true, a dummy file-system is exported in which the tests are run. This has the advantage of enabling testing of the code run on the BB free from the BB itself, without building the Debian file system, thereby enabling the automatic testing through Travis. -To run the tests, simply enter the /test/ directory and run +To run the tests, simply navigate to the `/test` directory and run ``` -julia run_tests.jl +julia runtests.jl ``` -If the tests are to be run on the BB with hardware in the loop, run +If the tests are to be run on the BB with hardware in the loop, SSH into the BB and run the tests from a local Julia REPL ``` -julia run_tests.jl +push!(LOAD_PATH, "/home/debian/juliapackages") +using LabConnections +include("/home/debian/juliapackages/LabConnections/test/runtests.jl") ``` - -on the BB, to run examples separately, see - diff --git a/docs/build/fig/beaglebonetypes.png b/docs/build/fig/beaglebonetypes.png new file mode 100644 index 0000000..9078fca Binary files /dev/null and b/docs/build/fig/beaglebonetypes.png differ diff --git a/docs/build/fig/computertypes.png b/docs/build/fig/computertypes.png new file mode 100644 index 0000000..1dc70e4 Binary files /dev/null and b/docs/build/fig/computertypes.png differ diff --git a/docs/images/labio_overview.png b/docs/build/fig/labio_overview.png similarity index 100% rename from docs/images/labio_overview.png rename to docs/build/fig/labio_overview.png diff --git a/docs/build/index.md b/docs/build/index.md index 7a600d2..b209639 100644 --- a/docs/build/index.md +++ b/docs/build/index.md @@ -6,20 +6,27 @@ + + +## Getting Started + +- [Introduction](man/introduction.md#Introduction-1) +- [Installation instructions](man/installation.md#Installation-instructions-1) + + ## Examples - [Examples](examples/examples.md#Examples-1) -- [Tests](examples/testing.md#Tests-1) - + -## Guide +## Development -- [Introduction](man/introduction.md#Introduction-1) -- [Installation Instructions](man/installation.md#Installation-Instructions-1) +- [Package Development](man/development.md#Package-Development-1) +- [Testing](examples/testing.md#Testing-1) @@ -37,7 +44,6 @@ - [`LabConnections.BeagleBone.Debug`](lib/io_devices.md#LabConnections.BeagleBone.Debug) - [`LabConnections.BeagleBone.GPIO`](lib/io_devices.md#LabConnections.BeagleBone.GPIO) - [`LabConnections.BeagleBone.IO_Object`](lib/io_devices.md#LabConnections.BeagleBone.IO_Object) -- [`LabConnections.BeagleBone.PWM`](lib/io_devices.md#LabConnections.BeagleBone.PWM) - [`LabConnections.BeagleBone.SysLED`](lib/io_devices.md#LabConnections.BeagleBone.SysLED) - [`Base.read`](lib/functions.md#Base.read) - [`Base.read`](lib/functions.md#Base.read) diff --git a/docs/build/lib/functions.md b/docs/build/lib/functions.md index 07f1f3f..c23e902 100644 --- a/docs/build/lib/functions.md +++ b/docs/build/lib/functions.md @@ -33,7 +33,7 @@ -``` +```julia run_server(port=2001; debug=false) ``` @@ -44,30 +44,30 @@ Run a server on `port` that listens for commands from computer Optional debug ke -``` -l = read(gpio::GPIO, operation::Int32, debug::Bool=false) +```julia +l = read(led::SysLED, debug::Bool=false) ``` -Reads the current value from an operation on a GPIO. +Reads the current brightness value from the LED 'SysLED'. # **`Base.read`** — *Function*. -``` -l = read(led::SysLED, debug::Bool=false) +```julia +l = read(pwm::PWM, operation::Int32, debug::Bool=false) ``` -Reads the current brightness value from the LED 'SysLED'. +Reads the current value from an operation on a PWM pin. # **`Base.read`** — *Function*. -``` -l = read(pwm::PWM, operation::Int32, debug::Bool=false) +```julia +l = read(gpio::GPIO, operation::Int32, debug::Bool=false) ``` Reads the current value from an operation on a GPIO. @@ -77,7 +77,7 @@ Reads the current value from an operation on a GPIO. -``` +```julia assert_pwm_write(operation::Int32, entry::String) ``` @@ -88,7 +88,7 @@ Assertsion for the PWM input data. -``` +```julia bbparse(cmd) ``` @@ -99,18 +99,18 @@ Parse and execute the command `cmd`. -``` +```julia bbparse(l::Tuple, sock) ``` -Parse input on the form `l=(iswrite, ndev, cmd1, cmd2, ..., cmdn)` where if `iswrite` `cmdi = (devname, id, val)` and if not `iswrite` `cmdi = (devname, id)` and send back on socket (vals, timestamps). +Parse input on the form `l=(operation, ndev, cmd1, cmd2, ..., cmdn)` where if `operation==1` (write) `cmdi = (devname, id, val)` and if `operation==0` (read) `cmdi = (devname, id)` and if `operation==2` (initialize) `cmdi = (devname, id)` and send back on socket (vals, timestamps). # **`LabConnections.BeagleBone.closedev`** — *Method*. -``` +```julia closedev(dev_name::String, i::Int32) ``` @@ -121,7 +121,7 @@ Closes down a currently active device of type 'dev_name' at index 'i' on the Bea -``` +```julia export_gpio(i::Int32, debug::Bool=false) ``` @@ -132,7 +132,7 @@ Export the GPIO file system, either for real-time or testing usecases. -``` +```julia export_led(i::Int32, debug::Bool=false) ``` @@ -143,18 +143,18 @@ Exports a dummy filesystem for testing the LED implementation -``` -export_gpio(i::Int32, debug::Bool=false) +```julia +export_pwm(i::Int32, debug::Bool=false) ``` -Export the GPIO file system, either for real-time or testing usecases. +Export the PWM file system, either for real-time or testing usecases. # **`LabConnections.BeagleBone.getdev`** — *Method*. -``` +```julia dev = getdev(dev_name::String, i::Int32) ``` @@ -165,18 +165,18 @@ Retrieves the active device of type `dev_name` at index 'i'. -``` +```julia active_device = initdev(dev_name::String, i:Int32) ``` -Initializes a new device of type 'dev_name' at index 'i' on the BeagleBone, and adds it to the dict of currently active devices. Returns the initialized device 'active_device'. +Initializes a new device of type 'dev*name' at index 'i' on the BeagleBone, and adds it to the dict of currently active devices. Returns the initialized device 'active*device'. # **`LabConnections.BeagleBone.listdev`** — *Method*. -``` +```julia message = listdev() ``` @@ -187,7 +187,7 @@ Lists all the active devices as an insidence array for testing. -``` +```julia message = printdev() ``` @@ -198,7 +198,7 @@ Prints all the active devices and writes out specifics of a single devices. -``` +```julia teardown(led::SysLED, debug::Bool=false) ``` @@ -209,29 +209,29 @@ Closes all open filestreams for the SysLED 'led'. -``` -teardown!(pwd::PWM) +```julia +teardown(gpio::GPIO, debug::Bool=false) ``` -Closes all open streams on the PWM, and unexports it from the file system +Closes all open streams on the GPIO, and unexports it from the file system. # **`LabConnections.BeagleBone.teardown`** — *Function*. -``` -teardown(gpio::GPIO, debug::Bool=false) +```julia +teardown!(pwd::PWM) ``` -Closes all open streams on the GPIO, and unexports it from the file system. +Closes all open streams on the PWM, and unexports it from the file system # **`LabConnections.BeagleBone.to_string`** — *Function*. -``` +```julia to_string(led::SysLED, debug::Bool=false) ``` @@ -242,8 +242,8 @@ Generates a string representation of the GPIO device. -``` -to_string(pwm::PWM,, debug::Bool=false) +```julia +to_string(gpio::GPIO, debug::Bool=false) ``` Generates a string representation of the GPIO device. @@ -253,42 +253,42 @@ Generates a string representation of the GPIO device. -``` -to_string(gpio::GPIO, debug::Bool=false) +```julia +to_string(pwm::PWM,, debug::Bool=false) ``` -Generates a string representation of the GPIO device. +Generates a string representation of the PWM pin. # **`LabConnections.BeagleBone.write!`** — *Function*. -``` -write!(gpio::GPIO, args::Tuple{Int32,String}, debug::Bool=false) +```julia +write!(led::SysLED, val::Bool, debug::Bool=false) ``` -Writes an entry to an operation on a GPIO, of the form args = (operation, entry). +Turns the LED 'SysLed' on/off for val = true/false respectively. # **`LabConnections.BeagleBone.write!`** — *Function*. -``` -write!(led::SysLED, val::Bool, debug::Bool=false) +```julia +write!(pwm::PWM, args::Tuple{Int32,String}, debug::Bool=false) ``` -Turns the LED 'SysLed' on/off for val = true/false respectively. +Writes an entry to an operation on the PWM, of the form args = (operation, entry). # **`LabConnections.BeagleBone.write!`** — *Function*. -``` -write!(pwm::PWM, args::Tuple{Int32,String}, debug::Bool=false) +```julia +write!(gpio::GPIO, args::Tuple{Int32,String}, debug::Bool=false) ``` -Writes an entry to an operation on the PWM, of the form args = (operation, entry). +Writes an entry to an operation on a GPIO, of the form args = (operation, entry). diff --git a/docs/build/lib/io_devices.md b/docs/build/lib/io_devices.md index f01fba9..f559bd2 100644 --- a/docs/build/lib/io_devices.md +++ b/docs/build/lib/io_devices.md @@ -1,7 +1,6 @@ - [`LabConnections.BeagleBone.Debug`](io_devices.md#LabConnections.BeagleBone.Debug) - [`LabConnections.BeagleBone.GPIO`](io_devices.md#LabConnections.BeagleBone.GPIO) - [`LabConnections.BeagleBone.IO_Object`](io_devices.md#LabConnections.BeagleBone.IO_Object) -- [`LabConnections.BeagleBone.PWM`](io_devices.md#LabConnections.BeagleBone.PWM) - [`LabConnections.BeagleBone.SysLED`](io_devices.md#LabConnections.BeagleBone.SysLED) @@ -14,7 +13,7 @@ -``` +```julia Debug(i::Int32) ``` @@ -25,7 +24,7 @@ Type for debugging and precompile. -``` +```julia GPIO(i::Int32) ``` @@ -52,23 +51,12 @@ See the test/BeagleBone/GPIO_test.jl for more examples. Define abstract type for pins/LEDS on the BeagleBone -# -**`LabConnections.BeagleBone.PWM`** — *Type*. - - - -``` -PWM(i::Int32) -``` - -This device allows for low level PWM control of selected pins. The valid pins dictionary pwm_pins relates to memory adresses in of the AM3359 chip, see p.182 in www.ti.com/product/AM3359/technicaldocuments. - # **`LabConnections.BeagleBone.SysLED`** — *Type*. -``` +```julia SysLED(i::Int32) ``` diff --git a/docs/build/man/development.md b/docs/build/man/development.md new file mode 100644 index 0000000..9394339 --- /dev/null +++ b/docs/build/man/development.md @@ -0,0 +1,279 @@ + + + +# Package Development + + + + +## Host computer development environment + + +If you want to develop the code in LabConnections.jl, then this is how you setup a development environment. First, open up a Julia REPL and type + + +``` +] dev https://gitlab.control.lth.se/labdev/LabConnections.jl +``` + + +Open a new terminal and navigate to `.julia/dev/LabConnections`, where the package source code is now located. Then type + + +``` +git checkout julia1 +git pull +``` + + +to ensure that you are working on the correct development branch for Julia v1.0.X. You can now edit the code in `.julia/dev/LabConnections` and run it using a Julia REPL. When you are satisfied with your changes, simply commit and push the changes in the `.julia/dev/LabConnections` directory to the GitLab server. + + + + +## Development with the BeagleBone + + + + +### Transferring development code from host to the BeagleBone + + +Because of the limited performance of the BeagleBone (BB), it is often preferable to do most code development on the host computer. However, you will also do testing of the code locally on the BB, and will thus need to transfer the latest code from the host computer to the BB. To do this, there is a handy utility shell script found in `/util` that handles this. Open a terminal on the host computer and type + + +``` +cd ~/.julia/dev/LabConnections/util +./copyfoldertobb.sh +``` + + +This will transfer the current development version of `LabConnections.jl` found in the `/dev` directory to the BB. + + + + +### Development with hardware in the loop + + +When testing `LabConnections.jl` with hardware in the loop, the external hardware will be connected to the pin headers on the BB. For reference, the pin map of the BeagleBone (BB) is shown below. + + +

+ + +When running examples and tests with hardware in the loop, take caution not to short the BB ground with any output pin, as this will damage the board. For instance, if connecting a diode to the output pins, always use a resistor of >1 kOhm in parallel. + + + + +## Notes on updates with the >=v.4.14 kernel + + +At the time of writing, the image used to flash the beaglebone is a v4.14 kernel, more specifically Linux beaglebone 4.14.71-ti-r80. + + +Since the deployment of the v4.14 kernel, the slots file and bone_capemgr have been permanantly disabled. This means that there is no need for compiling the device tree overlays as we did for the v0.6 version of the software stack. Instead, we need to configure the /boot/uEnv.txt file to enable the PWM pins correctly. Simply open the `/boot/uEnv.txt` file, add the line + + +``` +cape_enable=bone_capemgr.enable_partno=univ-all,BB-ADC,BB-PWM0,BB-PWM1,BB-PWM2 +``` + + +and uncomment the line + + +``` +disable_uboot_overlay_video=1 +``` + + +Reboot the BeagleBone, and you should now have access to the PWM pins. + + + + +### Changes to the device maps + + +The filesystem has also changed with 4.14. we now have a pwm device in `/sys/class/pwm` where we can export and then write to the PWM pins of of the BBB. However, in order to do this, we first need to idetify which pwm chip that corresponds to which pin. + + +The address of each PWM interface is + + +``` +> ls -lh /sys/class/pwm + +lrwxrwxrwx 1 root pwm 0 Oct 7 16:40 pwmchip0 -> ../../devices/platform/ocp/48300000.epwmss/48300100.ecap/pwm/pwmchip0 +lrwxrwxrwx 1 root pwm 0 Oct 7 16:40 pwmchip1 -> ../../devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip1 +lrwxrwxrwx 1 root pwm 0 Oct 7 16:40 pwmchip3 -> ../../devices/platform/ocp/48302000.epwmss/48302100.ecap/pwm/pwmchip3 +lrwxrwxrwx 1 root pwm 0 Oct 7 16:40 pwmchip4 -> ../../devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/pwmchip4 +lrwxrwxrwx 1 root pwm 0 Oct 7 16:40 pwmchip6 -> ../../devices/platform/ocp/48304000.epwmss/48304100.ecap/pwm/pwmchip6 +lrwxrwxrwx 1 root pwm 0 Oct 7 16:40 pwmchip7 -> ../../devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip7 +``` + + +Page 184 of the TI AM335x and AMIC110 Sitara Processors Technical Reference Manual gives the memory map for the PWM chips + + +``` + PWM Subsystem 0: 0x48300000 + eCAP0: 0x48300100 + ePWM0: 0x48300200 + PWM Subsystem 1: 0x48302000 + eCAP1: 0x48302100 + ePWM1: 0x48302200 + PWM Subsystem 2: 0x48304000 + eCAP2: 0x48304100 + ePWM2: 0x48304200 +``` + + +From this we can conclude that + + +``` +ECAP0 (eCAP0) is pwmchip0 +EHRPWM0 (ePWM0) is pwmchip1 +eCAP1 (eCAP1) is pwmchip3 +EHRPWM1 (ePWM1) is pwmchip4 +eCAP2 (eCAP2) is pwmchip6 +EHRPWM2 (ePWM2) is pwmchip7 +``` + + +Based on the headers on the BeagleBone expansion cape + + +``` +EHRPWM0A = P9_22 +EHRPWM0B = P9_21 +EHRPWM1A = P9_14 +EHRPWM1B = P9_16 +EHRPWM2A = P8_19 +EHRPWM2B = P8_13 +ECAP0 = P9_42 +``` + + +which means that we get a mapping + + +``` +const pwm_pins = Dict( + "P9.22" => ("PWM0A", "pwmchip1", "0"), + "P9.21" => ("PWM0B", "pwmchip1", "1"), + "P9.14" => ("PWM1A", "pwmchip4", "0"), + "P9.16" => ("PWM1B", "pwmchip4", "1"), + "P8.19" => ("PWM2A", "pwmchip7", "0"), + "P8.13" => ("PWM2B", "pwmchip7", "1"), +) +``` + + +note that before the v4.14 kernel, this mapping was + + +``` +const pwm_pins = Dict( + "P9.22" => ("PWM0A", "pwmchip0", "0"), + "P9.21" => ("PWM0B", "pwmchip0", "1"), + "P9.14" => ("PWM1A", "pwmchip2", "0"), + "P9.16" => ("PWM1B", "pwmchip2", "1"), + "P8.19" => ("PWM2A", "pwmchip4", "0"), + "P8.13" => ("PWM2B", "pwmchip4", "1"), +) +``` + + + + +### Changes to the file system + + +Before the v4.14 kernel, the file system was structured in such a way that, after export, P9.22 could be enabled by writing to the file + + +``` +/sys/class/pwm/pwmchip0/pwm0/enable +``` + + +however, in the new kernel + + +``` +/sys/class/pwm/pwmchip1/pwm-1:0/enable +``` + + +is used to enable the PWM on the P9.22 pin. + + + + +### Testing the PWM pins individually + + +In order to test the PWM pins from the terminal, make sure that you have added the lines in the /boot/uEnv.txt file, and then configure the desired pin to a PWM pin. For instance, if we wish to control the P9.22 pin, run + + +``` +config-pin P9.22 pwm +``` + + +and make sure that it is configured correctly by running + + +``` +config-pin -q P9.22 +``` + + +which should return "P9_22 Mode: pwm". Now you first need to export the correct pin, which, according the the device mapping above, can be done by + + +``` +echo 0 > /sys/class/pwm/pwmchip1/export +``` + + +once this is done, we set a period and duty cycle to the pin + + +``` +echo 1000000000 > /sys/class/pwm/pwmchip1/pwm-1\:0/period +echo 800000000 > /sys/class/pwm/pwmchip1/pwm-1\:0/duty_cycle +``` + + +and enable it through + + +``` +echo 1 > /sys/class/pwm/pwmchip1/pwm-1\:0/enable +``` + + +disable and unexport the PWM pin by + + +``` +echo 0 > /sys/class/pwm/pwmchip1/pwm-1\:0/enable +echo 0 > /sys/class/pwm/pwmchip1/unexport +``` + + +Alternatively, this can be done using the Julia, by writing + + +``` +p = PWM(1) +write!(p, (1, "1")) +write!(p, (2, "1000000000")) +write!(p, (3, "800000000")) +``` + diff --git a/docs/build/man/installation.md b/docs/build/man/installation.md index a4c478b..bbfba5c 100644 --- a/docs/build/man/installation.md +++ b/docs/build/man/installation.md @@ -1,129 +1,198 @@ - + -# Installation Instructions +# Installation instructions - +In these instructions we explain how to set up a working environment on a host computer and a BeagleBone Black (BB). -## On the BBB + -On the BeagleBone, first flash it with a Debian image for 32 bit ARM processors (BeagleBoard.org Debian Image 2017-03-19) using a micro-SD by following [this guide](http://derekmolloy.ie/write-a-new-image-to-the-beaglebone-black/). You may also include a Julia v0.6 tarball, alternatively transferring it using after an installation. +## Host computer setup -If using the provided SD card, flash the BB by holding down S2 for about 5 seconds while connecting the BB to 5V power. Keep the button pressed until the four system LEDs (D2/D3/D4/D5) start blinking in a periodical sequence. Leave the BB alone for 15-20 minutes while flashing, until all four lights are turned off (or on). Power off the BB, remove the SD card, and power it on again. + +### Installing Julia and LabConnections.jl -Log on to the BB via SSH by + +To get started, first install Julia v1.0.X on the host computer running a Linux distribution by following the instructions specified [here](https://github.com/JuliaLang/julia/blob/master/README.md). Once Julia is installed, open up a Julia REPL and add LabConnections.jl using the package manager by typing ``` -`ssh debian@192.168.7.2' +] add https://gitlab.control.lth.se/labdev/LabConnections.jl#julia1 ``` -an unpack the tarball. Julia should now be operational by running +You now have the LabConnections.jl package available on the host computer. Note that for Julia v1.0.X it is the branch `julia1` of the package that should be used. -``` -`/home/debian/julia-/bin/julia' -``` + +### Installing Serbus -and before leaving the BB, remove the distibution specific tag by renaming + +To work with SPI on the BB you will need a forked `serbus` repository which wraps the`linux/spi/spidev`. Open up a terminal and type ``` -`mv /home/debian/julia-/bin/julia /home/debian/julia/bin/julia' +cd ~/.julia/packages +git clone https://github.com/mgreiff/serbus ``` - +to get the latest revision of the `serbus` fork. You are now done with the setup required on the host computer side. + + + -## On the HOST +## BeagleBone setup -To get started, first install Julia v0.6.X on the PC running a Linux distribution by following the instructions specified [here](https://github.com/JuliaLang/julia/blob/master/README.md). So far, the system has only been tested on Ubuntu 14.04 and 16.04. + +### Preparing a micro-SD card -Once Julia is installed, run + +First, we will prepare a micro-SD card with an image of Debian and a binary of Julia, which we then can flash onto the BB. + + +Start by downloading the Debian image [here](http://beagleboard.org/latest-images) (Debian 9.5 2018-10-07 4GB SD IoT) and write the image onto a micro-SD card ([this guide](http://derekmolloy.ie/write-a-new-image-to-the-beaglebone-black/) is helpful). Proceed by downloading the Julia v1.0 binary for 32-bit ARMv7 found [here](https://julialang.org/downloads/). Put the .tar-file of the Julia binary on the micro-SD card containing the Debian image under `/home/debian`, and unzip it. Make sure that the Julia folder has the correct name by typing ``` -`Pkg.clone(https://gitlab.control.lth.se/labdev/LabConnections.jl)' +mv /home/debian/julia- /home/debian/julia ``` -in the Julia prompt to install all dependencies on the HOST, the source code is then located in `./julia/v0.6/LabCOnnections'. +The file structure on the micro-SD now has the correct structure. + + +The final step is to make sure that the micro-SD will automatically flash the Debian image onto the BB when booting up. To do this, follow the instructions found [here](https://elinux.org/Beagleboard:BeagleBoneBlack_Debian#Flashing_eMMC). Congratulations, you now have a prepared micro-SD card ready for flashing a BB. + + + + +### Flashing the BeagleBone + + +Insert a prepared micro-SD card in the slot on the BB, and press down the boot button S2 (the button closest to the micro-SD slot) and hold it down while you plug in the USB-cable to the BB. Keep the S2 button held down for a couple of seconds, until the onboard LEDs start to blink. After a short while the onboard LEDs should start to blink in a wave pattern, indicating that the BB is being flashed. After a while (can vary between 5-45 minutes) the BB will be turn off automatically, indicating that the flashing is complete. Remove the micro-SD before powering on the BB again (otherwise it will start to flash the BB again). + + + + +### Accessing the BeagleBone + + +Now your BB should be ready to use. Log on to the BeagleBone via SSH by opening a terminal and typing + + +``` +ssh debian@192.168.7.2 +``` -If you plan on working with the SPI devices to debug the ADC/DAC, then you will need a forked `serbus' repository which wraps the`linux/spi/spidev'. Simply +The default password is `temppwd`. You are now logged in to the BB running Debian. If the micro-SD was prepared correctly, the Julia binary should be located at `/home/debian/julia/bin/julia`. You can now start a Julia REPL on the BB by typing ``` -`cd && cd .julia/v0.6' -`git clone https://github.com/mgreiff/serbus' +/home/debian/julia/bin/julia ``` -to get the latest revision of the serbus fork. +If the Julia REPL starts up correctly, then you have a functioning BB ready for use with the LabConnections.jl package. + + + + +### Getting LabConnections.jl and serbus on the BeagleBone + + +To update the BB with the latest revision of the code, open up a terminal on the host computer and begin by cloning the `serbus` and `LabConnections.jl` repositories to a common directory -To update the BB with the latest revision of the code, +``` +git clone https://github.com/mgreiff/serbus +git clone --branch julia1 https://gitlab.control.lth.se/labdev/LabConnections.jl.git +``` + + +Then proceed by navigating to `LabConnections.jl/util` and run the `flash_BB.sh` shell script ``` -`cd && cd .julia/v0.6/LabConnection/util' -`./flash_BB.sh' +cd LabConnections/util +./flash_BB.sh ``` -This scripts bundles the current code in LabCOnnections and serbus on the host computer and transfers it to the /home/debian/juliapackages directory on the BB. +This scripts bundles the current code in LabConnections.jl and serbus on the host computer and transfers it to the BB and puts it in the directory `/home/debian/juliapackages`. -## Setting up automatic communication + + + +### Setting up the uEnv file -To setup automatic start of Julia server on the BB, make sure to have completed all prior installation instructions, and that the lates revision of the LabConnections package is located on the BB. SSH to the BeagleBone and copy the julilaserver.service to the systemd/system +Since the deployment of the v4.14 kernel, the slots file and bone_capemgr have been permanantly disabled. This means that there is no need for compiling the device tree overlays as we did for the v0.6 version of the software stack. Instead, we need to configure the /boot/uEnv.txt file to enable the PWM pins correctly. Simply open the `/boot/uEnv.txt` file, add the line ``` -`ssh debian@192.168.7.2' -`sudo cp -r /home/debian/juliapackets/LabConnections/src/BeagleBone/startup/juliaserver.service /lib/systemd/system/juliaserver.service` (on the BeagleBone) +cape_enable=bone_capemgr.enable_partno=univ-all,BB-ADC,BB-PWM0,BB-PWM1,BB-PWM2 ``` -Then execute the commands +and uncomment the line -`sudo systemctl enable juliaserver` (on the BeagleBone) `sudo systemctl start juliaserver` (on the BeagleBone) +``` +disable_uboot_overlay_video=1 +``` + + +Reboot the BeagleBone, and you should now have access to the PWM pins. + + + +### Setting up a Julia server on the 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, and you should be able to run the examples in in /Examples on the host computer. +To setup automatic start of Julia server on the BB, make sure to have completed all prior installation instructions, and that the latest revision of the LabConnections package is located on the BB. SSH into the BB, and copy the file `juliaserver.service` to the folder `systemd/system` -```@systemConfiguration ``` +ssh debian@192.168.7.2 +sudo cp -r /home/debian/juliapackages/LabConnections/src/BeagleBone/startup/juliaserver.service /lib/systemd/system/juliaserver.service +``` + + +Then, still SSH:d into the BB, execute the commands - +``` +sudo systemctl enable juliaserver +sudo systemctl start juliaserver +``` + -## Debugging +After a while, the BB should start blinking onboard LED 2 in the following pattern: on-off-on-sleep-repeat. This indicates that the server on the BB is now running, and server should now start automatically every time you restart the BB. With this setup ready, you should be able to run the examples in the `/Examples` folder from the host computer. -No errors will be seen on the BeagleBone when the automatic startup is used. For debugging purposes it might be useful to start the service manually on the beagle bone. Start julia as root: +Note that no errors will be seen on the BB when the automatic startup is used. For debugging purposes it can therefore also be useful to start the service manually on the BB. This way, any warnings or errors will be printed when starting up the Julia server. To start up the Julia server manually on the BB, SHH into the BB and start Julia as root ``` +ssh debian@192.168.7.2 sudo /home/debian/julia/bin/julia ``` -and run the startup script: +and then run the startup script ``` diff --git a/docs/build/man/introduction.md b/docs/build/man/introduction.md index 6d7027e..0990b82 100644 --- a/docs/build/man/introduction.md +++ b/docs/build/man/introduction.md @@ -4,7 +4,11 @@ # Introduction - + -## Installation + +This project is developing a software package in [Julia](https://julialang.org/) for interfacing with lab processes using either the [BeagleBone Black Rev C](http://beagleboard.org/) (BB) with custom [IO-board cape](https://gitlab.control.lth.se/labdev/ioboards), or the old IO-boxes in the labs using Comedi. With this package, the user is able to setup a connection between the host computer and the IO-device, and send and receive control signals and measurements from the lab process. + + +To get started, first follow the installation instruction found [here](installation.md). diff --git a/docs/images/beaglebonetypes.png b/docs/images/beaglebonetypes.png deleted file mode 100644 index d6174c5..0000000 Binary files a/docs/images/beaglebonetypes.png and /dev/null differ diff --git a/docs/images/computertypes.png b/docs/images/computertypes.png deleted file mode 100644 index e696f1b..0000000 Binary files a/docs/images/computertypes.png and /dev/null differ diff --git a/docs/make.jl b/docs/make.jl index 56a17c7..6c510eb 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,32 +1,5 @@ push!(LOAD_PATH,"../src/") println(LOAD_PATH) -using Documenter, LabConnections -# makedocs() -# deploydocs( -# deps = Deps.pip("pygments", "mkdocs", "python-markdown-math", "mkdocs-cinder"), -# repo = "gitlab.control.lth.se/processes/LabProcesses.jl", -# branch = "gh-pages", -# julia = "0.6", -# osname = "linux" -# ) +using Documenter, LabConnections, DocumenterMarkdown -makedocs(modules=[LabConnections]) - -#makedocs( -# format = :html, -# sitename = "LabConnections", -# pages = [ -# "index.md", -# "installation.md", -# "systemConfiguration.md", -# "testing.md", -# "examples.md", -# ] -#) - -#deploydocs( -# repo = "gitlab.control.lth.se/labdev/LabConnections.jl.git", -# target = "build", -# deps = nothing, -# make = nothing -#) +makedocs(modules=[LabConnections],format=Markdown(),sitename="LabConnections") diff --git a/docs/makeOld.jl b/docs/makeOld.jl deleted file mode 100644 index be2ee4f..0000000 --- a/docs/makeOld.jl +++ /dev/null @@ -1,30 +0,0 @@ -push!(LOAD_PATH,"../src/") -println(LOAD_PATH) -using Documenter, LabConnections -# makedocs() -# deploydocs( -# deps = Deps.pip("pygments", "mkdocs", "python-markdown-math", "mkdocs-cinder"), -# repo = "gitlab.control.lth.se/processes/LabProcesses.jl", -# branch = "gh-pages", -# julia = "0.6", -# osname = "linux" -# ) - -makedocs( - format = :html, - sitename = "LabConnections", - pages = [ - "index.md", - "installation.md", - "systemConfiguration.md", - "testing.md", - "examples.md", - ] -) - -deploydocs( - repo = "gitlab.control.lth.se/labdev/LabConnections.jl.git", - target = "build", - deps = nothing, - make = nothing -) diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 47530e9..30f1baf 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -29,6 +29,7 @@ pages: - Guide: - Introduction: 'man/introduction.md' - Installation: 'man/installation.md' + - Development: 'man/development.md' - API: - IO devices: 'lib/io_devices.md' - Functions: 'lib/functions.md' diff --git a/docs/src/examples/examples.md b/docs/src/examples/examples.md index 4bac901..2747250 100644 --- a/docs/src/examples/examples.md +++ b/docs/src/examples/examples.md @@ -1,15 +1,14 @@ # Examples -The following examples may be run from the BB, and may require the user to +The following examples may be run from the BeagleBone (BB), and may require the user to export the the LabConnections module to the LOAD_PATH manually, executing the -following line in the Julia prompt - - push!(LOAD_PATH, "/home/debian/juliapackages") - +following line in the Julia REPL (while SSH:d into the BB) +``` +push!(LOAD_PATH, "/home/debian/juliapackages") +``` When running the examples with hardware in the loop, take caution not to short -the BB ground with any output pin, as this will damage the board. For instance, +the BBB ground with any output pin, as this will damage the board. For instance, if connecting a diode to the output pins, always use a resistor of >1000 Ohm in -parallel. See the configuration page for information on which functionality -specific pins support. +parallel. ## Example with LEDs (BB) To test the system LED functionality of the Julia code from the BBB, open a diff --git a/docs/src/examples/testing.md b/docs/src/examples/testing.md index 98cde17..2e7d8eb 100644 --- a/docs/src/examples/testing.md +++ b/docs/src/examples/testing.md @@ -1,16 +1,13 @@ -# Tests -The BeagleBone tests can be run on any computer, regrdless of their file-syste. -By setting the flag RUNNING_TESTS to true, a dummy file-system is exported in -which the tests are run operate. This has the advantage of enabling testing of -the code run on the BB free from the BB itself, without building the Debian FS, -thereby enabling the automatic testing through Travis. - -To run the tests, simply enter the /test/ directory and run - - julia run_tests.jl - -If the tests are to be run on the BB with hardware in the loop, run - - julia run_tests.jl - -on the BB, to run examples separately, see +# Testing +Scripts for testing the code in `LabConnections.jl` are found under `/test`. The test-sets under `/test/BeagleBone` can be run on any computer (i.e not only on a real BeagleBone (BB)), regardless of their file system. By setting the flag RUNNING_TESTS to true, a dummy file-system is exported in which the tests are run. This has the advantage of enabling testing of the code run on the BB free from the BB itself, without building the Debian file system, thereby enabling the automatic testing through Travis. + +To run the tests, simply navigate to the `/test` directory and run +``` +julia runtests.jl +``` +If the tests are to be run on the BB with hardware in the loop, SSH into the BB and run the tests from a local Julia REPL +``` +push!(LOAD_PATH, "/home/debian/juliapackages") +using LabConnections +include("/home/debian/juliapackages/LabConnections/test/runtests.jl") +``` diff --git a/docs/src/fig/beaglebonetypes.png b/docs/src/fig/beaglebonetypes.png new file mode 100644 index 0000000..9078fca Binary files /dev/null and b/docs/src/fig/beaglebonetypes.png differ diff --git a/docs/src/fig/computertypes.png b/docs/src/fig/computertypes.png new file mode 100644 index 0000000..1dc70e4 Binary files /dev/null and b/docs/src/fig/computertypes.png differ diff --git a/docs/src/fig/labio_overview.png b/docs/src/fig/labio_overview.png new file mode 100644 index 0000000..d6e7cf6 Binary files /dev/null and b/docs/src/fig/labio_overview.png differ diff --git a/docs/src/index.md b/docs/src/index.md index 6532b2d..d19da74 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -3,24 +3,25 @@ ```@meta CurrentModule = LabConnections ``` - +## Getting Started +```@contents +Pages = ["man/introduction.md", "man/installation.md"] +Depth = 1 +``` ## Examples ```@contents -Pages = ["examples/examples.md", "examples/testing.md"] +Pages = ["examples/examples.md"] Depth = 1 ``` - -## Guide +## Development ```@contents -Pages = ["man/introduction.md", "man/installation.md"] +Pages = ["man/development.md", "examples/testing.md"] Depth = 1 ``` - ## Functions ```@contents Pages = ["lib/io_devices.md", "lib/functions.md"] ``` - ## Documentation Index ```@index Pages = ["lib/io_devices.md", "lib/functions.md"] diff --git a/docs/src/man/development.md b/docs/src/man/development.md new file mode 100644 index 0000000..9837dfb --- /dev/null +++ b/docs/src/man/development.md @@ -0,0 +1,166 @@ +# Package Development + +## Host computer development environment +If you want to develop the code in LabConnections.jl, then this is how you setup a development environment. First, open up a Julia REPL and type +``` +] dev https://gitlab.control.lth.se/labdev/LabConnections.jl +``` +Open a new terminal and navigate to `.julia/dev/LabConnections`, where the package source code is now located. Then type +``` +git checkout julia1 +git pull +``` +to ensure that you are working on the correct development branch for Julia v1.0.X. You can now edit the code in `.julia/dev/LabConnections` +and run it using a Julia REPL. When you are satisfied with your changes, simply commit and push the changes in the `.julia/dev/LabConnections` directory to the GitLab server. + +## Development with the BeagleBone + +### Transferring development code from host to the BeagleBone +Because of the limited performance of the BeagleBone (BB), it is often preferable to do most code development on the host computer. However, you will also do testing of the code locally on the BB, and will thus need to transfer the latest code from the host computer to the BB. To do this, there is a handy utility shell script found in `/util` that handles this. Open a terminal on the host computer and type +``` +cd ~/.julia/dev/LabConnections/util +./copyfoldertobb.sh +``` +This will transfer the current development version of `LabConnections.jl` found in the `/dev` directory to the BB. + +### Development with hardware in the loop +When testing `LabConnections.jl` with hardware in the loop, the external hardware will be connected to the pin headers on the BB. For reference, the pin map of the BeagleBone (BB) is shown below. + +

+ +

+ +When running examples and tests with hardware in the loop, take caution not to short the BB ground with any output pin, as this will damage the board. For instance, if connecting a diode to the output pins, always use a resistor of >1 kOhm in parallel. + +## Notes on updates with the >=v.4.14 kernel +At the time of writing, the image used to flash the beaglebone is +a v4.14 kernel, more specifically Linux beaglebone 4.14.71-ti-r80. + +Since the deployment of the v4.14 kernel, the slots file and bone_capemgr have been permanantly disabled. This means that there is no need for compiling the device tree overlays as we did for the v0.6 version of the software stack. Instead, we need to configure the /boot/uEnv.txt file to enable the PWM pins correctly. Simply open the `/boot/uEnv.txt` file, add the line + +``` +cape_enable=bone_capemgr.enable_partno=univ-all,BB-ADC,BB-PWM0,BB-PWM1,BB-PWM2 +``` +and uncomment the line +``` +disable_uboot_overlay_video=1 +``` +Reboot the BeagleBone, and you should now have access to the PWM pins. + +### Changes to the device maps +The filesystem has also changed with 4.14. we now have a pwm device in +`/sys/class/pwm` where we can export and then write to the PWM pins of +of the BBB. However, in order to do this, we first need to idetify which +pwm chip that corresponds to which pin. + +The address of each PWM interface is +``` +> ls -lh /sys/class/pwm + +lrwxrwxrwx 1 root pwm 0 Oct 7 16:40 pwmchip0 -> ../../devices/platform/ocp/48300000.epwmss/48300100.ecap/pwm/pwmchip0 +lrwxrwxrwx 1 root pwm 0 Oct 7 16:40 pwmchip1 -> ../../devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip1 +lrwxrwxrwx 1 root pwm 0 Oct 7 16:40 pwmchip3 -> ../../devices/platform/ocp/48302000.epwmss/48302100.ecap/pwm/pwmchip3 +lrwxrwxrwx 1 root pwm 0 Oct 7 16:40 pwmchip4 -> ../../devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/pwmchip4 +lrwxrwxrwx 1 root pwm 0 Oct 7 16:40 pwmchip6 -> ../../devices/platform/ocp/48304000.epwmss/48304100.ecap/pwm/pwmchip6 +lrwxrwxrwx 1 root pwm 0 Oct 7 16:40 pwmchip7 -> ../../devices/platform/ocp/48304000.epwmss/48304200.pwm/pwm/pwmchip7 +``` +Page 184 of the TI AM335x and AMIC110 Sitara Processors Technical Reference Manual gives the memory map for the PWM chips +``` + PWM Subsystem 0: 0x48300000 + eCAP0: 0x48300100 + ePWM0: 0x48300200 + PWM Subsystem 1: 0x48302000 + eCAP1: 0x48302100 + ePWM1: 0x48302200 + PWM Subsystem 2: 0x48304000 + eCAP2: 0x48304100 + ePWM2: 0x48304200 +``` +From this we can conclude that +``` +ECAP0 (eCAP0) is pwmchip0 +EHRPWM0 (ePWM0) is pwmchip1 +eCAP1 (eCAP1) is pwmchip3 +EHRPWM1 (ePWM1) is pwmchip4 +eCAP2 (eCAP2) is pwmchip6 +EHRPWM2 (ePWM2) is pwmchip7 +``` +Based on the headers on the BeagleBone expansion cape +``` +EHRPWM0A = P9_22 +EHRPWM0B = P9_21 +EHRPWM1A = P9_14 +EHRPWM1B = P9_16 +EHRPWM2A = P8_19 +EHRPWM2B = P8_13 +ECAP0 = P9_42 +``` + +which means that we get a mapping +``` +const pwm_pins = Dict( + "P9.22" => ("PWM0A", "pwmchip1", "0"), + "P9.21" => ("PWM0B", "pwmchip1", "1"), + "P9.14" => ("PWM1A", "pwmchip4", "0"), + "P9.16" => ("PWM1B", "pwmchip4", "1"), + "P8.19" => ("PWM2A", "pwmchip7", "0"), + "P8.13" => ("PWM2B", "pwmchip7", "1"), +) +``` +note that before the v4.14 kernel, this mapping was +``` +const pwm_pins = Dict( + "P9.22" => ("PWM0A", "pwmchip0", "0"), + "P9.21" => ("PWM0B", "pwmchip0", "1"), + "P9.14" => ("PWM1A", "pwmchip2", "0"), + "P9.16" => ("PWM1B", "pwmchip2", "1"), + "P8.19" => ("PWM2A", "pwmchip4", "0"), + "P8.13" => ("PWM2B", "pwmchip4", "1"), +) +``` + +### Changes to the file system +Before the v4.14 kernel, the file system was structured in such a way that, after export, P9.22 could be enabled by writing to the file +``` +/sys/class/pwm/pwmchip0/pwm0/enable +``` +however, in the new kernel +``` +/sys/class/pwm/pwmchip1/pwm-1:0/enable +``` +is used to enable the PWM on the P9.22 pin. + +### Testing the PWM pins individually +In order to test the PWM pins from the terminal, make sure that you have added the lines in the /boot/uEnv.txt file, and then configure the desired pin to a PWM pin. For instance, if we wish to control the P9.22 pin, run +``` +config-pin P9.22 pwm +``` +and make sure that it is configured correctly by running +``` +config-pin -q P9.22 +``` +which should return "P9_22 Mode: pwm". Now you first need to export the correct pin, which, according the the device mapping above, can be done by +``` +echo 0 > /sys/class/pwm/pwmchip1/export +``` +once this is done, we set a period and duty cycle to the pin +``` +echo 1000000000 > /sys/class/pwm/pwmchip1/pwm-1\:0/period +echo 800000000 > /sys/class/pwm/pwmchip1/pwm-1\:0/duty_cycle +``` +and enable it through +``` +echo 1 > /sys/class/pwm/pwmchip1/pwm-1\:0/enable +``` +disable and unexport the PWM pin by +``` +echo 0 > /sys/class/pwm/pwmchip1/pwm-1\:0/enable +echo 0 > /sys/class/pwm/pwmchip1/unexport +``` +Alternatively, this can be done using the Julia, by writing +``` +p = PWM(1) +write!(p, (1, "1")) +write!(p, (2, "1000000000")) +write!(p, (3, "800000000")) +``` diff --git a/docs/src/man/installation.md b/docs/src/man/installation.md index 58798a2..eafab98 100644 --- a/docs/src/man/installation.md +++ b/docs/src/man/installation.md @@ -1,86 +1,101 @@ -# Installation Instructions +# Installation instructions +In these instructions we explain how to set up a working environment on a host computer and a BeagleBone Black (BB). -## On the BBB -On the BeagleBone, first flash it with a Debian image for 32 bit ARM processors -(BeagleBoard.org Debian Image 2017-03-19) using a micro-SD by following [this guide](http://derekmolloy.ie/write-a-new-image-to-the-beaglebone-black/). -You may also include a Julia v0.6 tarball, alternatively transferring it -using after an installation. +## Host computer setup -If using the provided SD card, flash the BB by holding down S2 for about 5 -seconds while connecting the BB to 5V power. Keep the button pressed until the -four system LEDs (D2/D3/D4/D5) start blinking in a periodical sequence. Leave -the BB alone for 15-20 minutes while flashing, until all four lights are turned -off (or on). Power off the BB, remove the SD card, and power it on again. +### Installing Julia and LabConnections.jl -Log on to the BB via SSH by - - `ssh debian@192.168.7.2' - -an unpack the tarball. Julia should now be operational by running - - `/home/debian/julia-/bin/julia' - -and before leaving the BB, remove the distibution specific tag by renaming - - `mv /home/debian/julia-/bin/julia /home/debian/julia/bin/julia' - -## On the HOST -To get started, first install Julia v0.6.X on the PC running a Linux -distribution by following the instructions specified -[here](https://github.com/JuliaLang/julia/blob/master/README.md). So far, the -system has only been tested on Ubuntu 14.04 and 16.04. - -Once Julia is installed, run - - `Pkg.clone(https://gitlab.control.lth.se/labdev/LabConnections.jl)' - -in the Julia prompt to install all dependencies on the HOST, the source code -is then located in `./julia/v0.6/LabCOnnections'. +To get started, first install Julia v1.0.X on the host computer running a Linux distribution by following the instructions specified [here](https://github.com/JuliaLang/julia/blob/master/README.md). Once Julia is installed, open up a Julia REPL and add LabConnections.jl using the package manager by typing +``` +] add https://gitlab.control.lth.se/labdev/LabConnections.jl#julia1 +``` +You now have the LabConnections.jl package available on the host computer. Note that for Julia v1.0.X it is the branch `julia1` of the package that should be used. -If you plan on working with the SPI devices to debug the ADC/DAC, then you will -need a forked `serbus' repository which wraps the `linux/spi/spidev'. Simply +### Installing Serbus +To work with SPI on the BB you will need a forked `serbus` repository which wraps the`linux/spi/spidev`. Open up a terminal and type +``` +cd ~/.julia/packages +git clone https://github.com/mgreiff/serbus +``` +to get the latest revision of the `serbus` fork. You are now done with the setup required on the host computer side. - `cd && cd .julia/v0.6' - `git clone https://github.com/mgreiff/serbus' +## BeagleBone setup -to get the latest revision of the serbus fork. +### Preparing a micro-SD card +First, we will prepare a micro-SD card with an image of Debian and a binary of Julia, which we then can flash onto the BB. -To update the BB with the latest revision of the code, +Start by downloading the Debian image [here](http://beagleboard.org/latest-images) (Debian 9.5 2018-10-07 4GB SD IoT) and write the image onto a micro-SD card ([this guide](http://derekmolloy.ie/write-a-new-image-to-the-beaglebone-black/) is helpful). +Proceed by downloading the Julia v1.0 binary for 32-bit ARMv7 found [here](https://julialang.org/downloads/). Put the .tar-file of the Julia binary on the micro-SD card containing the Debian image under `/home/debian`, and unzip it. +Make sure that the Julia folder has the correct name by typing +``` +mv /home/debian/julia- /home/debian/julia +``` +The file structure on the micro-SD now has the correct structure. - `cd && cd .julia/v0.6/LabConnection/util' - `./flash_BB.sh' +The final step is to make sure that the micro-SD will automatically flash the Debian image onto the BB when booting up. To do this, follow the instructions found [here](https://elinux.org/Beagleboard:BeagleBoneBlack_Debian#Flashing_eMMC). Congratulations, you now have a prepared micro-SD card ready for flashing a BB. -This scripts bundles the current code in LabCOnnections and serbus on the host -computer and transfers it to the /home/debian/juliapackages directory on the BB. +### Flashing the BeagleBone +Insert a prepared micro-SD card in the slot on the BB, and press down the boot button S2 (the button closest to the micro-SD slot) and hold it down while you plug in the USB-cable to the BB. Keep the S2 button held down for a couple of seconds, until the onboard LEDs start to blink. After a short while the onboard LEDs should start to blink in a wave pattern, indicating that the BB is being flashed. After a while (can vary between 5-45 minutes) the BB will be turn off automatically, indicating that the flashing is complete. Remove the micro-SD before powering on the BB again (otherwise it will start to flash the BB again). -## Setting up automatic communication -To setup automatic start of Julia server on the BB, make sure to have completed -all prior installation instructions, and that the lates revision of the -LabConnections package is located on the BB. SSH to the BeagleBone and copy the -julilaserver.service to the systemd/system +### Accessing the BeagleBone +Now your BB should be ready to use. Log on to the BeagleBone via SSH by opening a terminal and typing +``` +ssh debian@192.168.7.2 +``` +The default password is `temppwd`. You are now logged in to the BB running Debian. If the micro-SD was prepared correctly, the Julia binary should be located at `/home/debian/julia/bin/julia`. +You can now start a Julia REPL on the BB by typing +``` +/home/debian/julia/bin/julia +``` +If the Julia REPL starts up correctly, then you have a functioning BB ready for use with the LabConnections.jl package. - `ssh debian@192.168.7.2' - `sudo cp -r /home/debian/juliapackets/LabConnections/src/BeagleBone/startup/juliaserver.service /lib/systemd/system/juliaserver.service` (on the BeagleBone) +### Getting LabConnections.jl and serbus on the BeagleBone -Then execute the commands +To update the BB with the latest revision of the code, open up a terminal on the host computer and begin by cloning the `serbus` and `LabConnections.jl` repositories to a common directory +``` +git clone https://github.com/mgreiff/serbus +git clone --branch julia1 https://gitlab.control.lth.se/labdev/LabConnections.jl.git +``` +Then proceed by navigating to `LabConnections.jl/util` and run the `flash_BB.sh` shell script +``` +cd LabConnections/util +./flash_BB.sh +``` +This scripts bundles the current code in LabConnections.jl and serbus on the host computer and transfers it to the BB and puts it in the directory `/home/debian/juliapackages`. -`sudo systemctl enable juliaserver` (on the BeagleBone) -`sudo systemctl start juliaserver` (on the 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, and you should be able to run the examples in in /Examples on the host computer. +### Setting up the uEnv file +Since the deployment of the v4.14 kernel, the slots file and bone_capemgr have been permanantly disabled. This means that there is no need for compiling the device tree overlays as we did for the v0.6 version of the software stack. Instead, we need to configure the /boot/uEnv.txt file to enable the PWM pins correctly. Simply open the `/boot/uEnv.txt` file, add the line -```@systemConfiguration ``` +cape_enable=bone_capemgr.enable_partno=univ-all,BB-ADC,BB-PWM0,BB-PWM1,BB-PWM2 +``` +and uncomment the line +``` +disable_uboot_overlay_video=1 +``` +Reboot the BeagleBone, and you should now have access to the PWM pins. +### Setting up a Julia server on the BeagleBone +To setup automatic start of Julia server on the BB, make sure to have completed all prior installation instructions, and that the latest revision of the LabConnections package is located on the BB. SSH into the BB, and copy the file `juliaserver.service` to the folder `systemd/system` +``` +ssh debian@192.168.7.2 +sudo cp -r /home/debian/juliapackages/LabConnections/src/BeagleBone/startup/juliaserver.service /lib/systemd/system/juliaserver.service +``` +Then, still SSH:d into the BB, execute the commands +``` +sudo systemctl enable juliaserver +sudo systemctl start juliaserver +``` +After a while, the BB should start blinking onboard LED 2 in the following pattern: on-off-on-sleep-repeat. This indicates that the server on the BB is now running, and server should now start automatically every time you restart the BB. With this setup ready, you should be able to run the examples in the `/Examples` folder from the host computer. -## Debugging - -No errors will be seen on the BeagleBone when the automatic startup is used. For debugging purposes it might be useful to start the service manually on the beagle bone. -Start julia as root: +Note that no errors will be seen on the BB when the automatic startup is used. For debugging purposes it can therefore also be useful to start the service manually on the BB. This way, any warnings or errors will be printed when starting up the Julia server. To start up the Julia server manually on the BB, SHH into the BB and start Julia as root ``` +ssh debian@192.168.7.2 sudo /home/debian/julia/bin/julia ``` -and run the startup script: +and then run the startup script ``` include("/home/debian/juliapackages/LabConnections/src/BeagleBone/startup/startup.jl") ``` diff --git a/docs/src/man/introduction.md b/docs/src/man/introduction.md index c35df1d..1d57dcf 100644 --- a/docs/src/man/introduction.md +++ b/docs/src/man/introduction.md @@ -1,3 +1,11 @@ # Introduction -## Installation + +This project is developing a software package in [Julia](https://julialang.org/) +for interfacing with lab processes using either the [BeagleBone Black Rev C](http://beagleboard.org/) (BB) +with custom [IO-board cape](https://gitlab.control.lth.se/labdev/ioboards), or the old IO-boxes in the labs using Comedi. +With this package, the user is able to setup a connection between the +host computer and the IO-device, and send and +receive control signals and measurements from the lab process. + +To get started, first follow the installation instruction found [here](installation.md). diff --git a/src/BeagleBone/BeagleBone.jl b/src/BeagleBone/BeagleBone.jl index 9aa402b..95e7aca 100644 --- a/src/BeagleBone/BeagleBone.jl +++ b/src/BeagleBone/BeagleBone.jl @@ -1,3 +1,7 @@ +const READ = Int32(0) +const WRITE = Int32(1) +const INIT = Int32(2) + include("IO_Object.jl") include("Debug.jl") include("SysLED.jl") @@ -106,27 +110,29 @@ end """ bbparse(l::Tuple, sock) -Parse input on the form `l=(iswrite, ndev, cmd1, cmd2, ..., cmdn)` -where if `iswrite` +Parse input on the form `l=(operation, ndev, cmd1, cmd2, ..., cmdn)` +where if `operation==1` (write) `cmdi = (devname, id, val)` - and if not `iswrite` + and if `operation==0` (read) + `cmdi = (devname, id)` + and if `operation==2` (initialize) `cmdi = (devname, id)` and send back on socket (vals, timestamps). """ function bbparse(l::Tuple, sock) - iswrite = l[1]::Bool #True if write command, false if read + operation = l[1]::Int32 #1 if write command, 0 if read, 2 if init ndev = l[2]::Int32 #Number of devices/commands - if iswrite + if operation == WRITE for i = 1:ndev command = l[2+i]::Tuple dev = getdev(command[1], command[2]) write!(dev, command[3]) end return - else + elseif operation == READ #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]) @@ -135,6 +141,26 @@ function bbparse(l::Tuple, sock) end bbsend(sock, (vals, timestamps)) return + elseif operation == INIT + for i = 1:ndev + command = l[2+i]::Tuple + dev = initdev(command[1], command[2]) + end + return + else + error("Unknown operation $operation, cmd: $l") + end +end + +function close_all_devices() + # When connection fails or closes, close devices + for key in keys(DEVICES) + for (devkey, active_device) in active_devices[key] + println("teardown $active_device") + teardown(active_device) + #Remove the device from the dict of active devices + delete!(active_devices[key], devkey) + end end end @@ -146,7 +172,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 @@ -167,21 +193,31 @@ function run_server(port=2001; debug=false) @async while isopen(sock) try l = deserialize(sock); - bbparse(l, sock) + # println("deserialized:") + # println(l) + try + bbparse(l, sock) + catch err + @warn "Failure in bbparse, server should keep running, error:" + println(err) + end catch err if !isopen(sock) && (isa(err, Base.EOFError) || isa(err, Base.UVError)) println("Connection to server closed") + close_all_devices() else println("error: $(typeof(err))") - throw(err) + println("err: $err") + rethrow(err) end end end catch err + close_all_devices() if isa(err,Base.UVError) && err.prefix == "accept" println("Server closed successfully") else - throw(err) + rethrow(err) end end end diff --git a/src/BeagleBone/Debug.jl b/src/BeagleBone/Debug.jl index e2fd369..5c7f84b 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 cc03657..662f761 100644 --- a/src/BeagleBone/GPIO.jl +++ b/src/BeagleBone/GPIO.jl @@ -1,3 +1,7 @@ +const GPIO_VALUE = Int32(1) +const GPIO_DIRECTION = Int32(2) +const GPIO_EDGE = Int32(3) + """ GPIO(i::Int32) Lowest form of communication with the GPIO pins. The available pins are @@ -15,7 +19,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} @@ -35,6 +39,11 @@ type GPIO <: IO_Object end end +# Default to writing "value" +function write!(gpio::GPIO, val::String, debug::Bool=false) + write!(gpio, (GPIO_VALUE, val), debug=debug) +end + """ write!(gpio::GPIO, args::Tuple{Int32,String}, debug::Bool=false) Writes an entry to an operation on a GPIO, of the form args = (operation, entry). @@ -53,6 +62,10 @@ function write!(gpio::GPIO, args::Tuple{Int32,String}, debug::Bool=false) end end +# Default to reading "value" +function read(gpio::GPIO, debug::Bool=false) + read(gpio, GPIO_VALUE, debug) +end """ l = read(gpio::GPIO, operation::Int32, debug::Bool=false) Reads the current value from an operation on a GPIO. @@ -79,7 +92,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 +114,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/IO_Object.jl b/src/BeagleBone/IO_Object.jl index 9215ea2..bc25ddb 100644 --- a/src/BeagleBone/IO_Object.jl +++ b/src/BeagleBone/IO_Object.jl @@ -44,14 +44,23 @@ const gpio_channels =[ "gpio7" ] -# These pins are exported with the Device Tree Overlay cape-universaln (default) +# Device Tree Overlay cape-universaln (default) before the v.4.14 kernel +#const pwm_pins = Dict( +# "P9.22" => ("PWM0A", "pwmchip0", "0"), +# "P9.21" => ("PWM0B", "pwmchip0", "1"), +# "P9.14" => ("PWM1A", "pwmchip2", "0"), +# "P9.16" => ("PWM1B", "pwmchip2", "1"), +# "P8.19" => ("PWM2A", "pwmchip4", "0"), +# "P8.13" => ("PWM2B", "pwmchip4", "1"), +#) +# After and including the 4.14 kernel const pwm_pins = Dict( - "P9.22" => ("PWM0A", "pwmchip0", "0"), - "P9.21" => ("PWM0B", "pwmchip0", "1"), - "P9.14" => ("PWM1A", "pwmchip2", "0"), - "P9.16" => ("PWM1B", "pwmchip2", "1"), - "P8.19" => ("PWM2A", "pwmchip4", "0"), - "P8.13" => ("PWM2B", "pwmchip4", "1"), + "P9.22" => ("1", "pwmchip1", "0"), # PWM0A + "P9.21" => ("1", "pwmchip1", "1"), # PWM0B + "P9.14" => ("4", "pwmchip4", "0"), # PWM1A + "P9.16" => ("4", "pwmchip4", "1"), # PWM1B + "P8.19" => ("7", "pwmchip7", "0"), # PWM2A + "P8.13" => ("7", "pwmchip7", "1"), # PWM2B ) # These pins are exported with the Device Tree Overlay cape-universala diff --git a/src/BeagleBone/PWM.jl b/src/BeagleBone/PWM.jl index 33fa9c4..1e91d9a 100644 --- a/src/BeagleBone/PWM.jl +++ b/src/BeagleBone/PWM.jl @@ -1,11 +1,24 @@ """ PWM(i::Int32) This device allows for low level PWM control of selected pins. The valid pins -dictionary pwm_pins relates to memory adresses in of the AM3359 chip, see p.182 +dictionary pwm_pins relates to memory adresses in of the AM3359 chip, see p.184 in www.ti.com/product/AM3359/technicaldocuments. + + pwm = PWM(1) + write!(pwm, (1,"1")) + write!(pwm, (2, "1000000000")) + write!(pwm, (3, "800000000")) + +The operation of reading the current output value of the GPIO is done by + + read(pwm, 1) + read(pwm, 2) + read(pwm, 3) + +See the test/BeagleBone/GPIO_test.jl for more examples. """ -type PWM <: IO_Object +struct PWM <: IO_Object i::Int32 pin::String chip::String @@ -20,13 +33,14 @@ type PWM <: IO_Object # Setup filestreams pins = collect(keys(pwm_pins)) - pin = pins[i] + pin = pins[i] chip = pwm_pins[pin][2] + location = "$(basedir)/$(pwm_pins[pin][2])/pwm-$(pwm_pins[pin][1]):$(pwm_pins[pin][3])" - enable_filestream = open("$(basedir)/$(pwm_pins[pin][2])/pwm$(pwm_pins[pin][3])/enable","r+") - period_filestream = open("$(basedir)/$(pwm_pins[pin][2])/pwm$(pwm_pins[pin][3])/period","r+") - duty_cycle_filestream = open("$(basedir)/$(pwm_pins[pin][2])/pwm$(pwm_pins[pin][3])/duty_cycle","r+") - polarity_filestream = open("$(basedir)/$(pwm_pins[pin][2])/pwm$(pwm_pins[pin][3])/polarity","r+") + enable_filestream = open("$(location)/enable","r+") + period_filestream = open("$(location)/period","r+") + duty_cycle_filestream = open("$(location)/duty_cycle","r+") + polarity_filestream = open("$(location)/polarity","r+") return new(i, pin, chip, basedir, [enable_filestream, period_filestream, duty_cycle_filestream, polarity_filestream]) end end @@ -37,17 +51,17 @@ Writes an entry to an operation on the PWM, of the form args = (operation, entry """ function write!(pwm::PWM, args::Tuple{Int32,String}, debug::Bool=false) debug && return - operation, entry = args[1], args[2] - (operation < 1 || operation > length(pwm.filestreams)) && error("Invalid PWM operation: $operation") - # Input data check - assert_pwm_write(operation, entry) + operation ∉ [1,2,3,4] && error("Invalid PWM operation $operation for writing") - # Write to file - seekstart(pwm.filestreams[operation]) - write(pwm.filestreams[operation], "$entry\n") - flush(pwm.filestreams[operation]) + if assert_pwm_write(operation, entry) + seekstart(pwm.filestreams[operation]) + write(pwm.filestreams[operation], "$entry\n") + #flush(pwm.filestreams[operation]) + else + error("Invalid entry for PWM operation $(operation): $(entry)") + end end """ @@ -55,34 +69,31 @@ end Assertsion for the PWM input data. """ function assert_pwm_write(operation::Int32, entry::String) - if operation == "1" - entry ∉ ["0", "1"] && error("Invalid SysLED entry $(entry), valid options are 0 and 1 ::String") + if operation == 1 + entry in ["0", "1"] || error("Invalid PWM entry $(entry), valid options are 0 and 1 of type ::String") else number = try parse(Int32, entry) catch error("Invalid SysLED entry $(entry), cannot parse as Int32") end - (number < 0 || number > 100000000) && error("Invalid SysLED entry $(entry), not in the range [0,100000000]") + !(number < 0 || number > 1000000000) || error("Invalid PWM entry $(entry), not in the range [0,1000000000]") end end """ l = read(pwm::PWM, operation::Int32, debug::Bool=false) -Reads the current value from an operation on a GPIO. +Reads the current value from an operation on a PWM pin. """ function read(pwm::PWM, operation::Int32, debug::Bool=false) debug && return # Filestreams 1, 2 and 3 are readable - operation ∉ [1,2,3,4] && error("Invalid GPIO operation: $operation for reading") + operation ∉ [1,2,3,4] && error("Invalid PWM operation: $operation for reading") seekstart(pwm.filestreams[operation]) l = readline(pwm.filestreams[operation]) return l end - - - """ teardown!(pwd::PWM) Closes all open streams on the PWM, and unexports it from the file system @@ -95,12 +106,13 @@ 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) catch - error("Could not remove the requested GPIO testfiles for channel $(pwm_pins[pwm.pin][2])/pwm$(pwm_pins[pwm.pin][3]).") + error("Could not remove the requested PWM testfiles for channel $(pwm_pins[pwm.pin][2])/pwm$(pwm_pins[pwm.pin][3]).") end else #Unexport filestructure @@ -111,8 +123,8 @@ function teardown(pwm::PWM, debug::Bool=false) end """ - export_gpio(i::Int32, debug::Bool=false) -Export the GPIO file system, either for real-time or testing usecases. + export_pwm(i::Int32, debug::Bool=false) +Export the PWM file system, either for real-time or testing usecases. """ function export_pwm(i::Int32) # Find chip and export number @@ -120,7 +132,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])" @@ -135,7 +148,7 @@ function export_pwm(i::Int32) f = open("$(complete_path)/duty_cycle", "w"); write(f,"0"); close(f); f = open("$(complete_path)/polarity", "w"); write(f,"0"); close(f); catch - error("Could not open the requested GPIO testfiles for $(complete_path).") + error("Could not open the requested PWM testfiles for $(complete_path).") end else basedir = "/sys/class/pwm" @@ -145,6 +158,7 @@ function export_pwm(i::Int32) # Export the filestructure of the corresponding chip filename = "/sys/class/pwm/$(chip)/export" + println(filename) exportNumber = pwm_pins[pin][3] write(filename, exportNumber) end @@ -153,7 +167,7 @@ end """ to_string(pwm::PWM,, debug::Bool=false) -Generates a string representation of the GPIO device. +Generates a string representation of the PWM pin. """ function to_string(pwm::PWM, debug::Bool=false) debug && return diff --git a/src/BeagleBone/SysLED.jl b/src/BeagleBone/SysLED.jl index 03cca51..5f06999 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 @@ -31,6 +31,11 @@ function write!(led::SysLED, entry::String, debug::Bool=false) flush(led.filestream) end +# Catch Boolean writes +write!(led::SysLED, entry::Bool, debug::Bool=false) = + write!(led::SysLED, entry ? "1" : "0", debug) + + """ l = read(led::SysLED, debug::Bool=false) Reads the current brightness value from the LED 'SysLED'. @@ -49,7 +54,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 +73,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 72fac56..55842b4 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/BeagleBone/precompile.jl b/src/BeagleBone/precompile.jl index 77862a6..93ac201 100644 --- a/src/BeagleBone/precompile.jl +++ b/src/BeagleBone/precompile.jl @@ -8,39 +8,52 @@ function precompile_bb() #Precompile serialize initdev("debug", Int32(1)) - 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))) - + serialize(clientside, (WRITE, Int32(2), ("debug", Int32(1), true), ("debug", Int32(1), (1,2.0,"asd")))) + serialize(clientside, (WRITE, Int32(2), ("debug", Int32(1), Int32(1)), ("debug", Int32(1), 1.0))) + serialize(clientside, (READ, Int32(2), ("debug", Int32(1)), ("debug", Int32(1)))) + + serialize(clientside, (WRITE, Int32(1), ("debug", Int32(1), true))) + serialize(clientside, (READ, Int32(1), ("debug", Int32(1)))) + initdev("debug", Int32(2)) + initdev("debug", Int32(3)) + initdev("debug", Int32(4)) + serialize(clientside, (WRITE, Int32(4), ("debug", Int32(1), true), ("debug", Int32(2), false), ("debug", Int32(3), true), ("debug", Int32(4), false))) + + closedev("debug", Int32(1)) + closedev("debug", Int32(2)) + closedev("debug", Int32(3)) + closedev("debug", Int32(4)) + + println("closing clientside") # Close the client side close(clientside) + println("closing server") #Close server close(server) debug = true - + println("initdev") #Precompile SysLED led = initdev("sysled",Int32(1)) write!(led, "1", debug) read(led, debug) + println("closedev") + closedev("sysled", Int32(1)) ind = 1 println("False: $(ind ∉ [1,2,3,4])") # Precompile GPIO gpio = initdev("gpio",Int32(1)) - write!(gpio, (Int32(1), "1"), debug) + closedev("gpio", Int32(1)) #read(gpio, ind, args, debug) - # Precompile PWM - pwm = initdev("pwm", Int32(1)) - write!(pwm, (Int32(1),"1"), debug) + # TODO activate when pwn is working + pwm = initdev("pwm",Int32(1)) + write!(pwm, (Int32(1), "1"), debug) + closedev("pwm", Int32(1)) #Do read/write to file val = true diff --git a/src/BeagleBone/startup/juliaserver.service b/src/BeagleBone/startup/juliaserver.service index 27861b3..aa7d285 100644 --- a/src/BeagleBone/startup/juliaserver.service +++ b/src/BeagleBone/startup/juliaserver.service @@ -2,7 +2,7 @@ Description=JuliaServer service [Service] -ExecStart=/home/debian/julia/bin/julia -i -e 'include("/home/debian/juliapackages/LabConnections/src/BeagleBone/startup/startup.jl")' & +ExecStart=/usr/bin/screen -Dm /home/debian/julia/bin/julia -i -e 'include("/home/debian/juliapackages/LabConnections/src/BeagleBone/startup/startup.jl")' & [Install] WantedBy=multi-user.target diff --git a/src/Computer/10V.jl b/src/Computer/10V.jl index 4c84a49..ae2e982 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/Computer/AbstractDevice.jl b/src/Computer/AbstractDevice.jl index f5c5552..c88a2b0 100644 --- a/src/Computer/AbstractDevice.jl +++ b/src/Computer/AbstractDevice.jl @@ -10,6 +10,8 @@ getstream(dev::AbstractDevice) = dev.stream #Set the stream the AbstractDevice is connected to setstream!(dev::AbstractDevice, stream::LabStream) = dev.stream = stream +# Write command that needs to be sent after setup (for example direction of GPIO) +getsetupwrite(::LabStream, ::AbstractDevice) = nothing function safe_getwritecommand(dev::AbstractDevice, val) stream = try getstream(dev) catch diff --git a/src/Computer/BeagleBoneStream.jl b/src/Computer/BeagleBoneStream.jl index d046000..4ec6a38 100644 --- a/src/Computer/BeagleBoneStream.jl +++ b/src/Computer/BeagleBoneStream.jl @@ -1,5 +1,9 @@ export BeagleBoneStream, init_devices! +const BB_READ = Int32(0) +const BB_WRITE = Int32(1) +const BB_INIT = Int32(2) + struct BeagleBoneStream <: LabStream devices::Array{AbstractDevice,1} sendbuffer::Array{Tuple,1} @@ -21,8 +25,22 @@ function init_devices!(bbstream::BeagleBoneStream, devs::AbstractDevice...) setstream!(dev, bbstream) push!(bbstream.devices, dev) initialize(dev) + # Send to beaglebone 2: initialize, 1 device, (name, index) + # TODO create proper functionality to initialize + readcmd = getreadcommand(bbstream, dev) + name = readcmd[1]::String + idx = readcmd[2]::Integer + serialize(bbstream.stream, (BB_INIT, Int32(1), (name, Int32(idx)))) + + setupwrite = getsetupwrite(bbstream, dev) + if setupwrite !== nothing + name = setupwrite[1]::String + idx = setupwrite[2]::Integer + commands = setupwrite[3]::Tuple + serialize(bbstream.stream, (BB_WRITE, Int32(1), (name, Int32(idx), commands))) + end else - warn("Device $dev already added to a stream") + @warn "Device $dev already added to a stream" end end return @@ -30,14 +48,14 @@ end function send(bbstream::BeagleBoneStream) ncmds = length(bbstream.sendbuffer) - serialize(bbstream.stream, (true, Int32(ncmds), bbstream.sendbuffer...)) + serialize(bbstream.stream, (BB_WRITE, Int32(ncmds), bbstream.sendbuffer...)) empty!(bbstream.sendbuffer) return end #TODO know the types of outputs some way function read(bbstream::BeagleBoneStream) ncmds = length(bbstream.readbuffer) - serialize(bbstream.stream, (false, Int32(ncmds), bbstream.readbuffer...)) + serialize(bbstream.stream, (BB_READ, Int32(ncmds), bbstream.readbuffer...)) empty!(bbstream.readbuffer) vals, timestamps = deserialize(bbstream.stream) length(vals) == ncmds || error("Wrong number of return values in $vals on request $(bbstream.readbuffer)") @@ -47,13 +65,13 @@ end #The following are for interal use only function send(bbstream::BeagleBoneStream, cmd) - allcmds = (true, Int32(1), cmd) + allcmds = (BB_WRITE, Int32(1), cmd) println("Sending single command: $allcmds") serialize(bbstream.stream, allcmds) return end function read(bbstream::BeagleBoneStream, cmd) - allcmds = (false, Int32(1), cmd) + allcmds = (BB_READ, Int32(1), cmd) println("Sending single command: $allcmds") serialize(bbstream.stream, allcmds) vals, timestamps = deserialize(bbstream.stream) @@ -61,12 +79,3 @@ function read(bbstream::BeagleBoneStream, cmd) #TODO Do something with timestamps return vals[1], timestamps[1] end - -function close(bbstream::BeagleBoneStream) - cmds = Tuple[] - for dev in bbstream.devices - close(dev) - end - close(bbstream.stream) - return -end diff --git a/src/Computer/ComediStream.jl b/src/Computer/ComediStream.jl index c2cddda..f3ac457 100644 --- a/src/Computer/ComediStream.jl +++ b/src/Computer/ComediStream.jl @@ -23,7 +23,7 @@ function init_devices!(comedistream::ComediStream, devs::AbstractDevice...) push!(comedistream.devices, dev) initialize(dev) else - warn("Device $dev already added to the stream") + @warn "Device $dev already added to the stream" end end return diff --git a/src/Computer/Computer.jl b/src/Computer/Computer.jl index 19e6ab5..1a803e4 100644 --- a/src/Computer/Computer.jl +++ b/src/Computer/Computer.jl @@ -34,4 +34,5 @@ include("BeagleBoneStream.jl") #Include the device definitions include("SysLED.jl") +include("GPIO.jl") include("10V.jl") diff --git a/src/Computer/GPIO.jl b/src/Computer/GPIO.jl new file mode 100644 index 0000000..30a2216 --- /dev/null +++ b/src/Computer/GPIO.jl @@ -0,0 +1,39 @@ +export GPIO + +const GPIO_VALUE = Int32(1) +const GPIO_DIRECTION = Int32(2) +const GPIO_EDGE = Int32(3) +""" +GPIO(i::Integer, direction:Bool) +direction = true if output (write) +direction = false if input (read) + +""" +mutable struct GPIO <: AbstractDevice + i::Int32 + direction::Bool + stream::LabStream + GPIO(i::Int32, direction::Bool) = new(i, direction) +end +GPIO(i::Integer, direction::Bool) = GPIO(convert(Int32, i), direction) + +function getsetupwrite(stream::BeagleBoneStream, gpio::GPIO) + if gpio.direction + return ("gpio", gpio.i, (GPIO_DIRECTION, "out")) + else + return ("gpio", gpio.i, (GPIO_DIRECTION, "in")) + end +end + +#Stream specific methods +function getwritecommand(stream::BeagleBoneStream, gpio::GPIO, val::Bool) + if !gpio.direction + error("Can not write to GPIO input (read) device") + end + # TODO Check valid GPIO index + return ("gpio", gpio.i, (GPIO_VALUE, val ? "1" : "0")) +end +function getreadcommand(stream::BeagleBoneStream, gpio::GPIO) + # TODO Check valid GPIO index + return ("gpio", gpio.i) +end diff --git a/src/LabConnections.jl b/src/LabConnections.jl index 0b63148..10e9c6b 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 07ca2d5..ad0d118 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 7a61d00..18bf4a2 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 @@ -59,13 +59,13 @@ using Base.Test @test_throws ErrorException write!(device, (Int32(1), "-1")) @test_throws ErrorException write!(device, (Int32(1), "bad_entry")) @test_throws ErrorException write!(device, (Int32(2), "-1")) - @test_throws ErrorException write!(device, (Int32(2), "100000001")) + @test_throws ErrorException write!(device, (Int32(2), "1000000001")) @test_throws ErrorException write!(device, (Int32(2), "bad_entry")) @test_throws ErrorException write!(device, (Int32(3), "-1")) - @test_throws ErrorException write!(device, (Int32(3), "100000001")) + @test_throws ErrorException write!(device, (Int32(3), "1000000001")) @test_throws ErrorException write!(device, (Int32(3), "bad_entry")) @test_throws ErrorException write!(device, (Int32(4), "-1")) - @test_throws ErrorException write!(device, (Int32(4), "100000001")) + @test_throws ErrorException write!(device, (Int32(4), "1000000001")) @test_throws ErrorException write!(device, (Int32(4), "bad_entry")) # Close Gpio @@ -81,8 +81,8 @@ using Base.Test for ii = 1:length(pwm_pins) device = initdev("pwm", Int32(ii)) # Operation 2 -> in/out, set out - write!(device, (Int32(2), "100000000")) - @test read(device, Int32(2)) == "100000000" + write!(device, (Int32(2), "1000000000")) + @test read(device, Int32(2)) == "1000000000" write!(device, (Int32(3), "50000000")) @test read(device, Int32(3)) == "50000000" write!(device, (Int32(1), "1")) diff --git a/test/BeagleBone/SYS_LED_test.jl b/test/BeagleBone/SYS_LED_test.jl index d513ddf..fb3ed90 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 66269cc..cdeb529 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 f0499b3..078ae46 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 deleted file mode 100644 index 9344e0b..0000000 --- a/test/testConenction.jl +++ /dev/null @@ -1,38 +0,0 @@ -#BB side -function startbb() - @async begin - server = listen(2001) - while true - sock = accept(server) - println("accepted") - @async while isopen(sock) - l = deserialize(sock); - println(typeof(l)) - #print("Read: "); - println(l); - serialize(sock,l) - end - end - end -end - -#Computer side -clientside = connect(ip"192.168.7.2", 2001) -function getminor(t) - println(Int64(t)) - t2 = UInt64(floor(UInt64,t/1e9)*1e9) - tsmall = Int32(t-t2) -end - -function runcomp(clientside) - @async while isopen(clientside) - l = deserialize(clientside)::Int32; - #print("Read:"); - t = time_ns() - #println(t) - t2 = getminor(t) - println((t2-l)/1e6) - end -end -serialize(clientside, getminor(time_ns())) -end # module diff --git a/util/copy_BB.sh b/util/copy_BB.sh deleted file mode 100755 index 7e6de24..0000000 --- a/util/copy_BB.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -#Run in this file un util folder, copies to BB -BLUE='\033[0;34m' -GREEN='\033[0;32m' -RED='\033[0;31m' -NC='\033[0m' -BASEDIR=../$(dirname "$0") - -# store arguments in a special array -args=("$@") -# get number of elements -numberOfArguments=${#args[@]} -echo $ELEMENTS -# echo each element in array -# for loop -#for (( i=0;i<$ELEMENTS;i++)); do -# echo ${args[${i}]} -#done - -if [ ${#args[@]} == 0 ] -then - printf "${RED}ABORTING.${NC} No directory provided\n" -else - for (( i=0;i<$numberOfArguments;i++)); do - if [ -d $BASEDIR/${args[${i}]} ] - then - printf "${GREEN}Copying $BASEDIR/${args[${i}]} to BB${NC}\n" - scp -r $BASEDIR/${args[${i}]} debian@192.168.7.2:/home/debian/juliapackages/LabConnections/${args[${i}]} - else - printf "${RED}ABORTING.${NC} The provided directory $BASEDIR/${args[${i}]} does not exist\n" - fi - done -fi diff --git a/util/flash_BB.sh b/util/flash_BB.sh index cfb7432..867cf10 100755 --- a/util/flash_BB.sh +++ b/util/flash_BB.sh @@ -9,7 +9,7 @@ BASEDIR=../../$(dirname "$0") # Dependencies # LabConnections - main repository # serbus - a fork of a SPI communicaiton interface -packages=(LabConnections serbus) +packages=(LabConnections.jl serbus) # Create an empty directory to bundle packages if [ -d ${BASEDIR}/juliapackages ]; then @@ -29,6 +29,7 @@ for (( i=0; i<${#packages[@]}; i++ )); do flag=false } done +mv ${BASEDIR}/juliapackages/LabConnections.jl ${BASEDIR}/juliapackages/LabConnections # Transfer files if [ "$flag" = true ] ; then diff --git a/util/startup.sh b/util/startup.sh deleted file mode 100755 index f7fd68d..0000000 --- a/util/startup.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -ls -cd "LabConnections.jl/test/BeagleBone" -sudo /home/debian/julia-903644385b/bin/julia