renamed files from cmd to tcp_cmd

This commit is contained in:
Roelandts_Gert
2023-11-22 17:45:18 +01:00
committed by Sander Speetjens
parent 61d2994e40
commit 6de8684d89
4 changed files with 42 additions and 271 deletions

View File

@@ -1,22 +0,0 @@
/*
* cmd.h
*
* Created on: 13 Nov 2023
* Author: gertr
*/
#ifndef INC_CMD_H_
#define INC_CMD_H_
#include "lcd_api.h"
#include "llfs.h"
#include "log.h"
#include <tcp.h>
#include <stdio.h>
#include <string.h>
void tcp_cmd_init( void );
#endif /* INC_CMD_H_ */

View File

@@ -1,197 +0,0 @@
/*
* cmd.c
*
* Created on: 13 Nov 2023
* Author: Gert Roelandts
*/
#include "cmd.h"
uint32_t result_txt = 0xff000000; // Store text color
uint32_t result_bg = 0xff000000; // Store background color
static void tcp_cmd_close(struct tcp_pcb* pcb) {
tcp_arg(pcb, NULL);
tcp_sent(pcb, NULL);
tcp_recv(pcb, NULL);
tcp_close(pcb);
}
static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
size_t i;
size_t len;
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;
size_t number_of_files;
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];
}
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, 0);
tcp_output(pcb);
} else if (!strncmp(tcp_buffer, "text ", 5)) {
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, LCD_FONT16);
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();
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);
}
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];
}
for (size_t i = 0; i < 3; i++) {
extension[i] = tcp_buffer[i + len - 3];
}
filename[sizeof(filename) - 1] = '\0';
extension[3] = '\0';
number_of_files = llfs_file_count();
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;
}
}
// 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);
}
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, 0);
}
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, 0);
}
return 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);
tcp_setprio(pcb, TCP_PRIO_MIN);
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, 0);
tcp_sent(pcb, NULL);
return ERR_OK;
}
void tcp_cmd_init(void) {
struct tcp_pcb* tcp_pcb;
tcp_pcb = tcp_new();
tcp_bind(tcp_pcb, IP_ADDR_ANY, 23);
tcp_pcb = tcp_listen(tcp_pcb);
tcp_accept(tcp_pcb, tcp_cmd_accept);
}

View File

@@ -32,7 +32,7 @@
#include "tftp.h"
#include "modbus_tcp.h"
#include "UDP_broadcast.h"
#include "cmd.h"
#include "tcp_cmd.h"
#include "website_backend.h"
#include "cmd.h"

View File

@@ -1,9 +1,10 @@
/**
* @file tcp_cmd.c
* @brief TCP CMD interface
* @author Gert R.
/*
* cmd.c
*
* Created on: 13 Nov 2023
* Author: Gert Roelandts
*/
#include "tcp_cmd.h"
#include <tcp_cmd.h>
static uint32_t result_txt = 0xff000000; // Store text color
static uint32_t result_bg = 0xff000000; // Store background color
@@ -16,8 +17,8 @@ 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) {
size_t i;
size_t len;
size_t number_of_files;
uint8_t file_in_fs;
uint8_t check = 0;
@@ -36,6 +37,7 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t
char* endptr;
if (err == ERR_OK && p != NULL) {
tcp_recved(pcb, p->tot_len);
pc = (char*)p->payload;
@@ -47,23 +49,20 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t
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);
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);
lcd_display_text(text, 10, 10, result_txt, LCD_FONT16);
check = 1;
} else if (!strncmp(tcp_buffer, "color", 5)) {
@@ -91,13 +90,10 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t
} 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);
llfs_file_t file_list[number_of_files];
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);
}
} else {
@@ -118,32 +114,29 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t
number_of_files = llfs_file_count();
if (number_of_files > 0) {
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);
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;
}
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;
}
}
// 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);
}
// 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, "NO files in filesystem\r\n", 24, 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);
}
check = 1;
@@ -155,8 +148,7 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t
}
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);
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);
@@ -173,7 +165,7 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t
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);
tcp_write(pcb, "User: ", 6, 0);
}
return ERR_OK;
@@ -186,12 +178,10 @@ 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_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);
return ERR_OK;
}