Merge branch 'Modbus_TCP_Obe' of https://github.com/Sani7/2023-Webservices_And_Applications into Modbus_TCP_Obe
This commit is contained in:
@@ -12,8 +12,8 @@
|
|||||||
|
|
||||||
// Defines
|
// Defines
|
||||||
#define MAX_REG 250
|
#define MAX_REG 250
|
||||||
#define EXTENSION_LENGHT 4
|
#define EXTENSION_LENGTH 4
|
||||||
#define TEXT_LENGHT 200
|
#define TEXT_LENGTH 200
|
||||||
#define MULTIPLE_REG 0x10
|
#define MULTIPLE_REG 0x10
|
||||||
#define REG_LENGTH 428
|
#define REG_LENGTH 428
|
||||||
#define START_DATA 28
|
#define START_DATA 28
|
||||||
@@ -26,7 +26,6 @@
|
|||||||
#define REG_06 24
|
#define REG_06 24
|
||||||
#define REG_07 26
|
#define REG_07 26
|
||||||
|
|
||||||
|
|
||||||
// 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
|
||||||
@@ -43,7 +42,7 @@ 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) {
|
static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
|
||||||
uint8_t counter;
|
uint8_t counter;
|
||||||
char* pc;
|
char* pc;
|
||||||
char text[TEXT_LENGHT];
|
char text[TEXT_LENGTH];
|
||||||
uint8_t background_red = 0;
|
uint8_t background_red = 0;
|
||||||
uint8_t background_green = 0;
|
uint8_t background_green = 0;
|
||||||
uint8_t background_blue = 0;
|
uint8_t background_blue = 0;
|
||||||
@@ -54,19 +53,17 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p
|
|||||||
uint32_t result_background = 0;
|
uint32_t result_background = 0;
|
||||||
uint32_t text_foreground_color = 0;
|
uint32_t text_foreground_color = 0;
|
||||||
|
|
||||||
|
memset(text, '_', TEXT_LENGTH); // Putting underscores in the whole array
|
||||||
memset(text,'_',TEXT_LENGHT); // Putting underscores in the whole array
|
text[TEXT_LENGTH - 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");
|
||||||
// Procces the modbusdata
|
// Process the modbus data
|
||||||
tcp_recved(pcb, p->tot_len);
|
tcp_recved(pcb, p->tot_len);
|
||||||
pc = (char*)p->payload;
|
pc = (char*)p->payload;
|
||||||
|
|
||||||
for(uint16_t i = 0; i < MAX_REG; i++) { // putting the bufer in the register array
|
for (uint16_t i = 0; i < MAX_REG; i++) { // Putting the buffer 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[MODBUS_MODE] == 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)
|
||||||
@@ -99,16 +96,20 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p
|
|||||||
text_foreground_color |= ((uint32_t)text_color_red) << 16;
|
text_foreground_color |= ((uint32_t)text_color_red) << 16;
|
||||||
text_foreground_color |= ((uint32_t)text_color_green) << 8;
|
text_foreground_color |= ((uint32_t)text_color_green) << 8;
|
||||||
text_foreground_color |= text_color_blue;
|
text_foreground_color |= text_color_blue;
|
||||||
// proccesing the image index
|
// Processing 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
|
||||||
if(number_of_files > 0){
|
|
||||||
llfs_file_t file_list[number_of_files]; // Reserving memory for the list
|
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
|
number_of_files = llfs_file_list(file_list, number_of_files, NULL); // Freed memory filled with the list
|
||||||
|
|
||||||
if (number_of_files < nr_img) {
|
if (number_of_files < nr_img) {
|
||||||
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, text_foreground_color, 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);
|
lcd_display_text("FILE NOT IN FILESYSTEM", 10, 75, LCD_RED, LCD_BLACK, LCD_FONT24);
|
||||||
} else {
|
} else {
|
||||||
const char* ext = strrchr(file_list[nr_img - 1].name, '.');
|
const char* ext = strrchr(file_list[nr_img - 1].name, '.');
|
||||||
@@ -119,6 +120,7 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p
|
|||||||
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, text_foreground_color, 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
|
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) {
|
} else if (strcmp(ext, ".bmp") == 0) {
|
||||||
@@ -129,7 +131,6 @@ static err_t modbus_incoming_data(void* arg, struct tcp_pcb* pcb, struct pbuf* p
|
|||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -149,7 +150,7 @@ 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(arg); // Eliminates compiler warning about unused arguments
|
||||||
LWIP_UNUSED_ARG(err); // 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_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
|
tcp_recv(pcb, modbus_incoming_data); // Sets which function is being called when new data arrives
|
||||||
|
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user