Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
vecs
FIJI Public
Commits
969b1f3b
Commit
969b1f3b
authored
Nov 29, 2017
by
Christian Fibich
Browse files
[FIC Emulator] generate PTY if device not specified, allow replacing CONF_DONE with UNDERRUN
parent
5b147530
Changes
1
Hide whitespace changes
Inline
Side-by-side
test/fic_emulator/fic-emulator.c
View file @
969b1f3b
...
...
@@ -53,7 +53,6 @@
#include
<inttypes.h>
#include
<signal.h>
#define PATH "/dev/pts/2"
#define CEILING(x,y) (((x) + (y) - 1) / (y))
#ifndef CFG_FILE
...
...
@@ -111,7 +110,7 @@ int read_msg (int fd, uint8_t *buf) {
while
(
done
<
NUM_BYTES
)
{
int
rd
=
read
(
fd
,
buf
+
done
,
to_read
);
if
(
rd
<
0
)
{
perror
(
"read()"
);
fprintf
(
stderr
,
"read(): %d/%d %s
\n
"
,
to_read
,
NUM_BYTES
,
strerror
(
errno
)
);
return
-
1
;
}
else
if
(
rd
==
0
)
{
...
...
@@ -129,19 +128,19 @@ int read_msg (int fd, uint8_t *buf) {
return
done
;
}
void
putstatus
(
uint8_t
msg
,
uint8_t
err
,
uint8_t
underrun
,
uint8_t
*
rmsg
,
unsigned
int
nmsg
)
{
void
putstatus
(
uint8_t
msg
,
uint8_t
err
,
uint8_t
underrun
,
uint8_t
replace_conf_done
,
uint8_t
*
rmsg
,
unsigned
int
nmsg
)
{
struct
winsize
w
;
ioctl
(
0
,
TIOCGWINSZ
,
&
w
);
int
wr1
=
0
,
wr2
=
0
,
wt
;
char
*
str
;
if
((
wr1
=
asprintf
(
&
str
,
"
\r
FD0: %d FD1: %d UART: %d ID: %d CRC: %d UNDERRUN: %d%n"
,
if
((
wr1
=
asprintf
(
&
str
,
"
\r
FD0: %d FD1: %d UART: %d ID: %d CRC: %d UNDERRUN:
%d REPLACE:
%d%n"
,
(
msg
&
FD0
)
>
0
,
(
msg
&
FD1
)
>
0
,
(
err
&
U
)
>
0
,
(
err
&
I
)
>
0
,
(
err
&
C
)
>
0
,
underrun
,
&
wr1
))
<
0
)
{
underrun
,
replace_conf_done
,
&
wr1
))
<
0
)
{
return
;
}
printf
(
"%s"
,
str
);
...
...
@@ -180,9 +179,10 @@ int main (int argc, char *argv[]) {
char
opt
;
uint8_t
in
[
NUM_BYTES
];
uint8_t
underrun
=
0
;
uint8_t
replace_conf_done
=
0
;
unsigned
int
nmsg
=
0
;
double
period
=
0
;
char
*
path
=
PATH
;
char
*
path
=
NULL
;
fd_set
rfds
;
struct
timeval
tv
;
...
...
@@ -239,26 +239,54 @@ int main (int argc, char *argv[]) {
exit
(
EXIT_FAILURE
);
}
fd
=
open
(
path
,
O_RDWR
|
O_NOCTTY
|
O_SYNC
);
if
(
fd
<
0
)
{
perror
(
"open()"
);
RESTORE_TERM
();
return
EXIT_FAILURE
;
int
ptsfd
=
-
1
;
if
(
!
path
)
{
fd
=
open
(
"/dev/ptmx"
,
O_RDWR
|
O_NOCTTY
|
O_SYNC
);
if
(
fd
<
0
)
{
fprintf
(
stderr
,
"%s open() of ptmx: %s
\n
"
,
argv
[
0
],
strerror
(
errno
));
RESTORE_TERM
();
return
EXIT_FAILURE
;
}
if
(
grantpt
(
fd
)
||
unlockpt
(
fd
))
{
fprintf
(
stderr
,
"%s grantpt()/unlockpt() of ptmx: %s
\n
"
,
argv
[
0
],
strerror
(
errno
));
RESTORE_TERM
();
return
EXIT_FAILURE
;
}
char
pts
[
1024
];
if
(
ptsname_r
(
fd
,
pts
,
sizeof
(
pts
))
!=
0
)
{
RESTORE_TERM
();
fprintf
(
stderr
,
"%s: ptsname(): %s
\n
"
,
argv
[
0
],
strerror
(
errno
));
exit
(
EXIT_FAILURE
);
}
ptsfd
=
open
(
pts
,
O_RDONLY
);
if
(
ptsfd
<
0
)
{
fprintf
(
stderr
,
"%s: open(): %s
\n
"
,
argv
[
0
],
strerror
(
errno
));
exit
(
EXIT_FAILURE
);
}
(
void
)
printf
(
"
\x1b
[1mConnect FIJI EE to: %s
\x1b
[0m
\n\n
"
,
pts
);
}
else
{
fd
=
open
(
path
,
O_RDWR
|
O_NOCTTY
|
O_SYNC
);
if
(
fd
<
0
)
{
perror
(
"open()"
);
RESTORE_TERM
();
return
EXIT_FAILURE
;
}
printf
(
"Emulating FIC on %s
\n\n
"
,
path
);
}
printf
(
"Emulating FIC on %s
\n\n
"
,
path
);
printf
(
"[1] FD1 on/off
\n
"
\
"[2] FD2 on/off
\n
"
\
"[u] UART Error on/off
\n
"
\
"[i] ID Error on/off
\n
"
\
"[c] CRC Error on/off
\n
"
\
"[r] Underrun on/off
\n
"
\
"[r] Underrun after READY on/off
\n
"
\
"[z] Underrun instead of CONF_DONE on/off
\n
"
\
/* "[f] MSG_TYPE_ILLEGAL\n" \ */
"[x] Exit
\n
"
);
puts
(
"
\033
[25l
\033
[7m"
);
putstatus
(
msg
,
err
,
underrun
,
NULL
,
nmsg
);
putstatus
(
msg
,
err
,
underrun
,
replace_conf_done
,
NULL
,
nmsg
);
while
(
1
)
{
...
...
@@ -273,30 +301,36 @@ int main (int argc, char *argv[]) {
perror
(
"select()"
);
else
if
(
retval
)
{
if
(
FD_ISSET
(
STDIN_FILENO
,
&
rfds
))
{
read
(
STDIN_FILENO
,
&
dat
,
1
);
switch
(
dat
)
{
case
'1'
:
msg
^=
FD0
;
break
;
case
'2'
:
msg
^=
FD1
;
break
;
case
'u'
:
err
^=
U
;
break
;
case
'i'
:
err
^=
I
;
break
;
case
'c'
:
err
^=
C
;
break
;
case
'r'
:
underrun
^=
1
;
break
;
case
'x'
:
goto
END
;
if
(
read
(
STDIN_FILENO
,
&
dat
,
1
)
==
1
)
{
switch
(
dat
)
{
case
'1'
:
msg
^=
FD0
;
break
;
case
'2'
:
msg
^=
FD1
;
break
;
case
'u'
:
err
^=
U
;
break
;
case
'i'
:
err
^=
I
;
break
;
case
'c'
:
err
^=
C
;
break
;
case
'r'
:
underrun
^=
1
;
break
;
case
'z'
:
replace_conf_done
^=
1
;
break
;
case
'x'
:
goto
END
;
}
putstatus
(
msg
,
err
,
underrun
,
replace_conf_done
,
NULL
,
nmsg
);
}
else
{
perror
(
"read()"
);
}
putstatus
(
msg
,
err
,
underrun
,
NULL
,
nmsg
);
}
if
(
!
FD_ISSET
(
fd
,
&
rfds
))
{
continue
;
...
...
@@ -304,6 +338,7 @@ int main (int argc, char *argv[]) {
}
else
{
continue
;
}
if
(
read_msg
(
fd
,
in
)
==
-
1
)
{
fprintf
(
stderr
,
"read_msg()
\n
"
);
...
...
@@ -332,10 +367,10 @@ int main (int argc, char *argv[]) {
fprintf
(
stderr
,
"%02d: 0x%02x
\n
"
,
i
,
in
[
i
]);
}
#endif
putstatus
(
msg
,
err
,
underrun
,(
in
+
CRC_OFFSET
),
++
nmsg
);
putstatus
(
msg
,
err
,
underrun
,
replace_conf_done
,
(
in
+
CRC_OFFSET
),
++
nmsg
);
ret
=
MSG_TYPE_CONF_DONE
;
ret
=
replace_conf_done
?
MSG_TYPE_UNDERRUN
:
MSG_TYPE_CONF_DONE
;
ret
|=
msg
;
ret
|=
err
;
ret
|=
parity
(
ret
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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