Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
wr-switch-sw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
white-rabbit
wr-switch-sw
Commits
39bb6cba
Commit
39bb6cba
authored
Nov 08, 2013
by
Grzegorz Daniluk
Committed by
Alessandro Rubini
Nov 14, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add -s option to wr_mon to produce logs that are easy to parse
parent
4876da8b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
160 additions
and
91 deletions
+160
-91
wr_mon.c
userspace/tools/wr_mon.c
+160
-91
No files found.
userspace/tools/wr_mon.c
View file @
39bb6cba
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <minipc.h>
...
...
@@ -10,6 +11,10 @@
#include "hal_client.h"
#define SHOW_GUI 0
#define SHOW_STATS 1
hexp_port_list_t
port_list
;
static
struct
minipc_ch
*
ptp_ch
;
...
...
@@ -31,127 +36,167 @@ void init(int usecolor)
halexp_query_ports
(
&
port_list
);
}
void
show_ports
()
void
show_ports
(
int
mode
)
{
int
i
,
j
;
time_t
t
;
struct
tm
*
tm
;
char
datestr
[
32
];
time
(
&
t
);
tm
=
localtime
(
&
t
);
strftime
(
datestr
,
sizeof
(
datestr
),
"%Y-%m-%d %H:%M:%S"
,
tm
);
term_pcprintf
(
3
,
1
,
C_BLUE
,
"Switch ports at %s
\n
"
,
datestr
);
if
(
mode
==
SHOW_GUI
)
{
time
(
&
t
);
tm
=
localtime
(
&
t
);
strftime
(
datestr
,
sizeof
(
datestr
),
"%Y-%m-%d %H:%M:%S"
,
tm
);
term_pcprintf
(
3
,
1
,
C_BLUE
,
"Switch ports at %s
\n
"
,
datestr
);
for
(
i
=
0
;
i
<
18
;
i
++
)
{
char
if_name
[
10
],
found
=
0
;
hexp_port_state_t
state
;
for
(
i
=
0
;
i
<
18
;
i
++
)
{
char
if_name
[
10
],
found
=
0
;
hexp_port_state_t
state
;
snprintf
(
if_name
,
10
,
"wr%d"
,
i
);
for
(
j
=
0
;
j
<
port_list
.
num_ports
;
j
++
)
if
(
!
strcmp
(
port_list
.
port_names
[
j
],
if_name
))
{
found
=
1
;
break
;
}
snprintf
(
if_name
,
10
,
"wr%d"
,
i
);
if
(
!
found
)
continue
;
halexp_get_port_state
(
&
state
,
if_name
);
term_cprintf
(
C_WHITE
,
" %05s: "
,
if_name
);
if
(
state
.
up
)
term_cprintf
(
C_GREEN
,
"Link up "
);
else
term_cprintf
(
C_RED
,
"Link down "
);
for
(
j
=
0
;
j
<
port_list
.
num_ports
;
j
++
)
if
(
!
strcmp
(
port_list
.
port_names
[
j
],
if_name
))
{
found
=
1
;
break
;
}
if
(
!
found
)
continue
;
halexp_get_port_state
(
&
state
,
if_name
);
term_cprintf
(
C_WHITE
,
" %-5s: "
,
if_name
);
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
;
}
term_cprintf
(
C_GREY
,
"mode: "
);
if
(
state
.
is_locked
)
term_cprintf
(
C_GREEN
,
"Locked "
);
else
term_cprintf
(
C_RED
,
"NoLock "
);
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
;
if
(
state
.
rx_calibrated
&&
state
.
tx_calibrated
)
term_cprintf
(
C_GREEN
,
"Calibrated
\n
"
);
else
term_cprintf
(
C_RED
,
"Uncalibrated
\n
"
);
}
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
\n
"
);
else
term_cprintf
(
C_RED
,
"Uncalibrated
\n
"
);
}
else
if
(
mode
==
SHOW_STATS
)
{
printf
(
"PORTS "
);
for
(
i
=
0
;
i
<
18
;
++
i
)
{
char
if_name
[
10
],
found
=
0
;
hexp_port_state_t
state
;
snprintf
(
if_name
,
10
,
"wr%d"
,
i
);
for
(
j
=
0
;
j
<
port_list
.
num_ports
;
j
++
)
if
(
!
strcmp
(
port_list
.
port_names
[
j
],
if_name
))
{
found
=
1
;
break
;
}
if
(
!
found
)
continue
;
halexp_get_port_state
(
&
state
,
if_name
);
printf
(
"port:%s "
,
if_name
);
printf
(
"lnk:%d "
,
state
.
up
?
1
:
0
);
printf
(
"mode:%s "
,
state
.
mode
==
HEXP_PORT_MODE_WR_SLAVE
?
"S"
:
"M"
);
printf
(
"lock:%d "
,
state
.
is_locked
?
1
:
0
);
}
printf
(
"
\n
"
);
}
}
void
show_servo
()
void
show_servo
(
int
mode
)
{
ptpdexp_sync_state_t
ss
;
minipc_call
(
ptp_ch
,
2000
,
&
__rpcdef_get_sync_state
,
&
ss
);
term_cprintf
(
C_BLUE
,
"Synchronization status:
\n
"
);
if
(
mode
==
SHOW_GUI
)
{
term_cprintf
(
C_BLUE
,
"Synchronization status:
\n
"
);
if
(
!
ss
.
valid
)
{
term_cprintf
(
C_RED
,
"Master mode or sync info not valid
\n
"
);
return
;
}
if
(
!
ss
.
valid
)
{
term_cprintf
(
C_RED
,
"Master mode or sync info not valid
\n
"
);
return
;
}
term_cprintf
(
C_GREY
,
"Servo state: "
);
term_cprintf
(
C_WHITE
,
"%s
\n
"
,
ss
.
slave_servo_state
);
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
,
"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
,
"Synchronization source: "
);
term_cprintf
(
C_WHITE
,
"%s
\n
"
,
ss
.
sync_source
);
term_cprintf
(
C_BLUE
,
"
\n
Timing parameters:
\n\n
"
);
term_cprintf
(
C_BLUE
,
"
\n
Timing parameters:
\n\n
"
);
term_cprintf
(
C_GREY
,
"Round-trip time (mu): "
);
term_cprintf
(
C_WHITE
,
"%.2
f nsec
\n
"
,
ss
.
mu
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Round-trip time (mu): "
);
term_cprintf
(
C_WHITE
,
"%.3
f nsec
\n
"
,
ss
.
mu
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Master-slave delay: "
);
term_cprintf
(
C_WHITE
,
"%.2
f nsec
\n
"
,
ss
.
delay_ms
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Master-slave delay: "
);
term_cprintf
(
C_WHITE
,
"%.3
f 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
,
"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: %.2
f nsec
\n
"
,
ss
.
delta_tx_m
/
1000
.
0
,
ss
.
delta_rx_m
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Master PHY delays: "
);
term_cprintf
(
C_WHITE
,
"TX: %.3f nsec, RX: %.3
f 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: %.2
f nsec
\n
"
,
ss
.
delta_tx_s
/
1000
.
0
,
ss
.
delta_rx_s
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Slave PHY delays: "
);
term_cprintf
(
C_WHITE
,
"TX: %.3f nsec, RX: %.3
f 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
,
"%.2
f nsec
\n
"
,
ss
.
total_asymmetry
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Total link asymmetry: "
);
term_cprintf
(
C_WHITE
,
"%.3
f nsec
\n
"
,
ss
.
total_asymmetry
/
1000
.
0
);
if
(
0
)
{
term_cprintf
(
C_GREY
,
"Fiber asymmetry: "
);
term_cprintf
(
C_WHITE
,
"%.2
f nsec
\n
"
,
ss
.
fiber_asymmetry
/
1000
.
0
);
}
if
(
0
)
{
term_cprintf
(
C_GREY
,
"Fiber asymmetry: "
);
term_cprintf
(
C_WHITE
,
"%.3
f nsec
\n
"
,
ss
.
fiber_asymmetry
/
1000
.
0
);
}
term_cprintf
(
C_GREY
,
"Clock offset: "
);
term_cprintf
(
C_WHITE
,
"%.2
f nsec
\n
"
,
ss
.
cur_offset
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Clock offset: "
);
term_cprintf
(
C_WHITE
,
"%.3
f nsec
\n
"
,
ss
.
cur_offset
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Phase setpoint: "
);
term_cprintf
(
C_WHITE
,
"%.2
f nsec
\n
"
,
ss
.
cur_setpoint
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Phase setpoint: "
);
term_cprintf
(
C_WHITE
,
"%.3
f nsec
\n
"
,
ss
.
cur_setpoint
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Skew: "
);
term_cprintf
(
C_WHITE
,
"%.2
f nsec
\n
"
,
ss
.
cur_skew
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Skew: "
);
term_cprintf
(
C_WHITE
,
"%.3
f nsec
\n
"
,
ss
.
cur_skew
/
1000
.
0
);
term_cprintf
(
C_GREY
,
"Servo update counter: "
);
term_cprintf
(
C_WHITE
,
"%lld times
\n
"
,
ss
.
update_count
);
term_cprintf
(
C_GREY
,
"Servo update counter: "
);
term_cprintf
(
C_WHITE
,
"%lld times
\n
"
,
ss
.
update_count
);
}
else
if
(
mode
==
SHOW_STATS
)
{
printf
(
"SERVO "
);
printf
(
"sv:%d "
,
ss
.
valid
?
1
:
0
);
printf
(
"ss:'%s' "
,
ss
.
slave_servo_state
);
printf
(
"mu:%llu "
,
ss
.
mu
);
printf
(
"dms:%llu "
,
ss
.
delay_ms
);
printf
(
"dtxm:%llu drxm:%llu "
,
ss
.
delta_tx_m
,
ss
.
delta_rx_m
);
printf
(
"dtxs:%llu drxs:%llu "
,
ss
.
delta_tx_s
,
ss
.
delta_rx_s
);
printf
(
"asym:%lld "
,
ss
.
total_asymmetry
);
printf
(
"crtt:%llu "
,
ss
.
mu
-
ss
.
delta_tx_m
-
ss
.
delta_rx_m
-
ss
.
delta_tx_s
-
ss
.
delta_rx_s
);
printf
(
"cko:%lld "
,
ss
.
cur_offset
);
printf
(
"setp:%lld "
,
ss
.
cur_setpoint
);
printf
(
"ucnt:%llu "
,
ss
.
update_count
);
printf
(
"
\n
"
);
}
}
int
track_onoff
=
1
;
...
...
@@ -161,17 +206,40 @@ void show_screen()
term_clear
();
term_pcprintf
(
1
,
1
,
C_BLUE
,
"WR Switch Sync Monitor v 1.0 [q = quit]"
);
show_ports
();
show_servo
();
show_ports
(
SHOW_GUI
);
show_servo
(
SHOW_GUI
);
fflush
(
stdout
);
}
int
main
(
int
argc
,
char
**
argv
)
void
show_stats
(
)
{
show_ports
(
SHOW_STATS
);
show_servo
(
SHOW_STATS
);
fflush
(
stdout
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
opt
;
int
stats
=
0
;
int
usecolor
=
1
;
if
(
argc
>
1
&&
!
strcmp
(
argv
[
1
],
"-b"
))
usecolor
=
0
;
while
((
opt
=
getopt
(
argc
,
argv
,
"sb"
))
!=
-
1
)
{
switch
(
opt
)
{
case
's'
:
stats
=
1
;
break
;
case
'b'
:
usecolor
=
0
;
break
;
default:
fprintf
(
stderr
,
"Unrecognized option.
\n
"
);
break
;
}
}
init
(
usecolor
);
setvbuf
(
stdout
,
NULL
,
_IOFBF
,
4096
);
...
...
@@ -192,7 +260,8 @@ int main(int argc, char **argv)
track_onoff
);
}
}
show_screen
();
if
(
stats
)
show_stats
();
else
show_screen
();
}
term_restore
();
setlinebuf
(
stdout
);
...
...
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