Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Mart Lubbers
CleanSerial
Commits
3afa2bb4
Commit
3afa2bb4
authored
Jan 28, 2017
by
Mart Lubbers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change readline"
parent
71526f6a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
29 deletions
+29
-29
TTY.dcl
TTY.dcl
+1
-0
TTY.icl
TTY.icl
+13
-3
tty.c
tty.c
+15
-26
No files found.
TTY.dcl
View file @
3afa2bb4
...
...
@@ -23,6 +23,7 @@ instance zero TTYSettings
TTYclose
::
!*
TTY
!*
env
->
(!
Bool
,
!*
env
)
TTYerror
::
!*
env
->
(!
String
,
!*
env
)
TTYopen
::
!
String
!
TTYSettings
!*
env
->
(!
Bool
,!*
TTY
,!*
env
)
TTYread
::
!*
TTY
->
(!
Int
,
!*
TTY
)
TTYreadline
::
!*
TTY
->
(!
String
,
!*
TTY
)
TTYavailable
::
!*
TTY
->
(!
Bool
,
!*
TTY
)
TTYwrite
::
!
String
!*
TTY
->
*
TTY
TTY.icl
View file @
3afa2bb4
implementation
module
TTY
import
_SystemArray
import
StdClass
import
StdString
import
StdChar
import
code
from
"ctty."
...
...
@@ -50,11 +53,18 @@ TTYclose _ _ = code {
ccall
ttyclose
"I:I:A"
}
TTYread
line
::
!*
TTY
->
(!
String
,
!*
TTY
)
TTYread
line
_
=
code {
ccall
ttyread
line
"I:V
S
I"
TTYread
::
!*
TTY
->
(!
Int
,
!*
TTY
)
TTYread
_
=
code {
ccall
ttyread
"I:V
I
I"
}
TTYreadline
::
!*
TTY
->
(!
String
,
!*
TTY
)
TTYreadline
tty
=
case
TTYread
tty
of
(
10
,
tty
)
=
(
""
,
tty
)
(
c
,
tty
)
#
(
rest
,
tty
)
=
TTYreadline
tty
=
({#
toChar
c
}
+++
rest
,
tty
)
TTYwrite
::
!
String
!*
TTY
->
*
TTY
TTYwrite
_
_
=
code {
ccall
ttywrite
"SI:I"
...
...
tty.c
View file @
3afa2bb4
...
...
@@ -146,7 +146,8 @@ void ttyopen(CleanString fn, int baudrate, int bytesize, int parity,
tio
.
c_cflag
&=
~
IXON
;
//Set
tio
.
c_oflag
=
0
;
tio
.
c_lflag
|=
ICANON
;
tio
.
c_lflag
&=
~
(
ECHO
|
ECHONL
|
ICANON
|
IEXTEN
|
ISIG
);
// tio.c_lflag |= ICANON;
tio
.
c_cc
[
VMIN
]
=
5
;
tio
.
c_cc
[
VTIME
]
=
0
;
...
...
@@ -173,33 +174,17 @@ void ttyerror(CleanString *result)
debug
(
"ttyerror-done"
);
}
unsigned
long
*
readlinecl
=
NULL
;
void
ttyreadline
(
int
fd
,
CleanString
*
result
,
int
*
fdo
)
void
ttyread
(
int
fd
,
int
*
ch
,
int
*
fdo
)
{
debug
(
"ttyreadline"
);
size_t
bufsize
=
INITIAL_BUFFERSIZE
;
char
*
buf
=
NULL
;
ssize_t
cr
,
charsread
=
0
;
while
(
buf
==
NULL
||
buf
[
charsread
-
1
]
!=
'\n'
){
if
((
buf
=
realloc
(
buf
,
(
bufsize
*=
2
)
+
1
))
==
NULL
)
die
(
"realloc"
);
if
((
cr
=
read
(
fd
,
buf
+
charsread
,
bufsize
-
charsread
))
<
0
)
die
(
"read"
);
charsread
+=
cr
;
debug
(
"ttyread"
);
unsigned
int
c
;
if
(
read
(
fd
,
&
c
,
1
)
==
-
1
){
die
(
"read"
);
}
buf
[
charsread
]
=
'\0'
;
if
(
readlinecl
!=
NULL
)
free
(
readlinecl
);
readlinecl
=
my_malloc
(
sizeof
(
unsigned
long
)
*
CleanStringSizeInts
(
charsread
));
*
result
=
(
CleanString
)
readlinecl
;
memcpy
(
CleanStringCharacters
(
readlinecl
),
buf
,
charsread
);
CleanStringLength
(
readlinecl
)
=
charsread
;
printf
(
"read: %o
\n
"
,
c
);
*
ch
=
(
int
)
c
;
*
fdo
=
fd
;
free
(
buf
);
debug
(
"ttyreadline-done"
);
debug
(
"ttyread done"
);
}
void
ttyavailable
(
int
fd
,
int
*
r
,
int
*
fdo
)
...
...
@@ -223,7 +208,11 @@ void ttyavailable(int fd, int *r, int *fdo)
int
ttywrite
(
CleanString
s
,
int
fd
)
{
debug
(
"ttywrite"
);
write
(
fd
,
CleanStringCharacters
(
s
),
CleanStringLength
(
s
));
for
(
int
i
=
0
;
i
<
CleanStringLength
(
s
);
i
++
){
unsigned
char
c
=
((
unsigned
char
*
)
CleanStringCharacters
(
s
))[
i
];
printf
(
"%02x(%u) "
,
c
,
c
);
}
write
(
fd
,
(
void
*
)
CleanStringCharacters
(
s
),
CleanStringLength
(
s
));
tcdrain
(
fd
);
debug
(
"ttywrite-done"
);
return
fd
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment