remove old io.serial

db4
Doug Coleman 2009-02-22 17:44:09 -06:00
parent edbaba2322
commit d0030ba899
17 changed files with 0 additions and 377 deletions

View File

@ -1 +0,0 @@
Doug Coleman

View File

@ -1,21 +0,0 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types assocs combinators destructors
kernel math math.bitwise math.parser sequences summary system
vocabs.loader ;
IN: io.serial
TUPLE: serial stream path baud
termios iflag oflag cflag lflag ;
ERROR: invalid-baud baud ;
M: invalid-baud summary ( invalid-baud -- string )
baud>> number>string
"Baud rate " " not supported" surround ;
HOOK: lookup-baud os ( m -- n )
HOOK: open-serial os ( serial -- stream )
{
{ [ os unix? ] [ "io.serial.unix" ] }
} cond require

View File

@ -1 +0,0 @@
Serial port library

View File

@ -1 +0,0 @@
unportable

View File

@ -1,86 +0,0 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.syntax kernel math.bitwise sequences system io.serial ;
IN: io.serial.unix
M: bsd lookup-baud ( m -- n )
dup {
0 50 75 110 134 150 200 300 600 1200 1800 2400 4800
7200 9600 14400 19200 28800 38400 57600 76800 115200
230400 460800 921600
} member? [ invalid-baud ] unless ;
: TCSANOW 0 ; inline
: TCSADRAIN 1 ; inline
: TCSAFLUSH 2 ; inline
: TCSASOFT HEX: 10 ; inline
: TCIFLUSH 1 ; inline
: TCOFLUSH 2 ; inline
: TCIOFLUSH 3 ; inline
: TCOOFF 1 ; inline
: TCOON 2 ; inline
: TCIOFF 3 ; inline
: TCION 4 ; inline
! iflags
: IGNBRK HEX: 00000001 ; inline
: BRKINT HEX: 00000002 ; inline
: IGNPAR HEX: 00000004 ; inline
: PARMRK HEX: 00000008 ; inline
: INPCK HEX: 00000010 ; inline
: ISTRIP HEX: 00000020 ; inline
: INLCR HEX: 00000040 ; inline
: IGNCR HEX: 00000080 ; inline
: ICRNL HEX: 00000100 ; inline
: IXON HEX: 00000200 ; inline
: IXOFF HEX: 00000400 ; inline
: IXANY HEX: 00000800 ; inline
: IMAXBEL HEX: 00002000 ; inline
: IUTF8 HEX: 00004000 ; inline
! oflags
: OPOST HEX: 00000001 ; inline
: ONLCR HEX: 00000002 ; inline
: OXTABS HEX: 00000004 ; inline
: ONOEOT HEX: 00000008 ; inline
! cflags
: CIGNORE HEX: 00000001 ; inline
: CSIZE HEX: 00000300 ; inline
: CS5 HEX: 00000000 ; inline
: CS6 HEX: 00000100 ; inline
: CS7 HEX: 00000200 ; inline
: CS8 HEX: 00000300 ; inline
: CSTOPB HEX: 00000400 ; inline
: CREAD HEX: 00000800 ; inline
: PARENB HEX: 00001000 ; inline
: PARODD HEX: 00002000 ; inline
: HUPCL HEX: 00004000 ; inline
: CLOCAL HEX: 00008000 ; inline
: CCTS_OFLOW HEX: 00010000 ; inline
: CRTS_IFLOW HEX: 00020000 ; inline
: CRTSCTS { CCTS_OFLOW CRTS_IFLOW } flags ; inline
: CDTR_IFLOW HEX: 00040000 ; inline
: CDSR_OFLOW HEX: 00080000 ; inline
: CCAR_OFLOW HEX: 00100000 ; inline
: MDMBUF HEX: 00100000 ; inline
! lflags
: ECHOKE HEX: 00000001 ; inline
: ECHOE HEX: 00000002 ; inline
: ECHOK HEX: 00000004 ; inline
: ECHO HEX: 00000008 ; inline
: ECHONL HEX: 00000010 ; inline
: ECHOPRT HEX: 00000020 ; inline
: ECHOCTL HEX: 00000040 ; inline
: ISIG HEX: 00000080 ; inline
: ICANON HEX: 00000100 ; inline
: ALTWERASE HEX: 00000200 ; inline
: IEXTEN HEX: 00000400 ; inline
: EXTPROC HEX: 00000800 ; inline
: TOSTOP HEX: 00400000 ; inline
: FLUSHO HEX: 00800000 ; inline
: NOKERNINFO HEX: 02000000 ; inline
: PENDIN HEX: 20000000 ; inline
: NOFLSH HEX: 80000000 ; inline

