Compare commits
76 Commits
experiment
...
experiment
| Author | SHA1 | Date | |
|---|---|---|---|
|
b4623992ef
|
|||
|
b8553067d1
|
|||
|
c0b4a014f5
|
|||
|
fffbf6e8db
|
|||
|
d627da2999
|
|||
|
1ec27e9ee3
|
|||
|
6bc074a033
|
|||
|
87b6fecfd0
|
|||
|
3a745af9bf
|
|||
|
2a4de4fe34
|
|||
|
86f0a3bedc
|
|||
|
a37213b128
|
|||
|
992b9f3063
|
|||
|
589f56ecbd
|
|||
|
bd89deceb6
|
|||
|
5c5fda62e6
|
|||
|
76f3044d21
|
|||
|
f3818e805a
|
|||
|
6ee9e305cc
|
|||
|
f7dc10c7bb
|
|||
|
b9a6566267
|
|||
|
2d526b899a
|
|||
|
f8251a3e74
|
|||
|
e42cbc31ba
|
|||
|
a1add6b61b
|
|||
|
21a0207873
|
|||
|
b1f952ec58
|
|||
|
d5495e2e84
|
|||
|
414e53e6e9
|
|||
|
35656af040
|
|||
|
8a9df4d883
|
|||
|
12a7221a2e
|
|||
|
55ea5b31e1
|
|||
|
6a0be6e469
|
|||
|
5268ad0b7a
|
|||
|
1072e349c0
|
|||
|
2d345b04c3
|
|||
|
3d51fde427
|
|||
|
9f48f4eef1
|
|||
|
d3d6cada0a
|
|||
|
40662b33aa
|
|||
|
b7a924719e
|
|||
|
5bc3250c15
|
|||
|
ed2e7ef650
|
|||
|
0f1f041cbf
|
|||
|
9aa53db35f
|
|||
|
84f5a61ddf
|
|||
|
9885971549
|
|||
|
7c86563242
|
|||
|
edc60bafb8
|
|||
|
d7ff0010bd
|
|||
|
f16e92b7d8
|
|||
|
16c40ce7fe
|
|||
|
6ceee577de
|
|||
|
56846b7643
|
|||
|
2508d365c3
|
|||
|
42675a5fe1
|
|||
|
843c234bcf
|
|||
|
e9bcf0e712
|
|||
|
2baa820683
|
|||
|
a784f3c33f
|
|||
|
9cc94f25f2
|
|||
|
|
3cfb22f590
|
||
|
|
e924f2b82d
|
||
|
|
31e761300a
|
||
|
|
fb44367da7
|
||
|
|
6de8684d89
|
||
|
|
61d2994e40
|
||
|
|
8be959eefd
|
||
|
|
e852d29824
|
||
|
|
f11f71020d
|
||
|
|
1bcd9f1113
|
||
|
|
398bb2efde
|
||
|
|
26f2655e3f
|
||
|
|
e34b2855ba
|
||
|
|
9f25995c82
|
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(WSAA_tests LANGUAGES CXX C)
|
||||
|
||||
|
||||
104
docs/tcp_cmd_interface.md
Normal file
104
docs/tcp_cmd_interface.md
Normal file
@@ -0,0 +1,104 @@
|
||||
# TCP CMD Interface
|
||||
|
||||
## 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`).
|
||||
|
||||
## Table of contents
|
||||
|
||||
* [Introduction](#introduction)
|
||||
* [Table of contents](#table-of-contents)
|
||||
* [Usage of TCP CMD Interface](#usage-of-tcp-cmd-interface)
|
||||
* [Connecting to the device](#connecting-to-the-device)
|
||||
* [Sending commands](#sending-commands)
|
||||
* [Available commands](#available-commands)
|
||||
* [`help`](#help)
|
||||
* [`text`](#text)
|
||||
* [`bgcolor`](#bgcolor)
|
||||
* [`color`](#color)
|
||||
* [`listImages`](#listimages)
|
||||
* [`setImage`](#setimage)
|
||||
* [`setGif`](#setgif)
|
||||
|
||||
## Usage of TCP CMD Interface
|
||||
### Connecting to the device
|
||||
The device can be connected to using a TCP client. The device will listen on port 23. The device will send a welcome message when a client connects.
|
||||
|
||||
On Linux, the device can be connected to using the `nc` command:
|
||||
```bash
|
||||
nc <ip-address> 23
|
||||
```
|
||||
|
||||
### Sending commands
|
||||
Commands can be sent to the device by typing them in the terminal and pressing enter. The device will execute the command and send a response.
|
||||
|
||||
### Available commands
|
||||
#### `help`
|
||||
The `help` command will print a list of available commands.
|
||||
```bash
|
||||
$> help
|
||||
help : shows a list of commands
|
||||
text "<text>" : puts text on the lcd
|
||||
color (<a>) <r> <g> <b> : set the background color of the lcd
|
||||
textColor (<a>) <r> <g> <b> : set the color of the text
|
||||
listImages : shows a list with images in the filesystem
|
||||
setImage <image_name> : put an image on the screen
|
||||
setGif <image_name> : put a gif on the screen
|
||||
exit : closes the connection
|
||||
```
|
||||
|
||||
#### `text`
|
||||
The `text` command will print the given text on the screen. The text can be one or multiple words. one word does'n need quotes, multiple words do. The text will rapp around when it reaches the end of the screen.
|
||||
```bash
|
||||
$> text "Hello World!"
|
||||
```
|
||||
|
||||
#### `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. It also has the possible to set the alpha value as the first parameter, this is optional.
|
||||
```bash
|
||||
bgcolor 255 0 0
|
||||
```
|
||||
or
|
||||
```bash
|
||||
bgcolor 0xFF0000
|
||||
```
|
||||
|
||||
#### `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. It also has the possible to set the alpha value as the first parameter, this is optional.
|
||||
```bash
|
||||
color 255 0 0
|
||||
```
|
||||
or
|
||||
```bash
|
||||
color 0xFF0000
|
||||
```
|
||||
|
||||
#### `listImages`
|
||||
The `listImages` command will print a list of images that are present in the filesystem.
|
||||
```bash
|
||||
$> listImages
|
||||
image1.bmp
|
||||
image2.bmp
|
||||
image3.bmp
|
||||
gif1.gif
|
||||
...
|
||||
```
|
||||
|
||||
#### `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. 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
|
||||
$> setImage image1.bmp
|
||||
```
|
||||
or
|
||||
```bash
|
||||
$> setImage image1.bmp 128 64
|
||||
```
|
||||
|
||||
#### `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. 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
|
||||
$> setGif gif1.gif
|
||||
```
|
||||
or
|
||||
```bash
|
||||
$> setGif gif1.gif 128 64
|
||||
```
|
||||
@@ -1,19 +1,30 @@
|
||||
/**
|
||||
* @file tcp_cmd.h
|
||||
* @brief TCP CMD interface
|
||||
* @author Gert R.
|
||||
* @brief This file contains the headers of the tcp command interface
|
||||
* @author Sander S.
|
||||
*/
|
||||
|
||||
#ifndef INC_TCP_CMD_H_
|
||||
#define INC_TCP_CMD_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <tcp.h>
|
||||
#ifndef TESTING
|
||||
#include "lcd_api.h"
|
||||
#else
|
||||
#include "mocs.h"
|
||||
#endif
|
||||
#include "llfs.h"
|
||||
#include "log.h"
|
||||
#include <tcp.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <ctype.h>
|
||||
|
||||
void tcp_cmd_remove_newline(char* str, size_t len);
|
||||
char* tcp_cmd_remove_leading_space(char* str, size_t len);
|
||||
void tcp_cmd_str_tolower(char* str);
|
||||
char* tcp_cmd_get_next_token(char* input, const char* delimiters, char** next);
|
||||
void tcp_cmd_init(void);
|
||||
err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err);
|
||||
|
||||
#endif /* INC_TCP_CMD_H_ */
|
||||
|
||||
@@ -120,10 +120,7 @@ int main(void) {
|
||||
MX_QUADSPI_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* Initialize QSPI */
|
||||
BSP_QSPI_Init();
|
||||
BSP_QSPI_MemoryMappedMode();
|
||||
WRITE_REG(QUADSPI->LPTR, 0xFFF);
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Clear terminal */
|
||||
printf(CLEAR_SCREEN);
|
||||
@@ -133,6 +130,8 @@ int main(void) {
|
||||
|
||||
/* Initialize the filesystem */
|
||||
llfs_init();
|
||||
tcp_cmd_init();
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Initialize the tftp server */
|
||||
tftp_server_init();
|
||||
|
||||
@@ -1,184 +1,592 @@
|
||||
/**
|
||||
* @file tcp_cmd.c
|
||||
* @brief TCP CMD interface
|
||||
* @author Gert R.
|
||||
* @brief This file contains the implementation of the tcp command interface
|
||||
* @author Sander S.
|
||||
*/
|
||||
#include "tcp_cmd.h"
|
||||
|
||||
static uint32_t result_txt = 0xff000000; // Store text color
|
||||
static uint32_t result_bg = 0xff000000; // Store background color
|
||||
#define MAX_TOKENS 10
|
||||
#define MAX_CMD_LEN 50
|
||||
|
||||
static void tcp_cmd_close(struct tcp_pcb* pcb) {
|
||||
tcp_arg(pcb, NULL);
|
||||
tcp_sent(pcb, NULL);
|
||||
tcp_recv(pcb, NULL);
|
||||
#define NCAT
|
||||
|
||||
static const char* TAG = "tcp_cmd";
|
||||
static uint32_t color_txt = 0xffffffff; // Store text color
|
||||
static uint32_t color_bg = 0xff000000; // Store background color
|
||||
|
||||
static void tcp_cmd_write(struct tcp_pcb* pcb, const char* str);
|
||||
static void tcp_cmd_print_header(struct tcp_pcb* pcb);
|
||||
static void tcp_cmd_print_help(struct tcp_pcb* pcb);
|
||||
static void tcp_cmd_clear(struct tcp_pcb* pcb, int argc, char** argv);
|
||||
static void tcp_cmd_text(struct tcp_pcb* pcb, int argc, char** argv);
|
||||
static void tcp_cmd_bg_color(struct tcp_pcb* pcb, int argc, char** argv);
|
||||
static void tcp_cmd_color(struct tcp_pcb* pcb, int argc, char** argv);
|
||||
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_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_unknown_cmd(struct tcp_pcb* pcb, char* cmd);
|
||||
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 void tcp_cmd_close(struct tcp_pcb* pcb);
|
||||
|
||||
/**
|
||||
* @brief This function shifts the arguments in argv and argc
|
||||
* @param[in,out] argc The argc pointer
|
||||
* @param[in,out] argv The argv pointer
|
||||
* @return The shifted argument
|
||||
*/
|
||||
static char* shift_args(int* argc, char*** argv) {
|
||||
if (*argc == 0) {
|
||||
return NULL;
|
||||
}
|
||||
char* arg = (*argv)[0];
|
||||
(*argv)++;
|
||||
(*argc)--;
|
||||
return arg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function converts a string to a color
|
||||
* @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 bool str_to_color(int argc, char** argv, uint32_t* color) {
|
||||
if (argc == 1) {
|
||||
*color = (uint32_t)strtoul(argv[0], NULL, 16);
|
||||
return false;
|
||||
}
|
||||
if (argc == 3) {
|
||||
*color = 0xff000000;
|
||||
*color |= (uint32_t)strtoul(argv[0], NULL, 10) << 16;
|
||||
*color |= (uint32_t)strtoul(argv[1], NULL, 10) << 8;
|
||||
*color |= (uint32_t)strtoul(argv[2], NULL, 10);
|
||||
return false;
|
||||
}
|
||||
if (argc == 4) {
|
||||
*color = (uint32_t)strtoul(argv[0], NULL, 10) << 24;
|
||||
*color |= (uint32_t)strtoul(argv[1], NULL, 10) << 16;
|
||||
*color |= (uint32_t)strtoul(argv[2], NULL, 10) << 8;
|
||||
*color |= (uint32_t)strtoul(argv[3], NULL, 10);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function removes the newline from a string the string can contain multiple lines
|
||||
* @param[in,out] str The string to remove the newline from
|
||||
*/
|
||||
void tcp_cmd_remove_newline(char* str, size_t len) {
|
||||
size_t i = 0;
|
||||
size_t j = 0;
|
||||
while (str[i] != '\0' && j < len) {
|
||||
if (str[j] != '\n' && str[j] != '\r') {
|
||||
str[i] = str[j];
|
||||
i++;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
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) {
|
||||
size_t i = 0;
|
||||
if (str == NULL || str[0] == '\0' || len == 0) {
|
||||
return NULL;
|
||||
}
|
||||
while (str[i] != '\0' && i < len) {
|
||||
if (isspace((int)str[i]) == 0) {
|
||||
return &str[i];
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function converts a string to lowercase
|
||||
* @param[in,out] str The string to convert
|
||||
*/
|
||||
void tcp_cmd_str_tolower(char* str) {
|
||||
int i = 0;
|
||||
while (str[i] != '\0') {
|
||||
str[i] = (char)tolower((int)str[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function finds the next token in the input string
|
||||
* If the token is between quotes, return the whole string between quotes
|
||||
* @param[in] input The input string
|
||||
* @param[in] delimiter The delimiters to use
|
||||
* @param[in,out] next The next token
|
||||
* @return char* The next token
|
||||
*/
|
||||
char* tcp_cmd_get_next_token(char* input, const char* delimiters, char** next) {
|
||||
if (input == NULL && *next == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (input == NULL) {
|
||||
input = *next;
|
||||
}
|
||||
|
||||
// Skip leading delimiters
|
||||
input += strspn(input, delimiters);
|
||||
if (*input == '\0') {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// If the token is between quotes, return the whole string between quotes
|
||||
if (*input == '"') {
|
||||
char* end = strchr(++input, '"');
|
||||
if (end == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
*end = '\0';
|
||||
*next = end + 1;
|
||||
return input;
|
||||
}
|
||||
|
||||
// Find the end of the token
|
||||
char* end = input + strcspn(input, delimiters);
|
||||
if (*end == '\0') {
|
||||
*next = end;
|
||||
} else {
|
||||
*end = '\0';
|
||||
*next = end + 1;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
|
||||
size_t len;
|
||||
size_t number_of_files;
|
||||
uint8_t file_in_fs;
|
||||
uint8_t check = 0;
|
||||
|
||||
char* pc;
|
||||
char tcp_buffer[1024];
|
||||
char text[256];
|
||||
char color_r[3];
|
||||
char color_g[3];
|
||||
char color_b[3];
|
||||
|
||||
char text_color_r[3];
|
||||
char text_color_g[3];
|
||||
char text_color_b[3];
|
||||
|
||||
char extension[4];
|
||||
|
||||
char* endptr;
|
||||
|
||||
if (err == ERR_OK && p != NULL) {
|
||||
tcp_recved(pcb, p->tot_len);
|
||||
pc = (char*)p->payload;
|
||||
len = p->tot_len;
|
||||
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
tcp_buffer[i] = pc[i];
|
||||
LOG_WARN(TAG, "Bad usage of exit");
|
||||
tcp_cmd_write(pcb, "Usage: exit\n");
|
||||
}
|
||||
|
||||
if (!strncmp(tcp_buffer, "help", 4)) {
|
||||
check = 1;
|
||||
tcp_write(pcb,
|
||||
"help : laat lijst zien met alle commando's\r\n"
|
||||
"text : geeft tekst mee die op LCD komt (uw_text)\r\n"
|
||||
"color : kleur achtergrond van scherm (255 255 255)\r\n"
|
||||
"textColor : kleur van tekst (255 255 255)\r\n"
|
||||
"listImages: laat een lijst zien van de mogelijke afbeeldingen\r\n"
|
||||
"setImage : veranderd te afbeelding (naam_afbeelding)\r\n"
|
||||
"exit : sluit de verbinding\r\n",
|
||||
354, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
} else if (!strncmp(tcp_buffer, "text ", 5)) {
|
||||
size_t i;
|
||||
for (i = 0; i < len - 4; i++) {
|
||||
text[i] = tcp_buffer[i + 5];
|
||||
}
|
||||
text[i - 1] = '\0';
|
||||
lcd_clear_text();
|
||||
lcd_display_text(text, 10, 10, result_txt, result_bg, LCD_FONT24);
|
||||
|
||||
check = 1;
|
||||
} else if (!strncmp(tcp_buffer, "color", 5)) {
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
color_r[i] = tcp_buffer[i + 6];
|
||||
color_g[i] = tcp_buffer[i + 10];
|
||||
color_b[i] = tcp_buffer[i + 14];
|
||||
}
|
||||
result_bg |= strtoul(color_r, &endptr, 10) << 16;
|
||||
result_bg |= strtoul(color_g, &endptr, 10) << 8;
|
||||
result_bg |= strtoul(color_b, &endptr, 10);
|
||||
|
||||
check = 1;
|
||||
} else if (!strncmp(tcp_buffer, "textColor", 9)) {
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
text_color_r[i] = tcp_buffer[i + 10];
|
||||
text_color_g[i] = tcp_buffer[i + 14];
|
||||
text_color_b[i] = tcp_buffer[i + 18];
|
||||
}
|
||||
result_txt |= strtoul(text_color_r, &endptr, 10) << 16;
|
||||
result_txt |= strtoul(text_color_g, &endptr, 10) << 8;
|
||||
result_txt |= strtoul(text_color_b, &endptr, 10);
|
||||
|
||||
check = 1;
|
||||
} else if (!strncmp(tcp_buffer, "listImages", 10)) {
|
||||
number_of_files = llfs_file_count();
|
||||
|
||||
if (number_of_files > 0) {
|
||||
llfs_file_t file_list[number_of_files];
|
||||
number_of_files = llfs_file_list(file_list, number_of_files, NULL);
|
||||
|
||||
for (size_t i = 0; i < number_of_files; i++) {
|
||||
tcp_write(pcb, file_list[i].name, strlen(file_list[i].name),
|
||||
TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
tcp_write(pcb, "\r\n", 2, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
}
|
||||
} else {
|
||||
tcp_write(pcb, "NO files in filesystem\r\n", 24, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
/**
|
||||
* @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");
|
||||
}
|
||||
|
||||
check = 1;
|
||||
} else if (!strncmp(tcp_buffer, "setImage", 8)) {
|
||||
char filename[len - 8];
|
||||
for (size_t i = 0; i < len - 9; i++) {
|
||||
filename[i] = tcp_buffer[i + 9];
|
||||
/**
|
||||
* @brief This function parses the command and calls the appropriate function
|
||||
*
|
||||
* @param[in] pcb Pointer to the tcp_pcb struct to write to
|
||||
* @param[in] argc Count of arguments
|
||||
* @param[in] argv Array of arguments
|
||||
* @return true Connection should be closed
|
||||
* @return false Connection should be kept open
|
||||
*/
|
||||
static bool tcp_cmd_parser(struct tcp_pcb* pcb, int argc, char** argv) {
|
||||
if (argc == 0) {
|
||||
LOG_WARN(TAG, "No command given");
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
extension[i] = tcp_buffer[i + len - 3];
|
||||
char* cmd = shift_args(&argc, &argv);
|
||||
tcp_cmd_str_tolower(cmd);
|
||||
if (strcmp(cmd, "help") == 0) {
|
||||
tcp_cmd_print_help(pcb);
|
||||
return false;
|
||||
}
|
||||
filename[sizeof(filename) - 1] = '\0';
|
||||
extension[3] = '\0';
|
||||
|
||||
number_of_files = llfs_file_count();
|
||||
|
||||
if (number_of_files > 0) {
|
||||
llfs_file_t file_list[number_of_files];
|
||||
|
||||
number_of_files = llfs_file_list(file_list, number_of_files, NULL);
|
||||
|
||||
file_in_fs = 0;
|
||||
for (size_t i = 0; i < number_of_files; i++) {
|
||||
if (!strcmp(filename, file_list[i].name)) {
|
||||
file_in_fs = 1;
|
||||
if (strcmp(cmd, "clear") == 0) {
|
||||
tcp_cmd_clear(pcb, argc, argv);
|
||||
return false;
|
||||
}
|
||||
if (strcmp(cmd, "text") == 0) {
|
||||
tcp_cmd_text(pcb, argc, argv);
|
||||
return false;
|
||||
}
|
||||
if (strcmp(cmd, "bgcolor") == 0) {
|
||||
tcp_cmd_bg_color(pcb, argc, argv);
|
||||
return false;
|
||||
}
|
||||
if (strcmp(cmd, "color") == 0) {
|
||||
tcp_cmd_color(pcb, argc, argv);
|
||||
return false;
|
||||
}
|
||||
if (strcmp(cmd, "listfiles") == 0) {
|
||||
tcp_cmd_list_files(pcb, argc, argv);
|
||||
return false;
|
||||
}
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
if (strcmp(cmd, "setgif") == 0) {
|
||||
tcp_cmd_set_gif(pcb, argc, argv);
|
||||
return false;
|
||||
}
|
||||
if (strcmp(cmd, "exit") == 0) {
|
||||
tcp_cmd_exit(pcb, argc, argv);
|
||||
return true;
|
||||
}
|
||||
tcp_cmd_unknown_cmd(pcb, cmd);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check which file extension is used and call right function
|
||||
if (!strncmp(extension, "bmp", 3) && file_in_fs) {
|
||||
lcd_clear_images();
|
||||
lcd_draw_img_from_fs(filename, 10, 10);
|
||||
} else if (!strncmp(extension, "gif", 3) && file_in_fs) {
|
||||
lcd_clear_images();
|
||||
lcd_draw_gif_from_fs(filename, 10, 10);
|
||||
} else if (!file_in_fs) {
|
||||
tcp_write(pcb, "File NOT in filesystem\n\r", 24, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
} else {
|
||||
tcp_write(pcb, "Extension NOT supported\n\r", 25, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
}
|
||||
} else {
|
||||
tcp_write(pcb, "NO files in filesystem\r\n", 24, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
}
|
||||
|
||||
check = 1;
|
||||
} else if (!strncmp(tcp_buffer, "exit", 4)) {
|
||||
lcd_clear_images();
|
||||
lcd_clear_text();
|
||||
tcp_cmd_close(pcb);
|
||||
check = 1;
|
||||
}
|
||||
|
||||
if (!check && (strncmp(tcp_buffer, "\r\n", 2) != 0)) {
|
||||
tcp_write(pcb, "Onbestaand commando: help voor lijst van commando's\r\n", 53,
|
||||
TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
}
|
||||
|
||||
pbuf_free(p);
|
||||
|
||||
if (len > tcp_sndbuf(pcb)) {
|
||||
len = tcp_sndbuf(pcb);
|
||||
}
|
||||
tcp_sent(pcb, NULL);
|
||||
} else {
|
||||
pbuf_free(p);
|
||||
}
|
||||
|
||||
if (err == ERR_OK && p == NULL) {
|
||||
tcp_cmd_close(pcb);
|
||||
}
|
||||
if (strncmp(tcp_buffer, "\r\n", 2) != 0) {
|
||||
tcp_write(pcb, "User: ", 6, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
/**
|
||||
* @brief This function is called when the tcp connection receives data
|
||||
* @param[in] arg The argument ptr
|
||||
* @param[in] pcb The tcp_pcb struct
|
||||
* @param[in] p The pbuf struct
|
||||
* @param[in] err The error code from the tcp stack
|
||||
* @return err_t ERR_OK if successful
|
||||
*/
|
||||
err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
|
||||
int argc = 0;
|
||||
char cmd[MAX_CMD_LEN] = {0};
|
||||
char* cmd_ptr = NULL;
|
||||
char* argv[MAX_TOKENS] = {0};
|
||||
bool close_conn = false;
|
||||
char* next = NULL;
|
||||
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
|
||||
// Connection closed?
|
||||
if (p == NULL && err == ERR_OK) {
|
||||
LOG_INFO(TAG, "Remote closed connection");
|
||||
return tcp_close(pcb);
|
||||
}
|
||||
|
||||
if (err != ERR_OK) {
|
||||
LOG_WARN(TAG, "TCP data received with error(%d): %s", err, lwip_strerr(err));
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
if (p->tot_len >= MAX_CMD_LEN) {
|
||||
LOG_WARN(TAG, "Command too long");
|
||||
tcp_cmd_write(pcb, "Command too long");
|
||||
}
|
||||
uint16_t len = p->tot_len >= MAX_CMD_LEN ? MAX_CMD_LEN : p->tot_len;
|
||||
// Make sure the string is null terminated
|
||||
pbuf_copy_partial(p, cmd, len, 0);
|
||||
cmd[len] = '\0';
|
||||
|
||||
// Tell the tcp stack that we have taken the data
|
||||
tcp_recved(pcb, p->tot_len);
|
||||
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
if (cmd[0] != '\0') {
|
||||
LOG_INFO(TAG, "cmd: %s", cmd);
|
||||
}
|
||||
// Split string into tokens by delimiter (space)
|
||||
cmd_ptr = tcp_cmd_remove_leading_space(cmd, strlen(cmd));
|
||||
argv[0] = tcp_cmd_get_next_token(cmd_ptr, " ", &next);
|
||||
if (argv[0] != NULL) {
|
||||
argc = 1;
|
||||
}
|
||||
while (argv[argc - 1] != NULL && argc < MAX_TOKENS) {
|
||||
// Check if the next token is 0 (end of string) strlen doesn't work here
|
||||
if (*next == 0) {
|
||||
argv[argc] = NULL;
|
||||
break;
|
||||
}
|
||||
next = tcp_cmd_remove_leading_space(next, strlen(next));
|
||||
argv[argc] = tcp_cmd_get_next_token(NULL, " ", &next);
|
||||
if (argv[argc] == NULL) {
|
||||
break;
|
||||
}
|
||||
argc++;
|
||||
}
|
||||
|
||||
close_conn = tcp_cmd_parser(pcb, argc, argv);
|
||||
|
||||
if (close_conn) {
|
||||
LOG_INFO(TAG, "Closing connection");
|
||||
tcp_cmd_close(pcb);
|
||||
#ifdef NCAT
|
||||
} else {
|
||||
tcp_cmd_write(pcb, "$>");
|
||||
}
|
||||
#else
|
||||
} else if (argc > 0) {
|
||||
tcp_cmd_write(pcb, "$>");
|
||||
} else {
|
||||
tcp_cmd_write(pcb, "");
|
||||
}
|
||||
#endif
|
||||
|
||||
defer:
|
||||
pbuf_free(p);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function is called when a new tcp connection is accepted
|
||||
* @param[in] arg The argument
|
||||
* @param[in] pcb The tcp_pcb struct
|
||||
* @param[in] err The error
|
||||
* @return err_t ERR_OK
|
||||
*/
|
||||
static err_t tcp_cmd_accept(void* arg, struct tcp_pcb* pcb, err_t err) {
|
||||
LWIP_UNUSED_ARG(arg);
|
||||
LWIP_UNUSED_ARG(err);
|
||||
@@ -186,21 +594,46 @@ static err_t tcp_cmd_accept(void* arg, struct tcp_pcb* pcb, err_t err) {
|
||||
tcp_recv(pcb, tcp_cmd_recv);
|
||||
tcp_err(pcb, NULL);
|
||||
tcp_poll(pcb, NULL, 4);
|
||||
tcp_write(pcb,
|
||||
" Welcom bij de TCP CMD Interface\r\n"
|
||||
"(Typ help voor een lijst van de commando's! X om te sluiten)\r\n"
|
||||
"============================================================\r\n"
|
||||
"User: ",
|
||||
168, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
tcp_sent(pcb, NULL);
|
||||
|
||||
LOG_INFO(TAG, "New connection accepted");
|
||||
tcp_cmd_print_header(pcb);
|
||||
return ERR_OK;
|
||||
}
|
||||
/**
|
||||
* @brief This function closes the tcp connection
|
||||
* @param[in] pcb The tcp_pcb struct to close
|
||||
*/
|
||||
static void tcp_cmd_close(struct tcp_pcb* pcb) {
|
||||
tcp_arg(pcb, NULL);
|
||||
tcp_sent(pcb, NULL);
|
||||
tcp_recv(pcb, NULL);
|
||||
tcp_close(pcb);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function initializes the tcp command interface
|
||||
*/
|
||||
void tcp_cmd_init(void) {
|
||||
struct tcp_pcb* tcp_pcb;
|
||||
tcp_pcb = tcp_new();
|
||||
tcp_bind(tcp_pcb, IP_ADDR_ANY, 23);
|
||||
|
||||
if (tcp_pcb == NULL) {
|
||||
LOG_CRIT(TAG, "Failed to allocate pcb");
|
||||
return;
|
||||
}
|
||||
|
||||
if (tcp_bind(tcp_pcb, IP_ADDR_ANY, 23) != ERR_OK) {
|
||||
LOG_CRIT(TAG, "Failed to bind pcb");
|
||||
free(tcp_pcb);
|
||||
return;
|
||||
}
|
||||
|
||||
tcp_pcb = tcp_listen(tcp_pcb);
|
||||
if (tcp_pcb == NULL) {
|
||||
LOG_CRIT(TAG, "Failed to listen");
|
||||
free(tcp_pcb);
|
||||
return;
|
||||
}
|
||||
|
||||
tcp_accept(tcp_pcb, tcp_cmd_accept);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ add_executable(tests)
|
||||
target_compile_definitions(tests
|
||||
PRIVATE
|
||||
"TESTING"
|
||||
"DEBUG"
|
||||
)
|
||||
|
||||
target_sources(tests
|
||||
@@ -21,6 +22,7 @@ target_sources(tests
|
||||
${CMAKE_SOURCE_DIR}/project/Core/Src/llfs_data.c
|
||||
${CMAKE_SOURCE_DIR}/project/Core/Src/llfs.c
|
||||
${CMAKE_SOURCE_DIR}/project/Core/Src/tftp.c
|
||||
${CMAKE_SOURCE_DIR}/project/Core/Src/tcp_cmd.c
|
||||
)
|
||||
|
||||
target_compile_options(tests PRIVATE $<$<CONFIG:Debug>:
|
||||
|
||||
92
tests/mocs.c
92
tests/mocs.c
@@ -1,49 +1,68 @@
|
||||
#include "mocs.h"
|
||||
#include "tftp.h"
|
||||
#include "mocs.h"
|
||||
#ifdef DEBUG
|
||||
#define dprint(fmt, ...) printf(fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define dprint(fmt, ...)
|
||||
#endif
|
||||
|
||||
void tftp_cleanup(void) {
|
||||
dprint("tftp_cleanup\n");
|
||||
}
|
||||
uint32_t logger_get_timestamp(void) {
|
||||
dprint("logger_get_timestamp\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tftp_init(struct tftp_context* context) {
|
||||
UNUSED(context);
|
||||
|
||||
dprint("tftp_init\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void lcd_display_text(const char* text,
|
||||
uint16_t x_pos,
|
||||
uint16_t y_pos,
|
||||
uint32_t color,
|
||||
uint32_t bg_color,
|
||||
sFONT* font) {
|
||||
void lcd_display_text(const char* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, uint32_t bg_color, sFONT* font) {
|
||||
UNUSED(text);
|
||||
UNUSED(x_pos);
|
||||
UNUSED(y_pos);
|
||||
UNUSED(color);
|
||||
UNUSED(bg_color);
|
||||
UNUSED(font);
|
||||
|
||||
printf("lcd_display_text @ %d %d with color 0x%08X bg color 0x%08X\n%s\n", x_pos, y_pos, color, bg_color, text);
|
||||
dprint("lcd_display_text @ %d %d with color 0x%08X bg color 0x%08X\n%s\n", x_pos, y_pos, color, bg_color, text);
|
||||
}
|
||||
|
||||
void lcd_draw_img_from_fs(char* filename, uint32_t x_pos, uint32_t y_pos) {
|
||||
printf("lcd_draw_img_from_fs\n%s @%d %d\n", filename, x_pos, y_pos);
|
||||
UNUSED(filename);
|
||||
UNUSED(x_pos);
|
||||
UNUSED(y_pos);
|
||||
|
||||
dprint("lcd_draw_img_from_fs\n%s @%d %d\n", filename, x_pos, y_pos);
|
||||
}
|
||||
void lcd_draw_gif_from_fs(char* filename, uint32_t x_pos, uint32_t y_pos) {
|
||||
printf("lcd_draw_gif_from_fs\n%s @%d %d\n", filename, x_pos, y_pos);
|
||||
UNUSED(filename);
|
||||
UNUSED(x_pos);
|
||||
UNUSED(y_pos);
|
||||
|
||||
dprint("lcd_draw_gif_from_fs\n%s @%d %d\n", filename, x_pos, y_pos);
|
||||
}
|
||||
|
||||
void lcd_clear_images(void) {
|
||||
printf("lcd_clear_images\n");
|
||||
dprint("lcd_clear_images\n");
|
||||
}
|
||||
|
||||
void lcd_clear_text(void) {
|
||||
printf("lcd_clear_text\n");
|
||||
dprint("lcd_clear_text\n");
|
||||
}
|
||||
|
||||
void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos) {
|
||||
UNUSED(bmp_buff);
|
||||
UNUSED(x_pos);
|
||||
UNUSED(y_pos);
|
||||
|
||||
printf("lcd_draw_bmp_img @ %d %d\n", x_pos, y_pos);
|
||||
dprint("lcd_draw_bmp_img @ %d %d\n", x_pos, y_pos);
|
||||
}
|
||||
|
||||
void lcd_draw_gif(uint8_t* gif_buff, size_t len, uint32_t x_pos, uint32_t y_pos) {
|
||||
@@ -52,10 +71,11 @@ void lcd_draw_gif(uint8_t* gif_buff, size_t len, uint32_t x_pos, uint32_t y_pos)
|
||||
UNUSED(x_pos);
|
||||
UNUSED(y_pos);
|
||||
|
||||
printf("lcd_draw_gif @ %d %d\n", x_pos, y_pos);
|
||||
dprint("lcd_draw_gif @ %d %d\n", x_pos, y_pos);
|
||||
}
|
||||
|
||||
struct tcp_pcb* tcp_new(void) {
|
||||
dprint("tcp_new\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -63,48 +83,69 @@ err_t tcp_bind(void* pcb, void* ipaddr, uint16_t port) {
|
||||
UNUSED(pcb);
|
||||
UNUSED(ipaddr);
|
||||
UNUSED(port);
|
||||
|
||||
dprint("tcp_bind @ %d\n", port);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
struct tcp_pcb* tcp_listen(void* pcb) {
|
||||
UNUSED(pcb);
|
||||
|
||||
dprint("tcp_listen\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void tcp_accept(void* pcb, tcp_accept_fn arg) {
|
||||
UNUSED(pcb);
|
||||
UNUSED(arg);
|
||||
|
||||
dprint("tcp_accept\n");
|
||||
}
|
||||
|
||||
void tcp_arg(void* pcb, void* arg) {
|
||||
UNUSED(pcb);
|
||||
UNUSED(arg);
|
||||
|
||||
dprint("tcp_arg\n");
|
||||
}
|
||||
void tcp_sent(void* pcb, void* arg) {
|
||||
UNUSED(pcb);
|
||||
UNUSED(arg);
|
||||
|
||||
dprint("tcp_sent\n");
|
||||
}
|
||||
void tcp_recv(void* pcb, tcp_recv_fn arg) {
|
||||
UNUSED(pcb);
|
||||
UNUSED(arg);
|
||||
|
||||
dprint("tcp_recv\n");
|
||||
}
|
||||
|
||||
void tcp_setprio(void* pcb, uint8_t prio) {
|
||||
UNUSED(pcb);
|
||||
UNUSED(prio);
|
||||
|
||||
dprint("tcp_setprio\n");
|
||||
}
|
||||
void tcp_err(void* pcb, void* err) {
|
||||
UNUSED(pcb);
|
||||
UNUSED(err);
|
||||
|
||||
dprint("tcp_err\n");
|
||||
}
|
||||
void tcp_poll(void* pcb, void* poll, uint8_t interval) {
|
||||
UNUSED(pcb);
|
||||
UNUSED(poll);
|
||||
UNUSED(interval);
|
||||
|
||||
dprint("tcp_poll\n");
|
||||
}
|
||||
|
||||
void tcp_close(void* pcb) {
|
||||
err_t tcp_close(void* pcb) {
|
||||
UNUSED(pcb);
|
||||
|
||||
dprint("tcp_close\n");
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void tcp_write(void* pcb, const char* data, size_t len, uint8_t apiflags) {
|
||||
@@ -112,23 +153,44 @@ void tcp_write(void* pcb, const char* data, size_t len, uint8_t apiflags) {
|
||||
UNUSED(apiflags);
|
||||
UNUSED(len);
|
||||
|
||||
printf("tcp_write:\n%s\n", data);
|
||||
dprint("tcp_write:\n");
|
||||
printf("%s\n", data);
|
||||
}
|
||||
|
||||
void tcp_output(void* pcb) {
|
||||
UNUSED(pcb);
|
||||
|
||||
dprint("tcp_output\n");
|
||||
}
|
||||
|
||||
void tcp_recved(void* pcb, uint16_t len) {
|
||||
UNUSED(pcb);
|
||||
UNUSED(len);
|
||||
|
||||
dprint("tcp_recved\n");
|
||||
}
|
||||
|
||||
size_t tcp_sndbuf(void* pcb) {
|
||||
UNUSED(pcb);
|
||||
|
||||
dprint("tcp_sndbuf\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pbuf_free(struct pbuf* p) {
|
||||
UNUSED(p);
|
||||
|
||||
dprint("pbuf_free\n");
|
||||
}
|
||||
|
||||
uint16_t pbuf_copy_partial(const struct pbuf* buf, void* dataptr, uint16_t len, uint16_t offset) {
|
||||
memcpy(dataptr, ((uint8_t*)(buf->payload)) + offset, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
const char* lwip_strerr(err_t err) {
|
||||
UNUSED(err);
|
||||
|
||||
dprint("lwip_sterr\n");
|
||||
return NULL;
|
||||
}
|
||||
15
tests/mocs.h
15
tests/mocs.h
@@ -13,6 +13,15 @@ extern "C" {
|
||||
|
||||
#define LWIP_UNUSED_ARG(x) UNUSED(x)
|
||||
|
||||
typedef void sFONT;
|
||||
|
||||
#define LCD_COLOR_BLACK 0
|
||||
#define LCD_COLOR_WHITE 1
|
||||
#define LCD_TRANSPARENT 2
|
||||
|
||||
#define LCD_FONT16 0
|
||||
#define LCD_FONT24 (void*)1
|
||||
|
||||
typedef int8_t err_t;
|
||||
/** Definitions for error constants. */
|
||||
typedef enum {
|
||||
@@ -111,7 +120,7 @@ void tcp_recv(void* pcb, tcp_recv_fn arg);
|
||||
void tcp_setprio(void* pcb, uint8_t prio);
|
||||
void tcp_err(void* pcb, void* err);
|
||||
void tcp_poll(void* pcb, void* poll, uint8_t interval);
|
||||
void tcp_close(void* pcb);
|
||||
err_t tcp_close(void* pcb);
|
||||
|
||||
void tcp_write(void* pcb, const char* data, size_t len, uint8_t apiflags);
|
||||
void tcp_output(void* pcb);
|
||||
@@ -120,6 +129,10 @@ void pbuf_free(struct pbuf* p);
|
||||
|
||||
size_t tcp_sndbuf(void* pcb);
|
||||
|
||||
uint16_t pbuf_copy_partial(const struct pbuf* buf, void* dataptr, uint16_t len, uint16_t offset);
|
||||
|
||||
const char* lwip_strerr(err_t err);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
0
tests/tcp.h
Normal file
0
tests/tcp.h
Normal file
252
tests/tcp_cmd.cpp
Normal file
252
tests/tcp_cmd.cpp
Normal file
@@ -0,0 +1,252 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mocs.h"
|
||||
extern "C" {
|
||||
#include "tcp_cmd.h"
|
||||
}
|
||||
|
||||
TEST(TCP_CMD, tcp_cmd_remove_newline) {
|
||||
char* cmd = (char*)calloc(50, 1);
|
||||
strcpy(cmd, "help\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "help");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "help\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\nhelp\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhelp\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhelp\n\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhelp\n\n\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhelp\n\n\n\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhelp\n\n\n\n\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhelp\n\n\n\n\n\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhelp\n\n\n\n\n\n\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhelp\n\n\n\n\n\n\n\n\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
strcpy(cmd, "\n\nhel\np\n");
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
EXPECT_STREQ(cmd, "help");
|
||||
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
TEST(TCP_CMD, tcp_cmd_remove_leading_space) {
|
||||
char* cmd = (char*)calloc(50, 1);
|
||||
strcpy(cmd, "help");
|
||||
EXPECT_STREQ(tcp_cmd_remove_leading_space(cmd, strlen(cmd)), "help");
|
||||
strcpy(cmd, " help");
|
||||
EXPECT_STREQ(tcp_cmd_remove_leading_space(cmd, strlen(cmd)), "help");
|
||||
strcpy(cmd, " help");
|
||||
EXPECT_STREQ(tcp_cmd_remove_leading_space(cmd, strlen(cmd)), "help");
|
||||
strcpy(cmd, " help");
|
||||
EXPECT_STREQ(tcp_cmd_remove_leading_space(cmd, strlen(cmd)), "help");
|
||||
strcpy(cmd, " help");
|
||||
EXPECT_STREQ(tcp_cmd_remove_leading_space(cmd, strlen(cmd)), "help");
|
||||
strcpy(cmd, "\n\t\r\n help");
|
||||
EXPECT_STREQ(tcp_cmd_remove_leading_space(cmd, strlen(cmd)), "help");
|
||||
}
|
||||
|
||||
TEST(TCP_CMD, tcp_data_cb) {
|
||||
char* cmd = (char*)calloc(50, 1);
|
||||
std::string output;
|
||||
pbuf p = {.next = NULL, .payload = (void*)cmd, .tot_len = 4, .len = 0, .type_internal = 0, .flags = 0, .if_idx = 0};
|
||||
strcpy(cmd, "help");
|
||||
p.tot_len = (uint16_t)strlen(cmd);
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
#ifndef DEBUG
|
||||
EXPECT_EQ(output, "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\n$>\n");
|
||||
#else
|
||||
EXPECT_EQ(output, "tcp_recved\ntcp_write:\n"
|
||||
"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"
|
||||
"\ntcp_output\ntcp_write:\n$>\ntcp_output\npbuf_free\n");
|
||||
#endif
|
||||
|
||||
strcpy(cmd, "text \"This is printed on the display\"");
|
||||
p.tot_len = (uint16_t)strlen(cmd);
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
#ifndef DEBUG
|
||||
EXPECT_EQ(output, "$>\n");
|
||||
#else
|
||||
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
|
||||
|
||||
strcpy(cmd, "color 0x555555");
|
||||
p.tot_len = (uint16_t)strlen(cmd);
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
#ifndef DEBUG
|
||||
EXPECT_EQ(output, "$>\n");
|
||||
#else
|
||||
EXPECT_EQ(output, "tcp_recved\ntcp_write:\n$>\ntcp_output\npbuf_free\n");
|
||||
#endif
|
||||
|
||||
strcpy(cmd, "bgcolor 0xAAAAAA");
|
||||
p.tot_len = (uint16_t)strlen(cmd);
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
#ifndef DEBUG
|
||||
EXPECT_EQ(output, "$>\n");
|
||||
#else
|
||||
EXPECT_EQ(output, "tcp_recved\ntcp_write:\n$>\ntcp_output\npbuf_free\n");
|
||||
#endif
|
||||
|
||||
strcpy(cmd, "text \"This is printed on the display\"");
|
||||
p.tot_len = (uint16_t)strlen(cmd);
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
#ifndef DEBUG
|
||||
EXPECT_EQ(output, "$>\n");
|
||||
#else
|
||||
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
|
||||
|
||||
strcpy(cmd, "color 255 255 255");
|
||||
p.tot_len = (uint16_t)strlen(cmd);
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
#ifndef DEBUG
|
||||
EXPECT_EQ(output, "$>\n");
|
||||
#else
|
||||
EXPECT_EQ(output, "tcp_recved\ntcp_write:\n$>\ntcp_output\npbuf_free\n");
|
||||
#endif
|
||||
|
||||
strcpy(cmd, "bgcolor 255 255 255");
|
||||
p.tot_len = (uint16_t)strlen(cmd);
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
#ifndef DEBUG
|
||||
EXPECT_EQ(output, "$>\n");
|
||||
#else
|
||||
EXPECT_EQ(output, "tcp_recved\ntcp_write:\n$>\ntcp_output\npbuf_free\n");
|
||||
#endif
|
||||
|
||||
strcpy(cmd, "text \"This is printed on the display\"");
|
||||
p.tot_len = (uint16_t)strlen(cmd);
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
#ifndef DEBUG
|
||||
EXPECT_EQ(output, "$>\n");
|
||||
#else
|
||||
EXPECT_EQ(output, "tcp_recved\nlcd_display_text @ 10 10 with color 0xFFFFFFFF bg color 0xFFFFFFFF\nThis is printed on the display\ntcp_write:\n$>\ntcp_output\npbuf_free\n");
|
||||
#endif
|
||||
|
||||
strcpy(cmd, "setImage \"test.bmp\"");
|
||||
p.tot_len = (uint16_t)strlen(cmd);
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
#ifndef DEBUG
|
||||
EXPECT_EQ(output, "$>\n");
|
||||
#else
|
||||
EXPECT_EQ(output, "tcp_recved\nlcd_draw_img_from_fs\ntest.bmp @0 0\ntcp_write:\n$>\ntcp_output\npbuf_free\n");
|
||||
#endif
|
||||
|
||||
strcpy(cmd, "setImage \"test.gif\"");
|
||||
p.tot_len = (uint16_t)strlen(cmd);
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
#ifndef DEBUG
|
||||
EXPECT_EQ(output, "[Warning] ( 0) [tcp_cmd]: setimage: File is not a bmp\r\nFile is not a bmp\n\n$>\n");
|
||||
#else
|
||||
EXPECT_EQ(output, "tcp_recved\nlogger_get_timestamp\n[Warning] ( 0) [tcp_cmd]: setimage: File is not a bmp\r\ntcp_write:\nFile is not a bmp\n\ntcp_output\ntcp_write:\n$>\ntcp_output\npbuf_free\n");
|
||||
#endif
|
||||
|
||||
strcpy(cmd, "setGif \"test.gif\"");
|
||||
p.tot_len = (uint16_t)strlen(cmd);
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
#ifndef DEBUG
|
||||
EXPECT_EQ(output, "$>\n");
|
||||
#else
|
||||
EXPECT_EQ(output, "tcp_recved\nlcd_draw_gif_from_fs\ntest.gif @0 0\ntcp_write:\n$>\ntcp_output\npbuf_free\n");
|
||||
#endif
|
||||
|
||||
strcpy(cmd, "setGif \"test.bmp\"");
|
||||
p.tot_len = (uint16_t)strlen(cmd);
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
#ifndef DEBUG
|
||||
EXPECT_EQ(output, "[Warning] ( 0) [tcp_cmd]: setgif: File is not a gif\r\nFile is not a gif\n\n$>\n");
|
||||
#else
|
||||
EXPECT_EQ(output, "tcp_recved\nlogger_get_timestamp\n[Warning] ( 0) [tcp_cmd]: setgif: File is not a gif\r\ntcp_write:\nFile is not a gif\n\ntcp_output\ntcp_write:\n$>\ntcp_output\npbuf_free\n");
|
||||
#endif
|
||||
|
||||
strcpy(cmd, "exit");
|
||||
p.tot_len = (uint16_t)strlen(cmd);
|
||||
|
||||
testing::internal::CaptureStdout();
|
||||
tcp_cmd_recv(NULL, NULL, &p, ERR_OK);
|
||||
output = testing::internal::GetCapturedStdout();
|
||||
#ifndef DEBUG
|
||||
EXPECT_EQ(output, "Exiting...\n\n");
|
||||
#else
|
||||
EXPECT_EQ(output, "tcp_recved\ntcp_write:\nExiting...\n\ntcp_output\nlcd_clear_images\nlcd_clear_text\ntcp_close\ntcp_arg\ntcp_sent\ntcp_recv\ntcp_close\npbuf_free\n");
|
||||
#endif
|
||||
|
||||
free(cmd);
|
||||
}
|
||||
Reference in New Issue
Block a user