Merge branch 'Modbus_TCP_Obe' of https://github.com/Sani7/2023-Webservices_And_Applications into Modbus_TCP_Obe
This commit is contained in:
@@ -15,8 +15,8 @@
|
||||
|
||||
static const char* TAG = "UDP_broadcast"; // Tag used in logs
|
||||
static owner_details_t udp_owner;
|
||||
static uint16_t owner_name_x_pos;
|
||||
static uint16_t owner_name_y_pos;
|
||||
static uint32_t owner_name_x_pos;
|
||||
static uint32_t owner_name_y_pos;
|
||||
|
||||
// Functions
|
||||
static void udp_broadcast_set_owner_details_mac(void);
|
||||
@@ -388,7 +388,7 @@ err_t udp_broadcast_connection_init(void) {
|
||||
*
|
||||
* - ERR_ARG. one or both arguments of udp_broadcast_set_owner_details() are NULL pointers
|
||||
*/
|
||||
err_t udp_broadcast_init(uint16_t x_pos, uint16_t y_pos) {
|
||||
err_t udp_broadcast_init(uint32_t x_pos, uint32_t y_pos) {
|
||||
owner_name_x_pos = x_pos;
|
||||
owner_name_y_pos = y_pos;
|
||||
if(udp_broadcast_set_owner_details("name", "default") != ERR_OK){
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* @brief LCD API implementation
|
||||
* @author Tim S.
|
||||
* @author Lorenz C.
|
||||
* @author Sander S.
|
||||
*/
|
||||
|
||||
#include "lcd_api.h"
|
||||
@@ -84,7 +85,7 @@ void lcd_task(void) {
|
||||
}
|
||||
}
|
||||
|
||||
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, uint32_t x_pos, uint32_t y_pos, uint32_t color, uint32_t bg_color, sFONT* font) {
|
||||
BSP_LCD_SelectLayer(1);
|
||||
LOG_INFO(TAG, "Display text: %s @x=%d,y=%d", text, x_pos, y_pos);
|
||||
|
||||
@@ -100,7 +101,7 @@ void lcd_display_text(const char* text, uint16_t x_pos, uint16_t y_pos, uint32_t
|
||||
if (tot_length > BSP_LCD_GetXSize()) {
|
||||
for (unsigned int i = 0; i < (unsigned int)strlen(text); i++) {
|
||||
if ((x_pos) > BSP_LCD_GetXSize() - (font->Width) * 2) {
|
||||
if (isalpha(text[i - 1]) && isalpha(text[i])) {
|
||||
if (isalpha((int)text[i - 1]) && isalpha((int)text[i])) {
|
||||
BSP_LCD_DisplayChar(x_pos, y_pos, (uint8_t)'-');
|
||||
} else {
|
||||
BSP_LCD_DisplayChar(x_pos, y_pos, (uint8_t)text[i]);
|
||||
@@ -118,7 +119,7 @@ void lcd_display_text(const char* text, uint16_t x_pos, uint16_t y_pos, uint32_t
|
||||
}
|
||||
|
||||
void lcd_draw_raw_img(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_t x_size, uint32_t y_size, uint32_t color_mode) {
|
||||
LOG_INFO(TAG, "Displaying raw image: @x=%d, @y=%d, width=%d, height=%d", x_pos, y_pos, x_size, y_size);
|
||||
LOG_INFO(TAG, "Displaying raw image: @x=%lu, @y=%lu, width=%lu, height=%lu", x_pos, y_pos, x_size, y_size);
|
||||
BSP_LCD_SelectLayer(0);
|
||||
uint32_t address = hLtdcHandler.LayerCfg[1].FBStartAdress + (((BSP_LCD_GetXSize() * y_pos) + x_pos) * (4));
|
||||
void* p_dst = (void*)address;
|
||||
@@ -153,13 +154,13 @@ void lcd_draw_raw_img(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_
|
||||
}
|
||||
|
||||
void lcd_draw_bmp_img(uint8_t* bmp_buff, uint32_t x_pos, uint32_t y_pos) {
|
||||
LOG_INFO(TAG, "Displaying BMP image: @x=%d, @y=%d", x_pos, y_pos);
|
||||
LOG_INFO(TAG, "Displaying BMP image: @x=%lu, @y=%lu", x_pos, y_pos);
|
||||
BSP_LCD_SelectLayer(0);
|
||||
BSP_LCD_DrawBitmap(x_pos, y_pos, bmp_buff);
|
||||
}
|
||||
|
||||
void lcd_draw_img_from_fs(const char* name, uint32_t x_pos, uint32_t y_pos) {
|
||||
LOG_INFO(TAG, "Displaying BMP image %s: @x=%d, @y=%d", name, x_pos, y_pos);
|
||||
LOG_INFO(TAG, "Displaying BMP image %s: @x=%lu, @y=%lu", name, x_pos, y_pos);
|
||||
BSP_LCD_SelectLayer(0);
|
||||
llfs_file_t* file = llfs_file_open(name);
|
||||
if (file != NULL) {
|
||||
@@ -169,6 +170,16 @@ void lcd_draw_img_from_fs(const char* name, uint32_t x_pos, uint32_t y_pos) {
|
||||
LOG_WARN(TAG, "File \"%s\" not found", name);
|
||||
}
|
||||
|
||||
void lcd_draw_img_from_llfs_file(llfs_file_t* file, uint32_t x_pos, uint32_t y_pos) {
|
||||
LOG_INFO(TAG, "Displaying BMP image from llfs file: @x=%lu, @y=%lu", x_pos, y_pos);
|
||||
BSP_LCD_SelectLayer(0);
|
||||
if (file == NULL) {
|
||||
LOG_WARN(TAG, "File not found");
|
||||
return;
|
||||
}
|
||||
BSP_LCD_DrawBitmap(x_pos, y_pos, (uint8_t*)file->data);
|
||||
}
|
||||
|
||||
void lcd_clear_text(void) {
|
||||
LOG_INFO(TAG, "Clear text");
|
||||
BSP_LCD_SelectLayer(1);
|
||||
@@ -212,7 +223,7 @@ lcd_gif_t* lcd_draw_gif(uint8_t* src, size_t size, uint32_t x_pos, uint32_t y_po
|
||||
// Open the GIF and reset slot values
|
||||
GIF_begin(&(gif->gif), GIF_PALETTE_RGB888);
|
||||
if (GIF_openRAM(&(gif->gif), src, (int)size, gif_draw_cb)) {
|
||||
LOG_INFO(TAG, "Draw GIF: @x=%d, @y=%d with size: %d", x_pos, y_pos, size);
|
||||
LOG_INFO(TAG, "Draw GIF: @x=%lu, @y=%lu with size: %u", x_pos, y_pos, size);
|
||||
gif->src = src;
|
||||
gif->x_pos = x_pos;
|
||||
gif->y_pos = y_pos;
|
||||
@@ -248,6 +259,19 @@ lcd_gif_t* lcd_draw_gif_from_fs(const char* name, uint32_t x_pos, uint32_t y_pos
|
||||
return gif;
|
||||
}
|
||||
|
||||
lcd_gif_t* lcd_draw_gif_from_llfs_file(llfs_file_t* file, uint32_t x_pos, uint32_t y_pos) {
|
||||
BSP_LCD_SelectLayer(0);
|
||||
lcd_gif_t* gif;
|
||||
|
||||
if (file == NULL) {
|
||||
LOG_WARN(TAG, "File not found");
|
||||
return NULL;
|
||||
}
|
||||
// Draw the GIF using the file data
|
||||
gif = lcd_draw_gif((uint8_t*)file->data, file->len, x_pos, y_pos);
|
||||
return gif;
|
||||
}
|
||||
|
||||
void lcd_stop_gif(lcd_gif_t* gif) {
|
||||
free_gif_slot(gif);
|
||||
}
|
||||
|
||||
@@ -23,9 +23,11 @@ const char* TAG = "llfs";
|
||||
static size_t file_count = 0; // Cache for the number of files in the filesystem
|
||||
static FILE* file_table[POSIX_MAX_FILES];
|
||||
|
||||
#ifndef TESTING
|
||||
static int new_file_table_entry(void);
|
||||
static int free_file_table_entry(int file_id);
|
||||
static FILE* file_id_to_stream(int file_id);
|
||||
#endif
|
||||
static uint8_t file_ext_cmp(const char* filename, const char* ext);
|
||||
|
||||
int8_t llfs_init(void) {
|
||||
@@ -107,7 +109,6 @@ llfs_file_t* llfs_file_open(const char* name) {
|
||||
|
||||
llfs_file_t* llfs_next_file(void** mem, char* filter) {
|
||||
struct llfs_data_file* prev_file = (struct llfs_data_file*)*mem;
|
||||
uint8_t filter_ok = 0;
|
||||
|
||||
if (prev_file == NULL) {
|
||||
prev_file = llfs_root;
|
||||
@@ -126,7 +127,6 @@ llfs_file_t* llfs_next_file(void** mem, char* filter) {
|
||||
|
||||
while (prev_file != NULL) {
|
||||
if (file_ext_cmp(prev_file->name, filter)) {
|
||||
filter_ok = 1;
|
||||
break;
|
||||
}
|
||||
prev_file = (struct llfs_data_file*)prev_file->next;
|
||||
@@ -141,6 +141,14 @@ size_t llfs_file_count(void) {
|
||||
return file_count;
|
||||
}
|
||||
|
||||
char* llfs_get_filename_ext(char* filename) {
|
||||
char* dot = strrchr(filename, '.');
|
||||
if (dot == NULL || dot == filename)
|
||||
return NULL;
|
||||
return dot + 1;
|
||||
}
|
||||
|
||||
#ifndef TESTING
|
||||
/**
|
||||
* @brief Newlib open implementation
|
||||
*
|
||||
@@ -409,6 +417,7 @@ static FILE* file_id_to_stream(int file_id) {
|
||||
}
|
||||
return file_table[file_id];
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Check if a filename ends with a given extension
|
||||
@@ -433,3 +442,4 @@ static uint8_t file_ext_cmp(const char* const filename, const char* const ext) {
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,8 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p
|
||||
char text[TEXT_LENGTH];
|
||||
uint32_t result_background = 0xff000000;
|
||||
uint32_t text_foreground_color = 0xff000000;
|
||||
LWIP_UNUSED_ARG(arg); //removes warning
|
||||
|
||||
LWIP_UNUSED_ARG(arg); // This is used to prevent a warning
|
||||
|
||||
// Putting underscores in the whole array
|
||||
memset(text, '_', TEXT_LENGTH);
|
||||
@@ -110,9 +111,9 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p
|
||||
if (ext == NULL) {
|
||||
LOG_CRIT(TAG, "No valid extension found");
|
||||
} else if (strcmp(ext, ".gif") == 0) {
|
||||
lcd_draw_gif_from_fs(file_list[registers[REG_IMAGE_NR] - 1].name, 0, 75);
|
||||
lcd_draw_gif_from_llfs_file(&file_list[registers[REG_IMAGE_NR] - 1], 0, 75);
|
||||
} else if (strcmp(ext, ".bmp") == 0) {
|
||||
lcd_draw_img_from_fs(file_list[registers[REG_IMAGE_NR] - 1].name, 0, 75);
|
||||
lcd_draw_img_from_llfs_file(&file_list[registers[REG_IMAGE_NR] - 1], 0, 75);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,7 +149,7 @@ static err_t modbus_accept(void* arg, struct tcp_pcb* pcb, err_t err) {
|
||||
* @brief Initializes the modbus tcp
|
||||
*/
|
||||
void modbus_init(void) {
|
||||
LOG_INFO(TAG, "Initializing\n");
|
||||
LOG_INFO(TAG, "Initializing");
|
||||
// Creating a new tcp pcb
|
||||
modbus_pcb = tcp_new();
|
||||
|
||||
@@ -158,5 +159,5 @@ void modbus_init(void) {
|
||||
modbus_pcb = tcp_listen(modbus_pcb);
|
||||
// Set callback function for incoming connections
|
||||
tcp_accept(modbus_pcb, modbus_accept);
|
||||
LOG_INFO(TAG, "initialized\n");
|
||||
LOG_INFO(TAG, "initialized");
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
|
||||
#define LOGGER_LEVEL_ALL
|
||||
#include "tftp.h"
|
||||
#ifdef TESTING
|
||||
#include "mocs.h"
|
||||
#endif
|
||||
|
||||
#define VIRT_INDEX_TXT 0
|
||||
#define VIRT_IMAGE_BMP 1
|
||||
@@ -167,7 +170,7 @@ void tftp_close(void* handle) {
|
||||
if (handle == &virt_file[VIRT_TEXT_TXT]) {
|
||||
lcd_clear_images();
|
||||
lcd_clear_text();
|
||||
lcd_display_text((uint8_t*)virt_file[VIRT_TEXT_TXT].data, 0, 0, LCD_COLOR_WHITE, LCD_TRANSPARENT, LCD_FONT16);
|
||||
lcd_display_text((const char*)virt_file[VIRT_TEXT_TXT].data, 0, 0, LCD_COLOR_WHITE, LCD_TRANSPARENT, LCD_FONT16);
|
||||
}
|
||||
|
||||
if (handle == &virt_file[VIRT_INDEX_TXT] || handle == &virt_file[VIRT_IMAGE_BMP]
|
||||
@@ -279,10 +282,11 @@ struct tftp_context tftpContext_s = {.open = tftp_open, .close = tftp_close, .re
|
||||
*/
|
||||
void tftp_server_init(void) {
|
||||
LOG_INFO(TAG, "Initializing tftp server");
|
||||
// init the index.txt virt_file
|
||||
init_index();
|
||||
|
||||
LOG_DEBUG(TAG, "index.txt: %s", virt_file[VIRT_INDEX_TXT].data);
|
||||
// init the virtImage.raw virt_file with 80kb of ram
|
||||
|
||||
// init the virtImage virt_file with 80kb of ram
|
||||
virt_file[VIRT_IMAGE_BMP].data = calloc(IMAGE_BUFFER_SIZE, sizeof(char));
|
||||
if (virt_file[VIRT_IMAGE_BMP].data == NULL) {
|
||||
LOG_FATAL(TAG, "Could not allocate memory for virtImage.bmp/virtImage.gif");
|
||||
|
||||
Reference in New Issue
Block a user