]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
error handling: improved cmd_error() - print fatfs error strings
authorLeo C <erbl259-lmu@yahoo.de>
Fri, 31 Aug 2018 21:36:06 +0000 (23:36 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Fri, 31 Aug 2018 21:36:06 +0000 (23:36 +0200)
avr/Tupfile
avr/cmd_fat.c
avr/command.c
avr/strerror.c [new file with mode: 0644]
include/cmd_fat.h
include/command.h
include/strerror.h [new file with mode: 0644]

index 5e1f305229e38fddaa4c5a222a3b6e43a7ddbe21..b74b30575bce57a0400cd32c251950a8c02b9b30 100644 (file)
@@ -11,7 +11,7 @@ SRC           += cmd_run.c cmd_boot.c cmd_misc.c
 SRC            += cmd_date.c cmd_mem.c cmd_gpio.c cmd_attach.c
 SRC            += cmd_loadihex.c cmd_loadcpm3.c cmd_sd.c cmd_fat.c
 SRC            += env.c con-utils.c print-utils.c getopt-min.c eval_arg.c
 SRC            += cmd_date.c cmd_mem.c cmd_gpio.c cmd_attach.c
 SRC            += cmd_loadihex.c cmd_loadcpm3.c cmd_sd.c cmd_fat.c
 SRC            += env.c con-utils.c print-utils.c getopt-min.c eval_arg.c
-SRC            += timer.c serial.c i2c.c bcd.c pcf8583.c mmc.c
+SRC            += timer.c serial.c i2c.c bcd.c pcf8583.c mmc.c strerror.c
 SRC            += background.c z180-serv.c z80-if.c gpio.c
 SRC            += $(FATFS)
 
 SRC            += background.c z180-serv.c z80-if.c gpio.c
 SRC            += $(FATFS)
 
index ab16fa581c20ebc805ba0a34a3bd2d3106c9776f..7cc9e46ee9ae942691c38f7edd1923fa051cd817 100644 (file)
@@ -76,26 +76,26 @@ static bool check_abort(void)
 
 
 static const FLASH char * const FLASH rc_strings[] = {
 
 
 static const FLASH char * const FLASH rc_strings[] = {
-                       FSTR("OK"),
-                       FSTR("disk error"),
-                       FSTR("internal error"),
-                       FSTR("not ready"),
-                       FSTR("no file"),
-                       FSTR("no path"),
-                       FSTR("invalid name"),
-                       FSTR("denied"),
-                       FSTR("exist"),
-                       FSTR("invalid object"),
-                       FSTR("write protected"),
-                       FSTR("invalid drive"),
-                       FSTR("not enabled"),
-                       FSTR("no file system"),
-                       FSTR("mkfs aborted"),
-                       FSTR("timeout"),
-                       FSTR("locked"),
-                       FSTR("not enough core"),
-                       FSTR("too many open files"),
-                       FSTR("invalid parameter")
+                       FSTR("Success"),
+                       FSTR("Disk error"),
+                       FSTR("Internal error"),
+                       FSTR("Not ready"),
+                       FSTR("No file"),
+                       FSTR("No path"),
+                       FSTR("Invalid name"),
+                       FSTR("Denied"),
+                       FSTR("Exist"),
+                       FSTR("Invalid object"),
+                       FSTR("Write protected"),
+                       FSTR("Invalid drive"),
+                       FSTR("Not enabled"),
+                       FSTR("No file system"),
+                       FSTR("Mkfs aborted"),
+                       FSTR("Timeout"),
+                       FSTR("Locked"),
+                       FSTR("Not enough core"),
+                       FSTR("Too many open files"),
+                       FSTR("Invalid parameter")
                };
 
 static const FLASH char * const FLASH rc_names[] = {
                };
 
 static const FLASH char * const FLASH rc_names[] = {
@@ -135,7 +135,7 @@ void put_rc (FRESULT rc)
 }
 
 
 }
 
 
-const FLASH char * rctostr(FRESULT rc)
+const FLASH char * fat_rctostr(FRESULT rc)
 {
        return  rc < ARRAY_SIZE(rc_strings) ? rc_strings[rc] : PSTR(" Unknown Error");
 }
 {
        return  rc < ARRAY_SIZE(rc_strings) ? rc_strings[rc] : PSTR(" Unknown Error");
 }
@@ -198,13 +198,13 @@ static void strip_trailing_slash(PATH_T *p)
 static PATH_T *path_setup(char *string)
 {
        if (strlen(string) > PATH_MAX) {
 static PATH_T *path_setup(char *string)
 {
        if (strlen(string) > PATH_MAX) {
-               cmd_error(PSTR("'%s': name too long"), string);
+               cmd_error(0, 0, PSTR("'%s': Name too long"), string);
                return NULL;
        }
 
        PATH_T *p = (PATH_T *) malloc(sizeof *p);
        if (p == NULL) {
                return NULL;
        }
 
        PATH_T *p = (PATH_T *) malloc(sizeof *p);
        if (p == NULL) {
-               cmd_error(PSTR("'%s': Out of Memory"), string);
+               cmd_error(0, 0, PSTR("'%s': Out of Memory"), string);
                return NULL;
        }
 
                return NULL;
        }
 
@@ -216,7 +216,7 @@ static PATH_T *path_setup(char *string)
                        p->p_path[2] = '/';
                        len += 1;
                } else {
                        p->p_path[2] = '/';
                        len += 1;
                } else {
-                       cmd_error(PSTR("'%s': Out of Memory"), string);
+                       cmd_error(0, 0, PSTR("'%s': Out of Memory"), string);
                        return NULL;
                }
        }
                        return NULL;
                }
        }
