diff options
author | Jakob Odersky <jodersky@gmail.com> | 2013-06-30 11:56:29 +0200 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2013-06-30 11:56:29 +0200 |
commit | 94a0ee545ab71c6779f15a5192745bedddfdb4d4 (patch) | |
tree | 208ed050a4e90490dac231d42981833f8b33b092 /samples | |
parent | 719978035732a55261b753bbc33570d3c1f53785 (diff) | |
download | akka-serial-94a0ee545ab71c6779f15a5192745bedddfdb4d4.tar.gz akka-serial-94a0ee545ab71c6779f15a5192745bedddfdb4d4.tar.bz2 akka-serial-94a0ee545ab71c6779f15a5192745bedddfdb4d4.zip |
solve cyclic dependency issue
Diffstat (limited to 'samples')
-rw-r--r-- | samples/arduino/README | 1 | ||||
-rw-r--r-- | samples/rwc/README | 1 | ||||
-rw-r--r-- | samples/rwc/src/main/scala/com/github/jodersky/flow/example/Main.scala | 37 | ||||
-rw-r--r-- | samples/rwc/src/main/scala/com/github/jodersky/flow/example/SerialHandler.scala | 55 |
4 files changed, 0 insertions, 94 deletions
diff --git a/samples/arduino/README b/samples/arduino/README deleted file mode 100644 index 64c8a5c..0000000 --- a/samples/arduino/README +++ /dev/null @@ -1 +0,0 @@ -Code to run on an arduino for serial communication testing. diff --git a/samples/rwc/README b/samples/rwc/README deleted file mode 100644 index 843e38d..0000000 --- a/samples/rwc/README +++ /dev/null @@ -1 +0,0 @@ -This sample tests a read(loop)-write-close procedure. diff --git a/samples/rwc/src/main/scala/com/github/jodersky/flow/example/Main.scala b/samples/rwc/src/main/scala/com/github/jodersky/flow/example/Main.scala deleted file mode 100644 index 518efc2..0000000 --- a/samples/rwc/src/main/scala/com/github/jodersky/flow/example/Main.scala +++ /dev/null @@ -1,37 +0,0 @@ -package com.github.jodersky.flow -package example - -import akka.actor.ActorSystem -import akka.actor.Props -import akka.actor.actorRef2Scala -import akka.util.ByteString - -object Main { - - def main(args: Array[String]): Unit = { - - /*val isInt = Try(args(1).toInt) match { case Success(_) => true; case _ => false } - if (!(args.length == 2 && isInt)) { - println("invalid parameters") - println("parameters: port baud") - println("example: /dev/ttyACM0 115200") - return - }*/ - val port = "/dev/ttyACM0" - val baud = 115200 - - // InternalSerial.debug(true) - - implicit val system = ActorSystem("flow") - val serial = system.actorOf(Props(classOf[SerialHandler], port, baud), name = "serial-handler") - - readLine() - serial ! ByteString("hello back".getBytes()) - - readLine() - serial ! "close" - readLine() - - system.shutdown() - } -}
\ No newline at end of file diff --git a/samples/rwc/src/main/scala/com/github/jodersky/flow/example/SerialHandler.scala b/samples/rwc/src/main/scala/com/github/jodersky/flow/example/SerialHandler.scala deleted file mode 100644 index e616763..0000000 --- a/samples/rwc/src/main/scala/com/github/jodersky/flow/example/SerialHandler.scala +++ /dev/null @@ -1,55 +0,0 @@ -package com.github.jodersky.flow.example - -import com.github.jodersky.flow.Serial._ -import akka.actor.Actor -import akka.actor.ActorLogging -import akka.actor.ActorRef -import akka.util.ByteString -import akka.io.IO -import com.github.jodersky.flow.Serial -import akka.actor.Terminated - -class SerialHandler(port: String, baud: Int) extends Actor with ActorLogging { - import context._ - - log.info(s"Requesting manager to open port: ${port}, baud: ${baud}") - IO(Serial) ! Serial.Open(self, port, baud) - - def receive = { - - case OpenFailed(_, reason) => { - log.error(s"Connection failed, stopping handler. Reason: ${reason}") - context stop self - } - - case Opened(port) => { - log.info(s"Port ${port} is now open.") - context become opened(sender) - } - } - - def opened(operator: ActorRef): Receive = { - - case Received(data) => { - log.info("Received data: " + formatData(data)) - log.info("As string: " + new String(data.toArray, "UTF-8")) - } - case Wrote(data) => log.info("Got ACK for writing data: " + formatData(data)) - case Closed(None) => { - log.info("Operator closed normally, exiting handler.") - context stop self - } - case Closed(Some(ex)) => { - log.info("Operator crashed, exiting handler.") - context stop self - } - case "close" => { - log.info("Initiating close.") - operator ! Close - } - case data: ByteString => operator ! Write(data, true) - } - - private def formatData(data: ByteString) = data.mkString("[", ",", "]") - -}
\ No newline at end of file |