Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio output via stdout and UDP #440

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add -O option to redirect output to stderr.
  • Loading branch information
ars-ka0s committed Sep 25, 2023
commit 58652df5b9a73de5d8e385e13ab0b88733217624
2 changes: 1 addition & 1 deletion src/atest.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ int main (int argc, char *argv[])
}
#endif

text_color_init(1);
text_color_init(1, 0);
text_color_set(DW_COLOR_INFO);

/*
Expand Down
4 changes: 2 additions & 2 deletions src/cm108.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@

int main (void)
{
text_color_init (0); // Turn off text color.
text_color_init (0, 0); // Turn off text color.
#if defined(__OpenBSD__) || defined(__FreeBSD__)
dw_printf ("CM108 PTT support is not available for this operating system.\n");
#else
Expand Down Expand Up @@ -340,7 +340,7 @@ int main (int argc, char **argv)
int num_things;
int i;

text_color_init (0); // Turn off text color.
text_color_init (0, 0); // Turn off text color.
text_color_set(DW_COLOR_INFO);

if (argc >=2) {
Expand Down
2 changes: 1 addition & 1 deletion src/decode_aprs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5330,7 +5330,7 @@ int main (int argc, char *argv[])
}

// If you don't like the text colors, use 0 instead of 1 here.
text_color_init(1);
text_color_init(1, 0);
text_color_set(DW_COLOR_INFO);

while (fgets(stuff, sizeof(stuff), stdin) != NULL)
Expand Down
18 changes: 13 additions & 5 deletions src/direwolf.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ int main (int argc, char *argv[])
char x_opt_mode = ' '; /* "-x N" option for transmitting calibration tones. */
int x_opt_chan = 0; /* Split into 2 parts. Mode e.g. m, a, and optional channel. */

int O_opt = 0; /* Redirect text io to stderr for use with stdout audio */

strlcpy(l_opt_logdir, "", sizeof(l_opt_logdir));
strlcpy(L_opt_logfile, "", sizeof(L_opt_logfile));
strlcpy(P_opt, "", sizeof(P_opt));
Expand Down Expand Up @@ -270,8 +272,8 @@ int main (int argc, char *argv[])
#endif

/*
* Pre-scan the command line options for the text color option.
* We need to set this before any text output.
* Pre-scan the command line options for the text color and stdout redirect options.
* We need to set these before any text output.
* Default will be no colors if stdout is not a terminal (i.e. piped into
* something else such as "tee") but command line can override this.
*/
Expand All @@ -286,10 +288,12 @@ int main (int argc, char *argv[])

// FIXME: consider case of no space between t and number.

for (j=1; j<argc-1; j++) {
for (j=1; j<argc; j++) {
if (strcmp(argv[j], "-t") == 0) {
t_opt = atoi (argv[j+1]);
//dw_printf ("DEBUG: text color option = %d.\n", t_opt);
} else if (strcmp(argv[j], "-O") == 0) {
O_opt = 1;
}
}

Expand All @@ -299,7 +303,7 @@ int main (int argc, char *argv[])
// Might want to print OS version here. For Windows, see:
// https://msdn.microsoft.com/en-us/library/ms724451(v=VS.85).aspx

text_color_init(t_opt);
text_color_init(t_opt, O_opt);
text_color_set(DW_COLOR_INFO);
dw_printf ("Dire Wolf version %d.%d (%s) BETA TEST 7\n", MAJOR_VERSION, MINOR_VERSION, __DATE__);
//dw_printf ("Dire Wolf DEVELOPMENT version %d.%d %s (%s)\n", MAJOR_VERSION, MINOR_VERSION, "G", __DATE__);
Expand Down Expand Up @@ -421,7 +425,7 @@ int main (int argc, char *argv[])

/* ':' following option character means arg is required. */

c = getopt_long(argc, argv, "hP:B:gjJD:U:c:px:r:b:n:d:q:t:ul:L:Sa:E:T:e:X:AI:i:",
c = getopt_long(argc, argv, "hP:B:gjJD:U:c:px:r:b:n:d:q:t:ul:L:Sa:E:T:e:X:AI:i:O",
long_options, &option_index);
if (c == -1)
break;
Expand Down Expand Up @@ -738,6 +742,10 @@ int main (int argc, char *argv[])
A_opt_ais_to_obj = 1;
break;

case 'O': /* Was handled earlier. -O Redirects output to stderr. */
break;


default:

/* Should not be here. */
Expand Down
4 changes: 2 additions & 2 deletions src/il2p_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void decode_bitstream(void);
int main ()
{
int enable_color = 1;
text_color_init (enable_color);
text_color_init (enable_color, 0);

int enable_debug_out = 0;
il2p_init(enable_debug_out);
Expand Down Expand Up @@ -974,4 +974,4 @@ alevel_t demod_get_audio_level (int chan, int subchan)
return (alevel);
}

// end il2p_test.c
// end il2p_test.c
2 changes: 1 addition & 1 deletion src/kissutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static void trim (char *stuff)

int main (int argc, char *argv[])
{
text_color_init (0); // Turn off text color.
text_color_init (0, 0); // Turn off text color.
// It could interfere with trying to pipe stdout to some other application.

#if __WIN32__
Expand Down
18 changes: 12 additions & 6 deletions src/textcolor.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,20 @@ static const char clear_eos[] = "\e[0J";
*/

static int g_enable_color = 1;
static FILE *g_dw_printf_dest = 0;


void text_color_init (int enable_color)
void text_color_init (int enable_color, int redirect_output)
{

if (redirect_output != 0) {
g_dw_printf_dest = stderr;
enable_color = 0;
} else {
g_dw_printf_dest = stdout;
}

#if __WIN32__

g_enable_color = enable_color;

if (g_enable_color != 0) {

Expand Down Expand Up @@ -208,7 +214,7 @@ void text_color_init (int enable_color)
if (enable_color < 0 || enable_color > MAX_T) {
int t;
for (t = 0; t <= MAX_T; t++) {
text_color_init (t);
text_color_init (t, redirect_output);
printf ("-t %d", t);
if (t) printf (" [white background] ");
printf ("\n");
Expand Down Expand Up @@ -377,7 +383,7 @@ int dw_printf (const char *fmt, ...)

// TODO: other possible destinations...

fputs (buffer, stdout);
fputs (buffer, g_dw_printf_dest);
return (len);
}

Expand All @@ -387,7 +393,7 @@ int dw_printf (const char *fmt, ...)
main ()
{
printf ("Initial condition\n");
text_color_init (1);
text_color_init (1, 0);
printf ("After text_color_init\n");
text_color_set(DW_COLOR_INFO); printf ("Info\n");
text_color_set(DW_COLOR_ERROR); printf ("Error\n");
Expand Down
2 changes: 1 addition & 1 deletion src/textcolor.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum dw_color_e { DW_COLOR_INFO, /* black */
typedef enum dw_color_e dw_color_t;


void text_color_init (int enable_color);
void text_color_init (int enable_color, int redirect_output);
void text_color_set (dw_color_t c);
void text_color_term (void);

Expand Down