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
29
Issues
29
List
Board
Labels
Milestones
Merge Requests
5
Merge Requests
5
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
6bc87954
Commit
6bc87954
authored
Jun 04, 2012
by
Tomasz Wlostowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
monitor gui: moved utility functions to lib/
parent
7b9de0a7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
142 additions
and
134 deletions
+142
-134
mprintf.c
lib/mprintf.c
+6
-31
util.c
lib/util.c
+94
-0
monitor.c
monitor/monitor.c
+42
-103
No files found.
lib/mprintf.c
View file @
6bc87954
...
...
@@ -3,6 +3,7 @@
#include <stdlib.h>
#include "uart.h"
#include "util.h"
int
vprintf
(
char
const
*
format
,
va_list
ap
)
{
...
...
@@ -232,11 +233,11 @@ CONVERSION_LOOP:
int
mprintf
(
char
const
*
format
,
...)
{
int
rval
;
va_list
ap
;
va_start
(
ap
,
format
);
rval
=
vprintf
(
format
,
ap
);
va_end
(
ap
);
return
rval
;
va_list
ap
;
va_start
(
ap
,
format
);
rval
=
vprintf
(
format
,
ap
);
va_end
(
ap
);
return
rval
;
}
...
...
@@ -248,29 +249,3 @@ int sprintf(char *dst, char const *format, ...)
return
r
;
}
#define C_DIM 0x80
void
m_cprintf
(
int
color
,
const
char
*
fmt
,
...)
{
va_list
ap
;
mprintf
(
"
\033
[0%d;3%dm"
,
color
&
C_DIM
?
2
:
1
,
color
&
0x7f
);
va_start
(
ap
,
fmt
);
vprintf
(
fmt
,
ap
);
va_end
(
ap
);
}
void
m_pcprintf
(
int
row
,
int
col
,
int
color
,
const
char
*
fmt
,
...)
{
va_list
ap
;
mprintf
(
"
\033
[%d;%df"
,
row
,
col
);
mprintf
(
"
\033
[0%d;3%dm"
,
color
&
C_DIM
?
2
:
1
,
color
&
0x7f
);
va_start
(
ap
,
fmt
);
vprintf
(
fmt
,
ap
);
va_end
(
ap
);
}
void
m_term_clear
()
{
mprintf
(
"
\033
[2J
\033
[1;1H"
);
}
lib/util.c
0 → 100644
View file @
6bc87954
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <time.h>
#include "util.h"
/* cut from libc sources */
#define YEAR0 1900
#define EPOCH_YR 1970
#define SECS_DAY (24L * 60L * 60L)
#define LEAPYEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400)))
#define YEARSIZE(year) (LEAPYEAR(year) ? 366 : 365)
#define FIRSTSUNDAY(timp) (((timp)->tm_yday - (timp)->tm_wday + 420) % 7)
#define FIRSTDAYOF(timp) (((timp)->tm_wday - (timp)->tm_yday + 420) % 7)
#define TIME_MAX ULONG_MAX
#define ABB_LEN 3
static
const
char
*
_days
[]
=
{
"Sun"
,
"Mon"
,
"Tue"
,
"Wed"
,
"Thu"
,
"Fri"
,
"Sat"
};
static
const
char
*
_months
[]
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
static
const
int
_ytab
[
2
][
12
]
=
{
{
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
},
{
31
,
29
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
}
};
char
*
format_time
(
uint32_t
utc
)
{
struct
tm
t
;
static
char
buf
[
64
];
unsigned
long
dayclock
,
dayno
;
int
year
=
EPOCH_YR
;
dayclock
=
(
unsigned
long
)
utc
%
SECS_DAY
;
dayno
=
(
unsigned
long
)
utc
/
SECS_DAY
;
t
.
tm_sec
=
dayclock
%
60
;
t
.
tm_min
=
(
dayclock
%
3600
)
/
60
;
t
.
tm_hour
=
dayclock
/
3600
;
t
.
tm_wday
=
(
dayno
+
4
)
%
7
;
/* day 0 was a thursday */
while
(
dayno
>=
YEARSIZE
(
year
))
{
dayno
-=
YEARSIZE
(
year
);
year
++
;
}
t
.
tm_year
=
year
-
YEAR0
;
t
.
tm_yday
=
dayno
;
t
.
tm_mon
=
0
;
while
(
dayno
>=
_ytab
[
LEAPYEAR
(
year
)][
t
.
tm_mon
])
{
dayno
-=
_ytab
[
LEAPYEAR
(
year
)][
t
.
tm_mon
];
t
.
tm_mon
++
;
}
t
.
tm_mday
=
dayno
+
1
;
t
.
tm_isdst
=
0
;
sprintf
(
buf
,
"%s, %s %d, %d, %2d:%2d:%2d"
,
_days
[
t
.
tm_wday
],
_months
[
t
.
tm_mon
],
t
.
tm_mday
,
t
.
tm_year
+
YEAR0
,
t
.
tm_hour
,
t
.
tm_min
,
t
.
tm_sec
);
return
buf
;
}
void
cprintf
(
int
color
,
const
char
*
fmt
,
...)
{
va_list
ap
;
mprintf
(
"
\033
[0%d;3%dm"
,
color
&
C_DIM
?
2
:
1
,
color
&
0x7f
);
va_start
(
ap
,
fmt
);
vprintf
(
fmt
,
ap
);
va_end
(
ap
);
}
void
pcprintf
(
int
row
,
int
col
,
int
color
,
const
char
*
fmt
,
...)
{
va_list
ap
;
mprintf
(
"
\033
[%d;%df"
,
row
,
col
);
mprintf
(
"
\033
[0%d;3%dm"
,
color
&
C_DIM
?
2
:
1
,
color
&
0x7f
);
va_start
(
ap
,
fmt
);
vprintf
(
fmt
,
ap
);
va_end
(
ap
);
}
void
term_clear
()
{
mprintf
(
"
\033
[2J
\033
[1;1H"
);
}
monitor/monitor.c
View file @
6bc87954
This diff is collapsed.
Click to expand it.
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