Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
advLigoRTS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
CDS
software
advLigoRTS
Commits
866365f9
Commit
866365f9
authored
5 years ago
by
Jonathan Hanks
Browse files
Options
Downloads
Patches
Plain Diff
Working on the standalone edc timing
parent
e3343edb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/epics/seq/gps.hh
+136
-0
136 additions, 0 deletions
src/epics/seq/gps.hh
with
136 additions
and
0 deletions
src/epics/seq/gps.hh
0 → 100644
+
136
−
0
View file @
866365f9
//
// Created by jonathan.hanks on 10/20/17.
//
#ifndef TRANSFER_GPS_H
#define TRANSFER_GPS_H
#include
<ostream>
#include
<time.h>
#include
<sys/types.h>
#include
<sys/stat.h>
#include
<sys/ioctl.h>
#include
<fcntl.h>
#include
<unistd.h>
/**
* Operations on GPS time.
* Note for purposes of this testing, this does not return GPS time but system time.
*/
namespace
GPS
{
struct
gps_time
{
long
sec
;
long
nanosec
;
gps_time
()
:
sec
(
0
),
nanosec
(
0
)
{}
explicit
gps_time
(
long
s
)
:
sec
(
s
),
nanosec
(
0
)
{}
gps_time
(
long
s
,
long
ns
)
:
sec
(
s
),
nanosec
(
ns
)
{}
gps_time
(
const
gps_time
&
other
)
:
sec
(
other
.
sec
),
nanosec
(
other
.
nanosec
)
{}
gps_time
operator
-
(
const
gps_time
&
other
)
const
{
gps_time
result
(
sec
-
other
.
sec
,
nanosec
-
other
.
nanosec
);
while
(
result
.
nanosec
<
0
)
{
result
.
nanosec
+=
1000000000
;
--
result
.
sec
;
}
return
result
;
}
gps_time
operator
+
(
const
gps_time
&
other
)
const
{
gps_time
result
(
sec
+
other
.
sec
,
nanosec
+
other
.
nanosec
);
while
(
result
.
nanosec
>=
1000000000
)
{
result
.
nanosec
-=
1000000000
;
++
result
.
sec
;
}
return
result
;
}
bool
operator
==
(
const
gps_time
&
other
)
const
{
return
(
sec
==
other
.
sec
&&
nanosec
==
other
.
nanosec
);
}
bool
operator
!=
(
const
gps_time
&
other
)
const
{
return
!
(
*
this
==
other
);
}
bool
operator
<
(
const
gps_time
&
other
)
const
{
if
(
sec
<
other
.
sec
)
return
true
;
if
(
sec
>
other
.
sec
)
return
false
;
return
(
nanosec
<
other
.
nanosec
);
}
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
gps_time
&
gps
)
{
os
<<
gps
.
sec
<<
":"
<<
gps
.
nanosec
;
return
os
;
}
class
gps_clock
{
private:
int
fd_
;
int
offset_
;
bool
ok_
;
static
const
int
SYMMETRICOM_STATUS
=
0
;
static
const
int
SYMMETRICOM_TIME
=
1
;
static
bool
symm_ok
(
int
fd
)
{
if
(
fd
<
0
)
return
false
;
unsigned
long
req
=
0
;
ioctl
(
fd
,
gps_clock
::
SYMMETRICOM_STATUS
,
&
req
);
return
req
!=
0
;
}
public
:
explicit
gps_clock
(
int
offset
)
:
fd_
(
open
(
"/dev/gpstime"
,
O_RDWR
|
O_SYNC
)),
offset_
(
offset
),
ok_
(
gps_clock
::
symm_ok
(
fd_
))
{}
~
gps_clock
()
{
if
(
fd_
>=
0
)
close
(
fd_
);
}
bool
ok
()
const
{
return
ok_
;
}
gps_time
now
()
const
{
gps_time
result
;
if
(
ok_
)
{
unsigned
long
t
[
3
];
ioctl
(
fd_
,
gps_clock
::
SYMMETRICOM_TIME
,
&
t
);
t
[
1
]
*=
1000
;
t
[
1
]
+=
t
[
2
];
result
.
nanosec
=
t
[
1
];
result
.
sec
=
t
[
0
]
+
offset_
;
}
else
{
struct
timespec
ts
;
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
result
.
sec
=
ts
.
tv_sec
;
result
.
nanosec
=
ts
.
tv_nsec
;
}
return
result
;
}
};
}
#endif //TRANSFER_GPS_H
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