Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#37088 - 24/08/2001 10:28 How big is yours?
tms13
old hand

Registered: 30/07/2001
Posts: 1115
Loc: Lochcarron and Edinburgh
Today, I put my first program onto my empeg. It's called "hello world" and you can guess what it does.

I also put my second program onto it. It's a bit more useful. It's designed to answer the question everybody asks you: how much music is there on your empeg? It only works on single-drive machines at present, but I include source so you can see how to fix that.

To use, just install it on $PATH in your player (e.g. in /empeg/bin) and run it with no arguments to see how long it would take to play your root playlist, or with a list of FIDs to measure those.

Here's the code (binary is attached):




#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/limits.h>

#define FID_ROOTPLAYLIST 0x100

#define FIDS_DIR "/drive0/fids"
#define FIDS_FILE0_FORMAT FIDS_DIR"/%x0"
#define FIDS_FILE1_FORMAT FIDS_DIR"/%x1"

#define LINESZ 512

#define TYPE_TUNE 1
#define TYPE_PLAYLIST 2

#if 0
#define DEBUG0(s) fprintf(stderr, s);
#define DEBUG1(s, x) fprintf(stderr, s, x);
#endif

int measure_item(int playlist);
int measure_playlist(int playlist);


int main(int argc, char **argv) {

int playlist;
int duration; /* in milliseconds */
int total = 0;
int i;
char *numend;

if (argc <= 1) {
/* argument not supplied - measure root playlist */
total = duration = measure_item(FID_ROOTPLAYLIST);
printf("Root playlist: %d.%03d", duration/1000, duration%1000);
} else {
for (i = 1; i < argc; i++) {
/* Parse argument as hexadecimal FID */
playlist = (int)strtol(argv[ i], &numend, 16);
if (*numend) {
fprintf(stderr, "%s: Unrecognised argument %s\n", argv[ 0], argv[ i]);
fprintf(stderr, "Usage: %s [ fid...]\n", argv[ 0]);
exit(EXIT_FAILURE);
}
total += duration = measure_item(playlist);
printf("Playlist %5x: %d.%03d\n", playlist, duration/1000, duration%1000);
}
printf("Total: %d.%03d", total/1000, total%1000);
}

if (duration > 60000) {
int hours, minutes, seconds, millis;
millis = total % 1000;
total /= 1000;
seconds = total % 60;
minutes = total / 60 % 60;
hours = total / 3600;

printf(" (");
if (hours)
printf("%dh", hours);
if (minutes)
printf("%dm", minutes);
printf("%ds", seconds);
printf(")");
}
printf("\n");

return EXIT_SUCCESS;

}


/* Returns length of playlist or tune, in milliseconds. */
int measure_item(int playlist) {
char filename[ PATH_MAX+1];
char line[ LINESZ+1];
int duration = 0;
int type = 0;
FILE *f;

/* First, read the *1 file - is it a tune or a playlist? */
sprintf(filename, FIDS_FILE1_FORMAT, playlist/16);

/*DEBUG1("Opening %s\n", filename);*/
f = fopen(filename, "r");
if (f == NULL) {
perror(filename);
exit(EXIT_FAILURE);
}

while (fgets(line, LINESZ, f)) {
if (!strcmp(line, "type=tune\n")) {
type = TYPE_TUNE;
} else if (!strcmp(line, "type=playlist\n")) {
type = TYPE_PLAYLIST;
} else if (!strncmp(line, "duration=", 9)) {
duration = (int)strtol(line+9, NULL, 10);
}
}

if (ferror(f)) {
/* fgets failed, not at EOF */
perror(filename);
fclose(f);
exit(EXIT_FAILURE);
}

if (fclose(f)) {
perror(filename);
exit(EXIT_FAILURE);
}

switch (type) {
case TYPE_TUNE:
return duration;

case TYPE_PLAYLIST:
return measure_playlist(playlist);

default:
fprintf(stderr, "No type for %s", filename);
exit(EXIT_FAILURE);
}
}


int measure_playlist(int playlist) {
char filename[ PATH_MAX+1];
int fid;
int duration = 0;
FILE *f;

/* First, read the *0 file - this holds the child pointers. */
sprintf(filename, FIDS_FILE0_FORMAT, playlist/16);

f = fopen(filename, "rb");
if (f == NULL) {
perror(filename);
exit(EXIT_FAILURE);
}

while (1 == fread(&fid, 4, 1, f)) {
duration += measure_item(fid);
}

if (ferror(f)){
/* fread failed */
perror(filename);
fclose(f);
exit(EXIT_FAILURE);
}

if (fclose(f)) {
perror(filename);
exit(EXIT_FAILURE);
}

return duration;
}



