Move io.serial.unix to io.serial.linux, add platforms files. Move termios into io.serial.linux.ffi vocab.
							parent
							
								
									bbede53f78
								
							
						
					
					
						commit
						e1c123e157
					
				| 
						 | 
					@ -1,7 +1,37 @@
 | 
				
			||||||
! Copyright (C) 2008 Doug Coleman.
 | 
					! Copyright (C) 2008 Doug Coleman.
 | 
				
			||||||
! See http://factorcode.org/license.txt for BSD license.
 | 
					! See http://factorcode.org/license.txt for BSD license.
 | 
				
			||||||
USING: assocs alien.syntax kernel io.serial system unix ;
 | 
					USING: alien.c-types alien.syntax assocs classes.struct
 | 
				
			||||||
IN: io.serial.unix
 | 
					io.serial kernel system ;
 | 
				
			||||||
 | 
					IN: io.serial.linux.ffi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CONSTANT: NCCS 32
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TYPEDEF: uchar cc_t
 | 
				
			||||||
 | 
					TYPEDEF: uint speed_t
 | 
				
			||||||
 | 
					TYPEDEF: uint tcflag_t
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					STRUCT: termios
 | 
				
			||||||
 | 
					    { iflag tcflag_t }
 | 
				
			||||||
 | 
					    { oflag tcflag_t }
 | 
				
			||||||
 | 
					    { cflag tcflag_t }
 | 
				
			||||||
 | 
					    { lflag tcflag_t }
 | 
				
			||||||
 | 
					    { line cc_t }
 | 
				
			||||||
 | 
					    { cc { cc_t NCCS } }
 | 
				
			||||||
 | 
					    { ispeed speed_t }
 | 
				
			||||||
 | 
					    { ospeed speed_t } ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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 ) ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CONSTANT: TCSANOW     0
 | 
					CONSTANT: TCSANOW     0
 | 
				
			||||||
CONSTANT: TCSADRAIN   1
 | 
					CONSTANT: TCSADRAIN   1
 | 
				
			||||||
| 
						 | 
					@ -128,3 +158,4 @@ M: linux lookup-baud ( n -- n )
 | 
				
			||||||
        { 3500000 OCT: 0010016 }
 | 
					        { 3500000 OCT: 0010016 }
 | 
				
			||||||
        { 4000000 OCT: 0010017 }
 | 
					        { 4000000 OCT: 0010017 }
 | 
				
			||||||
    } ?at [ invalid-baud ] unless ;
 | 
					    } ?at [ invalid-baud ] unless ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,28 +1,9 @@
 | 
				
			||||||
! Copyright (C) 2008 Doug Coleman.
 | 
					! Copyright (C) 2008 Doug Coleman.
 | 
				
			||||||
! See http://factorcode.org/license.txt for BSD license.
 | 
					! See http://factorcode.org/license.txt for BSD license.
 | 
				
			||||||
USING: accessors alien.c-types alien.syntax alien.data 
 | 
					USING: accessors classes.struct combinators io.backend.unix
 | 
				
			||||||
classes.struct combinators io.ports io.streams.duplex
 | 
					io.ports io.serial io.streams.duplex kernel literals math
 | 
				
			||||||
system kernel math math.bitwise vocabs io.serial
 | 
					system unix unix.ffi ;
 | 
				
			||||||
io.serial.unix.termios io.backend.unix unix unix.ffi
 | 
					IN: io.serial.linux
 | 
				
			||||||
literals ;
 | 
					 | 
				
			||||||
IN: io.serial.unix
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
<< {
 | 
					 | 
				
			||||||
    { [ os linux? ] [ "io.serial.unix.linux" ] }
 | 
					 | 
				
			||||||
} 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>duplex-stream ( fd -- duplex-stream )
 | 
				
			||||||
    <fd> init-fd
 | 
					    <fd> init-fd
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,2 @@
 | 
				
			||||||
 | 
					linux
 | 
				
			||||||
 | 
					windows
 | 
				
			||||||
| 
						 | 
					@ -31,6 +31,6 @@ M: serial-port dispose* ( serial -- ) stream>> dispose ;
 | 
				
			||||||
    [ open-serial ] dip with-duplex-stream ; inline
 | 
					    [ open-serial ] dip with-duplex-stream ; inline
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    { [ os unix? ] [ "io.serial.unix" ] } 
 | 
					    { [ os linux? ] [ "io.serial.linux" ] } 
 | 
				
			||||||
    { [ os windows? ] [ "io.serial.windows" ] }
 | 
					    { [ os windows? ] [ "io.serial.windows" ] }
 | 
				
			||||||
} cond require
 | 
					} cond require
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1 +0,0 @@
 | 
				
			||||||
