From 24226b38cdb0aa757d1961bcbe6dad8a04da8926 Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Tue, 28 Nov 2023 12:45:05 +0100 Subject: [PATCH] modbus_tcp remove comments that bring no extra meaning to the code --- project/Core/Src/modbus_tcp.c | 47 +++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/project/Core/Src/modbus_tcp.c b/project/Core/Src/modbus_tcp.c index b27ce4a..2da8c9e 100644 --- a/project/Core/Src/modbus_tcp.c +++ b/project/Core/Src/modbus_tcp.c @@ -54,7 +54,8 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p uint32_t result_background = 0; uint32_t text_foreground_color = 0; - memset(text, '_', TEXT_LENGTH); // Putting underscores in the whole array + // Putting underscores in the whole array + memset(text, '_', TEXT_LENGTH); text[TEXT_LENGTH - 1] = '\0'; if (p != NULL) { @@ -70,13 +71,13 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p if (registers[MODBUS_MODE] == MULTIPLE_REG) { // Check if it's a Modbus Write Multiple Registers request (0x10) LOG_INFO(TAG, "in writing multiple register mode\n"); - background_red = registers[REG_01]; // 01 - background_green = registers[REG_02]; // 02 - background_blue = registers[REG_03]; // 03 - text_color_red = registers[REG_04]; // 04 - text_color_green = registers[REG_05]; // 05 - text_color_blue = registers[REG_06]; // 06 - nr_img = registers[REG_07]; // 07 + background_red = registers[REG_01]; + background_green = registers[REG_02]; + background_blue = registers[REG_03]; + text_color_red = registers[REG_04]; + text_color_green = registers[REG_05]; + text_color_blue = registers[REG_06]; + nr_img = registers[REG_07]; LOG_INFO(TAG, "%d %d %d %d %d %d %d", background_red, background_green, background_blue, text_color_red, text_color_green, text_color_blue, nr_img); @@ -103,8 +104,8 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p size_t number_of_files = llfs_file_count(); // How many files that there are if (number_of_files > 0) { - llfs_file_t file_list[number_of_files]; // Reserving memory for the list - number_of_files = llfs_file_list(file_list, number_of_files, NULL); // Freed memory filled with the list + llfs_file_t file_list[number_of_files]; + number_of_files = llfs_file_list(file_list, number_of_files, NULL); if (number_of_files < nr_img) { lcd_clear_text(); @@ -112,7 +113,7 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p lcd_stop_all_gifs(); lcd_display_text(text, 10, 10, text_foreground_color, result_background, - LCD_FONT24); // When no image + LCD_FONT24); lcd_display_text("FILE NOT IN FILESYSTEM", 10, 75, LCD_RED, LCD_BLACK, LCD_FONT24); } else { @@ -151,10 +152,14 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p * @brief Sets the function that's being called when theirs incoming data */ static err_t modbus_accept(void* arg, struct tcp_pcb* pcb, err_t err) { - LWIP_UNUSED_ARG(arg); // Eliminates compiler warning about unused arguments - LWIP_UNUSED_ARG(err); // Eliminates compiler warning about unused arguments - tcp_setprio(pcb, TCP_PRIO_MIN); // Sets the priority of a connection. - tcp_recv(pcb, modbus_incoming_data); // Sets which function is being called when new data arrives + LWIP_UNUSED_ARG(arg); + LWIP_UNUSED_ARG(err); + + // Sets the priority of a connection. + tcp_setprio(pcb, TCP_PRIO_MIN); + + // Sets which function is being called when new data arrives + tcp_recv(pcb, modbus_incoming_data); return ERR_OK; } @@ -165,10 +170,14 @@ static err_t modbus_accept(void* arg, struct tcp_pcb* pcb, err_t err) { */ void modbus_init(void) { LOG_INFO(TAG, "Initializing\n"); - modbus_pcb = tcp_new(); // Creating a new tcp pcb - tcp_bind(modbus_pcb, IP_ADDR_ANY, MODBUSPORT); // Bind the modbus_pcb to port 502 + // Creating a new tcp pcb + modbus_pcb = tcp_new(); - modbus_pcb = tcp_listen(modbus_pcb); // Listen - tcp_accept(modbus_pcb, modbus_accept); // Set callback function + // Bind the modbus_pcb to port 502 + tcp_bind(modbus_pcb, IP_ADDR_ANY, MODBUSPORT); + + modbus_pcb = tcp_listen(modbus_pcb); + // Set callback function for incoming connections + tcp_accept(modbus_pcb, modbus_accept); LOG_INFO(TAG, "initialized\n"); }