2016-08-11 12:06:45 +00:00
|
|
|
/*
|
|
|
|
* shell_commands.c
|
|
|
|
*
|
|
|
|
* Created on: Aug 10, 2016
|
|
|
|
* Author: tkl
|
|
|
|
*/
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
2016-08-30 06:41:02 +00:00
|
|
|
#include <string.h>
|
2016-08-28 09:22:00 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
2016-08-11 12:06:45 +00:00
|
|
|
|
|
|
|
#include "list.h"
|
|
|
|
#include "driver.h"
|
|
|
|
#include "shell.h"
|
2016-08-28 09:22:00 +00:00
|
|
|
#include "queue.h"
|
|
|
|
#include "stack.h"
|
|
|
|
#include "kernel.h"
|
2016-08-11 12:06:45 +00:00
|
|
|
#include "drive_ctrl.h"
|
2016-08-21 11:45:36 +00:00
|
|
|
#include "version.h"
|
2016-08-11 12:06:45 +00:00
|
|
|
|
|
|
|
static void *drive_turn_right_cb(const char *param);
|
|
|
|
static void *drive_turn_left_cb(const char *param);
|
|
|
|
static void *drive_boost_cb(const char *param);
|
|
|
|
static void *drive_retard_cb(const char *param);
|
|
|
|
static void *drive_halt_cb(const char *param);
|
|
|
|
static void *drive_forward_cb(const char *param);
|
|
|
|
static void *drive_backward_cb(const char *param);
|
2016-08-21 11:45:36 +00:00
|
|
|
static void *app_version(const char *param);
|
|
|
|
|
2016-08-21 11:47:57 +00:00
|
|
|
static struct command cmd_app_version = {
|
2016-08-21 11:45:36 +00:00
|
|
|
.command = "version",
|
|
|
|
.description = "Get application version.",
|
|
|
|
.command_callback = app_version,
|
|
|
|
};
|
2016-08-11 12:06:45 +00:00
|
|
|
|
|
|
|
static struct command drive_forward = {
|
|
|
|
.command = "f",
|
|
|
|
.description = "Start driving forward with preset speed.",
|
|
|
|
.command_callback = drive_forward_cb,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct command drive_backward = {
|
|
|
|
.command = "b",
|
|
|
|
.description = "Start driving backward with preset speed.",
|
|
|
|
.command_callback = drive_backward_cb,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct command drive_halt = {
|
|
|
|
.command = "h",
|
|
|
|
.description = "Stop driving.",
|
|
|
|
.command_callback = drive_halt_cb,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct command drive_boost = {
|
|
|
|
.command = "+",
|
|
|
|
.description = "Boost speed.",
|
|
|
|
.command_callback = drive_boost_cb,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct command drive_retard = {
|
|
|
|
.command = "-",
|
|
|
|
.description = "Retard speed",
|
|
|
|
.command_callback = drive_retard_cb,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct command drive_turn_left = {
|
|
|
|
.command = "l",
|
|
|
|
.description = "Turn left.",
|
|
|
|
.command_callback = drive_turn_left_cb,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct command drive_turn_right = {
|
|
|
|
.command = "r",
|
|
|
|
.description = "Turn right",
|
|
|
|
.command_callback = drive_turn_right_cb,
|
|
|
|
};
|
|
|
|
|
|
|
|
int shell_commands_init(void)
|
|
|
|
{
|
2016-08-30 06:41:02 +00:00
|
|
|
shell_add_command(&cmd_app_version);
|
2016-08-11 12:06:45 +00:00
|
|
|
shell_add_command(&drive_forward);
|
|
|
|
shell_add_command(&drive_backward);
|
|
|
|
shell_add_command(&drive_boost);
|
|
|
|
shell_add_command(&drive_retard);
|
|
|
|
shell_add_command(&drive_halt);
|
|
|
|
shell_add_command(&drive_turn_left);
|
|
|
|
shell_add_command(&drive_turn_right);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *drive_turn_right_cb(const char *param)
|
|
|
|
{
|
2016-08-30 08:07:47 +00:00
|
|
|
drive_ctrl_turn_right();
|
2016-08-11 12:06:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *drive_turn_left_cb(const char *param)
|
|
|
|
{
|
2016-08-30 08:07:47 +00:00
|
|
|
drive_ctrl_turn_left();
|
2016-08-11 12:06:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *drive_boost_cb(const char *param)
|
|
|
|
{
|
2016-08-30 08:07:47 +00:00
|
|
|
drive_ctrl_boost();
|
2016-08-11 12:06:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *drive_retard_cb(const char *param)
|
|
|
|
{
|
2016-08-30 08:07:47 +00:00
|
|
|
drive_ctrl_retard();
|
2016-08-11 12:06:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *drive_halt_cb(const char *param)
|
|
|
|
{
|
2016-08-30 08:07:47 +00:00
|
|
|
drive_ctrl_halt();
|
2016-08-11 12:06:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *drive_forward_cb(const char *param)
|
|
|
|
{
|
2016-08-30 08:07:47 +00:00
|
|
|
drive_ctrl_forward();
|
2016-08-11 12:06:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *drive_backward_cb(const char *param)
|
|
|
|
{
|
2016-08-30 08:07:47 +00:00
|
|
|
drive_ctrl_backward();
|
2016-08-11 12:06:45 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2016-08-21 11:45:36 +00:00
|
|
|
|
|
|
|
static void *app_version(const char *param)
|
|
|
|
{
|
|
|
|
char *greeter = "engine_control version: ";
|
|
|
|
|
2016-08-30 06:41:02 +00:00
|
|
|
shell_write(greeter, strlen(greeter));
|
|
|
|
shell_write(MAJOR_VERSION, strlen(MAJOR_VERSION));
|
|
|
|
shell_write(".", 1);
|
|
|
|
shell_write(MINOR_VERSION, strlen(MINOR_VERSION));
|
|
|
|
shell_write(".", 1);
|
|
|
|
shell_write(BUILD_NUMBER, strlen(BUILD_NUMBER));
|
|
|
|
shell_write("\r\n", 2);
|
|
|
|
|
2016-08-21 11:45:36 +00:00
|
|
|
return NULL;
|
|
|
|
}
|