@@ -255,8 +255,9 @@ command_ret_t do_pwd(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc
        }
        free(buf);
        if (res != FR_OK) {
        }
        free(buf);
        if (res != FR_OK) {
-               put_rc(res);
-               return CMD_RET_FAILURE;
+               cmd_error(CMD_RET_FAILURE, res, NULL);
+               //put_rc(res);
+               //return CMD_RET_FAILURE;
        }
        return CMD_RET_SUCCESS;
 }
        }
        return CMD_RET_SUCCESS;
 }
index b0d9c90219010a18d161fb52b045d9f14481715e..ff3a685831a51bf31da2b11ec63d4f22745d89b2 100644 (file)
@@ -22,6 +22,7 @@
 #include "env.h"
 #include "debug.h"
 #include "getopt-min.h"
 #include "env.h"
 #include "debug.h"
 #include "getopt-min.h"
+#include "strerror.h"
 
 #define DEBUG_CMD      0       /* set to 1 to debug */
 
 
 #define DEBUG_CMD      0       /* set to 1 to debug */
 
@@ -791,16 +792,24 @@ int cmd_process_error(cmd_tbl_t *cmdtp, int err)
        return 0;
 }
 
        return 0;
 }
 
-
-void cmd_error(const char *fmt, ...)
+void cmd_error(int status, int errnum, const char *fmt, ...)
 {
        va_list ap;
        va_start(ap, fmt);
        print_prefixed_name(cmd_invocation_ptr);
 {
        va_list ap;
        va_start(ap, fmt);
        print_prefixed_name(cmd_invocation_ptr);
-       my_puts_P(PSTR(": "));
-       vfprintf_P(stdout, fmt, ap);
+       if (fmt != NULL) {
+               my_puts_P(PSTR(": "));
+               vfprintf_P(stdout, fmt, ap);
+       }
        va_end(ap);
        va_end(ap);
+
+       if (errnum != 0)
+               printf_P(PSTR(": %S"), my_strerror_P(errnum));
+
        putchar('\n');
        _delay_ms(20);
        putchar('\n');
        _delay_ms(20);
-       //command_ret = CMD_RET_FAILURE;
+
+       if (status != 0) {
+               longjmp(cmd_jbuf, 1);
+       }
 }
 }
diff --git a/avr/strerror.c b/avr/strerror.c
new file mode 100644 (file)
index 0000000..d80a3bc
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * (C) Copyright 2018 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier:    GPL-2.0
+ */
+
+#include "common.h"
+#include "cmd_fat.h"
+
+static const FLASH char * const FLASH error_strings[] = {
+       FSTR("Unknown error")
+};
+
+const FLASH char * my_strerror_P(int errnum)
+{
+       if (errnum < 100)
+               return fat_rctostr(errnum);
+
+       errnum -= 100;
+       if (errnum < 0)
+               errnum = 0;
+       if ((unsigned) errnum >= ARRAY_SIZE(error_strings))
+               errnum = 0;
+
+       return  error_strings[errnum];
+}
index ed96a524d143d8a1f0262ae8f3dc8616e889a3b6..222b14c21dea5bfdb7a10087ffeea9f0017f78d0 100644 (file)
@@ -8,9 +8,11 @@
 #define CMD_FAT_H
 
 #include "command.h"
 #define CMD_FAT_H
 
 #include "command.h"
+#include "ff.h"
 
 extern cmd_tbl_t cmd_tbl_fat[];
 
 
 extern cmd_tbl_t cmd_tbl_fat[];
 
+const FLASH char * fat_rctostr(FRESULT rc);
 command_ret_t do_fat(cmd_tbl_t *, uint_fast8_t, int, char * const []);
 
 void setup_fatfs(void);
 command_ret_t do_fat(cmd_tbl_t *, uint_fast8_t, int, char * const []);
 
 void setup_fatfs(void);
index d5eeb36b2f9230c9281562f00e4d9bb77a817066..6109f9f97b969d4a7018ae4e26d1c59a8b4d9f48 100644 (file)
@@ -102,7 +102,7 @@ int cmd_process_error(cmd_tbl_t *cmdtp, int err);
  *
  * @fmt:
  */
  *
  * @fmt:
  */
-void cmd_error(const char *fmt, ...);
+void cmd_error(int status, int errnum, const char *fmt, ...);
 
 /*
  * Monitor Command
 
 /*
  * Monitor Command
diff --git a/include/strerror.h b/include/strerror.h
new file mode 100644 (file)
index 0000000..9cc0821
--- /dev/null
@@ -0,0 +1,12 @@
+/*
+ * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier:    GPL-2.0
+ */
+
+#ifndef STRERROR_H
+#define STRERROR_H
+
+const FLASH char * my_strerror_P(int errnum);
+
+#endif /* STRERROR_H */