Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
White Rabbit Switch - Software
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Projects
White Rabbit Switch - Software
Commits
ab63b0f0
Commit
ab63b0f0
authored
13 years ago
by
Alessandro Rubini
Browse files
Options
Downloads
Patches
Plain Diff
on-swtich-tests/wr_mon: cleanup (no functional change)
parent
fa59201e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
on-switch-tests/wr_mon/term.c
+47
-49
47 additions, 49 deletions
on-switch-tests/wr_mon/term.c
on-switch-tests/wr_mon/term.h
+5
-5
5 additions, 5 deletions
on-switch-tests/wr_mon/term.h
on-switch-tests/wr_mon/wr_mon.c
+91
-50
91 additions, 50 deletions
on-switch-tests/wr_mon/wr_mon.c
with
143 additions
and
104 deletions
on-switch-tests/wr_mon/term.c
+
47
−
49
View file @
ab63b0f0
#include
<stdio.h>
#include
<stdlib.h>
#include
<stdarg.h>
#include
<string.h>
#include
<unistd.h>
#include
<fcntl.h>
#include
<termios.h>
...
...
@@ -10,80 +11,77 @@
struct
termios
oldkey
,
newkey
;
int
term_restore
()
void
term_restore
(
void
)
{
tcsetattr
(
STDIN_FILENO
,
TCSANOW
,
&
oldkey
);
tcsetattr
(
STDIN_FILENO
,
TCSANOW
,
&
oldkey
);
}
void
term_init
()
void
term_init
(
void
)
{
fcntl
(
STDIN_FILENO
,
F_SETFL
,
O_NONBLOCK
);
fcntl
(
STDIN_FILENO
,
F_SETFL
,
O_NONBLOCK
);
tcgetattr
(
STDIN_FILENO
,
&
oldkey
);
tcgetattr
(
STDIN_FILENO
,
&
oldkey
);
memcpy
(
&
newkey
,
&
oldkey
,
sizeof
(
struct
termios
));
newkey
.
c_cflag
=
B9600
|
CRTSCTS
|
CS8
|
CLOCAL
|
CREAD
;
newkey
.
c_iflag
=
IGNPAR
;
newkey
.
c_oflag
=
OPOST
|
ONLCR
;
newkey
.
c_lflag
=
0
;
newkey
.
c_cc
[
VMIN
]
=
1
;
newkey
.
c_cc
[
VTIME
]
=
0
;
tcflush
(
STDIN_FILENO
,
TCIFLUSH
);
tcsetattr
(
STDIN_FILENO
,
TCSANOW
,
&
newkey
);
atexit
(
term_restore
);
newkey
.
c_cflag
=
B9600
|
CRTSCTS
|
CS8
|
CLOCAL
|
CREAD
;
newkey
.
c_iflag
=
IGNPAR
;
newkey
.
c_oflag
=
OPOST
|
ONLCR
;
newkey
.
c_lflag
=
0
;
newkey
.
c_cc
[
VMIN
]
=
1
;
newkey
.
c_cc
[
VTIME
]
=
0
;
tcflush
(
STDIN_FILENO
,
TCIFLUSH
);
tcsetattr
(
STDIN_FILENO
,
TCSANOW
,
&
newkey
);
atexit
(
term_restore
);
}
int
term_poll
()
int
term_poll
(
void
)
{
struct
pollfd
pfd
;
pfd
.
fd
=
STDIN_FILENO
;
pfd
.
events
=
POLLIN
|
POLLPRI
;
struct
pollfd
pfd
;
pfd
.
fd
=
STDIN_FILENO
;
pfd
.
events
=
POLLIN
|
POLLPRI
;
if
(
poll
(
&
pfd
,
1
,
0
)
>
0
)
return
1
;
if
(
poll
(
&
pfd
,
1
,
0
)
>
0
)
return
1
;
return
0
;
return
0
;
}
int
term_get
()
int
term_get
(
void
)
{
unsigned
char
c
;
int
q
;
if
(
read
(
STDIN_FILENO
,
&
c
,
1
)
==
1
)
{
q
=
c
;
}
else
q
=-
1
;
return
q
;
unsigned
char
c
;
int
q
;
if
(
read
(
STDIN_FILENO
,
&
c
,
1
)
==
1
)
{
q
=
c
;
}
else
q
=-
1
;
return
q
;
}
void
term_cprintf
(
int
color
,
const
char
*
fmt
,
...)
{
va_list
ap
;
printf
(
"
\033
[0%d;3%dm"
,
color
&
C_DIM
?
2
:
1
,
color
&
0x7f
);
//
printf("\033[01;%dm",color);
va_start
(
ap
,
fmt
);
vprintf
(
fmt
,
ap
);
va_end
(
ap
);
fflush
(
stdout
);
va_list
ap
;
printf
(
"
\033
[0%d;3%dm"
,
color
&
C_DIM
?
2
:
1
,
color
&
0x7f
);
//
printf("\033[01;%dm",color);
va_start
(
ap
,
fmt
);
vprintf
(
fmt
,
ap
);
va_end
(
ap
);
fflush
(
stdout
);
}
void
term_pcprintf
(
int
row
,
int
col
,
int
color
,
const
char
*
fmt
,
...)
{
va_list
ap
;
printf
(
"
\033
[%d;%df"
,
row
,
col
);
printf
(
"
\033
[0%d;3%dm"
,
color
&
C_DIM
?
2
:
1
,
color
&
0x7f
);
va_start
(
ap
,
fmt
);
vprintf
(
fmt
,
ap
);
va_end
(
ap
);
fflush
(
stdout
);
va_list
ap
;
printf
(
"
\033
[%d;%df"
,
row
,
col
);
printf
(
"
\033
[0%d;3%dm"
,
color
&
C_DIM
?
2
:
1
,
color
&
0x7f
);
va_start
(
ap
,
fmt
);
vprintf
(
fmt
,
ap
);
va_end
(
ap
);
fflush
(
stdout
);
}
void
term_clear
()
void
term_clear
(
void
)
{
printf
(
"
\033
[2J
\033
[1;1H"
);
printf
(
"
\033
[2J
\033
[1;1H"
);
}
This diff is collapsed.
Click to expand it.
on-switch-tests/wr_mon/term.h
+
5
−
5
View file @
ab63b0f0
...
...
@@ -10,10 +10,10 @@
#define C_GREEN 2
#define C_BLUE 4
int
term_restore
();
void
term_init
();
int
term_poll
();
int
term_get
();
void
term_restore
(
void
);
void
term_init
(
void
);
int
term_poll
(
void
);
int
term_get
(
void
);
void
term_cprintf
(
int
color
,
const
char
*
fmt
,
...);
void
term_pcprintf
(
int
row
,
int
col
,
int
color
,
const
char
*
fmt
,
...);
void
term_clear
();
void
term_clear
(
void
);
This diff is collapsed.
Click to expand it.
on-switch-tests/wr_mon/wr_mon.c
+
91
−
50
View file @
ab63b0f0
...
...
@@ -14,16 +14,16 @@ wripc_handle_t h_ptp;
void
init
()
{
halexp_client_init
();
if
(
(
h_ptp
=
wripc_connect
(
"ptpd"
))
<
0
)
{
fprintf
(
stderr
,
"Can't establish WRIPC connection to the PTP daemon!
\n
"
);
fprintf
(
stderr
,
"Can't establish WRIPC connection "
"to the PTP daemon!
\n
"
);
exit
(
-
1
);
}
term_init
();
term_init
();
halexp_query_ports
(
&
port_list
);
}
...
...
@@ -36,59 +36,98 @@ void show_ports()
{
hexp_port_state_t
state
;
halexp_get_port_state
(
&
state
,
port_list
.
port_names
[
i
]);
term_pcprintf
(
5
+
i
,
1
,
C_WHITE
,
"%s: "
,
port_list
.
port_names
[
i
]);
if
(
state
.
up
)
term_cprintf
(
C_GREEN
,
"Link up "
);
else
term_cprintf
(
C_RED
,
"Link down "
);
if
(
state
.
up
)
term_cprintf
(
C_GREEN
,
"Link up "
);
else
term_cprintf
(
C_RED
,
"Link down "
);
term_cprintf
(
C_GREY
,
"mode: "
);
switch
(
state
.
mode
)
{
case
HEXP_PORT_MODE_WR_MASTER
:
term_cprintf
(
C_WHITE
,
"WR Master "
);
break
;
case
HEXP_PORT_MODE_WR_SLAVE
:
term_cprintf
(
C_WHITE
,
"WR Slave "
);
break
;
case
HEXP_PORT_MODE_WR_MASTER
:
term_cprintf
(
C_WHITE
,
"WR Master "
);
break
;
case
HEXP_PORT_MODE_WR_SLAVE
:
term_cprintf
(
C_WHITE
,
"WR Slave "
);
break
;
}
if
(
state
.
is_locked
)
term_cprintf
(
C_GREEN
,
"Locked "
);
else
term_cprintf
(
C_RED
,
"NoLock "
);
if
(
state
.
rx_calibrated
&&
state
.
tx_calibrated
)
term_cprintf
(
C_GREEN
,
"Calibrated "
);
else
term_cprintf
(
C_RED
,
"Uncalibrated "
);
}
if
(
state
.
is_locked
)
term_cprintf
(
C_GREEN
,
"Locked "
);
else
term_cprintf
(
C_RED
,
"NoLock "
);
if
(
state
.
rx_calibrated
&&
state
.
tx_calibrated
)
term_cprintf
(
C_GREEN
,
"Calibrated "
);
else
term_cprintf
(
C_RED
,
"Uncalibrated "
);
}
}
void
show_servo
()
{
ptpdexp_sync_state_t
ss
;
wripc_call
(
h_ptp
,
"ptpdexp_get_sync_state"
,
&
ss
,
0
);
wripc_call
(
h_ptp
,
"ptpdexp_get_sync_state"
,
&
ss
,
0
);
term_cprintf
(
C_BLUE
,
"
\n\n
Synchronization status:
\n\n
"
);
if
(
!
ss
.
valid
)
{
term_cprintf
(
C_RED
,
"Master mode or sync info not valid
\n\n
"
);
return
;
}
term_cprintf
(
C_GREY
,
"Servo state: "
);
term_cprintf
(
C_WHITE
,
"%s
\n
"
,
ss
.
slave_servo_state
);
term_cprintf
(
C_GREY
,
"Phase tracking: "
);
if
(
ss
.
tracking_enabled
)
term_cprintf
(
C_GREEN
,
"ON
\n
"
);
else
term_cprintf
(
C_RED
,
"OFF
\n
"
);
term_cprintf
(
C_GREY
,
"Synchronization source: "
);
term_cprintf
(
C_WHITE
,
"%s
\n
"
,
ss
.
sync_source
);
}
term_cprintf
(
C_GREY
,
"Servo state: "
);
term_cprintf
(
C_WHITE
,
"%s
\n
"
,
ss
.
slave_servo_state
);
term_cprintf
(
C_GREY
,
"Phase tracking: "
);
if
(
ss
.
tracking_enabled
)
term_cprintf
(
C_GREEN
,
"ON
\n
"
);
else
term_cprintf
(
C_RED
,
"OFF
\n
"
);
term_cprintf
(
C_GREY
,
"Synchronization source: "
);
term_cprintf
(
C_WHITE
,
"%s
\n
"
,
ss
.
sync_source
);
term_cprintf
(
C_BLUE
,
"
\n
Timing parameters:
\n\n
"
);
term_cprintf
(
C_GREY
,
"Round-trip time (mu): "
);
term_cprintf
(
C_WHITE
,
"%.2f nsec
\n
"
,
ss
.
mu
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Master-slave delay: "
);
term_cprintf
(
C_WHITE
,
"%.2f nsec
\n
"
,
ss
.
delay_ms
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Link length: "
);
term_cprintf
(
C_WHITE
,
"%.0f meters
\n
"
,
ss
.
delay_ms
/
1e12
*
300e6
/
1
.
55
);
term_cprintf
(
C_GREY
,
"Master PHY delays: "
);
term_cprintf
(
C_WHITE
,
"TX: %.2f nsec, RX: %.2f nsec
\n
"
,
ss
.
delta_tx_m
/
1000
.
0
,
ss
.
delta_rx_m
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Slave PHY delays: "
);
term_cprintf
(
C_WHITE
,
"TX: %.2f nsec, RX: %.2f nsec
\n
"
,
ss
.
delta_tx_s
/
1000
.
0
,
ss
.
delta_rx_s
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Total link asymmetry: "
);
term_cprintf
(
C_WHITE
,
"%.2f nsec
\n
"
,
ss
.
total_asymmetry
/
1000
.
0
);
// term_cprintf(C_GREY, "Fiber asymmetry: "); term_cprintf(C_WHITE, "%.2f nsec\n", ss.fiber_asymmetry/1000.0);
term_cprintf
(
C_GREY
,
"Round-trip time (mu): "
);
term_cprintf
(
C_WHITE
,
"%.2f nsec
\n
"
,
ss
.
mu
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Master-slave delay: "
);
term_cprintf
(
C_WHITE
,
"%.2f nsec
\n
"
,
ss
.
delay_ms
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Link length: "
);
term_cprintf
(
C_WHITE
,
"%.0f meters
\n
"
,
ss
.
delay_ms
/
1e12
*
300e6
/
1
.
55
);
term_cprintf
(
C_GREY
,
"Master PHY delays: "
);
term_cprintf
(
C_WHITE
,
"TX: %.2f nsec, RX: %.2f nsec
\n
"
,
ss
.
delta_tx_m
/
1000
.
0
,
ss
.
delta_rx_m
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Clock offset: "
);
term_cprintf
(
C_WHITE
,
"%.2f nsec
\n
"
,
ss
.
cur_offset
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Phase setpoint: "
);
term_cprintf
(
C_WHITE
,
"%.2f nsec
\n
"
,
ss
.
cur_setpoint
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Skew: "
);
term_cprintf
(
C_WHITE
,
"%.2f nsec
\n
"
,
ss
.
cur_skew
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Slave PHY delays: "
);
term_cprintf
(
C_WHITE
,
"TX: %.2f nsec, RX: %.2f nsec
\n
"
,
ss
.
delta_tx_s
/
1000
.
0
,
ss
.
delta_rx_s
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Total link asymmetry: "
);
term_cprintf
(
C_WHITE
,
"%.2f nsec
\n
"
,
ss
.
total_asymmetry
/
1000
.
0
);
if
(
0
)
{
term_cprintf
(
C_GREY
,
"Fiber asymmetry: "
);
term_cprintf
(
C_WHITE
,
"%.2f nsec
\n
"
,
ss
.
fiber_asymmetry
/
1000
.
0
);
}
term_cprintf
(
C_GREY
,
"Clock offset: "
);
term_cprintf
(
C_WHITE
,
"%.2f nsec
\n
"
,
ss
.
cur_offset
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Phase setpoint: "
);
term_cprintf
(
C_WHITE
,
"%.2f nsec
\n
"
,
ss
.
cur_setpoint
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Skew: "
);
term_cprintf
(
C_WHITE
,
"%.2f nsec
\n
"
,
ss
.
cur_skew
/
1000
.
0
);
}
void
show_menu
()
...
...
@@ -102,40 +141,42 @@ void show_screen()
{
term_clear
();
term_pcprintf
(
1
,
1
,
C_BLUE
,
"WR Switch Sync Monitor v 0.1"
);
show_ports
();
show_servo
();
show_servo
();
show_menu
();
// handle_toggle();
}
main
()
{
init
();
for
(;;)
{
if
(
term_poll
())
{
int
c
=
term_get
();
if
(
c
==
'q'
)
break
;
else
if
(
c
==
't'
)
{
int
rval
;
if
(
c
==
'q'
)
break
;
if
(
c
==
't'
)
{
int
rval
;
track_onoff
=
1
-
track_onoff
;
wripc_call
(
h_ptp
,
"ptpdexp_cmd"
,
&
rval
,
2
,
A_INT32
(
PTPDEXP_COMMAND_TRACKING
),
A_INT32
(
track_onoff
));
wripc_call
(
h_ptp
,
"ptpdexp_cmd"
,
&
rval
,
2
,
A_INT32
(
PTPDEXP_COMMAND_TRACKING
),
A_INT32
(
track_onoff
));
}
}
show_screen
();
usleep
(
500000
);
}
term_cprintf
(
C_GREY
,
"bye...
\n\n
"
);
term_clear
();
term_clear
();
term_restore
();
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment