diff options
author | Jakob Odersky <jodersky@gmail.com> | 2013-02-26 18:22:53 +0100 |
---|---|---|
committer | Jakob Odersky <jodersky@gmail.com> | 2013-02-26 18:25:07 +0100 |
commit | 20a2350f9b33a797763413509781d0686fc38fe5 (patch) | |
tree | 0ee6f84433d8eaec6f2e3a89bae026c095502b25 /scala/ace/src/main/scala/com/github/jodersky/ace/protocol/PhysicalLayer.scala | |
parent | 7923f67f3090cd5a8c7e8281f62b0beca0846bec (diff) | |
download | ace-20a2350f9b33a797763413509781d0686fc38fe5.tar.gz ace-20a2350f9b33a797763413509781d0686fc38fe5.tar.bz2 ace-20a2350f9b33a797763413509781d0686fc38fe5.zip |
simplify scala implementation
Diffstat (limited to 'scala/ace/src/main/scala/com/github/jodersky/ace/protocol/PhysicalLayer.scala')
-rw-r--r-- | scala/ace/src/main/scala/com/github/jodersky/ace/protocol/PhysicalLayer.scala | 37 |
1 files changed, 0 insertions, 37 deletions
diff --git a/scala/ace/src/main/scala/com/github/jodersky/ace/protocol/PhysicalLayer.scala b/scala/ace/src/main/scala/com/github/jodersky/ace/protocol/PhysicalLayer.scala deleted file mode 100644 index 39c2d25..0000000 --- a/scala/ace/src/main/scala/com/github/jodersky/ace/protocol/PhysicalLayer.scala +++ /dev/null @@ -1,37 +0,0 @@ -package com.github.jodersky.ace.protocol - -import scala.concurrent._ -import scala.concurrent.ExecutionContext.Implicits.global -import jssc.SerialPort -import java.io.IOException -import jssc.SerialPortEvent -import jssc.SerialPortEventListener - -class PhysicalLayer(serial: SerialPort) extends ReactiveLayer[Nothing, Array[Byte]] { - - def receive(nothing: Nothing) = throw new UnsupportedOperationException("A receive function cannot be called on the lowest layer.") - - private val listener = new SerialPortEventListener { - override def serialEvent(event: SerialPortEvent) = { - if (event.isRXCHAR()) { - val bytes = serial.readBytes - if (bytes != null) notifyHigher(bytes) - } - } - } - - - def write(data: Array[Byte]) = future { - serial.writeBytes(data) - } map { success => - if (success) data - else throw new IOException("Could not write to serial port.") - } - - def begin() = { - val mask = SerialPort.MASK_RXCHAR + SerialPort.MASK_CTS + SerialPort.MASK_DSR - serial.setEventsMask(mask) - serial.addEventListener(listener) - } - -}
\ No newline at end of file |