aboutsummaryrefslogtreecommitdiff
path: root/Documentation
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2015-09-09 13:35:10 +0200
committerJakob Odersky <jodersky@gmail.com>2015-09-12 22:37:15 +0200
commit66ebda90a80f7429ca34b6cce2826a6b132d77f0 (patch)
tree8078bee5ab17e255f7c3e214ae11904a9b0ff2aa /Documentation
parent9b25ed521ad6ae7c54b83e47175b5589dae255cd (diff)
downloadakka-serial-66ebda90a80f7429ca34b6cce2826a6b132d77f0.tar.gz
akka-serial-66ebda90a80f7429ca34b6cce2826a6b132d77f0.tar.bz2
akka-serial-66ebda90a80f7429ca34b6cce2826a6b132d77f0.zip
update documentation
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/README.md13
-rw-r--r--Documentation/basics.md64
-rw-r--r--Documentation/building.md52
-rw-r--r--Documentation/getting-started.md37
-rw-r--r--Documentation/watching.md28
5 files changed, 122 insertions, 72 deletions
diff --git a/Documentation/README.md b/Documentation/README.md
index 165c4bc..a046f5f 100644
--- a/Documentation/README.md
+++ b/Documentation/README.md
@@ -1,12 +1,11 @@
-# Contents
+# Usage
-1. Usage
+1. [Getting Started](getting-started.md)
- 1. [Basics - initial concepts and communication protocol](basics.md) (Read this if you are new to flow)
+2. [Initial Concepts and Communication Protocol](basics.md)
- 2. [Watching for new ports](watching.md)
+3. [Watching Ports](watching.md)
-2. Developer's Guide
-
- 1. [Building from source](building.md)
+# Developer's Guide
+1. [Building from Source](building.md)
diff --git a/Documentation/basics.md b/Documentation/basics.md
index f18b62a..764b310 100644
--- a/Documentation/basics.md
+++ b/Documentation/basics.md
@@ -1,20 +1,24 @@
-# Introduction
-The following is a general guide on the usage of flow. If you prefer a complete example, check out the code contained in the flow-samples directory.
+# Communication Protocol
+The following is a general guide on the usage of flow. If you prefer a complete example, check out the code contained in the `flow-samples` directory.
-Flow's API follows that of an actor based system, where each actor is assigned specific functions involved in serial communication. The two main actor types are the serial "manager" and serial "operators".
+Flow's API follows that of an actor based system, where each actor is assigned specific functions involved in serial communication. The two main actor types are:
-The manager is a singleton actor that is instantiated once per actor system, a reference to it may be obtained with `IO(Serial)`. It is typically used to open serial ports (see following section).
+1. Serial "manager". The manager is a singleton actor that is instantiated once per actor system, a reference to it may be obtained with `IO(Serial)`. It is typically used to open serial ports (see following section).
-Serial operators are created once per open serial port and serve as an intermediate between client code and native code dealing with serial data transmission and reception. They isolate the user from threading issues and enable the reactive dispatch of incoming data. A serial operator is said to be "associated" to its underlying open serial port.
+2. Serial "operators". Operators are created once per open serial port and serve as an intermediate between client code and native code dealing with serial data transmission and reception. They isolate the user from threading issues and enable the reactive dispatch of incoming data. A serial operator is said to be "associated" to its underlying open serial port.
The messages understood by flow's actors are all contained in the `com.github.jodersky.flow.Serial` object. They are well documented and should serve as the entry point when searching the API documentation.
-#Opening a port
+## Opening a Port
A serial port is opened by sending an `Open` message to the serial manager. The response varies on the outcome of opening the underlying serial port.
- 1. In case of failure, the serial manager will respond with a `CommandFailed` message to the original sender. The message contains details on the reason to why the opening failed.
- 2. In case of success, the sender is notified with an `Opened` message. This message is sent from an operator actor, spawned by the serial manager. It is useful to capture the sender (=operator) of this message as all further communication with the newly opened port must pass through the operator.
-
+
+1. In case of failure, the serial manager will respond with a `CommandFailed` message to the original sender. The message contains details on the reason to why the opening failed.
+
+2. In case of success, the sender is notified with an `Opened` message. This message is sent from an operator actor, spawned by the serial manager. It is useful to capture the sender (i.e. the operator) of this message as all further communication with the newly opened port must pass through the operator.
+
```scala
+import com.github.jodersky.flow.{ Serial, SerialSettings, AccessDeniedException }
+
val port = "/dev/ttyXXX"
val settings = SerialSettings(
baud = 115200,
@@ -26,53 +30,49 @@ val settings = SerialSettings(
IO(Serial) ! Serial.Open(port, settings)
def receive = {
- case CommandFailed(cmd: Open, reason: AccessDeniedException) =>
- println("you're not allowed to open that port!")
- case CommandFailed(cmd: Open, reason) =>
- println("could not open port for some other reason: " + reason.getMessage)
- case Opened(settings) => {
+ case Serial.CommandFailed(cmd: Serial.Open, reason: AccessDeniedException) =>
+ println("You're not allowed to open that port!")
+ case Serial.CommandFailed(cmd: Serial.Open, reason) =>
+ println("Could not open port for some other reason: " + reason.getMessage)
+ case Serial.Opened(settings) => {
val operator = sender
//do stuff with the operator, e.g. context become opened(op)
}
}
```
-
-
-# Communicating
-## Writing data
-Writing data is as simple as sending a `Write` message containing data to an operator. The type of data is an instance of `akka.util.ByteString`:
+## Writing Data
+Writing data is as simple as sending a `Write` message to an operator. The data to send is an instance of `akka.util.ByteString`:
+
```scala
-operator ! Write(data)
+operator ! Serial.Write(data)
```
-To receive an acknowledgement when data has been sent (this means queued in the kernel buffer; no guarantees can be made on the actual transmission of the data), the sender may add an additional `ack` parameter to a `Write` message. The `ack` parameter is of type `Int => Serial.Event`, i.e. a function that takes the number of actual bytes written and returns an event.
+Optionally, an acknowledgement for sent data can be requested by adding an `ack` parameter to a `Write` message. The `ack` parameter is of type `Int => Serial.Event`, i.e. a function that takes the number of actual bytes written and returns an event. Note that "bytes written" refers to bytes enqueued in a kernel buffer; no guarantees can be made on the actual transmission of the data.
```scala
case class MyPacketAck(wrote: Int) extends Serial.Event
-operator ! Write(data, MyPacketAck(_))
-operator ! Write(data, MyPacketAck(_))
-operator ! Write(data, n => MyPacketAck(n))
+operator ! Serial.Write(data, MyPacketAck(_))
+operator ! Serial.Write(data, n => MyPacketAck(n))
def receive = {
- case MyPacketAck(x) => println("Wrote " + x + " bytes of data")
+ case MyPacketAck(n) => println("Wrote " + n + " bytes of data")
}
```
-## Receiving data
-The actor that opened a serial port (refered to as the client), exclusively receives incomming messages from the operator. These messages are in the form of `ByteStrings` and wrapped in a `Received` object.
+## Receiving Data
+The actor that opened a serial port (referred to as the client), exclusively receives incomming messages from the operator. These messages are in the form of `akka.util.ByteString`s and wrapped in a `Received` object.
```scala
def receive = {
- case Received(data) => println("got data: " + data.toString)
+ case Serial.Received(data) => println("Received data: " + data.toString)
}
```
-
-#Closing a port
+## Closing a Port
A port is closed by sending a `Close` message to its operator:
```scala
operator ! Serial.Close
@@ -80,9 +80,7 @@ operator ! Serial.Close
The operator will close the underlying serial port and respond with a final `Closed` message before terminating.
-# Resources and error handling
+## Resources and Error Handling
The operator has a deathwatch on the client actor that opened the port, this means that if the latter crashes, the operator closes the port and equally terminates, freeing any allocated resources.
The opposite is not true by default, i.e. if the operator crashes (this can happen for example on IO errors) it dies silently and the client is not informed. Therefore, it is recommended that the client keep a deathwatch on the operator.
-
-
diff --git a/Documentation/building.md b/Documentation/building.md
index 6283851..f198c77 100644
--- a/Documentation/building.md
+++ b/Documentation/building.md
@@ -1,26 +1,44 @@
-# Building from source
+# Building from Source
A complete build of flow involves two parts
- 1. building scala sources (the front-end)
- 2. building native sources (the back-end)
+1. Building Scala sources (the front-end), resulting in a platform independent artifact (i.e. a jar file).
-As any java or scala project, the first part results in a platform independent artifact. However, the second part yields a binary that may only be used on systems resembling the platform for which it was compiled. Both steps are independent, their only interaction being the header files generated by javah (see `sbt javah` for details), and may therefore be built in part and in any order.
+2. Building C sources (the back-end), yielding a native library that may only be used on systems resembling the platform for which it was compiled
-## Compiling and packaging java/scala sources
-Run `sbt main/packageBin` in the base directory. This simply compiles any scala and java sources as with any standard sbt project and produces a jar ready for being used.
+Both steps are independent, their only interaction being a header file generated by the JDK utility `javah` (see `sbt javah` for details), and may therefore be built in any order.
-## Compiling and linking native sources
-The back-end is managed by GNU Autotools and all relevant files are contained in 'flow-native'. The first time, run `./bootstrap`, then `./configure && make` to compile the back-end. After completing this step, native libraries for the different platforms are available to be copied and included in end-user applications or installed on the system. To copy the binaries to a local directory, run ```DESTDIR=`pwd`/<directory> make install```. To install them system-wide, simply run `make install` as an administrator.
+## Building Scala Sources
+Run `sbt flow/packageBin` in the base directory. This simply compiles Scala sources as with any standard SBT project and packages the resulting class-files in a jar.
-## Creating a fat jar
-The native binaries produced in the previous step may be bundled in a "fat" jar so that they can be included in sbt projects through its regular dependency mechanisms. In this process, sbt basically acts as a wrapper script around autotools, calling the native build process and packaging generated binaries. Running `sbt native/packageBin` in the base directory produces the fat jar in 'flow-native-sbt/target'.
+## Building Native Sources
+The back-end is managed by GNU Autotools and all relevant files are contained in `flow-native`.
-Note: an important feature of fat jars is to include binaries for several platforms. To copy binaries compiled on other platforms to the fat jar, place them in a subfolder of 'flow-native-sbt/lib_native'. The subfolder should have the name `$(os.name)-$(os.arch)`, where `os.name` and `os.arch` are the java system properties of the respective platforms.
+Several steps are involved in producing the native library:
-# Note about versioning
-A versioning quirk to be aware of is when building native sources. In this case, the project and package versions follow a sematic pattern: `M.m.p`, where
- - `M` is the major version, representing backwards incompatible changes
- - `m` is the minor version, indicating backwards compatible changes such as new feature additions
- - `p` is the patch number, representing internal modifications such as bug-fixes
+1. When compiling for the first time, initialize Autotools by running the script `./bootstrap`.
+
+2. Once initialized, `./configure && make` will build the back-end.
+
+3. The native library is now ready and can be:
+
+ - copied to a local directory: `DESTDIR=$(pwd)/<directory> make install`
+
+ - installed system-wide: `make install`
+
+ - put into a "fat" jar, useful for dependency management with SBT (see next section)
+
+### Creating a Fat Jar
+The native library produced in the previous step may be bundled into a "fat" jar so that it can be included in SBT projects through its regular dependency mechanisms. In this process, SBT basically acts as a wrapper script around Autotools, calling the native build process and packaging generated libraries. Running `sbt flow-native/packageBin` in the base directory produces the fat jar in `flow-native-sbt/target`.
+
+Note: an important feature of fat jars is to include native libraries for several platforms. To copy binaries compiled on other platforms to the fat jar, place them in a subfolder of `flow-native-sbt/lib_native`. The subfolder should have the name `$(os.name)-$(os.arch)`, where `os.name` and `os.arch` are the Java system properties of the respective platforms.
+
+### Note About Versioning
+The project and package versions follow a sematic pattern: `M.m.p`, where
+
+- `M` is the major version, representing backwards incompatible changes
+
+- `m` is the minor version, indicating backwards compatible changes such as new feature additions
+
+- `p` is the patch number, representing internal modifications such as bug-fixes
-Usually (following most linux distribution's conventions), shared libraries produced by a project `name` of version `M.m.p` are named `libname.M.m.p`. However, since when accessing shared libraries through the JVM, only the `name` can be specified and no particular version, the convention adopted by flow is to append `M` to the library name and always keep the major version at zero. E.g. `libflow.3.1.2` becomes `libflow3.0.1.2`.
+Usually (following most Linux distribution's conventions), shared libraries produced by a project `name` of version `M.m.p` are named `libname.so.M.m.p`. However, since when accessing shared libraries through the JVM, only the `name` can be specified and no particular version, the convention adopted by flow is to append `M` to the library name and always keep the major version at zero. E.g. `libflow.so.3.1.2` becomes `libflow3.so.0.1.2`.
diff --git a/Documentation/getting-started.md b/Documentation/getting-started.md
new file mode 100644
index 0000000..013388c
--- /dev/null
+++ b/Documentation/getting-started.md
@@ -0,0 +1,37 @@
+# Getting Started
+Flow uses SBT as build system. To get started, include a dependency to flow-core in your project:
+
+ libraryDependencies += "com.github.jodersky" %% "flow" % "2.2.2"
+
+## Including Native Library
+*NOTICE: flow uses native libraries to back serial communication, therefore before you can run any application depending on flow you must include flow's native library! To do so, you have two options.*
+
+### The Easy Way
+In case your OS/architecture combination is present in the table below, add a second dependency to your project:
+
+ libraryDependencies += "com.github.jodersky" % "flow-native" % "2.2.2"
+
+| OS | Architecture | Notes |
+|-------------------|-----------------------------|---------------------------------------------------------------------------------|
+| Linux | x86<br/>x86_64<br/>ARM (v7) | A user accessing a serial port will probably need to be in the `dialout` group. |
+| Mac OS X | x86_64 | |
+
+This will add a jar to your classpath containing native libraries for various platforms. At run time, the correct library for the current platform is selected, extracted and loaded. This solution enables running applications seamlessly, as if they were pure JVM applications.
+However, since the JVM does not enable full determination of the current platform (only OS and rough architecture are known), only a couple of platforms can be supported through this solution at the same time.
+
+### Maximum Portability
+Do not include the second dependency above. Instead, for every end-user application that relies on flow, manually add the native library for the current platform to the JVM's library path. This can be achieved through various ways, notably:
+
+- Per application:
+ Run your program with the command-line option ```-Djava.library.path=".:<folder containing libflow3.so>"```. E.g. ```java -Djava.library.path=".:/home/<folder containing libflow3.so>" -jar your-app.jar```
+
+- System- or user-wide:
+
+ - Copy the native library to a place that is on the default Java library path and run your application normally. Such places usually include `/usr/lib` and `/usr/local/lib`.
+
+ - Use a provided installer (currently Debian archive and Mac .pkg, available in releases)
+
+The native library can either be obtained by building flow (see section Build) or by taking a pre-compiled one, found in releases in the GitHub project. Native libraries need to be of major version 3 to work with this version of flow.
+
+
+It is recommended that you use the first option only for testing purposes or end-user applications. The second option is recomended for libraries, since it leaves more choice to the end-user.
diff --git a/Documentation/watching.md b/Documentation/watching.md
index 8735a46..3abf071 100644
--- a/Documentation/watching.md
+++ b/Documentation/watching.md
@@ -1,47 +1,45 @@
# Watching Ports
-As of version 2.2.0, flow can watch directories for new files. On most unix systems this can be used for watching for new serial ports in `/dev`.
+As of version 2.2.0, flow can watch directories for new files. On most unix systems this can be used for watching for new serial ports in `/dev/`.
Watching happens through a message-based, publish-subscribe protocol as explained in the sections below.
-## Subscribe
-A client actor may watch, i.e subscribe to notifications on, a directory by sending a `Watch` command to the serial manager.
+## Subscribing
+A client actor may watch -- i.e subscribe to notifications on -- a directory by sending a `Watch` command to the serial manager.
Should an error be encountered whilst trying to obtain the watch, the manager will respond with a `CommandFailed` message.
Otherwise, the client may be considered "subscribed" to the directory and the serial manager will thenceforth notify
the client on new files.
```scala
-IO(Serial) ! Watch(directory = "/dev", skipInitial = true)
+IO(Serial) ! Serial.Watch("/dev/")
def receive = {
- case CommandFailed(w: Watch, reason) =>
+ case Serial.CommandFailed(w: Watch, reason) =>
println(s"Cannot obtain a watch on ${w.directory}: ${reason.getMessage}")
}
```
-Note the second argument `skipInitial` of the watch command. This flag specifies if the client should not be notified of files already present
-during the manager's reception of the watch command.
-
## Notifications
Whilst subscribed to a directory, a client actor is informed of any new files in said directory by receiving
`Connected` messages from the manager.
```scala
def receive = {
- case Connected(port) if port matches "/dev/ttyUSB.*" =>
+ case Serial.Connected(port) if port matches "/dev/ttyUSB\\d+" =>
// do something with the available port, e.g.
// IO(Serial) ! Open(port, settings)
}
```
-## Unsubscribe
-Unsubscribing from events on a directory happens by sending an `Unsubscribe` message to the serial manager.
+## Unsubscribing
+Unsubscribing from events on a directory is done by sending an `Unsubscribe` message to the serial manager.
```scala
-IO(Serial) ! Unwatch(directory = "/dev")
+IO(Serial) ! Unwatch("/dev/")
```
-Note that the manager has a deathwatch on every subscribed client. Hence should a client die, underlying resources will be freed.
+## Resource Handling
+Note that the manager has a deathwatch on every subscribed client. Hence, should a client die, any underlying resources will be freed.
-# Requirements
-Flow uses java's `WatchService`s under the hood, therefore a java runtime of at least 1.7 is required.
+## Requirements
+Flow uses Java's `WatchService`s under the hood, therefore a Java runtime of a version of at least 1.7 is required.