@cond Doxygen_Suppress
| 1937 | |
| 1938 | //! @cond Doxygen_Suppress |
| 1939 | double HAMLIB_API elapsed_ms(struct timespec *start, int option) |
| 1940 | { |
| 1941 | // If option then we are starting the timing, else we get elapsed |
| 1942 | struct timespec stop; |
| 1943 | double elapsed_msec; |
| 1944 | |
| 1945 | if (option == HAMLIB_ELAPSED_SET) |
| 1946 | { |
| 1947 | start->tv_sec = start->tv_nsec = 0; |
| 1948 | } |
| 1949 | |
| 1950 | stop = *start; // just to suppress some compiler warnings |
| 1951 | |
| 1952 | //rig_debug(RIG_DEBUG_TRACE, "%s: start = %ld,%ld\n", __func__, |
| 1953 | // (long)start->tv_sec, (long)start->tv_nsec); |
| 1954 | |
| 1955 | |
| 1956 | switch (option) |
| 1957 | { |
| 1958 | case HAMLIB_ELAPSED_GET: |
| 1959 | if (start->tv_nsec == 0) // if we haven't done SET yet |
| 1960 | { |
| 1961 | clock_gettime(CLOCK_REALTIME, start); |
| 1962 | return 1000 * 1000; |
| 1963 | } |
| 1964 | |
| 1965 | clock_gettime(CLOCK_REALTIME, &stop); |
| 1966 | break; |
| 1967 | |
| 1968 | case HAMLIB_ELAPSED_SET: |
| 1969 | clock_gettime(CLOCK_REALTIME, start); |
| 1970 | //rig_debug(RIG_DEBUG_TRACE, "%s: after gettime, start = %ld,%ld\n", __func__, |
| 1971 | // (long)start->tv_sec, (long)start->tv_nsec); |
| 1972 | return 999 * 1000; // so we can tell the difference in debug where we came from |
| 1973 | |
| 1974 | case HAMLIB_ELAPSED_INVALIDATE: |
| 1975 | clock_gettime(CLOCK_REALTIME, start); |
| 1976 | stop = *start; |
| 1977 | start->tv_sec -= 10; // ten seconds should be more than enough |
| 1978 | break; |
| 1979 | } |
| 1980 | |
| 1981 | // Casts used to make sure the add is done as double |
| 1982 | elapsed_msec = (double)((stop.tv_sec - start->tv_sec) * 1000) + // sec -> ms |
| 1983 | (double)(stop.tv_nsec - start->tv_nsec) / 1e6; // ns -> ms |
| 1984 | |
| 1985 | //rig_debug(RIG_DEBUG_TRACE, "%s: elapsed_msecs=%.0f\n", __func__, elapsed_msec); |
| 1986 | |
| 1987 | if (elapsed_msec < 0 || option == HAMLIB_ELAPSED_INVALIDATE) { return 1000000; } |
| 1988 | |
| 1989 | return elapsed_msec; |
| 1990 | } |
| 1991 | //! @endcond |
| 1992 | |
| 1993 | static char *funcname = "Unknown"; |