last fixes

This commit is contained in:
Obe Van Lierde
2023-11-26 21:54:03 +01:00
parent eda5a045e7
commit 5631d62133

View File

@@ -16,6 +16,7 @@
#define TEXT_LENGHT 200
#define MULTIPLE_REG 0x10
// Global variables
char registers[MAX_REG];
//const char* TAG = "Modbus_TCP"; // Tag used in logs
@@ -32,66 +33,61 @@ static err_t modbus_accept(void *arg, struct tcp_pcb *pcb, err_t err);
*/
static err_t modbus_incomming_data(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err){
int j;
int len;
int lenght;
char extention[EXTENSION_LENGHT];
uint8_t counter;
char *pc;
char text[TEXT_LENGHT];
uint8_t bg_red = 0;
uint8_t bg_green = 0;
uint8_t bg_blue = 0;
uint8_t txt_red = 0;
uint8_t txt_green = 0;
uint8_t txt_blue = 0;
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_bg = 0;
uint32_t result_background = 0;
uint32_t result_txt = 0;
memcpy(text,'_',TEXT_LENGHT); // Putting underscores in the whole array
memcpy(text,'_',TEXT_LENGHT); // Putting underscores in the whole array
text[TEXT_LENGHT-1] = '\0';
if (p != NULL){
//LOG_INFO(TAG, "data not null\n");
// here im going to procces the modbusdata
// here im going to procces the modbusdata
tcp_recved( pcb, p->tot_len );
pc = (char*)p->payload;
len = p->tot_len;
for(int i = 0; i < len; 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
for(uint16_t i = 0; i < p->tot_len; 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)
//LOG_INFO(TAG, "in writing multiple register mode\n");
bg_red = (uint8_t)(registers[14]); // 01
bg_green = (uint8_t)(registers[16]); // 02
bg_blue = (uint8_t)(registers[18]); // 03
txt_red = (uint8_t)(registers[20]); // 04
txt_green = (uint8_t)(registers[22]); // 05
txt_blue = (uint8_t)(registers[24]); // 06
background_red = (uint8_t)(registers[14]); // 01
background_green = (uint8_t)(registers[16]); // 02
background_blue = (uint8_t)(registers[18]); // 03
text_color_red = (uint8_t)(registers[20]); // 04
text_color_green = (uint8_t)(registers[22]); // 05
text_color_blue = (uint8_t)(registers[24]); // 06
nr_img = (uint8_t)(registers[26]); // 07
//LOG_INFO(TAG, "%d %d %d %d %d %d %d ",bg_red,bg_green,bg_blue,txt_red,txt_green,txt_blue,nr_img);
//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);
j = 0;
counter = 0;
for(int i = 28; i < 428; i++){
if(i % 2 == 0){
text[j] = registers[i];
j++;
text[counter] = registers[i];
counter++;
}
}
result_bg = 0xff000000;
result_bg |= ((uint32_t)bg_red) << 16;
result_bg |= ((uint32_t)bg_green) << 8;
result_bg |= bg_blue;
result_background = 0xff000000;
result_background |= ((uint32_t)background_red) << 16;
result_background |= ((uint32_t)background_green) << 8;
result_background |= background_blue;
result_txt = 0xff000000;
result_txt |= ((uint32_t)txt_red) << 16;
result_txt |= ((uint32_t)txt_green) << 8;
result_txt |= txt_blue;
result_txt |= ((uint32_t)text_color_red) << 16;
result_txt |= ((uint32_t)text_color_green) << 8;
result_txt |= text_color_blue;
// proccesing the image index
size_t number_of_files = llfs_file_count(); // How many files that there are
@@ -103,27 +99,25 @@ 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_bg, LCD_FONT24); //When no image
lcd_display_text(text, 10, 10, result_txt, result_background, LCD_FONT24); //When no image
lcd_display_text("FILE NOT IN FILESYSTEM", 10, 75, LCD_RED, LCD_BLACK, LCD_FONT24);
}
else{
lenght = strlen(file_list[nr_img - 1].name); //lenght from filename
strncpy(extention, file_list[nr_img - 1].name + lenght - 3, 3); //putting the last tree digits in string
extention[3] = '\0'; //adding the \0
if(strcmp(extention,"gif") == 0){
lcd_clear_text();
lcd_clear_images();
lcd_stop_all_gifs();
lcd_display_text(text, 10, 10, result_txt, result_bg, LCD_FONT24);
lcd_gif_t* gif = lcd_draw_gif_from_fs(file_list[nr_img - 1].name, 0, 75); //GIF on screen
const char * ext = strrchr(file_list[nr_img - 1].name, '.');
if (ext == NULL) {
// No valid extension found
}
if(strcmp(extention,"bmp") == 0){
if (strcmp(ext,".gif") == 0) {
lcd_clear_text();
lcd_clear_images();
lcd_stop_all_gifs();
lcd_display_text(text, 10, 10, result_txt, result_bg, LCD_FONT24);
lcd_display_text(text, 10, 10, result_txt, 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_draw_img_from_fs(file_list[nr_img - 1].name, 0, 75); //BMP on screen
}
}