NewPiServo returns a servo.PiServo object configure for synchronizing the given device. maxFreq 0 is equivalent to no maxFreq
(interval time.Duration, firstStepth time.Duration, stepth time.Duration, device FrequencyGetter, maxFreq float64)
| 188 | |
| 189 | // NewPiServo returns a servo.PiServo object configure for synchronizing the given device. maxFreq 0 is equivalent to no maxFreq |
| 190 | func NewPiServo(interval time.Duration, firstStepth time.Duration, stepth time.Duration, device FrequencyGetter, maxFreq float64) (*servo.PiServo, error) { |
| 191 | servoCfg := servo.DefaultServoConfig() |
| 192 | if firstStepth != 0 { |
| 193 | // allow stepping clock on first update |
| 194 | servoCfg.FirstUpdate = true |
| 195 | servoCfg.FirstStepThreshold = int64(firstStepth) |
| 196 | } |
| 197 | servoCfg.StepThreshold = int64(stepth) |
| 198 | freq, err := device.FreqPPB() |
| 199 | if err != nil { |
| 200 | return nil, err |
| 201 | } |
| 202 | |
| 203 | pi := servo.NewPiServo(servoCfg, servo.DefaultPiServoCfg(), -freq) |
| 204 | pi.SyncInterval(interval.Seconds()) |
| 205 | |
| 206 | if maxFreq == 0 { |
| 207 | maxFreq, err = device.MaxFreqAdjPPB() |
| 208 | if err != nil { |
| 209 | log.Printf("unable to get max frequency adjustment from device, using default: %f", defaultMaxFreqAdj) |
| 210 | maxFreq = defaultMaxFreqAdj |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | pi.SetMaxFreq(maxFreq) |
| 215 | |
| 216 | return pi, nil |
| 217 | } |
| 218 | |
| 219 | func validatePPSEvent(eventTimestamp time.Time, dstDevice DeviceController) error { |
| 220 | dstTs, err := dstDevice.Time() |
searching dependent graphs…