From 2cddde4b505e4e50c5ad2493e6b37a4345fa5a66 Mon Sep 17 00:00:00 2001 From: microbuilder Date: Thu, 15 Dec 2016 18:11:45 +0100 Subject: [PATCH] Moved commands into separate file --- tools/bootutil/commands.c | 67 +++++++++++++++++++++++++++++++++++++++ tools/bootutil/commands.h | 7 ++++ 2 files changed, 74 insertions(+) create mode 100644 tools/bootutil/commands.c create mode 100644 tools/bootutil/commands.h diff --git a/tools/bootutil/commands.c b/tools/bootutil/commands.c new file mode 100644 index 00000000..f522aba7 --- /dev/null +++ b/tools/bootutil/commands.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include "commands.h" +#include "serialport.h" +#include "infohelper.h" + +/* +static int +commands_stol(char *param_val, long min, long max, long *output, uint8_t b) +{ + char *endptr; + long lval; + + if ((b != 10) && (b != 16)) { + return EINVAL; + } + + lval = strtol(param_val, &endptr, b); + if (param_val != '\0' && *endptr == '\0' && + lval >= min && lval <= max) { + *output = lval; + } else { + return EINVAL; + } + + return 0; +} +*/ + +static int +commands_err_unknown_arg(char *arg_name) +{ + LOGERR("unknown argument \"%s\"\n", + arg_name); + return EINVAL; +} + +int +commands_cmd_reset(void) +{ + LOGINFO("attempting to reset (toggling DTR)\n"); + + /* Toggle the DTR line to provoke a reset */ + serialport_set_dtr(1); + serialport_set_dtr(0); + + return 0; +} + +int +commands_parse(char *argv) +{ + int i = 0; + + while(argv[i]) { + argv[i] = tolower(argv[i]); + i++; + } + + if (strcmp(argv, "reset") == 0) { + return commands_cmd_reset(); + } else { + return commands_err_unknown_arg(argv); + } +} diff --git a/tools/bootutil/commands.h b/tools/bootutil/commands.h new file mode 100644 index 00000000..4e1f4018 --- /dev/null +++ b/tools/bootutil/commands.h @@ -0,0 +1,7 @@ +#ifndef __COMMANDS_H__ +#define __COMMANDS_H__ + +int commands_cmd_reset(void); +int commands_parse(char *argv); + +#endif