Skip to content

Commit 72e121a

Browse files
author
SkyMoCo
committed
Added log_heard to log non-aprs stations
1 parent 7d3c1d1 commit 72e121a

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

src/direwolf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@ void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alev
10991099
else {
11001100

11011101
dw_printf ("%s audio level = %s %s %s\n", heard, alevel_text, display_retries, spectrum);
1102+
log_heard(heard, alevel_text, display_retries, spectrum);
11021103
}
11031104
}
11041105

src/log.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,92 @@ void log_write (int chan, decode_aprs_t *A, packet_t pp, alevel_t alevel, retry_
426426

427427
} /* end log_write */
428428

429+
/*------------------------------------------------------------------
430+
*
431+
* Function: log_heard
432+
*
433+
* Purpose: Save packet information from non-APRS packets to log file.
434+
* Basically the same info as written to stdout
435+
*
436+
*------------------------------------------------------------------*/
437+
438+
439+
void log_heard(char *heard, char *alevel_text, char *display_retries, char *spectrum)
440+
{
441+
time_t now;
442+
struct tm tm;
443+
444+
dw_printf ("Logging heard packet\n");
445+
446+
if (strlen(g_log_path) == 0) return;
447+
448+
now = time(NULL); // Get current time.
449+
(void)gmtime_r (&now, &tm);
450+
451+
452+
if (g_daily_names) {
453+
char fname[20];
454+
strftime (fname, sizeof(fname), "%Y-%m-%d.log", &tm);
455+
456+
// Close current file if name has changed
457+
if (g_log_fp != NULL && strcmp(fname, g_open_fname) != 0) {
458+
log_term ();
459+
}
460+
if (g_log_fp == NULL) { // Open for append if not already open.
461+
char full_path[120];
462+
463+
strlcpy (full_path, g_log_path, sizeof(full_path));
464+
#if __WIN32__
465+
strlcat (full_path, "\\", sizeof(full_path));
466+
#else
467+
strlcat (full_path, "/", sizeof(full_path));
468+
#endif
469+
strlcat (full_path, fname, sizeof(full_path));
470+
471+
text_color_set(DW_COLOR_INFO);
472+
dw_printf("Opening log file \"%s\".\n", fname);
473+
474+
g_log_fp = fopen (full_path, "a");
475+
476+
if (g_log_fp != NULL) {
477+
strlcpy (g_open_fname, fname, sizeof(g_open_fname));
478+
}
479+
else {
480+
text_color_set(DW_COLOR_ERROR);
481+
dw_printf("Can't open log file \"%s\" for write.\n", full_path);
482+
dw_printf ("%s\n", strerror(errno));
483+
strlcpy (g_open_fname, "", sizeof(g_open_fname));
484+
return;
485+
}
486+
}
487+
} else { // Added in version 1.5. Single file.
488+
if (g_log_fp == NULL) { // Open for append if not already open.
489+
text_color_set(DW_COLOR_INFO);
490+
dw_printf("Opening log file \"%s\"\n", g_log_path);
491+
492+
g_log_fp = fopen (g_log_path, "a");
493+
494+
if (g_log_fp == NULL) {
495+
text_color_set(DW_COLOR_ERROR);
496+
dw_printf("Can't open log file \"%s\" for write.\n", g_log_path);
497+
dw_printf ("%s\n", strerror(errno));
498+
strlcpy (g_log_path, "", sizeof(g_log_path));
499+
return;
500+
}
501+
}
502+
}
503+
504+
if (g_log_fp != NULL) {
505+
char itime[24];
506+
strftime (itime, sizeof(itime), "%Y-%m-%d %H:%M:%SZ", &tm);
507+
508+
fprintf (g_log_fp, "%s, %s, %s, %s, %s\n",
509+
itime, heard, alevel_text, display_retries,spectrum);
510+
511+
fflush (g_log_fp);
512+
}
513+
} /* end log_heard */
514+
429515

430516

431517
/*------------------------------------------------------------------

src/log.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ void log_init (int daily_names, char *path);
1414

1515
void log_write (int chan, decode_aprs_t *A, packet_t pp, alevel_t alevel, retry_t retries);
1616

17+
void log_heard(char *heard, char *alevel_text, char *display_retries, char *spectrum);
18+
1719
void log_rr_bits (decode_aprs_t *A, packet_t pp);
1820

19-
void log_term (void);
21+
void log_term (void);

0 commit comments

Comments
 (0)