Skip to content

Commit

Permalink
Real time terminal enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldegrasse committed Aug 14, 2020
1 parent 9c3ff41 commit 19694d0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
42 changes: 42 additions & 0 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static int sdwrite(CLIContext *ctx, char **argv, int argc);
static int logfile_size(CLIContext *ctx, char **argv, int argc);
static int connect_log(CLIContext *ctx, char **argv, int argc);
static int disconnect_log(CLIContext *ctx, char **argv, int argc);
static int realtime_terminal(CLIContext *ctx, char **argv, int argc);

/**
* Declaration of commands. Syntax is as follows:
Expand All @@ -66,6 +67,8 @@ const CmdEntry COMMANDS[] = {
{"connect_log", connect_log, "Connects to the UART console being logged"},
{"disconnect_log", disconnect_log,
"Disconnects from the UART console being logged"},
{"rtt", realtime_terminal,
"Opens a 2 way connection to the UART console being logged"},
// Add more entries here.
{NULL, NULL, NULL}};

Expand Down Expand Up @@ -293,4 +296,43 @@ static int disconnect_log(CLIContext *ctx, char **argv, int argc) {
} else {
return 0;
}
}

/**
* Opens a real time terminal to the UART console being logged. This function
* will write data to the UART device being logged from, and request that
* the logger task print all data it reads to the CLI, creating a two way
* connection. Will run this until user enters escape sequence.
* @param ctx: CLI context to print to
* @param argv list of arguments
* @param argc argument count
* @return 0 on success, or another value on failure
*/
static int realtime_terminal(CLIContext *ctx, char **argv, int argc) {
char input;
// First, enable log forwarding.
if (enable_log_forwarding(ctx) != 0) {
cli_printf(ctx, "Could not start terminal, another console is using "
"log forwarding\r\n");
return 255;
}
/*
* Now, enter a loop. Until the user enters the escape sequence CTRL+E,
* read all the data they type and write it to the UART device being logged.
*/
cli_printf(ctx, "Starting real time terminal, press CTRL+E to exit\r\n");
while (1) {
ctx->cli_read(&input, 1);
if (input == 5) { // Corresponds to CTRL+E
break;
}
write_to_logger(&input, 1);
}
// Now that escape sequence was read, disable forwarding and return.
if (disable_log_forwarding() != 0) {
cli_printf(ctx, "Error, could not disable log forwarding. This should "
"not occur\r\n");
return 255;
}
return 0;
}
10 changes: 10 additions & 0 deletions uart_logger_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,14 @@ int disable_log_forwarding(void) {
// Now, drop the log variable mutex
pthread_mutex_unlock(&LOG_VAR_MUTEX);
return 0;
}

/**
* Writes to the UART device being logged from.
* @param data: buffer of data to write
* @param len: length of data to write
* @return number of bytes written.
*/
int write_to_logger(char* data, int len) {
return UART_write(uart, data, len);
}
8 changes: 8 additions & 0 deletions uart_logger_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@ int enable_log_forwarding(CLIContext *context);
*/
int disable_log_forwarding(void);

/**
* Writes to the UART device being logged from.
* @param data: buffer of data to write
* @param len: length of data to write
* @return number of bytes written.
*/
int write_to_logger(char* data, int len);

#endif

0 comments on commit 19694d0

Please sign in to comment.