Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
31
Issues
31
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
625b21ef
Commit
625b21ef
authored
Jan 14, 2016
by
Alessandro Rubini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/util: offer different time formats, for syslog mainly
Signed-off-by:
Alessandro Rubini
<
rubini@gnudd.com
>
parent
83bb333f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
8 deletions
+28
-8
util.h
include/util.h
+4
-1
syslog.c
lib/syslog.c
+2
-1
util.c
lib/util.c
+18
-4
monitor_ppsi.c
monitor/monitor_ppsi.c
+1
-1
cmd_time.c
shell/cmd_time.c
+3
-1
No files found.
include/util.h
View file @
625b21ef
...
...
@@ -16,7 +16,10 @@
#define C_BLUE 4
/* Return TAI date/time in human-readable form. Non-reentrant. */
char
*
format_time
(
uint64_t
sec
);
char
*
format_time
(
uint64_t
sec
,
int
format
);
#define TIME_FORMAT_LEGACY 0
#define TIME_FORMAT_SYSLOG 1
#define TIME_FORMAT_SORTED 2
/* Color printf() variant. */
void
cprintf
(
int
color
,
const
char
*
fmt
,
...);
...
...
lib/syslog.c
View file @
625b21ef
...
...
@@ -73,7 +73,8 @@ void syslog_poll(void)
shw_pps_gen_get_time
(
&
secs
,
NULL
);
len
=
pp_sprintf
(
buf
+
UDP_END
,
/* 8 == user + 6 == info */
"<14> %s wr-node: Alive and Well"
,
format_time
(
secs
));
"<14> %s wr-node: Alive and Well"
,
format_time
(
secs
,
TIME_FORMAT_SYSLOG
));
len
+=
UDP_END
;
memcpy
(
&
syslog_addr
.
saddr
,
ip
,
4
);
fill_udp
((
void
*
)
buf
,
len
,
&
syslog_addr
);
...
...
lib/util.c
View file @
625b21ef
...
...
@@ -41,7 +41,7 @@ static const int _ytab[2][12] = {
{
31
,
29
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
}
};
char
*
format_time
(
uint64_t
sec
)
char
*
format_time
(
uint64_t
sec
,
int
format
)
{
struct
tm
t
;
static
char
buf
[
64
];
...
...
@@ -69,9 +69,23 @@ char *format_time(uint64_t sec)
t
.
tm_mday
=
dayno
+
1
;
t
.
tm_isdst
=
0
;
sprintf
(
buf
,
"%s, %s %d, %d, %02d:%02d:%02d"
,
_days
[
t
.
tm_wday
],
_months
[
t
.
tm_mon
],
t
.
tm_mday
,
t
.
tm_year
+
YEAR0
,
t
.
tm_hour
,
t
.
tm_min
,
t
.
tm_sec
);
switch
(
format
)
{
case
TIME_FORMAT_LEGACY
:
default:
sprintf
(
buf
,
"%s, %s %d, %d, %02d:%02d:%02d"
,
_days
[
t
.
tm_wday
],
_months
[
t
.
tm_mon
],
t
.
tm_mday
,
t
.
tm_year
+
YEAR0
,
t
.
tm_hour
,
t
.
tm_min
,
t
.
tm_sec
);
break
;
case
TIME_FORMAT_SYSLOG
:
sprintf
(
buf
,
"%s %2d %02d:%02d:%02d"
,
_months
[
t
.
tm_mon
],
t
.
tm_mday
,
t
.
tm_hour
,
t
.
tm_min
,
t
.
tm_sec
);
break
;
case
TIME_FORMAT_SORTED
:
sprintf
(
buf
,
"%4d-%02d-%02d-%02d:%02d:%02d"
,
t
.
tm_year
+
YEAR0
,
t
.
tm_mon
+
1
,
t
.
tm_mday
,
t
.
tm_hour
,
t
.
tm_min
,
t
.
tm_sec
);
break
;
}
return
buf
;
}
...
...
monitor/monitor_ppsi.c
View file @
625b21ef
...
...
@@ -110,7 +110,7 @@ void wrc_mon_gui(void)
shw_pps_gen_get_time
(
&
sec
,
&
nsec
);
cprintf
(
C_BLUE
,
"
\n\n
TAI Time: "
);
cprintf
(
C_WHITE
,
"%s"
,
format_time
(
sec
));
cprintf
(
C_WHITE
,
"%s"
,
format_time
(
sec
,
TIME_FORMAT_LEGACY
));
/*show_ports */
wrpc_get_port_state
(
&
state
,
NULL
);
...
...
shell/cmd_time.c
View file @
625b21ef
...
...
@@ -53,7 +53,9 @@ static int cmd_time(const char *args[])
return
0
;
}
pp_printf
(
"%s +%d nanoseconds.
\n
"
,
format_time
(
sec
),
nsec
);
/* fixme: clock freq is not always 125 MHz */
pp_printf
(
"%s +%d nanoseconds.
\n
"
,
format_time
(
sec
,
TIME_FORMAT_LEGACY
),
nsec
);
/* fixme: clock freq is not always 125 MHz */
return
0
;
}
...
...
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