Skip to content

Commit d122bd3

Browse files
authored
Merge pull request #2421 from ControlSystemStudio/pva_time_valid
Detect EPICS epoch zero in PVA timestamp
2 parents 46bb2bf + fc155c8 commit d122bd3

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

core/pv/src/main/java/org/phoebus/pv/ca/DBRHelper.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017-2018 Oak Ridge National Laboratory.
2+
* Copyright (c) 2017-2022 Oak Ridge National Laboratory.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -69,6 +69,9 @@
6969
@SuppressWarnings("nls")
7070
public class DBRHelper
7171
{
72+
/** 1990/01/01 00:00:00 epoch used by Channel Access and records on IOC */
73+
public static final long EPICS_EPOCH = 631152000L;
74+
7275
/** @param plain Get plain type of CTRL_... type?
7376
* @param type Example data
7477
* @return CTRL_... type for this channel.
@@ -155,7 +158,7 @@ private static Time convertTime(final DBR dbr)
155158
if (epics_time == null)
156159
return Time.nowInvalid();
157160

158-
final Instant instant = Instant.ofEpochSecond(epics_time.secPastEpoch() + 631152000L, (int) epics_time.nsec());
161+
final Instant instant = Instant.ofEpochSecond(epics_time.secPastEpoch() + EPICS_EPOCH, (int) epics_time.nsec());
159162
if (epics_time.secPastEpoch() <= 0)
160163
return Time.of(instant, 0, false);
161164

core/pv/src/main/java/org/phoebus/pv/pva/Decoders.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import org.epics.vtype.VULongArray;
7777
import org.epics.vtype.VUShort;
7878
import org.epics.vtype.VUShortArray;
79+
import org.phoebus.pv.ca.DBRHelper;
7980

8081
/** Decodes {@link Time}, {@link Alarm}, {@link Display}, ...
8182
* @author Kay Kasemir
@@ -162,7 +163,14 @@ static Time decodeTime(final PVAStructure struct)
162163
timestamp = NO_TIME;
163164
usertag = NO_USERTAG;
164165
}
165-
return Time.of(timestamp, usertag, timestamp.getEpochSecond() > 0);
166+
167+
// A time stamp of all zeroes is not valid.
168+
// In addition, a time stamp of 1990/01/02 00:00:00
169+
// as used for the Channel Access and IOC time stamp epoch
170+
// is considered invalid because IOCs send it for never processed records
171+
final boolean valid = timestamp.getNano() != 0 &&
172+
(timestamp.getEpochSecond() > 0 && timestamp.getEpochSecond() != DBRHelper.EPICS_EPOCH);
173+
return Time.of(timestamp, usertag, valid);
166174
}
167175

168176
/** @param printfFormat Format from NTScalar display.format

0 commit comments

Comments
 (0)