Most changes okay, code works

This commit is contained in:
Roelandts_Gert
2023-12-11 12:10:46 +01:00
parent f9eb677dc0
commit 4b75f21a7d
3 changed files with 53 additions and 46 deletions

View File

@@ -1,9 +1,8 @@
/* /**
* cmd.h * @file tcp_cmd.h
* * @brief TCP CMD interface
* Created on: 13 Nov 2023 * @author Gert R.
* Author: gertr */
*/
#ifndef INC_TCP_CMD_H_ #ifndef INC_TCP_CMD_H_
#define INC_TCP_CMD_H_ #define INC_TCP_CMD_H_

View File

@@ -32,6 +32,7 @@
#include "tftp.h" #include "tftp.h"
#include "modbus_tcp.h" #include "modbus_tcp.h"
#include "UDP_broadcast.h" #include "UDP_broadcast.h"
#include "tcp_cmd.h"
/* USER CODE END Includes */ /* USER CODE END Includes */
@@ -136,6 +137,9 @@ int main(void)
/* Initialize the tftp server */ /* Initialize the tftp server */
tftp_server_init(); tftp_server_init();
/* Initialize tcp command interface*/
tcp_cmd_init();
/* Initialize Modbus*/ /* Initialize Modbus*/
modbus_init(); modbus_init();

View File

@@ -1,13 +1,12 @@
/* /**
* cmd.c * @file tcp_cmd.c
* * @brief TCP CMD interface
* Created on: 13 Nov 2023 * @author Gert R.
* Author: Gert Roelandts
*/ */
#include <tcp_cmd.h> #include "tcp_cmd.h"
uint32_t result_txt = 0xff000000; // Store text color static uint32_t result_txt = 0xff000000; // Store text color
uint32_t result_bg = 0xff000000; // Store background color static uint32_t result_bg = 0xff000000; // Store background color
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);
@@ -17,7 +16,6 @@ static void tcp_cmd_close(struct tcp_pcb* pcb) {
} }
static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) { static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
size_t i;
size_t len; size_t len;
size_t number_of_files; size_t number_of_files;
uint8_t file_in_fs; uint8_t file_in_fs;
@@ -57,8 +55,8 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t
"listImages: laat een lijst zien van de mogelijke afbeeldingen\r\n" "listImages: laat een lijst zien van de mogelijke afbeeldingen\r\n"
"setImage : veranderd te afbeelding (naam_afbeelding)\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); "exit : sluit de verbinding\r\n", 354, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
tcp_output(pcb);
} else if (!strncmp(tcp_buffer, "text ", 5)) { } else if (!strncmp(tcp_buffer, "text ", 5)) {
size_t i;
for (i = 0; i < len - 4; i++) { for (i = 0; i < len - 4; i++) {
text[i] = tcp_buffer[i + 5]; text[i] = tcp_buffer[i + 5];
} }
@@ -93,14 +91,17 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t
} else if (!strncmp(tcp_buffer, "listImages", 10)) { } else if (!strncmp(tcp_buffer, "listImages", 10)) {
number_of_files = llfs_file_count(); number_of_files = llfs_file_count();
if (number_of_files > 0) {
llfs_file_t file_list[number_of_files]; llfs_file_t file_list[number_of_files];
number_of_files = llfs_file_list(file_list, number_of_files, NULL); number_of_files = llfs_file_list(file_list, number_of_files, NULL);
for (size_t i = 0; i < number_of_files; i++) { 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, 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); 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);
}
check = 1; check = 1;
} else if (!strncmp(tcp_buffer, "setImage", 8)) { } else if (!strncmp(tcp_buffer, "setImage", 8)) {
@@ -116,6 +117,7 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t
number_of_files = llfs_file_count(); number_of_files = llfs_file_count();
if(number_of_files > 0) {
llfs_file_t file_list[number_of_files]; llfs_file_t file_list[number_of_files];
number_of_files = llfs_file_list(file_list, number_of_files, NULL); number_of_files = llfs_file_list(file_list, number_of_files, NULL);
@@ -139,6 +141,9 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t
} else { } else {
tcp_write(pcb, "Extension NOT supported\n\r", 25, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE); 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; check = 1;
} else if (!strncmp(tcp_buffer, "exit", 4)) { } else if (!strncmp(tcp_buffer, "exit", 4)) {
@@ -189,7 +194,6 @@ static err_t tcp_cmd_accept(void* arg, struct tcp_pcb* pcb, err_t err) {
void tcp_cmd_init(void) { void tcp_cmd_init(void) {
struct tcp_pcb* tcp_pcb; struct tcp_pcb* tcp_pcb;
tcp_pcb = tcp_new();
tcp_bind(tcp_pcb, IP_ADDR_ANY, 23); tcp_bind(tcp_pcb, IP_ADDR_ANY, 23);
tcp_pcb = tcp_listen(tcp_pcb); tcp_pcb = tcp_listen(tcp_pcb);