diff --git a/project/Core/Src/modbus_tcp.c b/project/Core/Src/modbus_tcp.c index d974226..42eea58 100644 --- a/project/Core/Src/modbus_tcp.c +++ b/project/Core/Src/modbus_tcp.c @@ -17,6 +17,7 @@ #define MULTIPLE_REG 0x10 #define REG_LENGTH 428 #define START_DATA 28 +#define MODBUS_MODE 7 #define REG_01 14 #define REG_02 16 #define REG_03 18 @@ -52,9 +53,9 @@ static err_t modbus_incomming_data(void *arg, struct tcp_pcb *pcb, struct pbuf * uint8_t text_color_blue = 0; uint8_t nr_img = 0; uint32_t result_background = 0; - uint32_t result_txt = 0; + uint32_t text_foreground_color = 0; - memcpy(text,'_',TEXT_LENGHT); // Putting underscores in the whole array + memset(text,'_',TEXT_LENGHT); // Putting underscores in the whole array text[TEXT_LENGHT-1] = '\0'; if (p != NULL){ @@ -63,11 +64,11 @@ static err_t modbus_incomming_data(void *arg, struct tcp_pcb *pcb, struct pbuf * tcp_recved( pcb, p->tot_len ); pc = (char*)p->payload; - for(uint16_t i = 0; i < p->tot_len; i++) { // putting the bufer in the register array + for(uint16_t i = 0; i < MAX_REG; i++) { // putting the bufer in the register array registers[i] = pc[i]; // getting the error "void value not ignored as it ought to be" on this line } - if(registers[7] == MULTIPLE_REG){ // Check if it's a Modbus Write Multiple Registers request (0x10) + 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 = (uint8_t)(registers[REG_01]); // 01 background_green = (uint8_t)(registers[REG_02]); // 02 @@ -92,10 +93,10 @@ static err_t modbus_incomming_data(void *arg, struct tcp_pcb *pcb, struct pbuf * result_background |= ((uint32_t)background_green) << 8; result_background |= background_blue; - result_txt = 0xff000000; - result_txt |= ((uint32_t)text_color_red) << 16; - result_txt |= ((uint32_t)text_color_green) << 8; - result_txt |= text_color_blue; + text_foreground_color = 0xff000000; + text_foreground_color |= ((uint32_t)text_color_red) << 16; + text_foreground_color |= ((uint32_t)text_color_green) << 8; + text_foreground_color |= text_color_blue; // proccesing the image index size_t number_of_files = llfs_file_count(); // How many files that there are @@ -107,7 +108,7 @@ static err_t modbus_incomming_data(void *arg, struct tcp_pcb *pcb, struct pbuf * lcd_clear_text(); lcd_clear_images(); lcd_stop_all_gifs(); - lcd_display_text(text, 10, 10, result_txt, result_background, LCD_FONT24); //When no image + lcd_display_text(text, 10, 10, text_foreground_color, result_background, LCD_FONT24); //When no image lcd_display_text("FILE NOT IN FILESYSTEM", 10, 75, LCD_RED, LCD_BLACK, LCD_FONT24); } else{ @@ -119,13 +120,13 @@ static err_t modbus_incomming_data(void *arg, struct tcp_pcb *pcb, struct pbuf * lcd_clear_text(); lcd_clear_images(); lcd_stop_all_gifs(); - lcd_display_text(text, 10, 10, result_txt, result_background, LCD_FONT24); + lcd_display_text(text, 10, 10, text_foreground_color, result_background, LCD_FONT24); lcd_gif_t* gif = lcd_draw_gif_from_fs(file_list[nr_img - 1].name, 0, 75); //GIF on screen } else if (strcmp(ext,".bmp") == 0) { lcd_clear_text(); lcd_clear_images(); lcd_stop_all_gifs(); - lcd_display_text(text, 10, 10, result_txt, result_background, LCD_FONT24); + lcd_display_text(text, 10, 10, text_foreground_color, result_background, LCD_FONT24); lcd_draw_img_from_fs(file_list[nr_img - 1].name, 0, 75); //BMP on screen } }