unix
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,21 +0,0 @@
 | 
				
			||||||
! Copyright (C) 2008 Doug Coleman.
 | 
					 | 
				
			||||||
! See http://factorcode.org/license.txt for BSD license.
 | 
					 | 
				
			||||||
USING: alien.c-types alien.syntax classes.struct kernel system
 | 
					 | 
				
			||||||
unix ;
 | 
					 | 
				
			||||||
IN: io.serial.unix.termios
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
CONSTANT: NCCS 32
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
TYPEDEF: uchar cc_t
 | 
					 | 
				
			||||||
TYPEDEF: uint speed_t
 | 
					 | 
				
			||||||
TYPEDEF: uint tcflag_t
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
STRUCT: termios
 | 
					 | 
				
			||||||
    { iflag tcflag_t }
 | 
					 | 
				
			||||||
    { oflag tcflag_t }
 | 
					 | 
				
			||||||
    { cflag tcflag_t }
 | 
					 | 
				
			||||||
    { lflag tcflag_t }
 | 
					 | 
				
			||||||
    { line cc_t }
 | 
					 | 
				
			||||||
    { cc { cc_t NCCS } }
 | 
					 | 
				
			||||||
    { ispeed speed_t }
 | 
					 | 
				
			||||||
    { ospeed speed_t } ;
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,20 +0,0 @@
 | 
				
			||||||
! Copyright (C) 2008 Doug Coleman.
 | 
					 | 
				
			||||||
! See http://factorcode.org/license.txt for BSD license.
 | 
					 | 
				
			||||||
USING: alien.c-types alien.syntax classes.struct kernel
 | 
					 | 
				
			||||||
sequences system ;
 | 
					 | 
				
			||||||
IN: io.serial.unix.termios
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
CONSTANT: NCCS 20
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
TYPEDEF: uint tcflag_t
 | 
					 | 
				
			||||||
TYPEDEF: uchar cc_t
 | 
					 | 
				
			||||||
TYPEDEF: uint speed_t
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
STRUCT: termios
 | 
					 | 
				
			||||||
    { iflag tcflag_t }
 | 
					 | 
				
			||||||
    { oflag tcflag_t }
 | 
					 | 
				
			||||||
    { cflag tcflag_t }
 | 
					 | 
				
			||||||
    { lflag tcflag_t }
 | 
					 | 
				
			||||||
    { cc { cc_t NCCS } }
 | 
					 | 
				
			||||||
    { ispeed speed_t }
 | 
					 | 
				
			||||||
    { ospeed speed_t } ;
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1 +0,0 @@
 | 
				
			||||||
macosx
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1 +0,0 @@
 | 
				
			||||||
unix
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,9 +0,0 @@
 | 
				
			||||||
! Copyright (C) 2008 Doug Coleman.
 | 
					 | 
				
			||||||
! See http://factorcode.org/license.txt for BSD license.
 | 
					 | 
				
			||||||
USING: combinators system vocabs ;
 | 
					 | 
				
			||||||
IN: io.serial.unix.termios
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    { [ os linux? ] [ "io.serial.unix.termios.linux" ] }
 | 
					 | 
				
			||||||
    { [ os macosx? ] [ "io.serial.unix.termios.macosx" ] }
 | 
					 | 
				
			||||||
} cond require
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,15 +0,0 @@
 | 
				
			||||||
! Copyright (C) 2008 Doug Coleman.
 | 
					 | 
				
			||||||
! See http://factorcode.org/license.txt for BSD license.
 | 
					 | 
				
			||||||
USING: accessors io io.serial io.serial.unix kernel literals
 | 
					 | 
				
			||||||
math.bitwise tools.test ;
 | 
					 | 
				
			||||||
IN: io.serial.unix
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
: <serial-port-test> ( -- serial-port )
 | 
					 | 
				
			||||||
    "/dev/ttyS0" 19200 <serial-port> ;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
: with-serial-port-test ( quot -- )
 | 
					 | 
				
			||||||
    [ <serial-port-test> ] dip with-serial-port ; inline
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
! [ ] [
 | 
					 | 
				
			||||||
    ! [ "hello" over stream-write stream-flush ] with-serial-port-test
 | 
					 | 
				
			||||||
! ] unit-test
 | 
					 | 
				
			||||||
		Loading…
	
		Reference in New Issue