Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI for Controller Board via UART Rx #278

Merged
merged 15 commits into from
May 27, 2024
Merged

CLI for Controller Board via UART Rx #278

merged 15 commits into from
May 27, 2024

Conversation

et312
Copy link
Contributor

@et312 et312 commented May 14, 2024

No description provided.

@et312 et312 requested a review from mitchellostler May 14, 2024 20:36
@et312 et312 marked this pull request as draft May 15, 2024 14:36
@et312 et312 marked this pull request as ready for review May 15, 2024 17:43
"MSXV Controller Board CLI. Usage: \n\r"
"<peripheral> <action> <parameters> \n\r\n"
"Enter \"help\" after any argument for detailed reference. \n\r\n"
"List of Peripherals: gpio \n\r";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should iterate over the cmd_lookup table to print out available peripherals, so we don't have to update this each time. this could be done in a print_help function

#include "cli_base.h"

void gpio_cmd(char *input);
void prv_set(char *args);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prv functions should not be declared in the header, they should be declared static in the c file. That's what makes them private, is that they can't be used outside of the module

@@ -78,6 +78,7 @@ StatusCode uart_init(UartPort uart, UartSettings *settings) {
// Init with disabled TX interrupts otherwise we will get TX
// buffer empty continuously when there is no data to send
USART_ITConfig(s_port[uart].base, USART_IT_TXE, DISABLE);
USART_ITConfig(s_port[uart].base, USART_IT_RXNE, ENABLE);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was breaking logs before. I would check that log_debug still works for other projects

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which specific project breaks from this line? I tried scons sim on leds and the log_debug statements display blink correctly.

@@ -0,0 +1,11 @@
#ifndef PROJECTS_UART_CLI_INC_CLI_H_
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use #pragma once instead of ifndef

@@ -0,0 +1,13 @@
#ifndef PROJECTS_UART_CLI_INC_CLI_BASE_H_
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#pragma once

static const CmdStruct cmd_lookup[] = { { .cmd_name = "gpio", .cmd_func = &gpio_cmd },
{ .cmd_name = "GPIO", .cmd_func = &gpio_cmd } };

TASK(cli_task, TASK_STACK_512) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add this and main function to a separate main.c file


void cli_init() {
gpio_init();
setbuf(stdout, NULL);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do on arm?

cmd_buffer[idx % MAX_CMD_LEN] = data;
++idx;
printf("%c", data);
if (idx == MAX_CMD_LEN) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this occurs, you should probably just stop accepting new characters instead of printing a warning. You can add this to the top, where you check against idx, and if they enter more characters, just don't echo anything or put them in the buffer, unless you get a newline.


void cmd_parse(char *cmd) {
char peripheral[MAX_CMD_LEN + 1] = { 0 };
strip_ws(cmd);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just add the strip_ws call to inside tok_cmd, since you'll need it for all instances of calling tok_cmd

strip_ws(cmd);
tok_cmd(cmd, peripheral);

if (strcmp(peripheral, "help") == 0 || strcmp(peripheral, "h") == 0 ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should just make the cmd automatically lower case here. This will cover any mixed-case or upper case scenarios, and will mean that you only need to add one check for each peripheral

printf("\r%s\n", cli_help);
}

void print_help() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this function used anywhere?


int valid_pin_mode(char *pin_mode) {
const char *pin_modes[NUM_GPIO_MODES] = {
"analog", "input_floating", "input_pull_down", "input_pull_up", "output_open_drain",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: fix spacing between these strings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scons format gives this spacing - the build fails if I change it

strip_ws(cmd_in);
strncpy(tmp, cmd_in, sizeof(tmp) - 1);
char *tmp_tok;
tmp_tok = strtok(tmp, delim); // NOLINT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the comment for no lint?

@mitchellostler mitchellostler merged commit e94622f into main May 27, 2024
1 check passed
@mitchellostler mitchellostler deleted the uart_rx_cli branch May 27, 2024 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants