1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Nicolas Pennequin, Dan Everton, Matthias Mohr
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #if defined(DEBUG) || defined(SIMULATOR)
37 #if defined(SIMULATOR) || defined(__PCTOOL__)
38 extern bool debug_wps
;
39 extern int wps_verbose_level
;
42 static char *next_str(bool next
) {
43 return next
? "next " : "";
46 static char *get_token_desc(struct wps_token
*token
, struct wps_data
*data
,
47 char *buf
, int bufsize
)
49 bool next
= token
->next
;
54 snprintf(buf
, bufsize
, "No token");
57 case WPS_TOKEN_UNKNOWN
:
58 snprintf(buf
, bufsize
, "Unknown token");
61 case WPS_TOKEN_CHARACTER
:
62 snprintf(buf
, bufsize
, "Character '%c'",
66 case WPS_TOKEN_STRING
:
67 snprintf(buf
, bufsize
, "String '%s'",
68 data
->strings
[token
->value
.i
]);
71 #ifdef HAVE_LCD_BITMAP
72 case WPS_TOKEN_ALIGN_LEFT
:
73 snprintf(buf
, bufsize
, "align left");
76 case WPS_TOKEN_ALIGN_CENTER
:
77 snprintf(buf
, bufsize
, "align center");
80 case WPS_TOKEN_ALIGN_RIGHT
:
81 snprintf(buf
, bufsize
, "align right");
85 case WPS_TOKEN_SUBLINE_TIMEOUT
:
86 snprintf(buf
, bufsize
, "subline timeout value: %d",
90 case WPS_TOKEN_CONDITIONAL
:
91 snprintf(buf
, bufsize
, "conditional, %d options",
95 case WPS_TOKEN_CONDITIONAL_START
:
96 snprintf(buf
, bufsize
, "conditional start, next cond: %d",
100 case WPS_TOKEN_CONDITIONAL_OPTION
:
101 snprintf(buf
, bufsize
, "conditional option, next cond: %d",
105 case WPS_TOKEN_CONDITIONAL_END
:
106 snprintf(buf
, bufsize
, "conditional end");
109 #ifdef HAVE_LCD_BITMAP
110 case WPS_TOKEN_IMAGE_PRELOAD
:
111 snprintf(buf
, bufsize
, "preload image");
114 case WPS_TOKEN_IMAGE_PRELOAD_DISPLAY
:
115 snprintf(buf
, bufsize
, "display preloaded image %d",
119 case WPS_TOKEN_IMAGE_DISPLAY
:
120 snprintf(buf
, bufsize
, "display image");
124 #ifdef HAS_BUTTON_HOLD
125 case WPS_TOKEN_MAIN_HOLD
:
126 snprintf(buf
, bufsize
, "mode hold");
130 #ifdef HAS_REMOTE_BUTTON_HOLD
131 case WPS_TOKEN_REMOTE_HOLD
:
132 snprintf(buf
, bufsize
, "mode remote hold");
136 case WPS_TOKEN_REPEAT_MODE
:
137 snprintf(buf
, bufsize
, "mode repeat");
140 case WPS_TOKEN_PLAYBACK_STATUS
:
141 snprintf(buf
, bufsize
, "mode playback");
144 case WPS_TOKEN_RTC_DAY_OF_MONTH
:
145 snprintf(buf
, bufsize
, "rtc: day of month (01..31)");
147 case WPS_TOKEN_RTC_DAY_OF_MONTH_BLANK_PADDED
:
148 snprintf(buf
, bufsize
,
149 "rtc: day of month, blank padded ( 1..31)");
151 case WPS_TOKEN_RTC_HOUR_24_ZERO_PADDED
:
152 snprintf(buf
, bufsize
, "rtc: hour (00..23)");
154 case WPS_TOKEN_RTC_HOUR_24
:
155 snprintf(buf
, bufsize
, "rtc: hour ( 0..23)");
157 case WPS_TOKEN_RTC_HOUR_12_ZERO_PADDED
:
158 snprintf(buf
, bufsize
, "rtc: hour (01..12)");
160 case WPS_TOKEN_RTC_HOUR_12
:
161 snprintf(buf
, bufsize
, "rtc: hour ( 1..12)");
163 case WPS_TOKEN_RTC_MONTH
:
164 snprintf(buf
, bufsize
, "rtc: month (01..12)");
166 case WPS_TOKEN_RTC_MINUTE
:
167 snprintf(buf
, bufsize
, "rtc: minute (00..59)");
169 case WPS_TOKEN_RTC_SECOND
:
170 snprintf(buf
, bufsize
, "rtc: second (00..59)");
172 case WPS_TOKEN_RTC_YEAR_2_DIGITS
:
173 snprintf(buf
, bufsize
,
174 "rtc: last two digits of year (00..99)");
176 case WPS_TOKEN_RTC_YEAR_4_DIGITS
:
177 snprintf(buf
, bufsize
, "rtc: year (1970...)");
179 case WPS_TOKEN_RTC_AM_PM_UPPER
:
180 snprintf(buf
, bufsize
,
181 "rtc: upper case AM or PM indicator");
183 case WPS_TOKEN_RTC_AM_PM_LOWER
:
184 snprintf(buf
, bufsize
,
185 "rtc: lower case am or pm indicator");
187 case WPS_TOKEN_RTC_WEEKDAY_NAME
:
188 snprintf(buf
, bufsize
,
189 "rtc: abbreviated weekday name (Sun..Sat)");
191 case WPS_TOKEN_RTC_MONTH_NAME
:
192 snprintf(buf
, bufsize
,
193 "rtc: abbreviated month name (Jan..Dec)");
195 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_MON
:
196 snprintf(buf
, bufsize
,
197 "rtc: day of week (1..7); 1 is Monday");
199 case WPS_TOKEN_RTC_DAY_OF_WEEK_START_SUN
:
200 snprintf(buf
, bufsize
,
201 "rtc: day of week (0..6); 0 is Sunday");
204 #if (CONFIG_CODEC == SWCODEC)
205 case WPS_TOKEN_CROSSFADE
:
206 snprintf(buf
, bufsize
, "crossfade");
209 case WPS_TOKEN_REPLAYGAIN
:
210 snprintf(buf
, bufsize
, "replaygain");
215 case WPS_TOKEN_ALBUMART_DISPLAY
:
216 snprintf(buf
, bufsize
, "album art display");
219 case WPS_TOKEN_ALBUMART_FOUND
:
220 snprintf(buf
, bufsize
, "%strack album art conditional",
225 #ifdef HAVE_LCD_BITMAP
226 case WPS_TOKEN_IMAGE_BACKDROP
:
227 snprintf(buf
, bufsize
, "backdrop image");
230 case WPS_TOKEN_IMAGE_PROGRESS_BAR
:
231 snprintf(buf
, bufsize
, "progressbar bitmap");
234 case WPS_TOKEN_PEAKMETER
:
235 snprintf(buf
, bufsize
, "peakmeter");
239 case WPS_TOKEN_PROGRESSBAR
:
240 snprintf(buf
, bufsize
, "progressbar");
243 #ifdef HAVE_LCD_CHARCELLS
244 case WPS_TOKEN_PLAYER_PROGRESSBAR
:
245 snprintf(buf
, bufsize
, "full line progressbar");
249 case WPS_TOKEN_TRACK_TIME_ELAPSED
:
250 snprintf(buf
, bufsize
, "time elapsed in track");
253 case WPS_TOKEN_TRACK_ELAPSED_PERCENT
:
254 snprintf(buf
, bufsize
, "played percentage of track");
257 case WPS_TOKEN_PLAYLIST_ENTRIES
:
258 snprintf(buf
, bufsize
, "number of entries in playlist");
261 case WPS_TOKEN_PLAYLIST_NAME
:
262 snprintf(buf
, bufsize
, "playlist name");
265 case WPS_TOKEN_PLAYLIST_POSITION
:
266 snprintf(buf
, bufsize
, "position in playlist");
269 case WPS_TOKEN_TRACK_TIME_REMAINING
:
270 snprintf(buf
, bufsize
, "time remaining in track");
273 case WPS_TOKEN_PLAYLIST_SHUFFLE
:
274 snprintf(buf
, bufsize
, "playlist shuffle mode");
277 case WPS_TOKEN_TRACK_LENGTH
:
278 snprintf(buf
, bufsize
, "track length");
281 case WPS_TOKEN_VOLUME
:
282 snprintf(buf
, bufsize
, "volume");
285 case WPS_TOKEN_METADATA_ARTIST
:
286 snprintf(buf
, bufsize
, "%strack artist",
290 case WPS_TOKEN_METADATA_COMPOSER
:
291 snprintf(buf
, bufsize
, "%strack composer",
295 case WPS_TOKEN_METADATA_ALBUM
:
296 snprintf(buf
, bufsize
, "%strack album",
300 case WPS_TOKEN_METADATA_GROUPING
:
301 snprintf(buf
, bufsize
, "%strack grouping",
305 case WPS_TOKEN_METADATA_GENRE
:
306 snprintf(buf
, bufsize
, "%strack genre",
310 case WPS_TOKEN_METADATA_DISC_NUMBER
:
311 snprintf(buf
, bufsize
, "%strack disc", next_str(next
));
314 case WPS_TOKEN_METADATA_TRACK_NUMBER
:
315 snprintf(buf
, bufsize
, "%strack number",
319 case WPS_TOKEN_METADATA_TRACK_TITLE
:
320 snprintf(buf
, bufsize
, "%strack title",
324 case WPS_TOKEN_METADATA_VERSION
:
325 snprintf(buf
, bufsize
, "%strack ID3 version",
329 case WPS_TOKEN_METADATA_ALBUM_ARTIST
:
330 snprintf(buf
, bufsize
, "%strack album artist",
334 case WPS_TOKEN_METADATA_COMMENT
:
335 snprintf(buf
, bufsize
, "%strack comment",
339 case WPS_TOKEN_METADATA_YEAR
:
340 snprintf(buf
, bufsize
, "%strack year", next_str(next
));
344 case WPS_TOKEN_DATABASE_PLAYCOUNT
:
345 snprintf(buf
, bufsize
, "track playcount (database)");
348 case WPS_TOKEN_DATABASE_RATING
:
349 snprintf(buf
, bufsize
, "track rating (database)");
352 case WPS_TOKEN_DATABASE_AUTOSCORE
:
353 snprintf(buf
, bufsize
, "track autoscore (database)");
357 case WPS_TOKEN_BATTERY_PERCENT
:
358 snprintf(buf
, bufsize
, "battery percentage");
361 case WPS_TOKEN_BATTERY_VOLTS
:
362 snprintf(buf
, bufsize
, "battery voltage");
365 case WPS_TOKEN_BATTERY_TIME
:
366 snprintf(buf
, bufsize
, "battery time left");
369 case WPS_TOKEN_BATTERY_CHARGER_CONNECTED
:
370 snprintf(buf
, bufsize
, "battery charger connected");
373 case WPS_TOKEN_BATTERY_CHARGING
:
374 snprintf(buf
, bufsize
, "battery charging");
377 case WPS_TOKEN_BATTERY_SLEEPTIME
:
378 snprintf(buf
, bufsize
, "sleep timer");
381 case WPS_TOKEN_FILE_BITRATE
:
382 snprintf(buf
, bufsize
, "%sfile bitrate", next_str(next
));
385 case WPS_TOKEN_FILE_CODEC
:
386 snprintf(buf
, bufsize
, "%sfile codec", next_str(next
));
389 case WPS_TOKEN_FILE_FREQUENCY
:
390 snprintf(buf
, bufsize
, "%sfile audio frequency in Hz",
394 case WPS_TOKEN_FILE_FREQUENCY_KHZ
:
395 snprintf(buf
, bufsize
, "%sfile audio frequency in KHz",
399 case WPS_TOKEN_FILE_NAME
:
400 snprintf(buf
, bufsize
, "%sfile name", next_str(next
));
403 case WPS_TOKEN_FILE_NAME_WITH_EXTENSION
:
404 snprintf(buf
, bufsize
, "%sfile name with extension",
408 case WPS_TOKEN_FILE_PATH
:
409 snprintf(buf
, bufsize
, "%sfile path", next_str(next
));
412 case WPS_TOKEN_FILE_SIZE
:
413 snprintf(buf
, bufsize
, "%sfile size", next_str(next
));
416 case WPS_TOKEN_FILE_VBR
:
417 snprintf(buf
, bufsize
, "%sfile is vbr", next_str(next
));
420 case WPS_TOKEN_FILE_DIRECTORY
:
421 snprintf(buf
, bufsize
, "%sfile directory, level: %d",
422 next_str(next
), token
->value
.i
);
425 #if (CONFIG_CODEC != MAS3507D)
426 case WPS_TOKEN_SOUND_PITCH
:
427 snprintf(buf
, bufsize
, "pitch value");
430 case WPS_VIEWPORT_ENABLE
:
431 snprintf(buf
, bufsize
, "enable VP:%d",
434 case WPS_TOKEN_BUTTON_VOLUME
:
435 snprintf(buf
, bufsize
, "Volume button timeout:%d",
439 snprintf(buf
, bufsize
, "FIXME (code: %d)",
447 #if defined(SIMULATOR) || defined(__PCTOOL__)
448 static void dump_wps_tokens(struct wps_data
*data
)
450 struct wps_token
*token
;
454 int num_string_tokens
= 0;
456 /* Dump parsed WPS */
457 for (i
= 0, token
= data
->tokens
; i
< data
->num_tokens
; i
++, token
++)
459 get_token_desc(token
, data
, buf
, sizeof(buf
));
463 case WPS_TOKEN_STRING
:
467 case WPS_TOKEN_CONDITIONAL_START
:
471 case WPS_TOKEN_CONDITIONAL_END
:
479 if (wps_verbose_level
> 2)
481 for(j
= 0; j
< indent
; j
++) {
485 DEBUGF("[%3d] = (%2d) %s\n", i
, token
->type
, buf
);
489 if (wps_verbose_level
> 0)
492 DEBUGF("Number of string tokens: %d\n", num_string_tokens
);
497 static void print_line_info(struct wps_data
*data
)
500 struct wps_line
*line
;
501 struct wps_subline
*subline
;
503 if (wps_verbose_level
> 0)
505 DEBUGF("Number of viewports : %d\n", data
->num_viewports
);
506 for (v
= 0; v
< data
->num_viewports
; v
++)
508 DEBUGF("vp %d: First line: %d\n", v
, data
->viewports
[v
].first_line
);
509 DEBUGF("vp %d: Last line: %d\n", v
, data
->viewports
[v
].last_line
);
511 DEBUGF("Number of sublines : %d\n", data
->num_sublines
);
512 DEBUGF("Number of tokens : %d\n", data
->num_tokens
);
516 if (wps_verbose_level
> 1)
518 for (v
= 0; v
< data
->num_viewports
; v
++)
520 DEBUGF("Viewport %d - +%d+%d (%dx%d)\n",v
,data
->viewports
[v
].vp
.x
,
521 data
->viewports
[v
].vp
.y
,
522 data
->viewports
[v
].vp
.width
,
523 data
->viewports
[v
].vp
.height
);
524 for (i
= data
->viewports
[v
].first_line
, line
= &data
->lines
[data
->viewports
[v
].first_line
]; i
<= data
->viewports
[v
].last_line
; i
++,line
++)
526 DEBUGF("Line %2d (num_sublines=%d, first_subline=%d)\n",
527 i
, line
->num_sublines
, line
->first_subline_idx
);
529 for (j
= 0, subline
= data
->sublines
+ line
->first_subline_idx
;
530 j
< line
->num_sublines
; j
++, subline
++)
532 DEBUGF(" Subline %d: first_token=%3d, last_token=%3d",
533 j
, subline
->first_token_idx
,
534 wps_last_token_index(data
, i
, j
));
536 if (subline
->line_type
& WPS_REFRESH_SCROLL
)
537 DEBUGF(", scrolled");
538 else if (subline
->line_type
& WPS_REFRESH_PLAYER_PROGRESS
)
539 DEBUGF(", progressbar");
540 else if (subline
->line_type
& WPS_REFRESH_PEAK_METER
)
541 DEBUGF(", peakmeter");
552 static void print_wps_strings(struct wps_data
*data
)
554 int i
, len
, total_len
= 0, buf_used
= 0;
556 if (wps_verbose_level
> 1) DEBUGF("Strings:\n");
557 for (i
= 0; i
< data
->num_strings
; i
++)
559 len
= strlen(data
->strings
[i
]);
562 if (wps_verbose_level
> 1)
563 DEBUGF("%2d: (%2d) '%s'\n", i
, len
, data
->strings
[i
]);
565 if (wps_verbose_level
> 1) DEBUGF("\n");
567 if (wps_verbose_level
> 0)
569 DEBUGF("Number of unique strings: %d (max: %d)\n",
570 data
->num_strings
, WPS_MAX_STRINGS
);
571 DEBUGF("Total string length: %d\n", total_len
);
572 DEBUGF("String buffer used: %d out of %d bytes\n",
573 buf_used
, STRING_BUFFER_SIZE
);
579 void print_debug_info(struct wps_data
*data
, enum wps_parse_error fail
, int line
)
581 #if defined(SIMULATOR) || defined(__PCTOOL__)
582 if (debug_wps
&& wps_verbose_level
)
584 dump_wps_tokens(data
);
585 print_wps_strings(data
);
586 print_line_info(data
);
588 #endif /* SIMULATOR */
590 if (data
->num_tokens
>= WPS_MAX_TOKENS
- 1) {
591 DEBUGF("Warning: Max number of tokens was reached (%d)\n",
595 if (fail
!= PARSE_OK
)
599 DEBUGF("ERR: Failed parsing on line %d : ", line
);
605 case PARSE_FAIL_UNCLOSED_COND
:
606 DEBUGF("ERR: Unclosed conditional");
609 case PARSE_FAIL_INVALID_CHAR
:
610 DEBUGF("ERR: Unexpected conditional char after token %d: \"%s\"",
612 get_token_desc(&data
->tokens
[data
->num_tokens
-1], data
,
617 case PARSE_FAIL_COND_SYNTAX_ERROR
:
618 DEBUGF("ERR: Conditional syntax error after token %d: \"%s\"",
620 get_token_desc(&data
->tokens
[data
->num_tokens
-1], data
,
625 case PARSE_FAIL_COND_INVALID_PARAM
:
626 DEBUGF("ERR: Invalid parameter list for token %d: \"%s\"",
628 get_token_desc(&data
->tokens
[data
->num_tokens
], data
,
633 case PARSE_FAIL_LIMITS_EXCEEDED
:
634 DEBUGF("ERR: Limits exceeded");
641 #endif /* DEBUG || SIMULATOR */