2016-03-01 17:40:38 +00:00
|
|
|
/* Simple debug functions for level and category filtering
|
|
|
|
*
|
|
|
|
* (C) 2016 by Andreas Eversberg <jolly@eversberg.eu>
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2016-06-12 08:50:55 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <errno.h>
|
2017-01-27 16:17:39 +00:00
|
|
|
#include <math.h>
|
2018-02-15 06:27:49 +00:00
|
|
|
#include <sys/ioctl.h>
|
2017-11-18 07:06:06 +00:00
|
|
|
#include "../libsample/sample.h"
|
2016-03-01 17:40:38 +00:00
|
|
|
#include "debug.h"
|
2017-11-18 07:49:13 +00:00
|
|
|
#include "../libdisplay/display.h"
|
2016-03-01 17:40:38 +00:00
|
|
|
|
|
|
|
const char *debug_level[] = {
|
|
|
|
"debug ",
|
|
|
|
"info ",
|
|
|
|
"notice ",
|
|
|
|
"error ",
|
2016-06-12 08:50:55 +00:00
|
|
|
NULL,
|
2016-03-01 17:40:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct debug_cat {
|
|
|
|
const char *name;
|
|
|
|
const char *color;
|
|
|
|
} debug_cat[] = {
|
2019-10-03 14:13:07 +00:00
|
|
|
{ "options", "\033[0;33m" },
|
2016-03-01 17:40:38 +00:00
|
|
|
{ "sender", "\033[1;33m" },
|
|
|
|
{ "sound", "\033[0;35m" },
|
2016-03-15 18:26:13 +00:00
|
|
|
{ "dsp", "\033[0;31m" },
|
2016-03-01 17:40:38 +00:00
|
|
|
{ "anetz", "\033[1;34m" },
|
|
|
|
{ "bnetz", "\033[1;34m" },
|
2016-02-16 17:56:55 +00:00
|
|
|
{ "cnetz", "\033[1;34m" },
|
2016-02-21 17:13:30 +00:00
|
|
|
{ "nmt", "\033[1;34m" },
|
2016-05-01 17:51:56 +00:00
|
|
|
{ "amps", "\033[1;34m" },
|
2017-06-10 13:30:20 +00:00
|
|
|
{ "r2000", "\033[1;34m" },
|
2019-07-21 19:19:54 +00:00
|
|
|
{ "imts", "\033[1;34m" },
|
2017-11-12 14:59:48 +00:00
|
|
|
{ "jollycom", "\033[1;34m" },
|
2019-11-29 15:19:56 +00:00
|
|
|
{ "eurosignal", "\033[1;34m" },
|
2016-02-21 17:13:30 +00:00
|
|
|
{ "frame", "\033[0;36m" },
|
2017-10-28 05:11:40 +00:00
|
|
|
{ "call", "\033[0;37m" },
|
2016-03-01 17:40:38 +00:00
|
|
|
{ "mncc", "\033[1;32m" },
|
2016-05-08 13:34:14 +00:00
|
|
|
{ "database", "\033[0;33m" },
|
2016-06-12 08:50:55 +00:00
|
|
|
{ "transaction", "\033[0;32m" },
|
2016-07-04 05:23:44 +00:00
|
|
|
{ "dms", "\033[0;33m" },
|
2016-07-04 17:52:00 +00:00
|
|
|
{ "sms", "\033[1;37m" },
|
2017-01-04 13:21:49 +00:00
|
|
|
{ "sdr", "\033[1;31m" },
|
2017-01-04 13:22:24 +00:00
|
|
|
{ "uhd", "\033[1;35m" },
|
2017-07-11 18:26:40 +00:00
|
|
|
{ "soapy", "\033[1;35m" },
|
2018-02-15 06:31:40 +00:00
|
|
|
{ "wave", "\033[1;33m" },
|
2018-01-20 15:03:47 +00:00
|
|
|
{ "radio", "\033[1;34m" },
|
2019-09-01 11:15:04 +00:00
|
|
|
{ "am791x", "\033[0;31m" },
|
|
|
|
{ "uart", "\033[0;32m" },
|
|
|
|
{ "device", "\033[0;33m" },
|
|
|
|
{ "datenklo", "\033[1;34m" },
|
2020-01-11 17:00:25 +00:00
|
|
|
{ "zeit", "\033[1;34m" },
|
2020-05-01 17:01:39 +00:00
|
|
|
{ "sim layer 1", "\033[0;31m" },
|
|
|
|
{ "sim layer 2", "\033[0;33m" },
|
|
|
|
{ "sim ICL layer", "\033[0;36m" },
|
|
|
|
{ "sim layer 7", "\033[0;37m" },
|
2016-06-12 08:50:55 +00:00
|
|
|
{ NULL, NULL }
|
2016-03-01 17:40:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int debuglevel = DEBUG_INFO;
|
2016-06-12 08:50:55 +00:00
|
|
|
uint64_t debug_mask = ~0;
|
2016-07-31 13:09:46 +00:00
|
|
|
extern int num_kanal;
|
2016-03-01 17:40:38 +00:00
|
|
|
|
2017-12-03 08:30:54 +00:00
|
|
|
void (*clear_console_text)(void) = NULL;
|
|
|
|
void (*print_console_text)(void) = NULL;
|
|
|
|
|
|
|
|
int debug_limit_scroll = 0;
|
|
|
|
|
2018-02-15 06:27:49 +00:00
|
|
|
void get_win_size(int *w, int *h)
|
|
|
|
{
|
|
|
|
struct winsize win;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = ioctl(0, TIOCGWINSZ, &win);
|
|
|
|
if (rc) {
|
|
|
|
*w = 80;
|
|
|
|
*h = 25;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*h = win.ws_row;
|
|
|
|
*w = win.ws_col;
|
|
|
|
if (*w > MAX_DISPLAY_WIDTH - 1)
|
|
|
|
*w = MAX_DISPLAY_WIDTH - 1;
|
|
|
|
}
|
|
|
|
|
2019-07-20 16:11:17 +00:00
|
|
|
void _printdebug(const char *file, const char __attribute__((unused)) *function, int line, int cat, int level, const char *kanal, const char *fmt, ...)
|
2016-03-01 17:40:38 +00:00
|
|
|
{
|
2016-07-31 13:09:46 +00:00
|
|
|
char buffer[4096], *b = buffer;
|
2017-01-05 07:29:10 +00:00
|
|
|
int s = sizeof(buffer) - 1;
|
2016-03-01 17:40:38 +00:00
|
|
|
const char *p;
|
|
|
|
va_list args;
|
2017-12-03 08:30:54 +00:00
|
|
|
int w, h;
|
2016-03-01 17:40:38 +00:00
|
|
|
|
|
|
|
if (debuglevel > level)
|
|
|
|
return;
|
|
|
|
|
2016-07-31 13:09:46 +00:00
|
|
|
buffer[sizeof(buffer) - 1] = '\0';
|
|
|
|
|
2019-07-20 16:11:17 +00:00
|
|
|
/* if kanal is used, prefix the channel number */
|
|
|
|
if (num_kanal > 1 && kanal) {
|
|
|
|
sprintf(buffer, "(chan %s) ", kanal);
|
2016-07-31 13:09:46 +00:00
|
|
|
b = strchr(buffer, '\0');
|
2017-01-05 07:29:10 +00:00
|
|
|
s -= strlen(buffer);
|
2016-07-31 13:09:46 +00:00
|
|
|
}
|
|
|
|
|
2016-06-12 08:50:55 +00:00
|
|
|
if (!(debug_mask & (1 << cat)))
|
|
|
|
return;
|
|
|
|
|
2016-03-01 17:40:38 +00:00
|
|
|
va_start(args, fmt);
|
2017-01-05 07:29:10 +00:00
|
|
|
vsnprintf(b, s, fmt, args);
|
2016-03-01 17:40:38 +00:00
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
while ((p = strchr(file, '/')))
|
|
|
|
file = p + 1;
|
2017-12-03 08:30:54 +00:00
|
|
|
if (clear_console_text)
|
|
|
|
clear_console_text();
|
|
|
|
if (debug_limit_scroll) {
|
|
|
|
get_win_size(&w, &h);
|
|
|
|
printf("\0337\033[%d;%dr\0338", debug_limit_scroll + 1, h);
|
|
|
|
}
|
2020-05-02 06:11:46 +00:00
|
|
|
printf("%s%s:%4d %s: %s\033[0;39m", debug_cat[cat].color, file, line, debug_level[level], buffer);
|
2017-12-03 08:30:54 +00:00
|
|
|
if (debug_limit_scroll)
|
|
|
|
printf("\0337\033[%d;%dr\0338", 1, h);
|
|
|
|
if (print_console_text)
|
|
|
|
print_console_text();
|
2016-03-01 17:40:38 +00:00
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
2016-05-15 18:31:42 +00:00
|
|
|
const char *debug_amplitude(double level)
|
|
|
|
{
|
|
|
|
static char text[42];
|
|
|
|
|
|
|
|
strcpy(text, " : ");
|
|
|
|
if (level > 1.0)
|
|
|
|
level = 1.0;
|
|
|
|
if (level < -1.0)
|
|
|
|
level = -1.0;
|
|
|
|
text[20 + (int)(level * 20)] = '*';
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2017-01-27 16:17:39 +00:00
|
|
|
#define level2db(level) (20 * log10(level))
|
|
|
|
|
|
|
|
const char *debug_db(double level_db)
|
|
|
|
{
|
|
|
|
static char text[128];
|
|
|
|
int l;
|
|
|
|
|
2017-01-28 07:02:11 +00:00
|
|
|
strcpy(text, ": . : . : . : . : . : . : . : . | . : . : . : . : . : . : . : . :");
|
2017-01-27 16:17:39 +00:00
|
|
|
if (level_db <= 0.0)
|
|
|
|
return text;
|
|
|
|
l = (int)round(level2db(level_db));
|
2017-01-28 07:02:11 +00:00
|
|
|
if (l > 48)
|
2017-01-27 16:17:39 +00:00
|
|
|
return text;
|
|
|
|
if (l < -48)
|
|
|
|
return text;
|
|
|
|
text[l + 48] = '*';
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2016-06-12 08:50:55 +00:00
|
|
|
void debug_list_cat(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printf("Give number of debug level:\n");
|
|
|
|
for (i = 0; debug_level[i]; i++)
|
|
|
|
printf(" %d = %s\n", i, debug_level[i]);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf("Give name(s) of debug category:\n");
|
|
|
|
for (i = 0; debug_cat[i].name; i++)
|
|
|
|
printf(" %s%s\033[0;39m\n", debug_cat[i].color, debug_cat[i].name);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int parse_debug_opt(const char *optarg)
|
|
|
|
{
|
|
|
|
int i, max_level = 0;
|
|
|
|
char *dstring, *p;
|
|
|
|
|
|
|
|
for (i = 0; debug_level[i]; i++)
|
|
|
|
max_level = i;
|
|
|
|
|
|
|
|
dstring = strdup(optarg);
|
|
|
|
p = strsep(&dstring, ",");
|
|
|
|
for (i = 0; i < p[i]; i++) {
|
|
|
|
if (p[i] < '0' || p[i] > '9') {
|
|
|
|
fprintf(stderr, "Only digits are allowed for debug level!\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debuglevel = atoi(p);
|
|
|
|
if (debuglevel > max_level) {
|
|
|
|
fprintf(stderr, "Debug level too high, use 'list' to show available levels!\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (dstring)
|
|
|
|
debug_mask = 0;
|
|
|
|
while((p = strsep(&dstring, ","))) {
|
|
|
|
for (i = 0; debug_cat[i].name; i++) {
|
|
|
|
if (!strcasecmp(p, debug_cat[i].name))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!debug_cat[i].name) {
|
|
|
|
fprintf(stderr, "Given debug category '%s' unknown, use 'list' to show available categories!\n", p);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
debug_mask |= (1 << i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|