engine_control/source/application/shell_commands.c

107 lines
2.3 KiB
C
Raw Permalink Normal View History

2016-08-11 12:06:45 +00:00
/*
* shell_commands.c
*
* Created on: Aug 10, 2016
* Author: tkl
*/
#include <stddef.h>
#include <stdlib.h>
#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-21 11:45:36 +00:00
#include "version.h"
2016-08-30 11:37:40 +00:00
#include "sensor_data.h"
2016-09-20 07:06:12 +00:00
#include "system_state.h"
2016-08-11 12:06:45 +00:00
static void *drive_halt_cb(const char *param);
static void *drive_forward_cb(const char *param);
2016-08-21 11:45:36 +00:00
static void *app_version(const char *param);
2016-08-30 11:37:40 +00:00
static void *sys_msg_on_cb(const char *param);
static void *sys_msg_off_cb(const char *param);
static struct command cmd_sys_msg_on = {
.command = "sys on",
.description = "Switch system message on.",
.command_callback = sys_msg_on_cb,
};
static struct command cmd_sys_msg_off = {
.command = "sys off",
.description = "Switch system message off.",
.command_callback = sys_msg_off_cb,
};
2016-08-21 11:45:36 +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 = {
2016-09-20 07:06:12 +00:00
.command = "d",
.description = "Start driving .",
2016-08-11 12:06:45 +00:00
.command_callback = drive_forward_cb,
};
static struct command drive_halt = {
.command = "h",
.description = "Stop driving.",
.command_callback = drive_halt_cb,
};
int shell_commands_init(void)
{
shell_add_command(&cmd_app_version);
2016-08-11 12:06:45 +00:00
shell_add_command(&drive_forward);
shell_add_command(&drive_halt);
2016-08-30 11:37:40 +00:00
shell_add_command(&cmd_sys_msg_off);
shell_add_command(&cmd_sys_msg_on);
2016-08-11 12:06:45 +00:00
return 0;
}
static void *drive_halt_cb(const char *param)
{
2016-09-20 07:06:12 +00:00
system_state_force(SYS_IDLE);
2016-08-11 12:06:45 +00:00
return NULL;
}
static void *drive_forward_cb(const char *param)
{
2016-09-20 07:06:12 +00:00
system_state_force(SYS_DRIVING);
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: ";
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;
}
2016-08-30 11:37:40 +00:00
static void *sys_msg_on_cb(const char *param)
{
sensor_data_sys_msg(true);
return NULL;
}
static void *sys_msg_off_cb(const char *param)
{
sensor_data_sys_msg(false);
return NULL;
}