Skip to content

Instantly share code, notes, and snippets.

@kg4sgp
Created June 5, 2013 21:31
Show Gist options
  • Save kg4sgp/5717485 to your computer and use it in GitHub Desktop.
Save kg4sgp/5717485 to your computer and use it in GitHub Desktop.
import java.io._
object Baudot {
val ShiftToFigures = 0x1b
val ShiftToLetters = 0x1f
val figures = Map(
0.toChar -> 0x0,
' ' -> 0x4,
'1' -> 0x1d,
'2' -> 0x19,
'3' -> 0x10,
'4' -> 0xa,
'5' -> 0x1,
'6' -> 0x15,
'7' -> 0x1c,
'8' -> 0xc,
'9' -> 0x3,
'0' -> 0xd,
'-' -> 0x18,
7.toChar -> 0x14,
'$' -> 0x12,
'!' -> 0x16,
'&' -> 0xb,
'#' -> 0x5,
'\'' -> 0x1a,
'(' -> 0x1e,
')' -> 0x9,
'"' -> 0x11,
'/' -> 0x17,
':' -> 0xe,
';' -> 0xf,
'?' -> 0x13,
',' -> 0x6,
'.' -> 0x7,
'\r' -> 0x2,
'\n' -> 0x8
)
val letters = Map(
0.toChar -> 0x0,
' ' -> 0x4,
'Q' -> 0x1d,
'W' -> 0x19,
'E' -> 0x10,
'R' -> 0xa,
'T' -> 0x1,
'Y' -> 0x15,
'U' -> 0x1c,
'I' -> 0xc,
'O' -> 0x3,
'P' -> 0xd,
'A' -> 0x18,
'S' -> 0x14,
'D' -> 0x12,
'F' -> 0x16,
'G' -> 0xb,
'H' -> 0x5,
'J'' -> 0x1a,
'K' -> 0x1e,
'L' -> 0x9,
'Z' -> 0x11,
'X' -> 0x17,
'C' -> 0xe,
'V' -> 0xf,
'B' -> 0x13,
'N' -> 0x6,
'M' -> 0x7,
'\r' -> 0x2,
'\n' -> 0x8
)
}
object RTTY {
def main(args: Array[String]) {
val input = new File(args(0))
val output = new File(args(1))
require(input.exists, "The input file does not exist.")
require(output.canWrite, "The output file must be writable.")
val inputStream = new DataInputStream(new BufferedInputStream(new FileInputStream(input)))
val outputStream = new FileOutputStream(output)
try {
Iterator
.continually(inputStream.readChar)
.foreach { char =>
// ...
}
} catch {
case e: Throwable => outputStream.close()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment