sysparam editor: add echo-on and echo-off commands. (#199)

Helpful to be able to disable echo when sending commands fast, so that
the editor can consume them fast than they arrive. This adds 'echo-on'
and 'echo-off' commands to set the echo state.
This commit is contained in:
Our Air Quality 2016-08-26 07:11:59 +10:00 committed by Johan Kanflo
parent 46840baed4
commit fb33995bc4

View file

@ -6,6 +6,8 @@
#include <sysparam.h> #include <sysparam.h>
#include <espressif/spi_flash.h> #include <espressif/spi_flash.h>
#include "espressif/esp_common.h"
#include "esp/uart.h"
#define CMD_BUF_SIZE 5000 #define CMD_BUF_SIZE 5000
@ -30,6 +32,8 @@ void usage(void) {
" <key>:<hexdata> -- Set <key> to binary value represented as hex\n" " <key>:<hexdata> -- Set <key> to binary value represented as hex\n"
" dump -- Show all currently set keys/values\n" " dump -- Show all currently set keys/values\n"
" reformat -- Reinitialize (clear) the sysparam area\n" " reformat -- Reinitialize (clear) the sysparam area\n"
" echo-off -- Disable input echo\n"
" echo-on -- Enable input echo\n"
" help -- Show this help screen\n" " help -- Show this help screen\n"
); );
} }
@ -150,6 +154,7 @@ void sysparam_editor_task(void *pvParameters) {
size_t len; size_t len;
uint8_t *data; uint8_t *data;
uint32_t base_addr, num_sectors; uint32_t base_addr, num_sectors;
bool echo = true;
if (!cmd_buffer) { if (!cmd_buffer) {
printf("ERROR: Cannot allocate command buffer!\n"); printf("ERROR: Cannot allocate command buffer!\n");
@ -171,7 +176,7 @@ void sysparam_editor_task(void *pvParameters) {
} }
while (true) { while (true) {
printf("==> "); printf("==> ");
len = tty_readline(cmd_buffer, CMD_BUF_SIZE, true); len = tty_readline(cmd_buffer, CMD_BUF_SIZE, echo);
status = 0; status = 0;
if (!len) continue; if (!len) continue;
if (cmd_buffer[len - 1] == '?') { if (cmd_buffer[len - 1] == '?') {
@ -214,6 +219,12 @@ void sysparam_editor_task(void *pvParameters) {
// using. // using.
status = sysparam_init(base_addr, 0); status = sysparam_init(base_addr, 0);
} }
} else if (!strcmp(cmd_buffer, "echo-on")) {
echo = true;
printf("Echo on\n");
} else if (!strcmp(cmd_buffer, "echo-off")) {
echo = false;
printf("Echo off\n");
} else if (!strcmp(cmd_buffer, "help")) { } else if (!strcmp(cmd_buffer, "help")) {
usage(); usage();
} else { } else {
@ -229,5 +240,7 @@ void sysparam_editor_task(void *pvParameters) {
void user_init(void) void user_init(void)
{ {
uart_set_baud(0, 115200);
xTaskCreate(sysparam_editor_task, (signed char *)"sysparam_editor_task", 512, NULL, 2, NULL); xTaskCreate(sysparam_editor_task, (signed char *)"sysparam_editor_task", 512, NULL, 2, NULL);
} }