--
Toby Speight


Attachments
36227-count-time (175 downloads)

_________________________
Toby Speight
030103016 (80GB Mk2a, blue)
030102806 (0GB Mk2a, blue)

Top
#37089 - 24/08/2001 15:42 Re: How big is yours? [Re: tms13]
arvind_bk
stranger

Registered: 14/08/2001
Posts: 29
How to install this program on empeg? Using serial link!?


Top
#37090 - 28/08/2001 02:47 Re: How big is yours? [Re: arvind_bk]
tms13
old hand

Registered: 30/07/2001
Posts: 1115
Loc: Lochcarron and Edinburgh
Upload the binary using zmodem - I'm assuming that anyone wanting this already knows how to get a shell on the empeg...

--
Toby Speight
_________________________
Toby Speight
030103016 (80GB Mk2a, blue)
030102806 (0GB Mk2a, blue)

Top
#37091 - 28/08/2001 04:12 Re: How big is yours? [Re: tms13]
peter
carpal tunnel

Registered: 13/07/2000
Posts: 4180
Loc: Cambridge, England
Kewl, although I do have to say at this point that, in v2.0, both Emplode and the player will give you this information too.

http://empeg.comms.net/php/showthreaded.php?Cat=&Board=wishlist&Number=33565&page=&view=&sb=&o=

Peter



Top
#37092 - 28/08/2001 04:23 Re: How big is yours? [Re: peter]
tms13
old hand

Registered: 30/07/2001
Posts: 1115
Loc: Lochcarron and Edinburgh
That's great - I did this mainly for my own amusement, and thought I'd share the code. If I were to do it properly, I'd read the database instead of grinding the discs reading fids/*1...

BTW, has anyone reverse-engineered the DB? I can imagine some cool uses...

--
Toby Speight
_________________________
Toby Speight
030103016 (80GB Mk2a, blue)
030102806 (0GB Mk2a, blue)

Top
#37093 - 28/08/2001 04:44 Re: How big is yours? [Re: tms13]
peter
carpal tunnel

Registered: 13/07/2000
Posts: 4180
Loc: Cambridge, England
has anyone reverse-engineered the DB

Well, I hope no-one's gone to the bother of reverse-engineering it... all the code to parse it is in the GPL'd emptool sources. (The emptool/emplode protocol just grabs the entire file, pipes it over the connection, and parses it at the PC end.)

Peter



Top
#37094 - 28/08/2001 05:40 Re: How big is yours? [Re: peter]
tms13
old hand

Registered: 30/07/2001
Posts: 1115
Loc: Lochcarron and Edinburgh
Peter wrote:

> Well, I hope no-one's gone to the bother of reverse-engineering it... all the code to parse it is in the GPL'd emptool sources.

I should have looked - I assumed that it was built on the player.

--
Toby Speight
_________________________
Toby Speight
030103016 (80GB Mk2a, blue)
030102806 (0GB Mk2a, blue)

Top
#37095 - 28/08/2001 07:17 Re: How big is yours? [Re: tms13]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5683
Loc: London, UK
It is -- it's built on the player during a sync. But it's parsed in emplode/emptool during a dowload from the player.



Roger - not necessarily speaking for empeg
_________________________
-- roger

Top
#37096 - 28/08/2001 08:52 Re: How big is yours? [Re: Roger]
fvgestel
old hand

Registered: 12/08/2000
Posts: 702
Loc: Netherlands
Cool, just looked into emptool source... This has potential...

Frank van Gestel
_________________________
Frank van Gestel

Top
#37097 - 28/08/2001 17:06 Re: How big is yours? [Re: fvgestel]
EngelenH
enthusiast

Registered: 29/09/2000
Posts: 313
Loc: Belgium/Holland
In reply to:

Cool, just looked into emptool source... This has potential...




Ut oh, Roger now you've done it ...

Cheers,
Hans

Mk2 - Blue & Red - 080000431
_________________________
Mk2 This message will selfdestruct in 5 seconds to prevent reproduction.

Top