1
0
Fork 0

Updated Libs

This commit is contained in:
Andreas Eversberg 2022-02-16 15:03:28 +01:00
parent aed1210513
commit 0ad29dcc63
3 changed files with 59 additions and 43 deletions

View File

@ -25,6 +25,7 @@
#include <errno.h>
#include <math.h>
#include <time.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include "debug.h"
@ -55,6 +56,7 @@ struct debug_cat {
{ "mpt1327", "\033[1;34m" },
{ "jollycom", "\033[1;34m" },
{ "eurosignal", "\033[1;34m" },
{ "pocsag", "\033[1;34m" },
{ "frame", "\033[0;36m" },
{ "call", "\033[0;37m" },
{ "cc", "\033[1;32m" },
@ -100,6 +102,9 @@ void (*print_console_text)(void) = NULL;
int debug_limit_scroll = 0;
static int lock_initialized = 0;
static pthread_mutex_t debug_mutex;
void get_win_size(int *w, int *h)
{
struct winsize win;
@ -123,10 +128,22 @@ void _printdebug(const char *file, const char __attribute__((unused)) *function,
const char *p;
va_list args;
int w, h;
int rc;
if (debuglevel > level)
return;
if (!(debug_mask & ((uint64_t)1 << cat)))
return;
if (!lock_initialized) {
rc = pthread_mutex_init(&debug_mutex, NULL);
if (rc == 0)
lock_initialized = 1;
}
if (lock_initialized)
pthread_mutex_lock(&debug_mutex);
buffer[sizeof(buffer) - 1] = '\0';
/* if kanal is used, prefix the channel number */
@ -136,9 +153,6 @@ void _printdebug(const char *file, const char __attribute__((unused)) *function,
s -= strlen(buffer);
}
if (!(debug_mask & ((uint64_t)1 << cat)))
return;
va_start(args, fmt);
vsnprintf(b, s, fmt, args);
va_end(args);
@ -166,6 +180,9 @@ void _printdebug(const char *file, const char __attribute__((unused)) *function,
if (print_console_text)
print_console_text();
fflush(stdout);
if (lock_initialized)
pthread_mutex_unlock(&debug_mutex);
}
const char *debug_amplitude(double level)

View File

@ -18,38 +18,39 @@
#define DMPT1327 11
#define DJOLLY 12
#define DEURO 13
#define DFRAME 14
#define DCALL 15
#define DCC 16
#define DDB 17
#define DTRANS 18
#define DDMS 19
#define DSMS 20
#define DSDR 21
#define DUHD 22
#define DSOAPY 23
#define DWAVE 24
#define DRADIO 25
#define DAM791X 26
#define DUART 27
#define DDEVICE 28
#define DDATENKLO 29
#define DZEIT 30
#define DSIM1 31
#define DSIM2 32
#define DSIMI 33
#define DSIM7 34
#define DMTP2 35
#define DMTP3 36
#define DMUP 37
#define DROUTER 38
#define DSTDERR 39
#define DSS5 40
#define DISDN 41
#define DMISDN 42
#define DDSS1 43
#define DSIP 44
#define DTEL 45
#define DPOCSAG 14
#define DFRAME 15
#define DCALL 16
#define DCC 17
#define DDB 18
#define DTRANS 19
#define DDMS 20
#define DSMS 21
#define DSDR 22
#define DUHD 23
#define DSOAPY 24
#define DWAVE 25
#define DRADIO 26
#define DAM791X 27
#define DUART 28
#define DDEVICE 29
#define DDATENKLO 30
#define DZEIT 31
#define DSIM1 32
#define DSIM2 33
#define DSIMI 34
#define DSIM7 35
#define DMTP2 36
#define DMTP3 37
#define DMUP 38
#define DROUTER 39
#define DSTDERR 40
#define DSS5 41
#define DISDN 42
#define DMISDN 43
#define DDSS1 44
#define DSIP 45
#define DTEL 46
void get_win_size(int *w, int *h);

View File

@ -21,7 +21,9 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
//#include <sys/time.h>
#include <time.h>
#include <errno.h>
#include "timer.h"
static struct timer *timer_head = NULL;
@ -29,11 +31,11 @@ static struct timer **timer_tail_p = &timer_head;
double get_time(void)
{
struct timeval tv;
static struct timespec tv;
gettimeofday(&tv, NULL);
clock_gettime(CLOCK_REALTIME, &tv);
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
return (double)tv.tv_sec + (double)tv.tv_nsec / 1000000000.0;
}
void timer_init(struct timer *timer, void (*fn)(struct timer *timer), void *priv)
@ -66,15 +68,11 @@ void timer_exit(struct timer *timer)
void timer_start(struct timer *timer, double duration)
{
struct timeval tv;
if (!timer->linked) {
fprintf(stderr, "Timer is not initialized, aborting!\n");
abort();
}
gettimeofday(&tv, NULL);
timer->duration = duration;
timer->timeout = get_time() + duration;
}