Index: apps/settings.h =================================================================== --- apps/settings.h (revision 18231) +++ apps/settings.h (working copy) @@ -81,6 +81,7 @@ #define VIEWERS_CONFIG ROCKBOX_DIR "/viewers.config" #define CONFIGFILE ROCKBOX_DIR "/config.cfg" #define FIXEDSETTINGSFILE ROCKBOX_DIR "/fixed.cfg" +#define LOGF_FILENAME ROCKBOX_DIR "/logf.log" #define MAX_FILENAME 32 Index: apps/main.c =================================================================== --- apps/main.c (revision 18231) +++ apps/main.c (working copy) @@ -111,6 +111,10 @@ #include "system-sdl.h" #endif +#ifdef ROCKBOX_HAS_LOGF +#include "logf.h" +#endif + /*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */ const char appsversion[]=APPSVERSION; @@ -375,6 +379,9 @@ show_logo(); lang_init(); +#ifdef ROCKBOX_HAS_LOGF + logf_file_open(LOGF_FILENAME); +#endif #ifdef DEBUG debug_init(); #else Index: apps/misc.c =================================================================== --- apps/misc.c (revision 18231) +++ apps/misc.c (working copy) @@ -81,6 +81,10 @@ #endif #endif +#ifdef ROCKBOX_HAS_LOGF +#include "logf.h" +#endif + /* Format a large-range value for output, using the appropriate unit so that * the displayed value is in the range 1 <= display < 1000 (1024 for "binary" * units) if possible, and 3 significant digits are shown. If a buffer is @@ -761,6 +765,10 @@ dircache_disable(); #endif +#ifdef ROCKBOX_HAS_LOGF + logf_file_close(); +#endif + shutdown_hw(); } #endif Index: firmware/export/logf.h =================================================================== --- firmware/export/logf.h (revision 18231) +++ firmware/export/logf.h (working copy) @@ -30,11 +30,20 @@ #ifndef __PCTOOL__ #define MAX_LOGF_LINES 1000 #define MAX_LOGF_ENTRY 30 +#define MAX_LOGF_FILE_ENTRY 150 #define MAX_LOGF_DATASIZE (MAX_LOGF_ENTRY*MAX_LOGF_LINES) extern unsigned char logfbuffer[MAX_LOGF_LINES][MAX_LOGF_ENTRY]; extern int logfindex; extern bool logfwrap; + +int logf_file_open(const char* fname); +void logf_file_close(void); +void logf_puts(char* s); +void logf_flush(int wait); +void clear_logf_buffer(void); +void logf_file_output_enabled(bool flg); + #endif /* __PCTOOL__ */ #define logf _logf @@ -51,6 +60,6 @@ /* Allow fine tuning (per file) of the logf output */ #ifndef LOGF_ENABLE -#undef logf -#define logf(...) +//#undef logf +//#define logf(...) #endif Index: firmware/logf.c =================================================================== --- firmware/logf.c (revision 18231) +++ firmware/logf.c (working copy) @@ -20,7 +20,7 @@ ****************************************************************************/ /* - * logf() logs MAX_LOGF_ENTRY (21) bytes per entry in a circular buffer. Each + * logf() logs MAX_LOGF_ENTRY (30) bytes per entry in a circular buffer. Each * logged string is space- padded for easier and faster output on screen. Just * output MAX_LOGF_ENTRY characters on each line. MAX_LOGF_ENTRY bytes fit * nicely on the iRiver remote LCD (128 pixels with an 8x6 pixels font). @@ -31,6 +31,7 @@ #include #include "config.h" #include "lcd-remote.h" +#define LOGF_ENABLE #include "logf.h" #include "serial.h" @@ -42,6 +43,10 @@ /* Only provide all this if asked to */ #ifdef ROCKBOX_HAS_LOGF +static int logf_id = -1; +static bool enabled_logf_file_output = false; +static char logf_path[512]; + #ifndef __PCTOOL__ unsigned char logfbuffer[MAX_LOGF_LINES][MAX_LOGF_ENTRY]; int logfindex; @@ -99,8 +104,11 @@ { int len; unsigned char *ptr; + unsigned char buf[MAX_LOGF_FILE_ENTRY]; va_list ap; va_start(ap, format); + vsnprintf(buf, MAX_LOGF_FILE_ENTRY, format, ap); + va_end(ap); if(logfindex >= MAX_LOGF_LINES) { /* wrap */ @@ -108,7 +116,8 @@ logfindex = 0; } ptr = logfbuffer[logfindex]; - len = vsnprintf(ptr, MAX_LOGF_ENTRY, format, ap); + strncpy(ptr, buf, MAX_LOGF_ENTRY); + len = strlen(ptr); #ifdef HAVE_SERIAL serial_tx(ptr); serial_tx("\r\n"); @@ -117,8 +126,8 @@ usb_serial_send(ptr,len); usb_serial_send("\r\n",2); #endif + logf_puts(buf); - va_end(ap); if(len < MAX_LOGF_ENTRY) /* pad with spaces up to the MAX_LOGF_ENTRY byte border */ memset(ptr+len, ' ', MAX_LOGF_ENTRY-len); @@ -127,6 +136,60 @@ displayremote(); } + +int logf_file_open(const char *fname) +{ + if (logf_id < 0) + { + if (fname != logf_path) + strcpy(logf_path, fname); + logf_id = open(logf_path, O_WRONLY | O_CREAT | O_APPEND); + + if(logf_id >= 0) + logf("logf file %s open. (non asyncfile version)", fname); + } + + return 0; +} + +void logf_file_close(void) +{ + if(logf_id >= 0) + { + close(logf_id); + logf_id = -1; + } +} + +void logf_puts(char *s) +{ + if (logf_id < 0) + logf_file_open(logf_path); + + if (logf_id >= 0) + { + write(logf_id, s, strlen(s)); + write(logf_id, "\n", 1); + } +} + +void logf_flush(int wait) +{ +} + +void logf_finalize(void) +{ + logf_file_close(); +} + +void clear_logf_buffer(void) +{ +} + +void logf_file_output_enabled(bool flg) +{ + enabled_logf_file_output = flg; +} #endif #endif