From 20a2350f9b33a797763413509781d0686fc38fe5 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Tue, 26 Feb 2013 18:22:53 +0100 Subject: simplify scala implementation --- .../jodersky/ace/protocol/PhysicalLayer.scala | 37 ---------------------- 1 file changed, 37 deletions(-) delete mode 100644 scala/ace/src/main/scala/com/github/jodersky/ace/protocol/PhysicalLayer.scala (limited to 'scala/ace/src/main/scala/com/github/jodersky/ace/protocol/PhysicalLayer.scala') 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 -- cgit v1.2.3