View File

@ -1 +0,0 @@
unportable

View File

@ -1,130 +0,0 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: assocs alien.syntax kernel io.serial system unix ;
IN: io.serial.unix
: TCSANOW 0 ; inline
: TCSADRAIN 1 ; inline
: TCSAFLUSH 2 ; inline
: TCIFLUSH 0 ; inline
: TCOFLUSH 1 ; inline
: TCIOFLUSH 2 ; inline
: TCOOFF 0 ; inline
: TCOON 1 ; inline
: TCIOFF 2 ; inline
: TCION 3 ; inline
! iflag
: IGNBRK OCT: 0000001 ; inline
: BRKINT OCT: 0000002 ; inline
: IGNPAR OCT: 0000004 ; inline
: PARMRK OCT: 0000010 ; inline
: INPCK OCT: 0000020 ; inline
: ISTRIP OCT: 0000040 ; inline
: INLCR OCT: 0000100 ; inline
: IGNCR OCT: 0000200 ; inline
: ICRNL OCT: 0000400 ; inline
: IUCLC OCT: 0001000 ; inline
: IXON OCT: 0002000 ; inline
: IXANY OCT: 0004000 ; inline
: IXOFF OCT: 0010000 ; inline
: IMAXBEL OCT: 0020000 ; inline
: IUTF8 OCT: 0040000 ; inline
! oflag
: OPOST OCT: 0000001 ; inline
: OLCUC OCT: 0000002 ; inline
: ONLCR OCT: 0000004 ; inline
: OCRNL OCT: 0000010 ; inline
: ONOCR OCT: 0000020 ; inline
: ONLRET OCT: 0000040 ; inline
: OFILL OCT: 0000100 ; inline
: OFDEL OCT: 0000200 ; inline
: NLDLY OCT: 0000400 ; inline
: NL0 OCT: 0000000 ; inline
: NL1 OCT: 0000400 ; inline
: CRDLY OCT: 0003000 ; inline
: CR0 OCT: 0000000 ; inline
: CR1 OCT: 0001000 ; inline
: CR2 OCT: 0002000 ; inline
: CR3 OCT: 0003000 ; inline
: TABDLY OCT: 0014000 ; inline
: TAB0 OCT: 0000000 ; inline
: TAB1 OCT: 0004000 ; inline
: TAB2 OCT: 0010000 ; inline
: TAB3 OCT: 0014000 ; inline
: BSDLY OCT: 0020000 ; inline
: BS0 OCT: 0000000 ; inline
: BS1 OCT: 0020000 ; inline
: FFDLY OCT: 0100000 ; inline
: FF0 OCT: 0000000 ; inline
: FF1 OCT: 0100000 ; inline
! cflags
: CSIZE OCT: 0000060 ; inline
: CS5 OCT: 0000000 ; inline
: CS6 OCT: 0000020 ; inline
: CS7 OCT: 0000040 ; inline
: CS8 OCT: 0000060 ; inline
: CSTOPB OCT: 0000100 ; inline
: CREAD OCT: 0000200 ; inline
: PARENB OCT: 0000400 ; inline
: PARODD OCT: 0001000 ; inline
: HUPCL OCT: 0002000 ; inline
: CLOCAL OCT: 0004000 ; inline
: CIBAUD OCT: 002003600000 ; inline
: CRTSCTS OCT: 020000000000 ; inline
! lflags
: ISIG OCT: 0000001 ; inline
: ICANON OCT: 0000002 ; inline
: XCASE OCT: 0000004 ; inline
: ECHO OCT: 0000010 ; inline
: ECHOE OCT: 0000020 ; inline
: ECHOK OCT: 0000040 ; inline
: ECHONL OCT: 0000100 ; inline
: NOFLSH OCT: 0000200 ; inline
: TOSTOP OCT: 0000400 ; inline
: ECHOCTL OCT: 0001000 ; inline
: ECHOPRT OCT: 0002000 ; inline
: ECHOKE OCT: 0004000 ; inline
: FLUSHO OCT: 0010000 ; inline
: PENDIN OCT: 0040000 ; inline
: IEXTEN OCT: 0100000 ; inline
M: linux lookup-baud ( n -- n )
dup H{
{ 0 OCT: 0000000 }
{ 50 OCT: 0000001 }
{ 75 OCT: 0000002 }
{ 110 OCT: 0000003 }
{ 134 OCT: 0000004 }
{ 150 OCT: 0000005 }
{ 200 OCT: 0000006 }
{ 300 OCT: 0000007 }
{ 600 OCT: 0000010 }
{ 1200 OCT: 0000011 }
{ 1800 OCT: 0000012 }
{ 2400 OCT: 0000013 }
{ 4800 OCT: 0000014 }
{ 9600 OCT: 0000015 }
{ 19200 OCT: 0000016 }
{ 38400 OCT: 0000017 }
{ 57600 OCT: 0010001 }
{ 115200 OCT: 0010002 }
{ 230400 OCT: 0010003 }
{ 460800 OCT: 0010004 }
{ 500000 OCT: 0010005 }
{ 576000 OCT: 0010006 }
{ 921600 OCT: 0010007 }
{ 1000000 OCT: 0010010 }
{ 1152000 OCT: 0010011 }
{ 1500000 OCT: 0010012 }
{ 2000000 OCT: 0010013 }
{ 2500000 OCT: 0010014 }
{ 3000000 OCT: 0010015 }
{ 3500000 OCT: 0010016 }
{ 4000000 OCT: 0010017 }
} at* [ nip ] [ drop invalid-baud ] if ;

