aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2016-07-24 09:12:54 +0200
committerAndreas Eversberg <jolly@eversberg.eu>2016-07-24 12:31:08 +0200
commitc273bbc5ff8c6e35ec7a0b1524e509e0a6520d98 (patch)
tree7cd127ca1b4b1f133fbd556ee4c2fea4ea9ab5f3
parent123979a0f366120155cc043fe8f8743340bdf85d (diff)
Remove console line before printing debugging and on exit
-rw-r--r--src/common/call.c30
-rw-r--r--src/common/call.h1
-rw-r--r--src/common/debug.c2
-rw-r--r--src/common/main_common.c2
-rw-r--r--src/test/Makefile.am9
-rw-r--r--src/test/dummy.c8
6 files changed, 44 insertions, 8 deletions
diff --git a/src/common/call.c b/src/common/call.c
index 0b0ab17..0abb7f6 100644
--- a/src/common/call.c
+++ b/src/common/call.c
@@ -472,6 +472,10 @@ void call_cleanup(void)
}
}
+static char console_text[256];
+static char console_clear[256];
+static int console_len = 0;
+
static void process_ui(int c)
{
switch (call.state) {
@@ -501,7 +505,7 @@ dial_after_hangup:
}
}
}
- printf("on-hook: %s%s (enter 0..9 or d=dial)\r", call.station_id, "..............." + 15 - call.dial_digits + strlen(call.station_id));
+ sprintf(console_text, "on-hook: %s%s (enter 0..9 or d=dial)\r", call.station_id, "..............." + 15 - call.dial_digits + strlen(call.station_id));
break;
case CALL_SETUP_MO:
case CALL_SETUP_MT:
@@ -521,22 +525,36 @@ dial_after_hangup:
}
}
if (call.state == CALL_SETUP_MT)
- printf("call setup: %s (enter h=hangup)\r", call.station_id);
+ sprintf(console_text, "call setup: %s (enter h=hangup)\r", call.station_id);
if (call.state == CALL_ALERTING)
- printf("call ringing: %s (enter h=hangup)\r", call.station_id);
+ sprintf(console_text, "call ringing: %s (enter h=hangup)\r", call.station_id);
if (call.state == CALL_CONNECT) {
if (call.dialing[0])
- printf("call active: %s->%s (enter h=hangup)\r", call.station_id, call.dialing);
+ sprintf(console_text, "call active: %s->%s (enter h=hangup)\r", call.station_id, call.dialing);
else
- printf("call active: %s (enter h=hangup)\r", call.station_id);
+ sprintf(console_text, "call active: %s (enter h=hangup)\r", call.station_id);
}
if (call.state == CALL_DISCONNECTED)
- printf("call disconnected: %s (enter h=hangup)\r", cause_name(call.disc_cause));
+ sprintf(console_text, "call disconnected: %s (enter h=hangup)\r", cause_name(call.disc_cause));
break;
}
+ console_len = strlen(console_text);
+ memset(console_clear, ' ', console_len - 1);
+ console_clear[console_len - 1] = '\r';
+ fwrite(console_text, console_len, 1, stdout);
fflush(stdout);
}
+void clear_console_text(void)
+{
+ if (!console_len)
+ return;
+
+ fwrite(console_clear, console_len, 1, stdout);
+ // note: fflused by user of this function
+}
+
+
/* get keys from keyboad to control call via console
* returns 1 on exit (ctrl+c) */
void process_call(int c)
diff --git a/src/common/call.h b/src/common/call.h
index a540aac..0ee3003 100644
--- a/src/common/call.h
+++ b/src/common/call.h
@@ -12,6 +12,7 @@ enum number_type {
int call_init(const char *station_id, const char *sounddev, int samplerate, int latency, int dial_digits, int loopback);
void call_cleanup(void);
void process_call(int c);
+void clear_console_text(void);
/* received messages */
int call_in_setup(int callref, const char *callerid, const char *dialing);
diff --git a/src/common/debug.c b/src/common/debug.c
index 2130ac5..c075f13 100644
--- a/src/common/debug.c
+++ b/src/common/debug.c
@@ -24,6 +24,7 @@
#include <stdint.h>
#include <errno.h>
#include "debug.h"
+#include "call.h"
const char *debug_level[] = {
"debug ",
@@ -78,6 +79,7 @@ void _printdebug(const char *file, const char *function, int line, int cat, int
while ((p = strchr(file, '/')))
file = p + 1;
+ clear_console_text();
// printf("%s%s:%d %s() %s: %s\033[0;39m", debug_cat[cat].color, file, line, function, debug_level[level], buffer);
printf("%s%s:%d %s: %s\033[0;39m", debug_cat[cat].color, file, line, debug_level[level], buffer);
fflush(stdout);
diff --git a/src/common/main_common.c b/src/common/main_common.c
index e104c56..4bd9e94 100644
--- a/src/common/main_common.c
+++ b/src/common/main_common.c
@@ -341,6 +341,8 @@ next_char:
usleep(interval * 1000);
}
+ clear_console_text();
+
/* reset terminal */
tcsetattr(0, TCSANOW, &term_orig);
}
diff --git a/src/test/Makefile.am b/src/test/Makefile.am
index 0a62340..f6cb592 100644
--- a/src/test/Makefile.am
+++ b/src/test/Makefile.am
@@ -14,28 +14,33 @@ test_compandor_LDADD = \
$(top_builddir)/src/common/libcommon.a \
-lm
-test_emphasis_SOURCES = test_emphasis.c
+test_emphasis_SOURCES = test_emphasis.c dummy.c
test_emphasis_LDADD = \
$(COMMON_LA) \
$(top_builddir)/src/common/libcommon.a \
+ $(ALSA_LIBS) \
-lm
test_dms_SOURCES = \
$(top_builddir)/src/nmt/dms.c \
- test_dms.c
+ test_dms.c \
+ dummy.c
test_dms_LDADD = \
$(COMMON_LA) \
$(top_builddir)/src/common/libcommon.a \
+ $(ALSA_LIBS) \
-lm
test_sms_SOURCES = \
$(top_builddir)/src/nmt/sms.c \
+ dummy.c \
test_sms.c
test_sms_LDADD = \
$(COMMON_LA) \
$(top_builddir)/src/common/libcommon.a \
+ $(ALSA_LIBS) \
-lm
diff --git a/src/test/dummy.c b/src/test/dummy.c
new file mode 100644
index 0000000..a7a44bc
--- /dev/null
+++ b/src/test/dummy.c
@@ -0,0 +1,8 @@
+void call_rx_audio() { }
+void call_out_setup() { }
+void call_out_release() { }
+void call_out_disconnect() { }
+void print_help() { }
+void sender_send() { }
+void sender_receive() { }
+