From 72e121a9b32288fd16cc52d80525c0120ad24387 Mon Sep 17 00:00:00 2001 From: SkyMoCo Date: Sun, 11 Dec 2022 17:01:04 -0800 Subject: [PATCH] Added log_heard to log non-aprs stations --- src/direwolf.c | 1 + src/log.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/log.h | 4 ++- 3 files changed, 90 insertions(+), 1 deletion(-) diff --git a/src/direwolf.c b/src/direwolf.c index 456b16f..abcfaa5 100644 --- a/src/direwolf.c +++ b/src/direwolf.c @@ -1099,6 +1099,7 @@ void app_process_rec_packet (int chan, int subchan, int slice, packet_t pp, alev else { dw_printf ("%s audio level = %s %s %s\n", heard, alevel_text, display_retries, spectrum); + log_heard(heard, alevel_text, display_retries, spectrum); } } diff --git a/src/log.c b/src/log.c index 02aab2a..5bfc9ba 100644 --- a/src/log.c +++ b/src/log.c @@ -426,6 +426,92 @@ void log_write (int chan, decode_aprs_t *A, packet_t pp, alevel_t alevel, retry_ } /* end log_write */ +/*------------------------------------------------------------------ + * + * Function: log_heard + * + * Purpose: Save packet information from non-APRS packets to log file. + * Basically the same info as written to stdout + * + *------------------------------------------------------------------*/ + + +void log_heard(char *heard, char *alevel_text, char *display_retries, char *spectrum) +{ + time_t now; + struct tm tm; + + dw_printf ("Logging heard packet\n"); + + if (strlen(g_log_path) == 0) return; + + now = time(NULL); // Get current time. + (void)gmtime_r (&now, &tm); + + + if (g_daily_names) { + char fname[20]; + strftime (fname, sizeof(fname), "%Y-%m-%d.log", &tm); + + // Close current file if name has changed + if (g_log_fp != NULL && strcmp(fname, g_open_fname) != 0) { + log_term (); + } + if (g_log_fp == NULL) { // Open for append if not already open. + char full_path[120]; + + strlcpy (full_path, g_log_path, sizeof(full_path)); +#if __WIN32__ + strlcat (full_path, "\\", sizeof(full_path)); +#else + strlcat (full_path, "/", sizeof(full_path)); +#endif + strlcat (full_path, fname, sizeof(full_path)); + + text_color_set(DW_COLOR_INFO); + dw_printf("Opening log file \"%s\".\n", fname); + + g_log_fp = fopen (full_path, "a"); + + if (g_log_fp != NULL) { + strlcpy (g_open_fname, fname, sizeof(g_open_fname)); + } + else { + text_color_set(DW_COLOR_ERROR); + dw_printf("Can't open log file \"%s\" for write.\n", full_path); + dw_printf ("%s\n", strerror(errno)); + strlcpy (g_open_fname, "", sizeof(g_open_fname)); + return; + } + } + } else { // Added in version 1.5. Single file. + if (g_log_fp == NULL) { // Open for append if not already open. + text_color_set(DW_COLOR_INFO); + dw_printf("Opening log file \"%s\"\n", g_log_path); + + g_log_fp = fopen (g_log_path, "a"); + + if (g_log_fp == NULL) { + text_color_set(DW_COLOR_ERROR); + dw_printf("Can't open log file \"%s\" for write.\n", g_log_path); + dw_printf ("%s\n", strerror(errno)); + strlcpy (g_log_path, "", sizeof(g_log_path)); + return; + } + } + } + + if (g_log_fp != NULL) { + char itime[24]; + strftime (itime, sizeof(itime), "%Y-%m-%d %H:%M:%SZ", &tm); + + fprintf (g_log_fp, "%s, %s, %s, %s, %s\n", + itime, heard, alevel_text, display_retries,spectrum); + + fflush (g_log_fp); + } +} /* end log_heard */ + /*------------------------------------------------------------------ diff --git a/src/log.h b/src/log.h index 3afb6b1..b9bfbd1 100644 --- a/src/log.h +++ b/src/log.h @@ -14,6 +14,8 @@ void log_init (int daily_names, char *path); void log_write (int chan, decode_aprs_t *A, packet_t pp, alevel_t alevel, retry_t retries); +void log_heard(char *heard, char *alevel_text, char *display_retries, char *spectrum); + void log_rr_bits (decode_aprs_t *A, packet_t pp); -void log_term (void); \ No newline at end of file +void log_term (void);