View File

@ -1 +0,0 @@
unportable

View File

@ -1 +0,0 @@
unportable

View File

@ -1,19 +0,0 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.syntax kernel sequences system ;
IN: io.serial.unix.termios
: NCCS 20 ; inline
TYPEDEF: uint tcflag_t
TYPEDEF: uchar cc_t
TYPEDEF: uint speed_t
C-STRUCT: termios
{ "tcflag_t" "iflag" } ! input mode flags
{ "tcflag_t" "oflag" } ! output mode flags
{ "tcflag_t" "cflag" } ! control mode flags
{ "tcflag_t" "lflag" } ! local mode flags
{ { "cc_t" NCCS } "cc" } ! control characters
{ "speed_t" "ispeed" } ! input speed
{ "speed_t" "ospeed" } ; ! output speed

View File

@ -1 +0,0 @@
unportable

View File

@ -1,20 +0,0 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.syntax kernel system unix ;
IN: io.serial.unix.termios
: NCCS 32 ; inline
TYPEDEF: uchar cc_t
TYPEDEF: uint speed_t
TYPEDEF: uint tcflag_t
C-STRUCT: termios
{ "tcflag_t" "iflag" } ! input mode flags
{ "tcflag_t" "oflag" } ! output mode flags
{ "tcflag_t" "cflag" } ! control mode flags
{ "tcflag_t" "lflag" } ! local mode flags
{ "cc_t" "line" } ! line discipline
{ { "cc_t" NCCS } "cc" } ! control characters
{ "speed_t" "ispeed" } ! input speed
{ "speed_t" "ospeed" } ; ! output speed

