Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop PtpClockTime.Time() #418

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions phc/offset.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ type SysoffResult struct {

// based on sysoff_estimate from ptp4l sysoff.c
func sysoffFromExtendedTS(extendedTS [3]PtpClockTime) SysoffResult {
t1 := extendedTS[0].Time()
tp := extendedTS[1].Time()
t2 := extendedTS[2].Time()
t1 := time.Unix(extendedTS[0].Sec, int64(extendedTS[0].Nsec))
tp := time.Unix(extendedTS[1].Sec, int64(extendedTS[1].Nsec))
t2 := time.Unix(extendedTS[2].Sec, int64(extendedTS[2].Nsec))
interval := t2.Sub(t1)
timestamp := t1.Add(interval / 2)
offset := timestamp.Sub(tp)
Expand All @@ -60,13 +60,14 @@ func sysoffFromExtendedTS(extendedTS [3]PtpClockTime) SysoffResult {
}

// SysoffFromPrecise returns SysoffResult from *PTPSysOffsetPrecise . Code based on sysoff_precise from ptp4l sysoff.c
func SysoffFromPrecise(precise *PTPSysOffsetPrecise) SysoffResult {
offset := precise.Realtime.Time().Sub(precise.Device.Time())
func SysoffFromPrecise(pre *PTPSysOffsetPrecise) SysoffResult {
tp := time.Unix(pre.Device.Sec, int64(pre.Device.Nsec))
tr := time.Unix(pre.Realtime.Sec, int64(pre.Realtime.Nsec))
return SysoffResult{
SysTime: precise.Realtime.Time(),
PHCTime: precise.Device.Time(),
SysTime: tr,
PHCTime: tp,
Delay: 0, // They are measured at the same time
Offset: offset,
Offset: tr.Sub(tp),
}
}

Expand Down
6 changes: 4 additions & 2 deletions phc/phc.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ func Time(iface string, method TimeMethod) (time.Time, error) {
return time.Time{}, err
}
latest := extended.Ts[extended.Samples-1]
return latest[1].Time(), nil
tp := latest[1]
return time.Unix(tp.Sec, int64(tp.Nsec)), nil
case MethodIoctlSysOffsetPrecise:
precise, err := dev.ReadSysoffPrecise()
if err != nil {
return time.Time{}, err
}
return precise.Device.Time(), nil
tp := precise.Device
return time.Unix(tp.Sec, int64(tp.Nsec)), nil
default:
return time.Time{}, fmt.Errorf("unknown method to get PHC time %q", method)
}
Expand Down
3 changes: 2 additions & 1 deletion phc/pps_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ func (ppsSink *PPSSink) getPPSEventTimestamp() (time.Time, error) {
return time.Time{}, fmt.Errorf("extts on unexpected pin index %d, expected %d", event.Index, ppsSink.InputPin)
}

eventTime := event.T.Time()
t := event.T
eventTime := time.Unix(t.Sec, int64(t.Nsec))

return eventTime, nil
}
Expand Down
19 changes: 0 additions & 19 deletions phc/unix/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,25 +270,6 @@ const (
PTP_PF_PHYSYNC //nolint:revive
)

// https://go-review.googlesource.com/c/sys/+/621498

// TimeToPtpClockTime returns t as PtpClockTime
func TimeToPtpClockTime(t time.Time) PtpClockTime {
sec := t.Unix()
nsec := uint32(t.Nanosecond())
return PtpClockTime{Sec: sec, Nsec: nsec}
}

// Time returns PTPClockTime as time.Time
func (t *PtpClockTime) Time() time.Time {
return time.Unix(t.Sec, int64(t.Nsec))
}

// Unix returns the time stored in t as seconds plus nanoseconds.
func (t *PtpClockTime) Unix() (sec int64, nsec int64) {
return t.Sec, int64(t.Nsec)
}

// bridging to upstream

type Cmsghdr = unix.Cmsghdr
Expand Down
Loading