Beispiel #1
0
epicsUInt32
evgMrm::sendTimestamp() {
    /*Start the timer*/
    m_timerEvent->signal();

    /*If the time since last update is more than 1.5 secs(i.e. if wdTimer expires) 
    then we need to resync the time after 5 good pulses*/
    if(m_wdTimer->getPilotCount()) {
        m_wdTimer->decrPilotCount();
        if(m_wdTimer->getPilotCount() == 0) {
            syncTimestamp();
            printf("Starting timestamping\n");
            ((epicsTime)getTimestamp()).show(1);
        }
        return 0;
    }

    m_alarmTimestamp = TS_ALARM_NONE;

    incrTimestamp();
    scanIoRequest(ioScanTimestamp);

    if(m_syncTimestamp) {
        syncTimestamp();
        m_syncTimestamp = false;
    }

    struct epicsTimeStamp ts;
    epicsTime ntpTime, storedTime;
    if(epicsTimeOK == generalTimeGetExceptPriority(&ts, 0, 50)) {
        ntpTime = ts;
        storedTime = (epicsTime)getTimestamp();

        double errorTime = ntpTime - storedTime;

        /*If there is an error between storedTime and ntpTime then we just print
            the relevant information but we send out storedTime*/
        if(fabs(errorTime) > evgAllowedTsGitter) {
            m_alarmTimestamp = TS_ALARM_MINOR;
            printf("NTP time:\n");
            ntpTime.show(1);
            printf("EVG time:\n");
            storedTime.show(1);
            printf("----Timestamping Error of %f Secs----\n", errorTime);
        } 
    }

    return getTimestamp().secPastEpoch + 1 + POSIX_TIME_AT_EPICS_EPOCH;
}
Beispiel #2
0
void
evgMrm::syncTimestamp() {
    if(epicsTimeOK != generalTimeGetExceptPriority(&m_timestamp, 0, 50))
        return;
    /*
     * Generally nano seconds should be close to zero.
     *  So the seconds value should be rounded to the nearest interger
     *  e.g. 26.000001000 should be rounded to 26 and
     *       26.996234643 should be rounded to 27.
     *  Also the nano second value can be assumed to be zero.
     */
    if(m_timestamp.nsec > 500*pow(10,6))
        incrTimestamp();
    
    m_timestamp.nsec = 0;
}
Beispiel #3
0
static void ClockTimeSync(void *dummy)
{
    taskwdInsert(0, NULL, NULL);

    for (epicsEventWaitWithTimeout(ClockTimePvt.loopEvent,
             ClockTimeSyncInterval);
         ClockTimePvt.synchronize == CLOCKTIME_SYNC;
         epicsEventWaitWithTimeout(ClockTimePvt.loopEvent,
             ClockTimeSyncInterval)) {
        epicsTimeStamp timeNow;
        int priority;

        if (generalTimeGetExceptPriority(&timeNow, &priority,
                LAST_RESORT_PRIORITY) == epicsTimeOK) {
            struct timespec clockNow;

            epicsTimeToTimespec(&clockNow, &timeNow);
            if (clock_settime(CLOCK_REALTIME, &clockNow)) {
                errlogPrintf("ClockTimeSync: clock_settime failed\n");
                continue;
            }

            epicsMutexMustLock(ClockTimePvt.lock);
            if (!ClockTimePvt.synchronized) {
                ClockTimePvt.startTime    = timeNow;
                ClockTimePvt.synchronized = 1;
            }
            ClockTimePvt.syncFromPriority = priority;
            ClockTimePvt.syncTime         = timeNow;
            epicsMutexUnlock(ClockTimePvt.lock);
        }
    }

    ClockTimePvt.synchronized = 0;
    taskwdRemove(0);
}
Beispiel #4
0
int epicsShareAPI epicsTimeGetCurrent(epicsTimeStamp *pDest)
{
    return generalTimeGetExceptPriority(pDest, NULL, 0);
}