modbus_tcp
remove redundant variables
This commit is contained in:
@@ -47,15 +47,8 @@ static err_t modbus_accept(void* arg, struct tcp_pcb* pcb, err_t err);
|
||||
static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
|
||||
uint8_t counter;
|
||||
char text[TEXT_LENGTH];
|
||||
uint8_t background_red = 0;
|
||||
uint8_t background_green = 0;
|
||||
uint8_t background_blue = 0;
|
||||
uint8_t text_color_red = 0;
|
||||
uint8_t text_color_green = 0;
|
||||
uint8_t text_color_blue = 0;
|
||||
uint8_t nr_img = 0;
|
||||
uint32_t result_background = 0;
|
||||
uint32_t text_foreground_color = 0;
|
||||
uint32_t result_background = 0xff000000;
|
||||
uint32_t text_foreground_color = 0xff000000;
|
||||
|
||||
// Putting underscores in the whole array
|
||||
memset(text, '_', TEXT_LENGTH);
|
||||
@@ -74,16 +67,10 @@ 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_COLOR_B_RED];
|
||||
background_green = registers[REG_COLOR_B_GREEN];
|
||||
background_blue = registers[REG_COLOR_B_BLUE];
|
||||
text_color_red = registers[REG_COLOR_F_RED];
|
||||
text_color_green = registers[REG_COLOR_F_GREEN];
|
||||
text_color_blue = registers[REG_COLOR_F_BLUE];
|
||||
nr_img = registers[REG_IMAGE_NR];
|
||||
|
||||
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);
|
||||
LOG_INFO(TAG, "Background R:%d G:%d B:%d\nForeground: R:%d G:%d B:%d\nImage Nr: %d", registers[REG_COLOR_B_RED],
|
||||
registers[REG_COLOR_B_GREEN], registers[REG_COLOR_B_BLUE], registers[REG_COLOR_F_RED], registers[REG_COLOR_F_GREEN],
|
||||
registers[REG_COLOR_F_BLUE], registers[REG_IMAGE_NR]);
|
||||
|
||||
counter = 0;
|
||||
for (int i = START_DATA; i < REG_LENGTH; i++) {
|
||||
@@ -93,15 +80,13 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p
|
||||
}
|
||||
}
|
||||
|
||||
result_background = 0xff000000;
|
||||
result_background |= ((uint32_t)background_red) << 16;
|
||||
result_background |= ((uint32_t)background_green) << 8;
|
||||
result_background |= background_blue;
|
||||
result_background |= ((uint32_t)registers[REG_COLOR_B_RED]) << 16;
|
||||
result_background |= ((uint32_t)registers[REG_COLOR_B_GREEN]) << 8;
|
||||
result_background |= (uint32_t)registers[REG_COLOR_B_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;
|
||||
text_foreground_color |= ((uint32_t)registers[REG_COLOR_F_RED]) << 16;
|
||||
text_foreground_color |= ((uint32_t)registers[REG_COLOR_F_GREEN]) << 8;
|
||||
text_foreground_color |= (uint32_t)registers[REG_COLOR_F_BLUE];
|
||||
|
||||
// Processing the image index
|
||||
size_t number_of_files = llfs_file_count(); // How many files that there are
|
||||
@@ -110,7 +95,7 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p
|
||||
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) {
|
||||
if (number_of_files < registers[REG_IMAGE_NR]) {
|
||||
lcd_clear_text();
|
||||
lcd_clear_images();
|
||||
lcd_stop_all_gifs();
|
||||
@@ -120,7 +105,7 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p
|
||||
|
||||
lcd_display_text("FILE NOT IN FILESYSTEM", 10, 75, LCD_RED, LCD_BLACK, LCD_FONT24);
|
||||
} else {
|
||||
const char* ext = strrchr(file_list[nr_img - 1].name, '.');
|
||||
const char* ext = strrchr(file_list[registers[REG_IMAGE_NR] - 1].name, '.');
|
||||
if (ext == NULL) {
|
||||
// No valid extension found
|
||||
}
|
||||
@@ -130,13 +115,13 @@ 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);
|
||||
lcd_gif_t* gif = lcd_draw_gif_from_fs(file_list[nr_img - 1].name, 0, 75); // GIF on screen
|
||||
lcd_gif_t* gif = lcd_draw_gif_from_fs(file_list[registers[REG_IMAGE_NR] - 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, text_foreground_color, result_background, LCD_FONT24);
|
||||
lcd_draw_img_from_fs(file_list[nr_img - 1].name, 0, 75); // BMP on screen
|
||||
lcd_draw_img_from_fs(file_list[registers[REG_IMAGE_NR] - 1].name, 0, 75); // BMP on screen
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user