aboutsummaryrefslogtreecommitdiff
path: root/scala/rxtx/src/test/scala/com/github/jodersky/ace/rxtx/test/Main.scala
blob: 99981c00ae385b095d96415878c0f3fda86c81fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.github.jodersky.ace.rxtx.test

import com.github.jodersky.ace.Arq;
import com.github.jodersky.ace.Framer;
import com.github.jodersky.ace._
import com.github.jodersky.ace.rxtx._
import scala.concurrent.ExecutionContext.Implicits.global


object Main {
  
  def main(args: Array[String]): Unit = {
    val serial = new Serial("/dev/ttyACM0", 9600)
    val framer = new Framer
    val arq = new Arq(200)
    val app = new SimpleActionLayer((s: Seq[Int]) => println(s))
    
    serial connect framer connect arq connect app
    serial.begin()
    
    print(">")
    while (true) {
      val bytes = readLine.getBytes().map(_.toInt)
      app.send(bytes).map(sent => "[sent] " + sent).recover{case ex => "[failed] " + ex}.map{s => println(s); print(">")}
    }
    
  }
  
}