kopia lustrzana https://github.com/Hamlib/Hamlib
added helper functions for cache timeout management
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2858 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.2.11
rodzic
7fa2926ebe
commit
7c91105efd
69
src/misc.c
69
src/misc.c
|
@ -1,8 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Hamlib Interface - toolbox
|
* Hamlib Interface - toolbox
|
||||||
* Copyright (c) 2000-2005 by Stephane Fillod
|
* Copyright (c) 2000-2010 by Stephane Fillod
|
||||||
*
|
|
||||||
* $Id$
|
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
@ -44,6 +42,9 @@
|
||||||
#ifdef HAVE_SYS_TYPES_H
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <hamlib/rig.h>
|
#include <hamlib/rig.h>
|
||||||
|
@ -776,4 +777,66 @@ const char * HAMLIB_API rig_strmtype(chan_type_t mtype)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static long timediff(const struct timeval *tv1, const struct timeval *tv2)
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
|
tv.tv_usec = tv1->tv_usec - tv2->tv_usec;
|
||||||
|
tv.tv_sec = tv1->tv_sec - tv2->tv_sec;
|
||||||
|
|
||||||
|
return ((tv.tv_sec * 1000L) + (tv.tv_usec / 1000L));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Helper for checking cache timeout
|
||||||
|
* \param tv pointer to timeval, date of cache
|
||||||
|
* \param timeout duration of cache validity, in millisec
|
||||||
|
* \return 1 when timed out, 0 when cache shall be used
|
||||||
|
*/
|
||||||
|
int HAMLIB_API rig_check_cache_timeout(const struct timeval *tv, int timeout)
|
||||||
|
{
|
||||||
|
struct timeval curr;
|
||||||
|
long t;
|
||||||
|
|
||||||
|
if (tv->tv_sec == 0 && tv->tv_usec == 0) {
|
||||||
|
rig_debug(RIG_DEBUG_VERBOSE, "forced cache timeout\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
gettimeofday(&curr, NULL);
|
||||||
|
|
||||||
|
t = timediff(&curr, tv);
|
||||||
|
if (t < timeout) {
|
||||||
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: using cache (%ld ms)\n",
|
||||||
|
__func__, t);
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
rig_debug(RIG_DEBUG_VERBOSE, "%s: cache timed out (%ld ms)\n",
|
||||||
|
__func__, t);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Helper for forcing cache timeout next call
|
||||||
|
*
|
||||||
|
* This function is typically to be called in backend_set_* functions,
|
||||||
|
* so that a sequence:
|
||||||
|
*
|
||||||
|
\code
|
||||||
|
rig_get_freq();
|
||||||
|
rig_set_freq();
|
||||||
|
rig_get_freq();
|
||||||
|
\endcode
|
||||||
|
*
|
||||||
|
* doesn't return a bogus (cached) value in the last rig_get_freq().
|
||||||
|
*
|
||||||
|
* \param tv pointer to timeval to be reset
|
||||||
|
*/
|
||||||
|
void HAMLIB_API rig_force_cache_timeout(struct timeval *tv)
|
||||||
|
{
|
||||||
|
tv->tv_sec = 0;
|
||||||
|
tv->tv_usec = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -62,7 +62,6 @@ extern HAMLIB_EXPORT(unsigned long long) from_bcd_be(const unsigned char bcd_dat
|
||||||
|
|
||||||
extern HAMLIB_EXPORT(int) sprintf_freq(char *str, freq_t);
|
extern HAMLIB_EXPORT(int) sprintf_freq(char *str, freq_t);
|
||||||
|
|
||||||
|
|
||||||
/* check if it's any of CR or LF */
|
/* check if it's any of CR or LF */
|
||||||
#define isreturn(c) ((c) == 10 || (c) == 13)
|
#define isreturn(c) ((c) == 10 || (c) == 13)
|
||||||
|
|
||||||
|
@ -71,6 +70,13 @@ extern HAMLIB_EXPORT(int) sprintf_freq(char *str, freq_t);
|
||||||
#ifdef HAVE_INTTYPES_H
|
#ifdef HAVE_INTTYPES_H
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_SYS_TIME_H
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern HAMLIB_EXPORT(int) rig_check_cache_timeout(const struct timeval *tv, int timeout);
|
||||||
|
extern HAMLIB_EXPORT(void) rig_force_cache_timeout(struct timeval *tv);
|
||||||
|
|
||||||
|
|
||||||
#ifdef PRId64
|
#ifdef PRId64
|
||||||
/** \brief printf(3) format to be used for long long (64bits) type */
|
/** \brief printf(3) format to be used for long long (64bits) type */
|
||||||
|
|
13
tuner/v4l.c
13
tuner/v4l.c
|
@ -1,8 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Hamlib Tuner backend - Video4Linux (v1) description
|
* Hamlib Tuner backend - Video4Linux (v1) description
|
||||||
* Copyright (c) 2004-2009 by Stephane Fillod
|
* Copyright (c) 2004-2010 by Stephane Fillod
|
||||||
*
|
*
|
||||||
* $Id: v4l.c,v 1.2 2004-09-25 14:33:52 fillods Exp $
|
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or modify
|
* This library is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Library General Public License as
|
* it under the terms of the GNU Library General Public License as
|
||||||
|
@ -26,15 +25,15 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "hamlib/rig.h"
|
||||||
|
#include "tuner.h" /* include config.h */
|
||||||
|
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
#ifdef HAVE_SYS_IOCTL_H
|
#ifdef HAVE_SYS_IOCTL_H
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "hamlib/rig.h"
|
|
||||||
#include "misc.h"
|
|
||||||
|
|
||||||
#include "tuner.h" /* include config.h */
|
|
||||||
|
|
||||||
#ifdef V4L_IOCTL
|
#ifdef V4L_IOCTL
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
Ładowanie…
Reference in New Issue