Moved commands into separate file
This commit is contained in:
1 parent
099533a4e2
commit
2cddde4b50
2 files changed
+74
No files matched your search
@@ -0,0 +1,67 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef __COMMANDS_H__
|
||||
#define __COMMANDS_H__
|
||||
|
||||
int commands_cmd_reset(void);
|
||||
int commands_parse(char *argv);
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user