aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgermeier <germeier>2002-10-27 02:45:28 +0000
committergermeier <germeier>2002-10-27 02:45:28 +0000
commit13b7579bd45e89304b8697a6fb471bf0524f49d4 (patch)
treea446bb30895a09bd1ff11a4bfbd5d44de468c102
parent9931f7bb5faf4407bfae23003071a6cb89e79c76 (diff)
downloadmpiosh-13b7579bd45e89304b8697a6fb471bf0524f49d4.tar.gz
mpiosh-13b7579bd45e89304b8697a6fb471bf0524f49d4.tar.bz2
mpiosh-13b7579bd45e89304b8697a6fb471bf0524f49d4.zip
added code to read/write and display config files (CONFIG.DAT and FMCONFIG.DAT)
another 8.3 fix :-(
-rw-r--r--ChangeLog12
-rw-r--r--libmpio/defs.h9
-rw-r--r--libmpio/directory.c4
-rw-r--r--libmpio/fat.c18
-rw-r--r--libmpio/mpio.c76
-rw-r--r--libmpio/mpio.h29
-rw-r--r--mpiosh/callback.c101
-rw-r--r--mpiosh/callback.h3
-rw-r--r--mpiosh/global.c16
9 files changed, 238 insertions, 30 deletions
diff --git a/ChangeLog b/ChangeLog
index b6f0cbb..e3d80e5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2002-10-27 Markus Germeier <mager@tzi.de>
+
+ * libmpio/mpio.{c,h}: split mpio_file_{get,put} into several
+ functions, to allow reading and writing files from/to memory
+ (needed for handling of config files)
+ * mpiosh/callback.c (mpiosh_cmd_channel): added function/command
+ channel to handle the radio channel of the *-Plus models
+ * libmpio/directory.c (mpio_dentry_put):
+ another fix for the 8.3 handling needed for the config file
+ (one day this will be bug free ...)
+ * mpiosh/callback.c (mpiosh_cmd_config): implement the function
+
2002-10-26 Markus Germeier <mager@tzi.de>
* libmpio/mpio.c (mpio_close): fixed segv
diff --git a/libmpio/defs.h b/libmpio/defs.h
index 89195f0..49d8311 100644
--- a/libmpio/defs.h
+++ b/libmpio/defs.h
@@ -1,7 +1,7 @@
/* -*- linux-c -*- */
/*
- * $Id: defs.h,v 1.12 2002/10/26 13:07:43 germeier Exp $
+ * $Id: defs.h,v 1.13 2002/10/27 02:45:28 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -63,7 +63,8 @@ typedef enum { GET_VERSION = 0x01,
/* file types on internal memory */
/* found in the code of salmoon, are these needed? -mager */
-typedef enum { FTYPE_MUSIC = 0x01,
+typedef enum { FTYPE_CHAN = 0x00,
+ FTYPE_MUSIC = 0x01,
FTYPE_CONF = 'C',
FTYPE_FONT = 'F',
FTYPE_OTHER = 'H',
@@ -71,6 +72,10 @@ typedef enum { FTYPE_MUSIC = 0x01,
FTYPE_WAV = 'V',
FTYPE_ENTRY = 'R' } mpio_filetype_t;
+/* fixed filenames */
+#define MPIO_CONFIG_FILE "CONFIG.DAT"
+#define MPIO_CHANNEL_FILE "FMCONFIG.DAT"
+
/* type of callback functions */
typedef BYTE (*mpio_callback_t)(int, int) ;
typedef BYTE (*mpio_callback_init_t)(mpio_mem_t, int, int) ;
diff --git a/libmpio/directory.c b/libmpio/directory.c
index d3cd677..4795b3d 100644
--- a/libmpio/directory.c
+++ b/libmpio/directory.c
@@ -1,6 +1,6 @@
/*
*
- * $Id: directory.c,v 1.8 2002/10/17 22:49:27 germeier Exp $
+ * $Id: directory.c,v 1.9 2002/10/27 02:45:28 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -525,7 +525,7 @@ mpio_dentry_put(mpio_t *m, mpio_mem_t mem,
f_8_3[12]=0x00;
i=0;
- while ((i<6) && (filename[i] != '.') && (i<(strlen(filename))))
+ while ((i<8) && (filename[i] != '.') && (i<(strlen(filename))))
{
f_8_3[i] = toupper(filename[i]);
i++;
diff --git a/libmpio/fat.c b/libmpio/fat.c
index ad9f9dd..8582aa9 100644
--- a/libmpio/fat.c
+++ b/libmpio/fat.c
@@ -1,6 +1,6 @@
-/*
+ /*
*
- * $Id: fat.c,v 1.18 2002/10/13 12:03:51 germeier Exp $
+ * $Id: fat.c,v 1.19 2002/10/27 02:45:28 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -498,7 +498,8 @@ mpio_fatentry_read(mpio_t *m, mpio_mem_t mem, mpio_fatentry_t *f )
(sm->fat[e+0x00] != 0xee)))
{
debug("defective block encountered, abort reading!\n");
- return 0xaaaaaaaa;
+/* return 0xaaaaaaaa; */
+ return 0xffffffff;
}
/* this is a special system file! */
if((sm->fat[e+6] != FTYPE_MUSIC) &&
@@ -507,7 +508,16 @@ mpio_fatentry_read(mpio_t *m, mpio_mem_t mem, mpio_fatentry_t *f )
(sm->fat[e+9] == 0xff) &&
(sm->fat[e+10] == 0xff))
return 0xffffffff;
-
+ /* this is a special system file! */
+ if (sm->fat[e+6] == FTYPE_CONF)
+ return 0xffffffff;
+ /* this is a special system file! */
+ if((sm->fat[e+6] != FTYPE_MUSIC) &&
+ (sm->fat[e+0x0b] == 0xff) &&
+ (sm->fat[e+0x0c] == 0xff) &&
+ (sm->fat[e+0x0d] == 0xff))
+ return 0xffffffff;
+
if((sm->fat[e+7] == 0xff) &&
(sm->fat[e+8] == 0xff) &&
(sm->fat[e+9] == 0xff) &&
diff --git a/libmpio/mpio.c b/libmpio/mpio.c
index 871bd98..e2a6ec5 100644
--- a/libmpio/mpio.c
+++ b/libmpio/mpio.c
@@ -1,6 +1,6 @@
/*
*
- * $Id: mpio.c,v 1.34 2002/10/26 13:07:43 germeier Exp $
+ * $Id: mpio.c,v 1.35 2002/10/27 02:45:28 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -46,6 +46,10 @@ void mpio_init_internal(mpio_t *);
void mpio_init_external(mpio_t *);
int mpio_check_filename(mpio_filename_t);
+int mpio_file_get_real(mpio_t *, mpio_mem_t, mpio_filename_t,
+ mpio_callback_t, BYTE **);
+int mpio_file_put_real(mpio_t *, mpio_mem_t, mpio_filename_t, mpio_filetype_t,
+ mpio_callback_t, BYTE *, int);
static BYTE *mpio_model_name[] = {
"MPIO-DME",
@@ -392,6 +396,20 @@ int
mpio_file_get(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename,
mpio_callback_t progress_callback)
{
+ return mpio_file_get_real(m, mem, filename, progress_callback, NULL);
+}
+
+int
+mpio_file_get_to_memory(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename,
+ mpio_callback_t progress_callback, BYTE **memory)
+{
+ return mpio_file_get_real(m, mem, filename, progress_callback, memory);
+}
+
+int
+mpio_file_get_real(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename,
+ mpio_callback_t progress_callback, BYTE **memory)
+{
mpio_smartmedia_t *sm;
BYTE block[BLOCK_SIZE];
int fd, towrite;
@@ -418,9 +436,14 @@ mpio_file_get(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename,
if (f && p) {
filesize=fsize=mpio_dentry_get_filesize(m, mem, p);
-
- unlink(filename);
- fd = open(filename, (O_RDWR | O_CREAT), (S_IRWXU | S_IRGRP | S_IROTH));
+
+ if (memory)
+ {
+ *memory = malloc(filesize);
+ } else {
+ unlink(filename);
+ fd = open(filename, (O_RDWR | O_CREAT), (S_IRWXU | S_IRGRP | S_IROTH));
+ }
do
{
@@ -431,13 +454,19 @@ mpio_file_get(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename,
} else {
towrite = filesize;
}
+
+ if (memory)
+ {
+ memcpy((*memory)+(fsize-filesize) , block, towrite);
+ } else {
+ if (write(fd, block, towrite) != towrite) {
+ debug("error writing file data\n");
+ close(fd);
+ free (f);
+ MPIO_ERR_RETURN(MPIO_ERR_WRITING_FILE);
+ }
+ }
- if (write(fd, block, towrite) != towrite) {
- debug("error writing file data\n");
- close(fd);
- free (f);
- MPIO_ERR_RETURN(MPIO_ERR_WRITING_FILE);
- }
filesize -= towrite;
if (progress_callback)
@@ -451,8 +480,11 @@ mpio_file_get(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename,
if (merror<0)
debug("defective block encountered!\n");
- close (fd);
- free (f);
+ if(!memory)
+ {
+ close (fd);
+ free (f);
+ }
/* read and copied code from mtools-3.9.8/mcopy.c
* to make this one right
@@ -474,6 +506,26 @@ mpio_file_put(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename,
mpio_filetype_t filetype,
mpio_callback_t progress_callback)
{
+ return mpio_file_put_real(m, mem, filename, filetype,
+ progress_callback, NULL,0);
+}
+
+int
+mpio_file_put_from_memory(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename,
+ mpio_filetype_t filetype,
+ mpio_callback_t progress_callback,
+ BYTE *memory, int memory_size)
+{
+ return mpio_file_put_real(m, mem, filename, filetype,
+ progress_callback, memory, memory_size);
+}
+
+int
+mpio_file_put_real(mpio_t *m, mpio_mem_t mem, mpio_filename_t filename,
+ mpio_filetype_t filetype,
+ mpio_callback_t progress_callback,
+ BYTE *memory, int memory_size)
+{
mpio_smartmedia_t *sm;
mpio_fatentry_t *f, current, firstblock, backup;
WORD start;
diff --git a/libmpio/mpio.h b/libmpio/mpio.h
index a36cc49..51decef 100644
--- a/libmpio/mpio.h
+++ b/libmpio/mpio.h
@@ -1,7 +1,7 @@
#/* -*- linux-c -*- */
/*
- * $Id: mpio.h,v 1.10 2002/10/26 13:07:43 germeier Exp $
+ * $Id: mpio.h,v 1.11 2002/10/27 02:45:28 germeier Exp $
*
* Library for USB MPIO-*
*
@@ -75,16 +75,41 @@ BYTE* mpio_dentry_next(mpio_t *, mpio_mem_t, BYTE *);
int mpio_dentry_get(mpio_t *, mpio_mem_t, BYTE *, BYTE *, int,WORD *,
BYTE *, BYTE *, BYTE *, BYTE *, DWORD *);
+/*
+ * reading/writing/deleting of files
+ */
+
/* context, memory bank, filename, callback */
int mpio_file_get(mpio_t *, mpio_mem_t, mpio_filename_t, mpio_callback_t);
-/* context, memory bank, filename, callback */
+/* context, memory bank, filename, filetype, callback */
int mpio_file_put(mpio_t *, mpio_mem_t, mpio_filename_t, mpio_filetype_t,
mpio_callback_t);
/* context, memory bank, filename, callback */
int mpio_file_del(mpio_t *, mpio_mem_t, mpio_filename_t, mpio_callback_t);
+/*
+ * reading/writing files into memory (used for config+font files)
+ */
+
+/* context, memory bank, filename, callback, pointer to memory */
+/* the needed memory is allocated and the memory pointer is return */
+/* via the "BYTE **" */
+
+int mpio_file_get_to_memory(mpio_t *, mpio_mem_t, mpio_filename_t,
+ mpio_callback_t, BYTE **);
+
+/* context, memory bank, filename, filetype, callback ... */
+/* ... memory pointer, size of file */
+int mpio_file_put_from_memory(mpio_t *, mpio_mem_t, mpio_filename_t,
+ mpio_filetype_t, mpio_callback_t,
+ BYTE *, int);
+
+/*
+ * formating a memory (internal mem or external SmartMedia card)
+ */
+
/* context, memory bank, callback */
int mpio_memory_format(mpio_t *, mpio_mem_t, mpio_callback_t);
diff --git a/mpiosh/callback.c b/mpiosh/callback.c
index 8f4be03..e9d7a0a 100644
--- a/mpiosh/callback.c
+++ b/mpiosh/callback.c
@@ -2,7 +2,7 @@
*
* Author: Andreas Büsching <crunchy@tzi.de>
*
- * $Id: callback.c,v 1.27 2002/10/18 08:39:23 crunchy Exp $
+ * $Id: callback.c,v 1.28 2002/10/27 02:45:28 germeier Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -628,11 +628,108 @@ mpiosh_cmd_dump_mem(char *args[])
void
mpiosh_cmd_config(char *args[])
{
+ BYTE *config_data, *p;
+ int size;
+
MPIOSH_CHECK_CONNECTION_CLOSED;
- UNUSED(args);
+ if (args[0] != NULL) {
+ if (!strcmp(args[0], "read")) {
+ if ((size = mpio_file_get(mpiosh.dev, MPIO_INTERNAL_MEM,
+ MPIO_CONFIG_FILE, NULL))<=0) {
+ fprintf(stderr, "Could not read config file\n");
+ } else {
+ printf("done.\n");
+ }
+ } else if (!strcmp(args[0], "write")) {
+ printf("deleting old config file ...\n");
+ mpio_file_del(mpiosh.dev, MPIO_INTERNAL_MEM,
+ MPIO_CONFIG_FILE, NULL);
+ printf("writing new config file ...\n");
+ if (mpio_file_put(mpiosh.dev, MPIO_INTERNAL_MEM, MPIO_CONFIG_FILE,
+ FTYPE_CONF, NULL)==-1)
+ mpio_perror("error");
+ mpio_sync(mpiosh.dev, MPIO_INTERNAL_MEM);
+ } else if (!strcmp(args[0], "show")) {
+ if ((size = mpio_file_get_to_memory(mpiosh.dev, MPIO_INTERNAL_MEM,
+ MPIO_CONFIG_FILE, NULL, &config_data))<=0) {
+ fprintf(stderr, "Could not read config file\n");
+ } else {
+ hexdumpn(0, config_data, size);
+ fprintf(stderr, "please implement me!\n");
+ free(config_data);
+ }
+ } else {
+ fprintf(stderr, "unknown config command\n");
+ printf("config [read|write|show] channel\n");
+ }
+ } else {
+ fprintf(stderr, "error: no arguments given\n");
+ printf("config [read|write|show] <\n");
+ }
+
}
+void
+mpiosh_cmd_channel(char *args[])
+{
+ BYTE *channel_data, *p, name[17];
+ int size;
+ int i;
+ int chan;
+
+ MPIOSH_CHECK_CONNECTION_CLOSED;
+
+ if (args[0] != NULL) {
+ if (!strcmp(args[0], "read")) {
+ if ((size = mpio_file_get(mpiosh.dev, MPIO_INTERNAL_MEM,
+ MPIO_CHANNEL_FILE, NULL))<=0) {
+ fprintf(stderr, "Could not read channel file\n");
+ } else {
+ printf("done.\n");
+ }
+ } else if (!strcmp(args[0], "write")) {
+ printf("deleting old config file ...\n");
+ mpio_file_del(mpiosh.dev, MPIO_INTERNAL_MEM,
+ MPIO_CHANNEL_FILE, NULL);
+ printf("writing new config file ...\n");
+ if (mpio_file_put(mpiosh.dev, MPIO_INTERNAL_MEM, MPIO_CHANNEL_FILE,
+ FTYPE_CHAN, NULL)==-1)
+ mpio_perror("error");
+ mpio_sync(mpiosh.dev, MPIO_INTERNAL_MEM);
+ } else if (!strcmp(args[0], "show")) {
+ if ((size = mpio_file_get_to_memory(mpiosh.dev, MPIO_INTERNAL_MEM,
+ MPIO_CHANNEL_FILE, NULL, &channel_data))<=0) {
+ fprintf(stderr, "Could not read channel file\n");
+ } else {
+ hexdump(channel_data, size);
+
+ i=0;
+ p=channel_data;
+ while ((i<20) && (*p))
+ {
+ memset(name, 0, 17);
+ strncpy(name, p, 16);
+ chan = (((p[16] * 0x100) + p[17]) - 0x600) + 1750;
+ printf("%2d. %-16s at %7.2f MHz\n", (i+1),
+ name, ((float)chan/20));
+ p+=18;
+ i++;
+ }
+ if (!i)
+ printf("no channel defined!\n");
+
+ free(channel_data);
+ }
+ } else {
+ fprintf(stderr, "unknown channel command\n");
+ printf("channel [read|write|show] channel\n");
+ }
+ } else {
+ fprintf(stderr, "error: no arguments given\n");
+ printf("channel [read|write|show] <\n");
+ }
+}
void
mpiosh_cmd_ldir(char *args[])
diff --git a/mpiosh/callback.h b/mpiosh/callback.h
index a377a49..eefbd31 100644
--- a/mpiosh/callback.h
+++ b/mpiosh/callback.h
@@ -2,7 +2,7 @@
*
* Author: Andreas Büsching <crunchy@tzi.de>
*
- * $Id: callback.h,v 1.6 2002/10/18 08:39:23 crunchy Exp $
+ * $Id: callback.h,v 1.7 2002/10/27 02:45:28 germeier Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -48,6 +48,7 @@ void mpiosh_cmd_format(char *args[]);
void mpiosh_cmd_switch(char *args[]);
void mpiosh_cmd_dump_mem(char *args[]);
void mpiosh_cmd_config(char *args[]);
+void mpiosh_cmd_channel(char *args[]);
/* local command callbacks */
void mpiosh_cmd_ldir(char *args[]);
diff --git a/mpiosh/global.c b/mpiosh/global.c
index 7fe21b6..d300f62 100644
--- a/mpiosh/global.c
+++ b/mpiosh/global.c
@@ -2,7 +2,7 @@
*
* Author: Andreas Buesching <crunchy@tzi.de>
*
- * $Id: global.c,v 1.3 2002/10/18 08:39:23 crunchy Exp $
+ * $Id: global.c,v 1.4 2002/10/27 02:45:28 germeier Exp $
*
* Copyright (C) 2001 Andreas Büsching <crunchy@tzi.de>
*
@@ -105,12 +105,18 @@ mpiosh_cmd_t commands[] = {
" dump FAT, directory, spare area and the first 0x100 of the\n"
" selected memory card",
mpiosh_cmd_dump_mem, NULL },
- { "config", (char *[]) { "conf", NULL }, "-w -r -s",
+ { "config", (char *[]) { "conf", NULL }, "[read|write|show]",
" give access to the configuration file of the MPIO player\n"
- " -w write the configuration back to the MPIO player\n"
- " -r read the configuration file and dumps it on the local disc\n"
- " -s show the current configuration",
+ " read read the configuration file and dump it on the local disc\n"
+ " write write the configuration back to the MPIO player\n"
+ " show show the current configuration",
mpiosh_cmd_config, mpiosh_readline_comp_config },
+ { "channel", (char *[]) { "channels", "chan", NULL }, "[read|write|show]",
+ " give access to the radio channel file of the MPIO player\n"
+ " read read the channel file and dump it on the local disc\n"
+ " write write the channel file back to the MPIO player\n"
+ " show show the current channel configuration",
+ mpiosh_cmd_channel, mpiosh_readline_comp_config },
{ NULL, NULL, NULL, NULL, NULL, NULL }
};