Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
CleanSerial
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mart Lubbers
CleanSerial
Commits
16e7ae6d
Commit
16e7ae6d
authored
Sep 06, 2018
by
Mart Lubbers
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into 'master'
Checking for device errors on TTYAvailable See merge request
!5
parents
ce8c8653
2db8582b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
16 deletions
+37
-16
POSIX/tty.c
POSIX/tty.c
+16
-5
TTY.dcl
TTY.dcl
+8
-1
TTY.icl
TTY.icl
+2
-2
iTasksTTY.icl
iTasksTTY.icl
+10
-7
test.icl
test.icl
+1
-1
No files found.
POSIX/tty.c
View file @
16e7ae6d
...
...
@@ -190,18 +190,29 @@ void ttyread(int fd, int *ch, int *fdo)
debug
(
"ttyread done"
);
}
void
ttyavailable
(
int
fd
,
int
*
r
,
int
*
fdo
)
void
ttyavailable
(
int
fd
,
int
*
r
,
int
*
e
,
int
*
fdo
)
{
// debug("ttyavailable");
fd_set
fds
;
fd_set
rfds
,
e
fds
;
struct
timeval
tv
;
tv
.
tv_sec
=
0
;
tv
.
tv_usec
=
0
;
FD_ZERO
(
&
fds
);
FD_SET
(
fd
,
&
fds
);
FD_ZERO
(
&
rfds
);
FD_SET
(
fd
,
&
rfds
);
FD_ZERO
(
&
efds
);
FD_SET
(
fd
,
&
efds
);
*
e
=
0
;
*
r
=
select
(
fd
+
1
,
&
rfds
,
NULL
,
&
efds
,
&
tv
);
if
(
FD_ISSET
(
fd
,
&
efds
)){
*
e
=
1
;
*
fdo
=
fd
;
return
;
}
*
r
=
select
(
fd
+
1
,
&
fds
,
NULL
,
NULL
,
&
tv
);
if
(
*
r
==
-
1
)
die
(
"select"
);
*
fdo
=
fd
;
...
...
TTY.dcl
View file @
16e7ae6d
...
...
@@ -29,5 +29,12 @@ TTYerror :: !*env -> (!String, !*env)
TTYopen
::
!
TTYSettings
!*
env
->
(!
Bool
,!*
TTY
,!*
env
)
TTYread
::
!*
TTY
->
(!
Int
,
!*
TTY
)
TTYreadline
::
!*
TTY
->
(!
String
,
!*
TTY
)
TTYavailable
::
!*
TTY
->
(!
Bool
,
!*
TTY
)
/**
* Checks if the TTY device is available for reading
*
* @param The TTY Device
* @return A 3-tuple containing whether there is data available,
* whether there was an error and the TTY device
*/
TTYavailable
::
!*
TTY
->
(!
Bool
,
!
Bool
,
!*
TTY
)
TTYwrite
::
!
String
!*
TTY
->
*
TTY
TTY.icl
View file @
16e7ae6d
...
...
@@ -90,9 +90,9 @@ TTYwrite _ _ = code {
ccall
ttywrite
"SI:I"
}
TTYavailable
::
!*
TTY
->
(!
Bool
,
!*
TTY
)
TTYavailable
::
!*
TTY
->
(!
Bool
,
!
Bool
,
!
*
TTY
)
TTYavailable
_
=
code {
ccall
ttyavailable
"I:VII"
ccall
ttyavailable
"I:VII
I
"
}
TTYerror
::
!*
env
->
(!
String
,
!*
env
)
...
...
iTasksTTY.icl
View file @
16e7ae6d
...
...
@@ -72,9 +72,10 @@ where
,
{
iworld
&
resources
=[
TTYd
dp
tty
:
resources
]})
(
r
,
s
,
ss
)
#
tty
=
foldr
TTYwrite
tty
$
reverse
$
map
enc
s
#
(
newdata
,
tty
)
=
readWhileAvailable
tty
#
(
merr
,
tty
)
=
readWhileAvailable
tty
|
isError
merr
=
(
exc
(
fromError
merr
),
iworld
)
#
iworld
=
{
iworld
&
resources
=[
TTYd
dp
tty
:
iworld
.
resources
]}
=
case
dec
(
acc
+++
toString
newdata
)
of
=
case
dec
(
acc
+++
toString
(
fromOk
merr
)
)
of
(
Left
err
,
newacc
)
=
(
exc
"Error while parsing"
,
iworld
)
(
Right
msgs
,
newacc
)
#
(
merr
,
iworld
)
=
if
(
msgs
=:
[]
&&
s
=:
[])
...
...
@@ -104,10 +105,12 @@ where
getResource
=
iworldResource
(\
t
=:(
TTYd
p
_)->(
p
==
opts
.
devicePath
,
t
))
exc
=
ExceptionResult
o
exception
readWhileAvailable
::
!*
TTY
->
([
Char
],
!*
TTY
)
readWhileAvailable
::
!*
TTY
->
(
MaybeError
String
[
Char
],
!*
TTY
)
readWhileAvailable
tty
#
(
available
,
tty
)
=
TTYavailable
tty
|
not
available
=
([],
tty
)
#
(
available
,
error
,
tty
)
=
TTYavailable
tty
|
error
=
(
Error
"TTY device disconnected"
,
tty
)
|
not
available
=
(
Ok
[],
tty
)
#
(
c
,
tty
)
=
TTYread
tty
#
(
cs
,
tty
)
=
readWhileAvailable
tty
=
([
toChar
c
:
cs
],
tty
)
#
(
merr
,
tty
)
=
readWhileAvailable
tty
|
isError
merr
=
(
merr
,
tty
)
=
(
Ok
[
toChar
c
:
fromOk
merr
],
tty
)
test.icl
View file @
16e7ae6d
...
...
@@ -17,7 +17,7 @@ Start w
#
(
ok
,
tty
,
w
)
=
TTYopen
{
zero
&
devicePath
=
"/dev/ttyUSB0"
}
w
|
not
ok
=
TTYerrorclose
io
w
#!
tty
=
TTYwrite
"echo123
\n
"
tty
#!
(
av
,
tty
)
=
TTYavailable
tty
#!
(
av
,
e
,
tty
)
=
TTYavailable
tty
#
io
=
io
<<<
(
"Bytes available: "
+++
toString
av
+++
"
\n
"
)
#!
(
l
,
tty
)
=
TTYreadline
tty
#
io
=
io
<<<
(
"Line read: "
+++
l
)
...
...
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