Compare commits
13 Commits
589f56ecbd
...
experiment
| Author | SHA1 | Date | |
|---|---|---|---|
|
b4623992ef
|
|||
|
b8553067d1
|
|||
|
c0b4a014f5
|
|||
|
fffbf6e8db
|
|||
|
d627da2999
|
|||
|
1ec27e9ee3
|
|||
|
6bc074a033
|
|||
|
87b6fecfd0
|
|||
|
3a745af9bf
|
|||
|
2a4de4fe34
|
|||
|
86f0a3bedc
|
|||
|
a37213b128
|
|||
|
992b9f3063
|
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
project(WSAA_tests LANGUAGES CXX C)
|
project(WSAA_tests LANGUAGES CXX C)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# TCP CMD Interface
|
# TCP CMD Interface
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
The tcp cmd interface is a way to control the device over TCP. It is a simple protocol that allows the user to send commands to the device and receive responses. The protocol looks like bash commands. The commands are separated by a new line character (`\n`). The response is sent after the command is executed. The response is also terminated by a new line character (`\n`). The response can be a simple string or a JSON object.
|
The tcp cmd interface is a way to control the device over TCP. It is a simple protocol that allows the user to send commands to the device and receive responses. The protocol looks like bash commands. The commands are separated by a new line character (`\n`). The response is sent after the command is executed. The response is also terminated by a new line character (`\n`).
|
||||||
|
|
||||||
## Table of contents
|
## Table of contents
|
||||||
|
|
||||||
@@ -38,8 +38,8 @@ The `help` command will print a list of available commands.
|
|||||||
$> help
|
$> help
|
||||||
help : shows a list of commands
|
help : shows a list of commands
|
||||||
text "<text>" : puts text on the lcd
|
text "<text>" : puts text on the lcd
|
||||||
color <r> <g> <b> : set the background color of the lcd
|
color (<a>) <r> <g> <b> : set the background color of the lcd
|
||||||
textColor <r> <g> <b> : set the color of the text
|
textColor (<a>) <r> <g> <b> : set the color of the text
|
||||||
listImages : shows a list with images in the filesystem
|
listImages : shows a list with images in the filesystem
|
||||||
setImage <image_name> : put an image on the screen
|
setImage <image_name> : put an image on the screen
|
||||||
setGif <image_name> : put a gif on the screen
|
setGif <image_name> : put a gif on the screen
|
||||||
@@ -53,7 +53,7 @@ $> text "Hello World!"
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### `bgcolor`
|
#### `bgcolor`
|
||||||
The `bgcolor` command will set the background color of the screen. The color can be provided in 2 ways: as three numbers between 0 and 255 and one hex value. The first number is the red value, the second is the green value and the third is the blue value.
|
The `bgcolor` command will set the background color of the screen. The color can be provided in 2 ways: as three numbers between 0 and 255 and one hex value. The first number is the red value, the second is the green value and the third is the blue value. It also has the possible to set the alpha value as the first parameter, this is optional.
|
||||||
```bash
|
```bash
|
||||||
bgcolor 255 0 0
|
bgcolor 255 0 0
|
||||||
```
|
```
|
||||||
@@ -63,7 +63,7 @@ bgcolor 0xFF0000
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### `color`
|
#### `color`
|
||||||
The `color` command will set the color of the text. The color can be provided in 2 ways: as three numbers between 0 and 255 and one hex value. The first number is the red value, the second is the green value and the third is the blue value.
|
The `color` command will set the color of the text. The color can be provided in 2 ways: as three numbers between 0 and 255 and one hex value. The first number is the red value, the second is the green value and the third is the blue value. It also has the possible to set the alpha value as the first parameter, this is optional.
|
||||||
```bash
|
```bash
|
||||||
color 255 0 0
|
color 255 0 0
|
||||||
```
|
```
|
||||||
@@ -84,13 +84,21 @@ $> listImages
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### `setImage`
|
#### `setImage`
|
||||||
The `setImage` command will put an image on the screen. The image must be present in the filesystem. If the image is not present in the filesystem, the device will send an error message. This function only works for BMP images, if you give any other file type, the device will send an error message.
|
The `setImage` command will put an image on the screen. The image must be present in the filesystem. If the image is not present in the filesystem, the device will send an error message. This function only works for BMP images, if you give any other file type, the device will send an error message. You can also provide the starting x and y coordinates as optional parameters. If no coordinates are provided, the image will be placed at the top left corner of the screen (0,0).
|
||||||
```bash
|
```bash
|
||||||
$> setImage image1.bmp
|
$> setImage image1.bmp
|
||||||
```
|
```
|
||||||
|
or
|
||||||
|
```bash
|
||||||
|
$> setImage image1.bmp 128 64
|
||||||
|
```
|
||||||
|
|
||||||
#### `setGif`
|
#### `setGif`
|
||||||
The `setGif` command will put a gif on the screen. The gif must be present in the filesystem. If the gif is not present in the filesystem, the device will send an error message. This function only works for GIF images, if you give any other file type, the device will send an error message.
|
The `setGif` command will put a gif on the screen. The gif must be present in the filesystem. If the gif is not present in the filesystem, the device will send an error message. This function only works for GIF images, if you give any other file type, the device will send an error message. You can also provide the starting x and y coordinates as optional parameters. If no coordinates are provided, the gif will be placed at the top left corner of the screen (0,0).
|
||||||
```bash
|
```bash
|
||||||
$> setGif gif1.gif
|
$> setGif gif1.gif
|
||||||
```
|
```
|
||||||
|
or
|
||||||
|
```bash
|
||||||
|
$> setGif gif1.gif 128 64
|
||||||
|
```
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#define MAX_TOKENS 10
|
#define MAX_TOKENS 10
|
||||||
#define MAX_CMD_LEN 50
|
#define MAX_CMD_LEN 50
|
||||||
|
|
||||||
#define LINUX
|
#define NCAT
|
||||||
|
|
||||||
static const char* TAG = "tcp_cmd";
|
static const char* TAG = "tcp_cmd";
|
||||||
static uint32_t color_txt = 0xffffffff; // Store text color
|
static uint32_t color_txt = 0xffffffff; // Store text color
|
||||||
@@ -25,239 +25,61 @@ static void tcp_cmd_list_files(struct tcp_pcb* pcb, int argc, char** argv);
|
|||||||
static void tcp_cmd_set_image(struct tcp_pcb* pcb, int argc, char** argv);
|
static void tcp_cmd_set_image(struct tcp_pcb* pcb, int argc, char** argv);
|
||||||
static void tcp_cmd_set_gif(struct tcp_pcb* pcb, int argc, char** argv);
|
static void tcp_cmd_set_gif(struct tcp_pcb* pcb, int argc, char** argv);
|
||||||
static void tcp_cmd_exit(struct tcp_pcb* pcb, int argc, char** argv);
|
static void tcp_cmd_exit(struct tcp_pcb* pcb, int argc, char** argv);
|
||||||
static void tcp_cmd_unknown_cmd(struct tcp_pcb* pcb, int argc, char** argv);
|
static void tcp_cmd_unknown_cmd(struct tcp_pcb* pcb, char* cmd);
|
||||||
static bool tcp_cmd_parser(struct tcp_pcb* pcb, int argc, char** argv);
|
static bool tcp_cmd_parser(struct tcp_pcb* pcb, int argc, char** argv);
|
||||||
static err_t tcp_cmd_accept(void* arg, struct tcp_pcb* pcb, err_t err);
|
static err_t tcp_cmd_accept(void* arg, struct tcp_pcb* pcb, err_t err);
|
||||||
static void tcp_cmd_close(struct tcp_pcb* pcb);
|
static void tcp_cmd_close(struct tcp_pcb* pcb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is a wrapper for tcp_write and tcp_output
|
* @brief This function shifts the arguments in argv and argc
|
||||||
* @param pcb The tcp_pcb struct to write to
|
* @param[in,out] argc The argc pointer
|
||||||
* @param str The string to write
|
* @param[in,out] argv The argv pointer
|
||||||
|
* @return The shifted argument
|
||||||
*/
|
*/
|
||||||
static void tcp_cmd_write(struct tcp_pcb* pcb, const char* str) {
|
static char* shift_args(int* argc, char*** argv) {
|
||||||
tcp_write(pcb, str, strlen(str), TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
if (*argc == 0) {
|
||||||
tcp_output(pcb);
|
return NULL;
|
||||||
|
}
|
||||||
|
char* arg = (*argv)[0];
|
||||||
|
(*argv)++;
|
||||||
|
(*argc)--;
|
||||||
|
return arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function prints the header of the tcp command interface
|
* @brief This function converts a string to a color
|
||||||
* @param pcb The tcp_pcb struct to write to
|
* @param[in] argc The number of arguments
|
||||||
|
* @param[in] argv The arguments
|
||||||
|
* @param[out] color The color to write to
|
||||||
|
* @return true The conversion failed
|
||||||
|
* @return false The conversion succeeded
|
||||||
*/
|
*/
|
||||||
static void tcp_cmd_print_header(struct tcp_pcb* pcb) {
|
static bool str_to_color(int argc, char** argv, uint32_t* color) {
|
||||||
tcp_cmd_write(pcb, " Welcome to the TCP CMD interface\n"
|
|
||||||
"(Type help for a list of the commands! exit to close)\n"
|
|
||||||
"============================================================\n"
|
|
||||||
"$>");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function prints the help text
|
|
||||||
* @param pcb The tcp_pcb struct to write to
|
|
||||||
*/
|
|
||||||
static void tcp_cmd_print_help(struct tcp_pcb* pcb) {
|
|
||||||
LOG_INFO(TAG, "Printing help");
|
|
||||||
tcp_cmd_write(pcb, "help : shows a list of commands\n"
|
|
||||||
"clear text/images : clears the text or images on the lcd\n"
|
|
||||||
"text \"<text>\" : puts text on the lcd\n"
|
|
||||||
"bgColor (<a>) <r> <g> <b> : set the background color of the lcd\n"
|
|
||||||
"color (<a>) <r> <g> <b> : set the color of the text\n"
|
|
||||||
"listFiles : shows a list with images in the filesystem\n"
|
|
||||||
"setImage <image_name> : put an image on the screen\n"
|
|
||||||
"setGif <image_name> : put a gif on the screen\n"
|
|
||||||
"exit : closes the connection\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tcp_cmd_clear(struct tcp_pcb* pcb, int argc, char** argv) {
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
LOG_INFO(TAG, "Clearing screen");
|
*color = (uint32_t)strtoul(argv[0], NULL, 16);
|
||||||
lcd_clear_text();
|
return false;
|
||||||
lcd_clear_images();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (argc == 2) {
|
if (argc == 3) {
|
||||||
if (strcmp(argv[1], "text") == 0) {
|
*color = 0xff000000;
|
||||||
LOG_INFO(TAG, "Clearing text");
|
*color |= (uint32_t)strtoul(argv[0], NULL, 10) << 16;
|
||||||
lcd_clear_text();
|
*color |= (uint32_t)strtoul(argv[1], NULL, 10) << 8;
|
||||||
return;
|
*color |= (uint32_t)strtoul(argv[2], NULL, 10);
|
||||||
}
|
return false;
|
||||||
if (strcmp(argv[1], "images") == 0) {
|
|
||||||
LOG_INFO(TAG, "Clearing images");
|
|
||||||
lcd_clear_images();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
LOG_WARN(TAG, "Bad usage of clear");
|
|
||||||
tcp_cmd_write(pcb, "Usage: clear\n");
|
|
||||||
tcp_cmd_write(pcb, "Usage: clear text\n");
|
|
||||||
tcp_cmd_write(pcb, "Usage: clear images\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tcp_cmd_text(struct tcp_pcb* pcb, int argc, char** argv) {
|
|
||||||
if (argc == 2) {
|
|
||||||
LOG_INFO(TAG, "Setting text %s @ 10, 10", argv[1]);
|
|
||||||
lcd_display_text((const char*)argv[1], 10, 10, color_txt, color_bg, LCD_FONT24);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (argc == 4) {
|
if (argc == 4) {
|
||||||
LOG_INFO(TAG, "Setting text %s @ %lu, %lu", argv[1], (uint32_t)strtoul(argv[2], NULL, 10), (uint32_t)strtoul(argv[3], NULL, 10));
|
*color = (uint32_t)strtoul(argv[0], NULL, 10) << 24;
|
||||||
lcd_display_text((const char*)argv[1], (uint32_t)strtoul(argv[2], NULL, 10), (uint32_t)strtoul(argv[3], NULL, 10), color_txt, color_bg, LCD_FONT24);
|
*color |= (uint32_t)strtoul(argv[1], NULL, 10) << 16;
|
||||||
return;
|
*color |= (uint32_t)strtoul(argv[2], NULL, 10) << 8;
|
||||||
}
|
*color |= (uint32_t)strtoul(argv[3], NULL, 10);
|
||||||
LOG_WARN(TAG, "Bad usage of text");
|
return false;
|
||||||
tcp_cmd_write(pcb, "Usage: text \"<text>\"\n");
|
|
||||||
tcp_cmd_write(pcb, "Usage: text <word>\n");
|
|
||||||
tcp_cmd_write(pcb, "Usage: text \"<text>\" <x> <y>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tcp_cmd_bg_color(struct tcp_pcb* pcb, int argc, char** argv) {
|
|
||||||
if (argc == 2) {
|
|
||||||
LOG_INFO(TAG, "Setting background color to %s", argv[1]);
|
|
||||||
color_bg = (uint32_t)strtoul(argv[1], NULL, 16);
|
|
||||||
color_bg ^= 0xff000000;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (argc == 4) {
|
|
||||||
LOG_INFO(TAG, "Setting background color to %s %s %s", argv[1], argv[2], argv[3]);
|
|
||||||
color_bg = 0xff000000;
|
|
||||||
color_bg |= (uint32_t)strtoul(argv[1], NULL, 10) << 16;
|
|
||||||
color_bg |= (uint32_t)strtoul(argv[2], NULL, 10) << 8;
|
|
||||||
color_bg |= (uint32_t)strtoul(argv[3], NULL, 10);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (argc == 5) {
|
|
||||||
LOG_INFO(TAG, "Setting background color to %s %s %s %s", argv[1], argv[2], argv[3], argv[4]);
|
|
||||||
color_txt = 0xff000000;
|
|
||||||
color_txt ^= (uint32_t)strtoul(argv[1], NULL, 10) << 24;
|
|
||||||
color_txt |= (uint32_t)strtoul(argv[2], NULL, 10) << 16;
|
|
||||||
color_txt |= (uint32_t)strtoul(argv[3], NULL, 10) << 8;
|
|
||||||
color_txt |= (uint32_t)strtoul(argv[4], NULL, 10);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
LOG_WARN(TAG, "Bad usage of bgcolor");
|
|
||||||
tcp_cmd_write(pcb, "Usage: bgcolor 0x<rrggbb>\n");
|
|
||||||
tcp_cmd_write(pcb, "Usage: bgcolor 0x<aarrggbb>\n");
|
|
||||||
tcp_cmd_write(pcb, "Usage: bgcolor <r> <g> <b>\n");
|
|
||||||
tcp_cmd_write(pcb, "Usage: bgcolor <a> <r> <g> <b>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tcp_cmd_color(struct tcp_pcb* pcb, int argc, char** argv) {
|
|
||||||
if (argc == 2) {
|
|
||||||
LOG_INFO(TAG, "Setting text color to %s", argv[1]);
|
|
||||||
color_txt = (uint32_t)strtoul(argv[1], NULL, 16);
|
|
||||||
color_txt ^= 0xff000000;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (argc == 4) {
|
|
||||||
LOG_INFO(TAG, "Setting text color to %s %s %s", argv[1], argv[2], argv[3]);
|
|
||||||
color_txt = 0xff000000;
|
|
||||||
color_txt |= (uint32_t)strtoul(argv[1], NULL, 10) << 16;
|
|
||||||
color_txt |= (uint32_t)strtoul(argv[2], NULL, 10) << 8;
|
|
||||||
color_txt |= (uint32_t)strtoul(argv[3], NULL, 10);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (argc == 5) {
|
|
||||||
LOG_INFO(TAG, "Setting text color to %s %s %s %s", argv[1], argv[2], argv[3], argv[4]);
|
|
||||||
color_txt = 0xff000000;
|
|
||||||
color_txt ^= (uint32_t)strtoul(argv[1], NULL, 10) << 24;
|
|
||||||
color_txt |= (uint32_t)strtoul(argv[2], NULL, 10) << 16;
|
|
||||||
color_txt |= (uint32_t)strtoul(argv[3], NULL, 10) << 8;
|
|
||||||
color_txt |= (uint32_t)strtoul(argv[4], NULL, 10);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
LOG_WARN(TAG, "Bad usage of color");
|
|
||||||
tcp_cmd_write(pcb, "Usage: color 0x<rrggbb>\n");
|
|
||||||
tcp_cmd_write(pcb, "Usage: color 0x<aarrggbb>\n");
|
|
||||||
tcp_cmd_write(pcb, "Usage: color <r> <g> <b>\n");
|
|
||||||
tcp_cmd_write(pcb, "Usage: color <a> <r> <g> <b>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tcp_cmd_list_files(struct tcp_pcb* pcb, int argc, char** argv) {
|
|
||||||
UNUSED(argc);
|
|
||||||
UNUSED(argv);
|
|
||||||
LOG_INFO(TAG, "Listing files");
|
|
||||||
void* mem = NULL; // Pointer for internal use by the llfs library
|
|
||||||
llfs_file_t* file;
|
|
||||||
while ((file = llfs_next_file(&mem, NULL)) != NULL) {
|
|
||||||
tcp_cmd_write(pcb, file->name);
|
|
||||||
tcp_cmd_write(pcb, "\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tcp_cmd_set_image(struct tcp_pcb* pcb, int argc, char** argv) {
|
|
||||||
char* ext = NULL;
|
|
||||||
if (argc >= 2) {
|
|
||||||
ext = llfs_get_filename_ext(argv[1]);
|
|
||||||
if (strcmp(ext, "bmp") != 0) {
|
|
||||||
LOG_WARN(TAG, "setimage: File is not a bmp");
|
|
||||||
tcp_cmd_write(pcb, "File is not a bmp\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (argc == 2) {
|
|
||||||
LOG_INFO(TAG, "Setting image %s @ 0, 0", argv[1]);
|
|
||||||
lcd_draw_img_from_fs(argv[1], 0, 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (argc == 4) {
|
|
||||||
LOG_INFO(TAG, "Setting image %s @ %lu, %lu", argv[1], (uint32_t)strtoul(argv[2], NULL, 10), (uint32_t)strtoul(argv[3], NULL, 10));
|
|
||||||
lcd_draw_img_from_fs(argv[1], (uint32_t)strtoul(argv[2], NULL, 10), (uint32_t)strtoul(argv[3], NULL, 10));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
LOG_WARN(TAG, "Bad usage of setimage");
|
|
||||||
tcp_cmd_write(pcb, "Usage: setimage <filename>\n");
|
|
||||||
tcp_cmd_write(pcb, "Usage: setimage <filename> <x> <y>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tcp_cmd_set_gif(struct tcp_pcb* pcb, int argc, char** argv) {
|
|
||||||
char* ext = NULL;
|
|
||||||
if (argc >= 2) {
|
|
||||||
ext = llfs_get_filename_ext(argv[1]);
|
|
||||||
if (strcmp(ext, "gif") != 0) {
|
|
||||||
LOG_WARN(TAG, "setgif: File is not a gif");
|
|
||||||
tcp_cmd_write(pcb, "File is not a gif\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (argc == 2) {
|
|
||||||
LOG_INFO(TAG, "Setting gif %s @ 0, 0", argv[1]);
|
|
||||||
lcd_draw_gif_from_fs(argv[1], 0, 0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (argc == 4) {
|
|
||||||
LOG_INFO(TAG, "Setting gif %s @ %lu, %lu", argv[1], (uint32_t)strtoul(argv[2], NULL, 10), (uint32_t)strtoul(argv[3], NULL, 10));
|
|
||||||
lcd_draw_gif_from_fs(argv[1], (uint32_t)strtoul(argv[2], NULL, 10), (uint32_t)strtoul(argv[3], NULL, 10));
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_WARN(TAG, "Bad usage of setgif");
|
return true;
|
||||||
tcp_cmd_write(pcb, "Usage: setgif <filename>\n");
|
|
||||||
tcp_cmd_write(pcb, "Usage: setgif <filename> <x> <y>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tcp_cmd_exit(struct tcp_pcb* pcb, int argc, char** argv) {
|
|
||||||
UNUSED(argc);
|
|
||||||
UNUSED(argv);
|
|
||||||
LOG_INFO(TAG, "Closing connection");
|
|
||||||
tcp_cmd_write(pcb, "Exiting...\n");
|
|
||||||
lcd_clear_images();
|
|
||||||
lcd_clear_text();
|
|
||||||
tcp_close(pcb);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void tcp_cmd_unknown_cmd(struct tcp_pcb* pcb, int argc, char** argv) {
|
|
||||||
UNUSED(argc);
|
|
||||||
LOG_WARN(TAG, "Unknown command: %s", argv[0]);
|
|
||||||
tcp_cmd_write(pcb, "Unknown command: ");
|
|
||||||
tcp_cmd_write(pcb, argv[0]);
|
|
||||||
tcp_cmd_write(pcb, "\n");
|
|
||||||
tcp_cmd_write(pcb, "Type help for list of commands\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function removes the newline from a string the string can contain multiple lines
|
* @brief This function removes the newline from a string the string can contain multiple lines
|
||||||
* @param str The string to remove the newline from
|
* @param[in,out] str The string to remove the newline from
|
||||||
*/
|
*/
|
||||||
void tcp_cmd_remove_newline(char* str, size_t len) {
|
void tcp_cmd_remove_newline(char* str, size_t len) {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
@@ -272,6 +94,12 @@ void tcp_cmd_remove_newline(char* str, size_t len) {
|
|||||||
str[i] = '\0';
|
str[i] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function 'removes' the leading spaces from a string
|
||||||
|
* @param[in] str The string to remove the leading spaces from
|
||||||
|
* @param[in] len The length of the string
|
||||||
|
* @return char* A pointer to the first non-space character
|
||||||
|
*/
|
||||||
char* tcp_cmd_remove_leading_space(char* str, size_t len) {
|
char* tcp_cmd_remove_leading_space(char* str, size_t len) {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
if (str == NULL || str[0] == '\0' || len == 0) {
|
if (str == NULL || str[0] == '\0' || len == 0) {
|
||||||
@@ -288,7 +116,7 @@ char* tcp_cmd_remove_leading_space(char* str, size_t len) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function converts a string to lowercase
|
* @brief This function converts a string to lowercase
|
||||||
* @param str The string to convert
|
* @param[in,out] str The string to convert
|
||||||
*/
|
*/
|
||||||
void tcp_cmd_str_tolower(char* str) {
|
void tcp_cmd_str_tolower(char* str) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -301,9 +129,9 @@ void tcp_cmd_str_tolower(char* str) {
|
|||||||
/**
|
/**
|
||||||
* @brief This function finds the next token in the input string
|
* @brief This function finds the next token in the input string
|
||||||
* If the token is between quotes, return the whole string between quotes
|
* If the token is between quotes, return the whole string between quotes
|
||||||
* @param input The input string
|
* @param[in] input The input string
|
||||||
* @param delimiter The delimiters to use
|
* @param[in] delimiter The delimiters to use
|
||||||
* @param next The next token
|
* @param[in,out] next The next token
|
||||||
* @return char* The next token
|
* @return char* The next token
|
||||||
*/
|
*/
|
||||||
char* tcp_cmd_get_next_token(char* input, const char* delimiters, char** next) {
|
char* tcp_cmd_get_next_token(char* input, const char* delimiters, char** next) {
|
||||||
@@ -342,12 +170,275 @@ char* tcp_cmd_get_next_token(char* input, const char* delimiters, char** next) {
|
|||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function is a wrapper for tcp_write and tcp_output
|
||||||
|
* @param[in] pcb The tcp_pcb struct to write to
|
||||||
|
* @param[in] str The string to write
|
||||||
|
*/
|
||||||
|
static void tcp_cmd_write(struct tcp_pcb* pcb, const char* str) {
|
||||||
|
tcp_write(pcb, str, strlen(str), TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||||
|
tcp_output(pcb);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function prints the header of the tcp command interface
|
||||||
|
* @param[in] pcb The tcp_pcb struct to write to
|
||||||
|
*/
|
||||||
|
static void tcp_cmd_print_header(struct tcp_pcb* pcb) {
|
||||||
|
tcp_cmd_write(pcb, " Welcome to the TCP CMD interface\n"
|
||||||
|
"(Type help for a list of the commands! exit to close)\n"
|
||||||
|
"============================================================\n"
|
||||||
|
"$>");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function prints the help text
|
||||||
|
* @param[in] pcb The tcp_pcb struct to write to
|
||||||
|
*/
|
||||||
|
static void tcp_cmd_print_help(struct tcp_pcb* pcb) {
|
||||||
|
LOG_INFO(TAG, "Printing help");
|
||||||
|
tcp_cmd_write(pcb, "help : shows a list of commands\n"
|
||||||
|
"clear text/images : clears the text or images on the lcd\n"
|
||||||
|
"text \"<text>\" : puts text on the lcd\n"
|
||||||
|
"bgColor (<a>) <r> <g> <b> : set the background color of the lcd\n"
|
||||||
|
"color (<a>) <r> <g> <b> : set the color of the text\n"
|
||||||
|
"listFiles : shows a list with images in the filesystem\n"
|
||||||
|
"setImage <image_name> : put an image on the screen\n"
|
||||||
|
"setGif <image_name> : put a gif on the screen\n"
|
||||||
|
"exit : closes the connection\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles the clear command
|
||||||
|
*
|
||||||
|
* @param[in] pcb The tcp_pcb struct to write to
|
||||||
|
* @param[in] argc The number of arguments
|
||||||
|
* @param[in] argv The arguments
|
||||||
|
*/
|
||||||
|
static void tcp_cmd_clear(struct tcp_pcb* pcb, int argc, char** argv) {
|
||||||
|
if (argc == 0) {
|
||||||
|
LOG_INFO(TAG, "Clearing screen");
|
||||||
|
lcd_clear_text();
|
||||||
|
lcd_clear_images();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (argc == 1) {
|
||||||
|
if (strcmp(argv[0], "text") == 0) {
|
||||||
|
LOG_INFO(TAG, "Clearing text");
|
||||||
|
lcd_clear_text();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (strcmp(argv[0], "images") == 0) {
|
||||||
|
LOG_INFO(TAG, "Clearing images");
|
||||||
|
lcd_clear_images();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOG_WARN(TAG, "Bad usage of clear");
|
||||||
|
tcp_cmd_write(pcb, "Usage: clear\n");
|
||||||
|
tcp_cmd_write(pcb, "Usage: clear text\n");
|
||||||
|
tcp_cmd_write(pcb, "Usage: clear images\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles the text command
|
||||||
|
*
|
||||||
|
* @param[in] pcb The tcp_pcb struct to write to
|
||||||
|
* @param[in] argc The number of arguments
|
||||||
|
* @param[in] argv The arguments
|
||||||
|
*/
|
||||||
|
static void tcp_cmd_text(struct tcp_pcb* pcb, int argc, char** argv) {
|
||||||
|
if (argc == 1) {
|
||||||
|
LOG_INFO(TAG, "Setting text %s @ 10, 10", argv[0]);
|
||||||
|
lcd_display_text((const char*)argv[0], 10, 10, color_txt, color_bg, LCD_FONT24);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (argc == 3) {
|
||||||
|
LOG_INFO(TAG, "Setting text %s @ %lu, %lu", argv[0], (uint32_t)strtoul(argv[1], NULL, 10),
|
||||||
|
(uint32_t)strtoul(argv[2], NULL, 10));
|
||||||
|
lcd_display_text((const char*)argv[0], (uint32_t)strtoul(argv[1], NULL, 10),
|
||||||
|
(uint32_t)strtoul(argv[2], NULL, 10), color_txt, color_bg, LCD_FONT24);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LOG_WARN(TAG, "Bad usage of text");
|
||||||
|
tcp_cmd_write(pcb, "Usage: text \"<text>\"\n");
|
||||||
|
tcp_cmd_write(pcb, "Usage: text <word>\n");
|
||||||
|
tcp_cmd_write(pcb, "Usage: text \"<text>\" <x> <y>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles the bgcolor command
|
||||||
|
*
|
||||||
|
* @param[in] pcb The tcp_pcb struct to write to
|
||||||
|
* @param[in] argc The number of arguments
|
||||||
|
* @param[in] argv The arguments
|
||||||
|
*/
|
||||||
|
static void tcp_cmd_bg_color(struct tcp_pcb* pcb, int argc, char** argv) {
|
||||||
|
if (!str_to_color(argc, argv, &color_bg)) {
|
||||||
|
LOG_INFO(TAG, "Setting background color to %08lX", color_bg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LOG_WARN(TAG, "Bad usage of bgcolor");
|
||||||
|
tcp_cmd_write(pcb, "Usage: bgcolor 0x<rrggbb>\n");
|
||||||
|
tcp_cmd_write(pcb, "Usage: bgcolor 0x<aarrggbb>\n");
|
||||||
|
tcp_cmd_write(pcb, "Usage: bgcolor <r> <g> <b>\n");
|
||||||
|
tcp_cmd_write(pcb, "Usage: bgcolor <a> <r> <g> <b>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles the color command
|
||||||
|
*
|
||||||
|
* @param[in] pcb The tcp_pcb struct to write to
|
||||||
|
* @param[in] argc The number of arguments
|
||||||
|
* @param[in] argv The arguments
|
||||||
|
*/
|
||||||
|
static void tcp_cmd_color(struct tcp_pcb* pcb, int argc, char** argv) {
|
||||||
|
if (!str_to_color(argc, argv, &color_txt)) {
|
||||||
|
LOG_INFO(TAG, "Setting color to %08lX", color_txt);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LOG_WARN(TAG, "Bad usage of color");
|
||||||
|
tcp_cmd_write(pcb, "Usage: color 0x<rrggbb>\n");
|
||||||
|
tcp_cmd_write(pcb, "Usage: color 0x<aarrggbb>\n");
|
||||||
|
tcp_cmd_write(pcb, "Usage: color <r> <g> <b>\n");
|
||||||
|
tcp_cmd_write(pcb, "Usage: color <a> <r> <g> <b>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles the listfiles command
|
||||||
|
*
|
||||||
|
* @param[in] pcb The tcp_pcb struct to write to
|
||||||
|
* @param[in] argc The number of arguments
|
||||||
|
* @param[in] argv The arguments
|
||||||
|
*/
|
||||||
|
static void tcp_cmd_list_files(struct tcp_pcb* pcb, int argc, char** argv) {
|
||||||
|
UNUSED(argv);
|
||||||
|
if (argc == 0) {
|
||||||
|
LOG_INFO(TAG, "Listing files");
|
||||||
|
void* mem = NULL; // Pointer for internal use by the llfs library
|
||||||
|
llfs_file_t* file;
|
||||||
|
while ((file = llfs_next_file(&mem, NULL)) != NULL) {
|
||||||
|
tcp_cmd_write(pcb, file->name);
|
||||||
|
tcp_cmd_write(pcb, "\n");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LOG_WARN(TAG, "Bad usage of listfiles");
|
||||||
|
tcp_cmd_write(pcb, "Usage: listfiles\n");
|
||||||
|
tcp_cmd_write(pcb, "Usage: ls\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles the setimage command
|
||||||
|
*
|
||||||
|
* @param[in] pcb The tcp_pcb struct to write to
|
||||||
|
* @param[in] argc The number of arguments
|
||||||
|
* @param[in] argv The arguments
|
||||||
|
*/
|
||||||
|
static void tcp_cmd_set_image(struct tcp_pcb* pcb, int argc, char** argv) {
|
||||||
|
const char* ext = NULL;
|
||||||
|
if (argc >= 1) {
|
||||||
|
ext = llfs_get_filename_ext(argv[0]);
|
||||||
|
if (strcmp(ext, "bmp") != 0) {
|
||||||
|
LOG_WARN(TAG, "setimage: File is not a bmp");
|
||||||
|
tcp_cmd_write(pcb, "File is not a bmp\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (argc == 1) {
|
||||||
|
LOG_INFO(TAG, "Setting image %s @ 0, 0", argv[0]);
|
||||||
|
lcd_draw_img_from_fs(argv[0], 0, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (argc == 3) {
|
||||||
|
LOG_INFO(TAG, "Setting image %s @ %lu, %lu", argv[0], (uint32_t)strtoul(argv[1], NULL, 10),
|
||||||
|
(uint32_t)strtoul(argv[2], NULL, 10));
|
||||||
|
lcd_draw_img_from_fs(argv[0], (uint32_t)strtoul(argv[1], NULL, 10), (uint32_t)strtoul(argv[2], NULL, 10));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LOG_WARN(TAG, "Bad usage of setimage");
|
||||||
|
tcp_cmd_write(pcb, "Usage: setimage <filename>\n");
|
||||||
|
tcp_cmd_write(pcb, "Usage: setimage <filename> <x> <y>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles the setgif command
|
||||||
|
*
|
||||||
|
* @param[in] pcb The tcp_pcb struct to write to
|
||||||
|
* @param[in] argc The number of arguments
|
||||||
|
* @param[in] argv The arguments
|
||||||
|
*/
|
||||||
|
static void tcp_cmd_set_gif(struct tcp_pcb* pcb, int argc, char** argv) {
|
||||||
|
const char* ext = NULL;
|
||||||
|
if (argc >= 1) {
|
||||||
|
ext = llfs_get_filename_ext(argv[0]);
|
||||||
|
if (strcmp(ext, "gif") != 0) {
|
||||||
|
LOG_WARN(TAG, "setgif: File is not a gif");
|
||||||
|
tcp_cmd_write(pcb, "File is not a gif\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (argc == 1) {
|
||||||
|
LOG_INFO(TAG, "Setting gif %s @ 0, 0", argv[0]);
|
||||||
|
lcd_draw_gif_from_fs(argv[0], 0, 0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (argc == 3) {
|
||||||
|
LOG_INFO(TAG, "Setting gif %s @ %lu, %lu", argv[0], (uint32_t)strtoul(argv[1], NULL, 10),
|
||||||
|
(uint32_t)strtoul(argv[2], NULL, 10));
|
||||||
|
lcd_draw_gif_from_fs(argv[0], (uint32_t)strtoul(argv[1], NULL, 10), (uint32_t)strtoul(argv[2], NULL, 10));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_WARN(TAG, "Bad usage of setgif");
|
||||||
|
tcp_cmd_write(pcb, "Usage: setgif <filename>\n");
|
||||||
|
tcp_cmd_write(pcb, "Usage: setgif <filename> <x> <y>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles the exit command
|
||||||
|
*
|
||||||
|
* @param[in] pcb The tcp_pcb struct to write to
|
||||||
|
* @param[in] argc The number of arguments
|
||||||
|
* @param[in] argv The arguments
|
||||||
|
*/
|
||||||
|
static void tcp_cmd_exit(struct tcp_pcb* pcb, int argc, char** argv) {
|
||||||
|
UNUSED(argv);
|
||||||
|
if (argc == 0) {
|
||||||
|
LOG_INFO(TAG, "Closing connection");
|
||||||
|
tcp_cmd_write(pcb, "Exiting...\n");
|
||||||
|
lcd_clear_images();
|
||||||
|
lcd_clear_text();
|
||||||
|
tcp_close(pcb);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_WARN(TAG, "Bad usage of exit");
|
||||||
|
tcp_cmd_write(pcb, "Usage: exit\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function handles unknown commands
|
||||||
|
*
|
||||||
|
* @param[in] pcb The tcp_pcb struct to write to
|
||||||
|
* @param[in] cmd The command
|
||||||
|
*/
|
||||||
|
static void tcp_cmd_unknown_cmd(struct tcp_pcb* pcb, char* cmd) {
|
||||||
|
LOG_WARN(TAG, "Unknown command: %s", cmd);
|
||||||
|
tcp_cmd_write(pcb, "Unknown command: ");
|
||||||
|
tcp_cmd_write(pcb, cmd);
|
||||||
|
tcp_cmd_write(pcb, "\n");
|
||||||
|
tcp_cmd_write(pcb, "Type help for list of commands\n");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function parses the command and calls the appropriate function
|
* @brief This function parses the command and calls the appropriate function
|
||||||
*
|
*
|
||||||
* @param pcb Pointer to the tcp_pcb struct to write to
|
* @param[in] pcb Pointer to the tcp_pcb struct to write to
|
||||||
* @param argc Count of arguments
|
* @param[in] argc Count of arguments
|
||||||
* @param argv Array of arguments
|
* @param[in] argv Array of arguments
|
||||||
* @return true Connection should be closed
|
* @return true Connection should be closed
|
||||||
* @return false Connection should be kept open
|
* @return false Connection should be kept open
|
||||||
*/
|
*/
|
||||||
@@ -356,53 +447,58 @@ static bool tcp_cmd_parser(struct tcp_pcb* pcb, int argc, char** argv) {
|
|||||||
LOG_WARN(TAG, "No command given");
|
LOG_WARN(TAG, "No command given");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tcp_cmd_str_tolower(argv[0]);
|
char* cmd = shift_args(&argc, &argv);
|
||||||
if (strcmp(argv[0], "help") == 0) {
|
tcp_cmd_str_tolower(cmd);
|
||||||
|
if (strcmp(cmd, "help") == 0) {
|
||||||
tcp_cmd_print_help(pcb);
|
tcp_cmd_print_help(pcb);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (strcmp(argv[0], "clear") == 0) {
|
if (strcmp(cmd, "clear") == 0) {
|
||||||
tcp_cmd_clear(pcb, argc, argv);
|
tcp_cmd_clear(pcb, argc, argv);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (strcmp(argv[0], "text") == 0) {
|
if (strcmp(cmd, "text") == 0) {
|
||||||
tcp_cmd_text(pcb, argc, argv);
|
tcp_cmd_text(pcb, argc, argv);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (strcmp(argv[0], "bgcolor") == 0) {
|
if (strcmp(cmd, "bgcolor") == 0) {
|
||||||
tcp_cmd_bg_color(pcb, argc, argv);
|
tcp_cmd_bg_color(pcb, argc, argv);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (strcmp(argv[0], "color") == 0) {
|
if (strcmp(cmd, "color") == 0) {
|
||||||
tcp_cmd_color(pcb, argc, argv);
|
tcp_cmd_color(pcb, argc, argv);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (strcmp(argv[0], "listfiles") == 0) {
|
if (strcmp(cmd, "listfiles") == 0) {
|
||||||
tcp_cmd_list_files(pcb, argc, argv);
|
tcp_cmd_list_files(pcb, argc, argv);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (strcmp(argv[0], "setimage") == 0) {
|
if (strcmp(cmd, "ls") == 0) {
|
||||||
|
tcp_cmd_list_files(pcb, argc, argv);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (strcmp(cmd, "setimage") == 0) {
|
||||||
tcp_cmd_set_image(pcb, argc, argv);
|
tcp_cmd_set_image(pcb, argc, argv);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (strcmp(argv[0], "setgif") == 0) {
|
if (strcmp(cmd, "setgif") == 0) {
|
||||||
tcp_cmd_set_gif(pcb, argc, argv);
|
tcp_cmd_set_gif(pcb, argc, argv);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (strcmp(argv[0], "exit") == 0) {
|
if (strcmp(cmd, "exit") == 0) {
|
||||||
tcp_cmd_exit(pcb, argc, argv);
|
tcp_cmd_exit(pcb, argc, argv);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
tcp_cmd_unknown_cmd(pcb, argc, argv);
|
tcp_cmd_unknown_cmd(pcb, cmd);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is called when the tcp connection receives data
|
* @brief This function is called when the tcp connection receives data
|
||||||
* @param arg The argument ptr
|
* @param[in] arg The argument ptr
|
||||||
* @param pcb The tcp_pcb struct
|
* @param[in] pcb The tcp_pcb struct
|
||||||
* @param p The pbuf struct
|
* @param[in] p The pbuf struct
|
||||||
* @param err The error code from the tcp stack
|
* @param[in] err The error code from the tcp stack
|
||||||
* @return err_t ERR_OK if successful
|
* @return err_t ERR_OK if successful
|
||||||
*/
|
*/
|
||||||
err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
|
err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
|
||||||
@@ -445,7 +541,7 @@ err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
|
|||||||
// Split string into tokens by delimiter (space)
|
// Split string into tokens by delimiter (space)
|
||||||
cmd_ptr = tcp_cmd_remove_leading_space(cmd, strlen(cmd));
|
cmd_ptr = tcp_cmd_remove_leading_space(cmd, strlen(cmd));
|
||||||
argv[0] = tcp_cmd_get_next_token(cmd_ptr, " ", &next);
|
argv[0] = tcp_cmd_get_next_token(cmd_ptr, " ", &next);
|
||||||
if(argv[0] != NULL) {
|
if (argv[0] != NULL) {
|
||||||
argc = 1;
|
argc = 1;
|
||||||
}
|
}
|
||||||
while (argv[argc - 1] != NULL && argc < MAX_TOKENS) {
|
while (argv[argc - 1] != NULL && argc < MAX_TOKENS) {
|
||||||
@@ -467,12 +563,12 @@ err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
|
|||||||
if (close_conn) {
|
if (close_conn) {
|
||||||
LOG_INFO(TAG, "Closing connection");
|
LOG_INFO(TAG, "Closing connection");
|
||||||
tcp_cmd_close(pcb);
|
tcp_cmd_close(pcb);
|
||||||
#ifdef LINUX
|
#ifdef NCAT
|
||||||
} else {
|
} else {
|
||||||
tcp_cmd_write(pcb, "$>");
|
tcp_cmd_write(pcb, "$>");
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
} else if(argc > 0) {
|
} else if (argc > 0) {
|
||||||
tcp_cmd_write(pcb, "$>");
|
tcp_cmd_write(pcb, "$>");
|
||||||
} else {
|
} else {
|
||||||
tcp_cmd_write(pcb, "");
|
tcp_cmd_write(pcb, "");
|
||||||
@@ -486,9 +582,9 @@ defer:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is called when a new tcp connection is accepted
|
* @brief This function is called when a new tcp connection is accepted
|
||||||
* @param arg The argument
|
* @param[in] arg The argument
|
||||||
* @param pcb The tcp_pcb struct
|
* @param[in] pcb The tcp_pcb struct
|
||||||
* @param err The error
|
* @param[in] err The error
|
||||||
* @return err_t ERR_OK
|
* @return err_t ERR_OK
|
||||||
*/
|
*/
|
||||||
static err_t tcp_cmd_accept(void* arg, struct tcp_pcb* pcb, err_t err) {
|
static err_t tcp_cmd_accept(void* arg, struct tcp_pcb* pcb, err_t err) {
|
||||||
@@ -505,7 +601,7 @@ static err_t tcp_cmd_accept(void* arg, struct tcp_pcb* pcb, err_t err) {
|
|||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief This function closes the tcp connection
|
* @brief This function closes the tcp connection
|
||||||
* @param pcb The tcp_pcb struct to close
|
* @param[in] pcb The tcp_pcb struct to close
|
||||||
*/
|
*/
|
||||||
static void tcp_cmd_close(struct tcp_pcb* pcb) {
|
static void tcp_cmd_close(struct tcp_pcb* pcb) {
|
||||||
tcp_arg(pcb, NULL);
|
tcp_arg(pcb, NULL);
|
||||||
|
|||||||
@@ -81,26 +81,26 @@ TEST(TCP_CMD, tcp_data_cb) {
|
|||||||
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
|
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
|
||||||
output = testing::internal::GetCapturedStdout();
|
output = testing::internal::GetCapturedStdout();
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
EXPECT_EQ(output, "help : shows a list of commands\n"
|
EXPECT_EQ(output, "help : shows a list of commands\n"
|
||||||
"clear text/images : clears the text or images on the lcd\n"
|
"clear text/images : clears the text or images on the lcd\n"
|
||||||
"text \"<text>\" : puts text on the lcd\n"
|
"text \"<text>\" : puts text on the lcd\n"
|
||||||
"bgColor <r> <g> <b> : set the background color of the lcd\n"
|
"bgColor (<a>) <r> <g> <b> : set the background color of the lcd\n"
|
||||||
"color <r> <g> <b> : set the color of the text\n"
|
"color (<a>) <r> <g> <b> : set the color of the text\n"
|
||||||
"listFiles : shows a list with images in the filesystem\n"
|
"listFiles : shows a list with images in the filesystem\n"
|
||||||
"setImage <image_name> : put an image on the screen\n"
|
"setImage <image_name> : put an image on the screen\n"
|
||||||
"setGif <image_name> : put a gif on the screen\n"
|
"setGif <image_name> : put a gif on the screen\n"
|
||||||
"exit : closes the connection\n\n$>\n");
|
"exit : closes the connection\n\n$>\n");
|
||||||
#else
|
#else
|
||||||
EXPECT_EQ(output, "tcp_recved\ntcp_write:\n"
|
EXPECT_EQ(output, "tcp_recved\ntcp_write:\n"
|
||||||
"help : shows a list of commands\n"
|
"help : shows a list of commands\n"
|
||||||
"clear text/images : clears the text or images on the lcd\n"
|
"clear text/images : clears the text or images on the lcd\n"
|
||||||
"text \"<text>\" : puts text on the lcd\n"
|
"text \"<text>\" : puts text on the lcd\n"
|
||||||
"bgColor <r> <g> <b> : set the background color of the lcd\n"
|
"bgColor (<a>) <r> <g> <b> : set the background color of the lcd\n"
|
||||||
"color <r> <g> <b> : set the color of the text\n"
|
"color (<a>) <r> <g> <b> : set the color of the text\n"
|
||||||
"listFiles : shows a list with images in the filesystem\n"
|
"listFiles : shows a list with images in the filesystem\n"
|
||||||
"setImage <image_name> : put an image on the screen\n"
|
"setImage <image_name> : put an image on the screen\n"
|
||||||
"setGif <image_name> : put a gif on the screen\n"
|
"setGif <image_name> : put a gif on the screen\n"
|
||||||
"exit : closes the connection\n"
|
"exit : closes the connection\n"
|
||||||
"\ntcp_output\ntcp_write:\n$>\ntcp_output\npbuf_free\n");
|
"\ntcp_output\ntcp_write:\n$>\ntcp_output\npbuf_free\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ TEST(TCP_CMD, tcp_data_cb) {
|
|||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
EXPECT_EQ(output, "$>\n");
|
EXPECT_EQ(output, "$>\n");
|
||||||
#else
|
#else
|
||||||
EXPECT_EQ(output, "tcp_recved\nlcd_display_text @ 10 10 with color 0xFF000000 bg color 0xFF000000\nThis is printed on the display\ntcp_write:\n$>\ntcp_output\npbuf_free\n");
|
EXPECT_EQ(output, "tcp_recved\nlcd_display_text @ 10 10 with color 0xFFFFFFFF bg color 0xFF000000\nThis is printed on the display\ntcp_write:\n$>\ntcp_output\npbuf_free\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
strcpy(cmd, "color 0x555555");
|
strcpy(cmd, "color 0x555555");
|
||||||
@@ -149,7 +149,7 @@ TEST(TCP_CMD, tcp_data_cb) {
|
|||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
EXPECT_EQ(output, "$>\n");
|
EXPECT_EQ(output, "$>\n");
|
||||||
#else
|
#else
|
||||||
EXPECT_EQ(output, "tcp_recved\nlcd_display_text @ 10 10 with color 0xFF555555 bg color 0xFFAAAAAA\nThis is printed on the display\ntcp_write:\n$>\ntcp_output\npbuf_free\n");
|
EXPECT_EQ(output, "tcp_recved\nlcd_display_text @ 10 10 with color 0x00555555 bg color 0x00AAAAAA\nThis is printed on the display\ntcp_write:\n$>\ntcp_output\npbuf_free\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
strcpy(cmd, "color 255 255 255");
|
strcpy(cmd, "color 255 255 255");
|
||||||
|
|||||||
Reference in New Issue
Block a user