further development, lay a framework for errors/responses

This commit is contained in:
Alex Hirzel 2018-04-05 23:01:27 -04:00
parent 478826390a
commit 3554a5b594
2 changed files with 48 additions and 1 deletions

View file

@ -380,8 +380,10 @@ top:
#undef STATE
// local variable that holds the status
struct serial_terminal_status cc;
void uart_repl_task(void *pvParameters) {
struct serial_terminal_status cc;
memset(&cc, 0, sizeof(cc));
cc.lineCb = pvParameters;
MainStateMachine(&cc);
@ -393,3 +395,42 @@ void uart_repl_init(uart_repl_handler line_cb) {
xTaskCreate(uart_repl_task, "uart_repl", 256, (void *)line_cb, 10, NULL);
}
void error(const char* format, ...) {
va_list argptr;
va_start(argptr, format);
// TODO preempt the console stuff
taskENTER_CRITICAL();
printf("\x1b[1;31mERROR:\x1b[1m ");
vprintf(format, argptr);
printf("\x1b[0m");
fflush(stdout);
taskEXIT_CRITICAL();
va_end(argptr);
}
// TODO some day replace this with a callback or something, so that it is not
// named statically
void response(const char* format, ...) {
va_list argptr;
va_start(argptr, format);
// TODO preempt the console stuff
vprintf(format, argptr);
fflush(stdout);
va_end(argptr);
// TODO track if the last character was a newline; if not, make sure
// prompt() handles it by adding a newline
}
void debug(const char* format, ...) {
va_list argptr;
va_start(argptr, format);
// TODO preempt the console stuff
vprintf(format, argptr);
fflush(stdout);
va_end(argptr);
}

View file

@ -1,6 +1,7 @@
#ifndef _SWC_UART_REPL_
#define _SWC_UART_REPL_
#include <stddef.h> /* size_t */
#include <stdarg.h> /* varargs */
#if 0
@ -16,6 +17,11 @@ enum uart_repl_special_key {
typedef void (*uart_repl_handler)(char const *);
/* various helpers to allow us to gracefully show output */
void error(const char *, ...);
void debug(const char *, ...);
void response(const char *, ...);
struct serial_terminal_status {
char line[80];
unsigned int lineCursorPosition; // this is the index of the next character to be written