Daniel Stenberg | b033f6c | 2005-05-23 22:47:42 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2005 by Daniel Stenberg |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Daniel Stenberg | b033f6c | 2005-05-23 22:47:42 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
| 22 | /* |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 23 | * logf() logs entries in a circular buffer. Each logged string is null-terminated. |
Maurus Cuelenaere | 4c793fe | 2008-12-31 17:01:00 +0000 | [diff] [blame] | 24 | * |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 25 | * When the length of log exceeds MAX_LOGF_SIZE bytes, the buffer wraps. |
Maurus Cuelenaere | 4c793fe | 2008-12-31 17:01:00 +0000 | [diff] [blame] | 26 | * |
Daniel Stenberg | b033f6c | 2005-05-23 22:47:42 +0000 | [diff] [blame] | 27 | */ |
| 28 | |
| 29 | #include <string.h> |
| 30 | #include <stdio.h> |
| 31 | #include <stdarg.h> |
Daniel Stenberg | b033f6c | 2005-05-23 22:47:42 +0000 | [diff] [blame] | 32 | #include "config.h" |
Thomas Martitz | 6ac6420 | 2010-05-06 22:17:34 +0000 | [diff] [blame] | 33 | #include "system.h" |
| 34 | #include "font.h" |
Frank Gevaerts | 25e50ed | 2014-01-05 22:20:26 +0100 | [diff] [blame] | 35 | #include "lcd.h" |
Rafaël Carré | d00b7e8 | 2012-01-07 19:54:47 +0000 | [diff] [blame] | 36 | #ifdef HAVE_REMOTE_LCD |
Daniel Stenberg | 9e9f58f | 2005-05-24 14:28:48 +0000 | [diff] [blame] | 37 | #include "lcd-remote.h" |
Rafaël Carré | d00b7e8 | 2012-01-07 19:54:47 +0000 | [diff] [blame] | 38 | #endif |
Daniel Stenberg | 11bf87f | 2005-05-24 14:26:54 +0000 | [diff] [blame] | 39 | #include "logf.h" |
Linus Nielsen Feltzing | 00d2182 | 2006-10-12 20:22:16 +0000 | [diff] [blame] | 40 | #include "serial.h" |
Jeffrey Goode | b8a51ad | 2010-05-15 03:47:06 +0000 | [diff] [blame] | 41 | #include "format.h" |
Daniel Stenberg | b033f6c | 2005-05-23 22:47:42 +0000 | [diff] [blame] | 42 | |
Frank Gevaerts | 776d015 | 2008-03-02 20:45:33 +0000 | [diff] [blame] | 43 | #ifdef HAVE_USBSTACK |
| 44 | #include "usb_core.h" |
| 45 | #include "usbstack/usb_serial.h" |
| 46 | #endif |
| 47 | |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 48 | #ifdef ROCKBOX_HAS_LOGDISKF |
| 49 | #include "logdiskf.h" |
| 50 | #include "file.h" |
| 51 | #include "rbpaths.h" |
| 52 | #include "ata_idle_notify.h" |
| 53 | |
| 54 | unsigned char logdiskfbuffer[MAX_LOGDISKF_SIZE]; |
Thomas Jarosch | cfbd9cb | 2015-01-11 18:02:43 +0100 | [diff] [blame] | 55 | static int logdiskfindex; |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 56 | #endif |
| 57 | |
Daniel Stenberg | edc0792 | 2005-05-30 13:00:43 +0000 | [diff] [blame] | 58 | /* Only provide all this if asked to */ |
| 59 | #ifdef ROCKBOX_HAS_LOGF |
| 60 | |
Miika Pekkarinen | 0dd7ea2 | 2006-11-10 08:03:33 +0000 | [diff] [blame] | 61 | #ifndef __PCTOOL__ |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 62 | unsigned char logfbuffer[MAX_LOGF_SIZE]; |
Linus Nielsen Feltzing | 056effc | 2005-05-24 14:01:16 +0000 | [diff] [blame] | 63 | int logfindex; |
Daniel Stenberg | b033f6c | 2005-05-23 22:47:42 +0000 | [diff] [blame] | 64 | bool logfwrap; |
Mihail Zenkov | e599810 | 2016-03-31 11:33:11 +0000 | [diff] [blame] | 65 | bool logfenabled = true; |
Miika Pekkarinen | 0dd7ea2 | 2006-11-10 08:03:33 +0000 | [diff] [blame] | 66 | #endif |
Daniel Stenberg | b033f6c | 2005-05-23 22:47:42 +0000 | [diff] [blame] | 67 | |
Daniel Stenberg | 11bf87f | 2005-05-24 14:26:54 +0000 | [diff] [blame] | 68 | #ifdef HAVE_REMOTE_LCD |
| 69 | static void displayremote(void) |
| 70 | { |
| 71 | /* TODO: we should have a debug option that enables/disables this! */ |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 72 | int w, h, i; |
| 73 | int fontnr; |
| 74 | int cur_x, cur_y, delta_y, delta_x; |
| 75 | struct font* font; |
| 76 | int nb_lines; |
| 77 | char buf[2]; |
| 78 | /* Memorize the pointer to the beginning of the last ... lines |
| 79 | I assume delta_y >= 6 to avoid wasting memory and allocating memory dynamically |
| 80 | I hope there is no font with height < 6 ! */ |
| 81 | const int NB_ENTRIES=LCD_REMOTE_HEIGHT / 6; |
| 82 | int line_start_ptr[NB_ENTRIES]; |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 83 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 84 | fontnr = lcd_getfont(); |
| 85 | font = font_get(fontnr); |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 86 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 87 | /* get the horizontal size of each line */ |
| 88 | font_getstringsize("A", NULL, &delta_y, fontnr); |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 89 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 90 | /* font too small ? */ |
| 91 | if(delta_y < 6) |
| 92 | return; |
| 93 | /* nothing to print ? */ |
| 94 | if(logfindex == 0 && !logfwrap) |
| 95 | return; |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 96 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 97 | w = LCD_REMOTE_WIDTH; |
| 98 | h = LCD_REMOTE_HEIGHT; |
| 99 | nb_lines = 0; |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 100 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 101 | if(logfwrap) |
| 102 | i = logfindex; |
| 103 | else |
| 104 | i = 0; |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 105 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 106 | cur_x = 0; |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 107 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 108 | line_start_ptr[0] = i; |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 109 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 110 | do |
| 111 | { |
| 112 | if(logfbuffer[i] == '\0') |
| 113 | { |
| 114 | line_start_ptr[++nb_lines % NB_ENTRIES] = i+1; |
| 115 | cur_x = 0; |
| 116 | } |
| 117 | else |
| 118 | { |
| 119 | /* does character fit on this line ? */ |
| 120 | delta_x = font_get_width(font, logfbuffer[i]); |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 121 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 122 | if(cur_x + delta_x > w) |
| 123 | { |
| 124 | cur_x = 0; |
| 125 | line_start_ptr[++nb_lines % NB_ENTRIES] = i; |
| 126 | } |
| 127 | /* update pointer */ |
| 128 | cur_x += delta_x; |
| 129 | } |
| 130 | i++; |
| 131 | if(i >= MAX_LOGF_SIZE) |
| 132 | i = 0; |
| 133 | } while(i != logfindex); |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 134 | |
Daniel Stenberg | 11bf87f | 2005-05-24 14:26:54 +0000 | [diff] [blame] | 135 | lcd_remote_clear_display(); |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 136 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 137 | i = line_start_ptr[ MAX(nb_lines - h / delta_y, 0) % NB_ENTRIES]; |
| 138 | cur_x = 0; |
| 139 | cur_y = 0; |
| 140 | buf[1] = '\0'; |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 141 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 142 | do { |
| 143 | if(logfbuffer[i] == '\0') |
| 144 | { |
| 145 | cur_y += delta_y; |
| 146 | cur_x = 0; |
| 147 | } |
| 148 | else |
| 149 | { |
| 150 | /* does character fit on this line ? */ |
| 151 | delta_x = font_get_width(font, logfbuffer[i]); |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 152 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 153 | if(cur_x + delta_x > w) |
| 154 | { |
| 155 | cur_y += delta_y; |
| 156 | cur_x = 0; |
| 157 | } |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 158 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 159 | buf[0] = logfbuffer[i]; |
| 160 | lcd_remote_putsxy(cur_x, cur_y, buf); |
| 161 | cur_x += delta_x; |
Daniel Stenberg | 11bf87f | 2005-05-24 14:26:54 +0000 | [diff] [blame] | 162 | } |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 163 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 164 | i++; |
| 165 | if(i >= MAX_LOGF_SIZE) |
| 166 | i = 0; |
| 167 | } while(i != logfindex); |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 168 | |
| 169 | lcd_remote_update(); |
Daniel Stenberg | 11bf87f | 2005-05-24 14:26:54 +0000 | [diff] [blame] | 170 | } |
| 171 | #else |
| 172 | #define displayremote() |
| 173 | #endif |
| 174 | |
Miika Pekkarinen | 0dd7ea2 | 2006-11-10 08:03:33 +0000 | [diff] [blame] | 175 | #ifdef __PCTOOL__ |
| 176 | void _logf(const char *format, ...) |
| 177 | { |
| 178 | char buf[1024]; |
| 179 | va_list ap; |
| 180 | va_start(ap, format); |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 181 | |
Miika Pekkarinen | 0dd7ea2 | 2006-11-10 08:03:33 +0000 | [diff] [blame] | 182 | vsnprintf(buf, sizeof buf, format, ap); |
| 183 | printf("DEBUG: %s\n", buf); |
| 184 | } |
| 185 | #else |
Frank Gevaerts | 7ae9c8d | 2009-02-07 19:59:51 +0000 | [diff] [blame] | 186 | static void check_logfindex(void) |
| 187 | { |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 188 | if(logfindex >= MAX_LOGF_SIZE) |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 189 | { |
Frank Gevaerts | 7ae9c8d | 2009-02-07 19:59:51 +0000 | [diff] [blame] | 190 | /* wrap */ |
| 191 | logfwrap = true; |
| 192 | logfindex = 0; |
| 193 | } |
| 194 | } |
| 195 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 196 | static int logf_push(void *userp, unsigned char c) |
Daniel Stenberg | b033f6c | 2005-05-23 22:47:42 +0000 | [diff] [blame] | 197 | { |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 198 | (void)userp; |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 199 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 200 | logfbuffer[logfindex++] = c; |
| 201 | check_logfindex(); |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 202 | |
Ralf Ertzinger | d2f97da | 2011-09-09 12:28:36 +0200 | [diff] [blame] | 203 | #if defined(HAVE_SERIAL) && !defined(SIMULATOR) && defined(LOGF_SERIAL) |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 204 | if(c != '\0') |
| 205 | { |
| 206 | char buf[2]; |
| 207 | buf[0] = c; |
| 208 | buf[1] = '\0'; |
| 209 | serial_tx(buf); |
| 210 | } |
| 211 | #endif |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 212 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 213 | return true; |
| 214 | } |
| 215 | |
| 216 | void _logf(const char *fmt, ...) |
| 217 | { |
Mihail Zenkov | e599810 | 2016-03-31 11:33:11 +0000 | [diff] [blame] | 218 | if (!logfenabled) |
| 219 | return; |
| 220 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 221 | #ifdef USB_ENABLE_SERIAL |
| 222 | int old_logfindex = logfindex; |
| 223 | #endif |
| 224 | va_list ap; |
| 225 | |
| 226 | va_start(ap, fmt); |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 227 | |
Thomas Martitz | 35e8b14 | 2010-06-21 16:53:00 +0000 | [diff] [blame] | 228 | #if (CONFIG_PLATFORM & PLATFORM_HOSTED) |
Jeffrey Goode | fade88a | 2009-11-02 15:30:06 +0000 | [diff] [blame] | 229 | char buf[1024]; |
| 230 | vsnprintf(buf, sizeof buf, fmt, ap); |
| 231 | DEBUGF("%s\n", buf); |
Amaury Pouly | c083806 | 2010-08-02 09:10:35 +0000 | [diff] [blame] | 232 | /* restart va_list otherwise the result if undefined when vuprintf is called */ |
| 233 | va_end(ap); |
| 234 | va_start(ap, fmt); |
Jeffrey Goode | fade88a | 2009-11-02 15:30:06 +0000 | [diff] [blame] | 235 | #endif |
| 236 | |
Thomas Martitz | 1ddb91a | 2009-11-03 21:20:09 +0000 | [diff] [blame] | 237 | vuprintf(logf_push, NULL, fmt, ap); |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 238 | va_end(ap); |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 239 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 240 | /* add trailing zero */ |
| 241 | logf_push(NULL, '\0'); |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 242 | |
Ralf Ertzinger | d2f97da | 2011-09-09 12:28:36 +0200 | [diff] [blame] | 243 | #if defined(HAVE_SERIAL) && !defined(SIMULATOR) && defined(LOGF_SERIAL) |
Linus Nielsen Feltzing | 00d2182 | 2006-10-12 20:22:16 +0000 | [diff] [blame] | 244 | serial_tx("\r\n"); |
| 245 | #endif |
Frank Gevaerts | c61a751 | 2009-05-23 14:30:20 +0000 | [diff] [blame] | 246 | #ifdef USB_ENABLE_SERIAL |
Frank Gevaerts | 776d015 | 2008-03-02 20:45:33 +0000 | [diff] [blame] | 247 | |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 248 | if(logfindex < old_logfindex) |
Maurus Cuelenaere | 4c793fe | 2008-12-31 17:01:00 +0000 | [diff] [blame] | 249 | { |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 250 | usb_serial_send(logfbuffer + old_logfindex, MAX_LOGF_SIZE - old_logfindex); |
| 251 | usb_serial_send(logfbuffer, logfindex - 1); |
Maurus Cuelenaere | 4c793fe | 2008-12-31 17:01:00 +0000 | [diff] [blame] | 252 | } |
Maurus Cuelenaere | 20b0dd2 | 2009-08-21 22:54:23 +0000 | [diff] [blame] | 253 | else |
| 254 | usb_serial_send(logfbuffer + old_logfindex, logfindex - old_logfindex - 1); |
| 255 | usb_serial_send("\r\n", 2); |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 256 | #endif |
Daniel Stenberg | 11bf87f | 2005-05-24 14:26:54 +0000 | [diff] [blame] | 257 | |
| 258 | displayremote(); |
Daniel Stenberg | b033f6c | 2005-05-23 22:47:42 +0000 | [diff] [blame] | 259 | } |
Miika Pekkarinen | 0dd7ea2 | 2006-11-10 08:03:33 +0000 | [diff] [blame] | 260 | #endif |
Daniel Stenberg | edc0792 | 2005-05-30 13:00:43 +0000 | [diff] [blame] | 261 | |
Frank Gevaerts | 25e50ed | 2014-01-05 22:20:26 +0100 | [diff] [blame] | 262 | void logf_panic_dump(int *y) |
| 263 | { |
| 264 | int i; |
| 265 | /* nothing to print ? */ |
| 266 | if(logfindex == 0 && !logfwrap) |
| 267 | { |
| 268 | lcd_puts(1, (*y)++, "no logf data"); |
| 269 | lcd_update(); |
| 270 | return; |
| 271 | } |
| 272 | |
| 273 | lcd_puts(1, (*y)++, "start of logf data"); |
| 274 | lcd_update(); |
| 275 | i = logfindex - 2; /* The last actual characer (i.e. not '\0') */ |
| 276 | |
| 277 | while(i >= 0) |
| 278 | { |
| 279 | while(logfbuffer[i] != 0 && i>=0) |
| 280 | { |
| 281 | i--; |
| 282 | } |
| 283 | if(strlen( &logfbuffer[i + 1]) > 0) |
| 284 | { |
| 285 | lcd_puts(1, (*y)++, &logfbuffer[i + 1]); |
| 286 | lcd_update(); |
| 287 | } |
| 288 | i--; |
| 289 | } |
| 290 | if(logfwrap) |
| 291 | { |
| 292 | i = MAX_LOGF_SIZE - 1; |
| 293 | while(i >= logfindex) |
| 294 | { |
| 295 | while(logfbuffer[i] != 0 && i >= logfindex) |
| 296 | { |
| 297 | i--; |
| 298 | } |
| 299 | if(strlen( &logfbuffer[i + 1]) > 0) |
| 300 | { |
| 301 | lcd_putsf(1, (*y)++, "%*s", (MAX_LOGF_SIZE-i) &logfbuffer[i + 1]); |
| 302 | lcd_update(); |
| 303 | } |
| 304 | } |
| 305 | i--; |
| 306 | } |
| 307 | lcd_puts(1, (*y)++, "end of logf data"); |
| 308 | lcd_update(); |
| 309 | } |
Daniel Stenberg | edc0792 | 2005-05-30 13:00:43 +0000 | [diff] [blame] | 310 | #endif |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 311 | |
| 312 | #ifdef ROCKBOX_HAS_LOGDISKF |
| 313 | static int logdiskf_push(void *userp, unsigned char c) |
| 314 | { |
| 315 | (void)userp; |
| 316 | |
| 317 | /*just stop logging if out of space*/ |
| 318 | if(logdiskfindex>=MAX_LOGDISKF_SIZE-1) |
| 319 | { |
| 320 | strcpy(&logdiskfbuffer[logdiskfindex-8], "LOGFULL"); |
| 321 | logdiskfindex=MAX_LOGDISKF_SIZE; |
| 322 | return false; |
| 323 | } |
| 324 | logdiskfbuffer[logdiskfindex++] = c; |
| 325 | |
| 326 | return true; |
| 327 | } |
| 328 | |
Thomas Martitz | 470989b | 2014-03-14 23:15:16 +0100 | [diff] [blame] | 329 | static void flush_buffer(void); |
Amaury Pouly | c13f21a | 2013-08-16 21:55:09 +0200 | [diff] [blame] | 330 | |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 331 | void _logdiskf(const char* file, const char level, const char *fmt, ...) |
| 332 | { |
| 333 | |
| 334 | va_list ap; |
| 335 | |
| 336 | va_start(ap, fmt); |
| 337 | int len =strlen(file); |
| 338 | if(logdiskfindex +len + 4 > MAX_LOGDISKF_SIZE-1) |
| 339 | { |
| 340 | strcpy(&logdiskfbuffer[logdiskfindex-8], "LOGFULL"); |
| 341 | logdiskfindex=MAX_LOGDISKF_SIZE; |
Thomas Jarosch | ef1497c | 2014-12-20 13:47:28 +0100 | [diff] [blame] | 342 | va_end(ap); |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 343 | return; |
| 344 | } |
| 345 | |
| 346 | logdiskf_push(NULL, level); |
| 347 | logdiskf_push(NULL, ' '); |
| 348 | logdiskf_push(NULL, '['); |
| 349 | strcpy(&logdiskfbuffer[logdiskfindex], file); |
| 350 | logdiskfindex += len; |
| 351 | logdiskf_push(NULL, ']'); |
| 352 | |
| 353 | vuprintf(logdiskf_push, NULL, fmt, ap); |
| 354 | va_end(ap); |
Amaury Pouly | c13f21a | 2013-08-16 21:55:09 +0200 | [diff] [blame] | 355 | register_storage_idle_func(flush_buffer); |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 356 | } |
Amaury Pouly | c13f21a | 2013-08-16 21:55:09 +0200 | [diff] [blame] | 357 | |
Thomas Martitz | 470989b | 2014-03-14 23:15:16 +0100 | [diff] [blame] | 358 | static void flush_buffer(void) |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 359 | { |
Michael Giacomelli | d46b090 | 2012-07-03 21:45:29 -0400 | [diff] [blame] | 360 | int fd; |
| 361 | if(logdiskfindex < 1) |
| 362 | return; |
| 363 | |
| 364 | fd = open(HOME_DIR"/rockbox_log.txt", O_RDWR | O_CREAT | O_APPEND, 0666); |
| 365 | if (fd < 0) |
| 366 | return; |
| 367 | |
| 368 | write(fd, logdiskfbuffer, logdiskfindex); |
| 369 | close(fd); |
| 370 | |
| 371 | logdiskfindex = 0; |
| 372 | } |
| 373 | |
Michael Giacomelli | 633dd49 | 2012-08-06 19:18:20 -0400 | [diff] [blame] | 374 | #endif |