View File

@ -1 +0,0 @@
unportable

View File

@ -1 +0,0 @@
unportable

View File

@ -1,9 +0,0 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: combinators system vocabs.loader ;
IN: io.serial.unix.termios
{
{ [ os linux? ] [ "io.serial.unix.termios.linux" ] }
{ [ os bsd? ] [ "io.serial.unix.termios.bsd" ] }
} cond require

View File

@ -1,21 +0,0 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel math.bitwise serial serial.unix ;
IN: io.serial.unix
: serial-obj ( -- obj )
serial new
"/dev/ttyS0" >>path
19200 >>baud
{ IGNPAR ICRNL } flags >>iflag
{ } flags >>oflag
{ CS8 CLOCAL CREAD } flags >>cflag
{ ICANON } flags >>lflag ;
: serial-test ( -- serial )
serial-obj
open-serial
dup get-termios >>termios
dup configure-termios
dup tciflush
dup apply-termios ;

View File

@ -1,62 +0,0 @@
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.syntax combinators io.ports
io.streams.duplex io.unix.backend system kernel math math.bitwise
vocabs.loader unix io.serial io.serial.unix.termios ;
IN: io.serial.unix
<< {
{ [ os linux? ] [ "io.serial.unix.linux" ] }
{ [ os bsd? ] [ "io.serial.unix.bsd" ] }
} cond require >>
FUNCTION: speed_t cfgetispeed ( termios* t ) ;
FUNCTION: speed_t cfgetospeed ( termios* t ) ;
FUNCTION: int cfsetispeed ( termios* t, speed_t s ) ;
FUNCTION: int cfsetospeed ( termios* t, speed_t s ) ;
FUNCTION: int tcgetattr ( int i1, termios* t ) ;
FUNCTION: int tcsetattr ( int i1, int i2, termios* t ) ;
FUNCTION: int tcdrain ( int i1 ) ;
FUNCTION: int tcflow ( int i1, int i2 ) ;
FUNCTION: int tcflush ( int i1, int i2 ) ;
FUNCTION: int tcsendbreak ( int i1, int i2 ) ;
FUNCTION: void cfmakeraw ( termios* t ) ;
FUNCTION: int cfsetspeed ( termios* t, speed_t s ) ;
: fd>duplex-stream ( fd -- duplex-stream )
<fd> init-fd
[ <input-port> ] [ <output-port> ] bi <duplex-stream> ;
: open-rw ( path -- fd ) O_RDWR file-mode open-file ;
: <file-rw> ( path -- stream ) open-rw fd>duplex-stream ;
M: unix open-serial ( serial -- serial' )
path>> { O_RDWR O_NOCTTY O_NDELAY } flags file-mode open-file
fd>duplex-stream ;
: serial-fd ( serial -- fd )
stream>> in>> handle>> fd>> ;
: get-termios ( serial -- termios )
serial-fd
"termios" <c-object> [ tcgetattr io-error ] keep ;
: configure-termios ( serial -- )
dup termios>>
{
[ [ iflag>> ] dip over [ set-termios-iflag ] [ 2drop ] if ]
[ [ oflag>> ] dip over [ set-termios-oflag ] [ 2drop ] if ]
[
[
[ cflag>> 0 or ] [ baud>> lookup-baud ] bi bitor
] dip set-termios-cflag
]
[ [ lflag>> ] dip over [ set-termios-lflag ] [ 2drop ] if ]
} 2cleave ;
: tciflush ( serial -- )
serial-fd TCIFLUSH tcflush io-error ;
: apply-termios ( serial -- )
[ serial-fd TCSANOW ]
[ termios>> ] bi tcsetattr io-error ;