001/*
002 * Copyright (C) Cross The Road Electronics.  All rights reserved.
003 * License information can be found in CTRE_LICENSE.txt
004 * For support and suggestions contact support@ctr-electronics.com or file
005 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
006 */
007package com.ctre.phoenixpro;
008
009/**
010 * A collection of timestamps for a received signal.
011 */
012public class AllTimestamps {
013    private Timestamp systemTimestamp = new Timestamp();
014    private Timestamp canivoreTimestamp = new Timestamp();
015
016    void update(Timestamp newSystemTimestamp, Timestamp newCanivoreTimestamp, Timestamp newDeviceTimestamp) {
017        systemTimestamp = newSystemTimestamp;
018        canivoreTimestamp = newCanivoreTimestamp;
019    }
020    void update(
021        double systemTimestampSeconds, Timestamp.TimestampSource systemTimestampSource, boolean systemTimestampValid,
022        double canivoreTimestampSeconds, Timestamp.TimestampSource canivoreTimestampSource, boolean canivoreTimestampValid,
023        double deviceTimestampSeconds, Timestamp.TimestampSource deviceTimestampSource, boolean deviceTimestampValid
024    ) {
025        this.systemTimestamp.update(systemTimestampSeconds, systemTimestampSource, systemTimestampValid);
026        this.canivoreTimestamp.update(canivoreTimestampSeconds, canivoreTimestampSource, canivoreTimestampValid);
027    }
028
029    /**
030     * Get the best timestamp available.
031     *
032     * @return Best available timestamp
033     */
034    public Timestamp getBestTimestamp() {
035        if (canivoreTimestamp.isValid())
036            return canivoreTimestamp;
037        /* System timestamp is always available */
038        return systemTimestamp;
039    }
040
041    /**
042     * Get the timestamp as reported by the system.
043     *
044     * @return {@link Timestamp.TimestampSource#System System} timestamp
045     */
046    public Timestamp getSystemTimestamp() {
047        return systemTimestamp;
048    }
049    /**
050     * Get the timestamp as reported by the CANivore.
051     *
052     * @return {@link Timestamp.TimestampSource#CANivore CANivore} timestamp
053     */
054    public Timestamp getCANivoreTimestamp() {
055        return canivoreTimestamp;
056    }
057}