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
99
Issue boards
Milestones
Wiki
Code
Merge requests
4
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Monitor
Incidents
Service Desk
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
Projects
White Rabbit Switch - Software
Commits
78df6a80
Commit
78df6a80
authored
3 months ago
by
Adam Wujek
Browse files
Options
Downloads
Patches
Plain Diff
userspace/tools/wr_irig: use mktime for day in month calculations
Signed-off-by:
Adam Wujek
<
dev_public@wujek.eu
>
parent
267965be
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
userspace/tools/wr_irig.c
+31
-50
31 additions, 50 deletions
userspace/tools/wr_irig.c
with
31 additions
and
50 deletions
userspace/tools/wr_irig.c
+
31
−
50
View file @
78df6a80
...
...
@@ -125,47 +125,45 @@ static int irig_get_date(struct irig_slave *irig, struct irig_time *t){
uint32_t
yr_raw
=
(
date
&
IRIG_SLAVE_DATE_YEARS_MASK
)
>>
IRIG_SLAVE_DATE_YEARS_SHIFT
;
uint32_t
valid
=
(
date
&
IRIG_SLAVE_DATE_VALID
);
uint32_t
days
=
(
day_raw
&
0x0f
);
uint32_t
y
days
=
(
day_raw
&
0x0f
);
uint32_t
yrs
=
(
yr_raw
&
0x0f
);
uint32_t
mon
=
0
;
const
int
m_to_d
[
12
]
=
{
0
,
31
,
59
,
90
,
120
,
151
,
181
,
212
,
243
,
273
,
304
,
334
};
struct
tm
t0
;
int
ret
;
int
i
=
0
;
for
(
i
=
0
;
i
<
6
;
i
++
)
{
if
((
day_raw
>>
5
)
&
1
<<
i
)
{
if
(
i
>=
4
)
{
days
+=
100
*
(
1
<<
(
i
-
4
));
y
days
+=
100
*
(
1
<<
(
i
-
4
));
}
else
{
days
+=
10
*
(
1
<<
i
);
y
days
+=
10
*
(
1
<<
i
);
}
}
}
//fixme
days
-=
1
;
for
(
i
=
0
;
i
<
4
;
i
++
)
{
if
((
yr_raw
>>
5
)
&
(
1
<<
i
)){
yrs
+=
10
*
(
1
<<
i
);
}
}
yrs
+=
2000
;
for
(
i
=
0
;
i
<
11
;
i
++
){
if
(
days
>=
m_to_d
[
i
]
&&
days
<
m_to_d
[
i
+
1
])
{
mon
=
i
+
1
;
days
-=
m_to_d
[
i
];
}
}
if
(
valid
){
t
->
day
=
day
s
;
t
->
mon
=
mon
;
t
->
year
=
yrs
;
memset
(
&
t0
,
0
,
sizeof
(
struct
tm
))
;
t0
.
tm_isdst
=
-
1
;
/* mktime counts year from 1900, irigb counts from 2000 */
t0
.
tm_year
=
yrs
+
100
;
/* Give days in a year as days in a month (tm_mday) to mktime to give
* month/day */
t0
.
tm_mday
=
ydays
;
ret
=
mktime
(
&
t0
);
if
(
valid
&&
ret
>
0
){
t
->
day
=
t0
.
tm_m
day
;
t
->
mon
=
t0
.
tm_mon
+
1
;
/* t0.tm_mon is 0..11 */
t
->
year
=
t0
.
tm_year
+
1900
;
return
0
;
}
return
-
1
;
}
...
...
@@ -194,35 +192,18 @@ static int irig_get_sbs(struct irig_slave *irig, struct irig_time *t)
static
int64_t
irig_time_to_seconds
(
struct
irig_time
*
t
)
{
short
month
,
year
;
int64_t
result
;
const
int
m_to_d
[
12
]
=
{
0
,
31
,
59
,
90
,
120
,
151
,
181
,
212
,
243
,
273
,
304
,
334
};
month
=
t
->
mon
;
year
=
t
->
year
+
month
/
12
+
1900
;
month
%=
12
;
if
(
month
<
0
)
{
year
-=
1
;
month
+=
12
;
}
result
=
(
year
-
1970
)
*
365
+
(
year
-
1969
)
/
4
+
m_to_d
[
month
];
result
=
(
year
-
1970
)
*
365
+
m_to_d
[
month
];
if
(
month
<=
1
)
year
-=
1
;
result
+=
(
year
-
1968
)
/
4
;
result
-=
(
year
-
1900
)
/
100
;
result
+=
(
year
-
1600
)
/
400
;
result
+=
t
->
day
;
result
-=
1
;
result
*=
24
;
result
+=
t
->
hour
;
result
*=
60
;
result
+=
t
->
min
;
result
*=
60
;
result
+=
t
->
sec
;
struct
tm
t0
;
memset
(
&
t0
,
0
,
sizeof
(
struct
tm
));
t0
.
tm_isdst
=
-
1
;
t0
.
tm_year
=
t
->
year
;
t0
.
tm_mon
=
t
->
mon
;
t0
.
tm_mday
=
t
->
day
;
t0
.
tm_hour
=
t
->
hour
;
t0
.
tm_min
=
t
->
min
;
t0
.
tm_sec
=
t
->
sec
;
result
=
mktime
(
&
t0
);
return
result
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
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!
Save comment
Cancel
Please
register
or
sign in
to comment