last fixes
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
#define TEXT_LENGHT 200
|
#define TEXT_LENGHT 200
|
||||||
#define MULTIPLE_REG 0x10
|
#define MULTIPLE_REG 0x10
|
||||||
|
|
||||||
|
|
||||||
// Global variables
|
// Global variables
|
||||||
char registers[MAX_REG];
|
char registers[MAX_REG];
|
||||||
//const char* TAG = "Modbus_TCP"; // Tag used in logs
|
//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){
|
static err_t modbus_incomming_data(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err){
|
||||||
int j;
|
uint8_t counter;
|
||||||
int len;
|
|
||||||
int lenght;
|
|
||||||
char extention[EXTENSION_LENGHT];
|
|
||||||
char *pc;
|
char *pc;
|
||||||
char text[TEXT_LENGHT];
|
char text[TEXT_LENGHT];
|
||||||
uint8_t bg_red = 0;
|
uint8_t background_red = 0;
|
||||||
uint8_t bg_green = 0;
|
uint8_t background_green = 0;
|
||||||
uint8_t bg_blue = 0;
|
uint8_t background_blue = 0;
|
||||||
uint8_t txt_red = 0;
|
uint8_t text_color_red = 0;
|
||||||
uint8_t txt_green = 0;
|
uint8_t text_color_green = 0;
|
||||||
uint8_t txt_blue = 0;
|
uint8_t text_color_blue = 0;
|
||||||
uint8_t nr_img = 0;
|
uint8_t nr_img = 0;
|
||||||
uint32_t result_bg = 0;
|
uint32_t result_background = 0;
|
||||||
uint32_t result_txt = 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';
|
text[TEXT_LENGHT-1] = '\0';
|
||||||
|
|
||||||
if (p != NULL){
|
if (p != NULL){
|
||||||
//LOG_INFO(TAG, "data not null\n");
|
//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 );
|
tcp_recved( pcb, p->tot_len );
|
||||||
pc = (char*)p->payload;
|
pc = (char*)p->payload;
|
||||||
len = p->tot_len;
|
|
||||||
|
|
||||||
|
for(uint16_t i = 0; i < p->tot_len; i++) { // putting the bufer in the register array
|
||||||
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
|
||||||
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[7] == MULTIPLE_REG){ // Check if it's a Modbus Write Multiple Registers request (0x10)
|
||||||
//LOG_INFO(TAG, "in writing multiple register mode\n");
|
//LOG_INFO(TAG, "in writing multiple register mode\n");
|
||||||
bg_red = (uint8_t)(registers[14]); // 01
|
background_red = (uint8_t)(registers[14]); // 01
|
||||||
bg_green = (uint8_t)(registers[16]); // 02
|
background_green = (uint8_t)(registers[16]); // 02
|
||||||
bg_blue = (uint8_t)(registers[18]); // 03
|
background_blue = (uint8_t)(registers[18]); // 03
|
||||||
txt_red = (uint8_t)(registers[20]); // 04
|
text_color_red = (uint8_t)(registers[20]); // 04
|
||||||
txt_green = (uint8_t)(registers[22]); // 05
|
text_color_green = (uint8_t)(registers[22]); // 05
|
||||||
txt_blue = (uint8_t)(registers[24]); // 06
|
text_color_blue = (uint8_t)(registers[24]); // 06
|
||||||
nr_img = (uint8_t)(registers[26]); // 07
|
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++){
|
for(int i = 28; i < 428; i++){
|
||||||
if(i % 2 == 0){
|
if(i % 2 == 0){
|
||||||
text[j] = registers[i];
|
text[counter] = registers[i];
|
||||||
j++;
|
counter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result_bg = 0xff000000;
|
result_background = 0xff000000;
|
||||||
result_bg |= ((uint32_t)bg_red) << 16;
|
result_background |= ((uint32_t)background_red) << 16;
|
||||||
result_bg |= ((uint32_t)bg_green) << 8;
|
result_background |= ((uint32_t)background_green) << 8;
|
||||||
result_bg |= bg_blue;
|
result_background |= background_blue;
|
||||||
|
|
||||||
result_txt = 0xff000000;
|
result_txt = 0xff000000;
|
||||||
result_txt |= ((uint32_t)txt_red) << 16;
|
result_txt |= ((uint32_t)text_color_red) << 16;
|
||||||
result_txt |= ((uint32_t)txt_green) << 8;
|
result_txt |= ((uint32_t)text_color_green) << 8;
|
||||||
result_txt |= txt_blue;
|
result_txt |= text_color_blue;
|
||||||
// proccesing the image index
|
// proccesing the image index
|
||||||
size_t number_of_files = llfs_file_count(); // How many files that there are
|
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_text();
|
||||||
lcd_clear_images();
|
lcd_clear_images();
|
||||||
lcd_stop_all_gifs();
|
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);
|
lcd_display_text("FILE NOT IN FILESYSTEM", 10, 75, LCD_RED, LCD_BLACK, LCD_FONT24);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
lenght = strlen(file_list[nr_img - 1].name); //lenght from filename
|
const char * ext = strrchr(file_list[nr_img - 1].name, '.');
|
||||||
|
if (ext == NULL) {
|
||||||
strncpy(extention, file_list[nr_img - 1].name + lenght - 3, 3); //putting the last tree digits in string
|
// No valid extension found
|
||||||
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
|
|
||||||
}
|
}
|
||||||
if(strcmp(extention,"bmp") == 0){
|
if (strcmp(ext,".gif") == 0) {
|
||||||
lcd_clear_text();
|
lcd_clear_text();
|
||||||
lcd_clear_images();
|
lcd_clear_images();
|
||||||
lcd_stop_all_gifs();
|
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
|
lcd_draw_img_from_fs(file_list[nr_img - 1].name, 0, 75); //BMP on screen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user