format format modbus-tcp
This commit is contained in:
@@ -7,100 +7,100 @@ char tcp_buffer[1024];
|
|||||||
char registers[MAX_REG];
|
char registers[MAX_REG];
|
||||||
|
|
||||||
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 i;
|
int i;
|
||||||
int len;
|
int len;
|
||||||
char *pc;
|
char *pc;
|
||||||
uint8_t bg_red = 0;
|
uint8_t bg_red = 0;
|
||||||
uint8_t bg_green = 0;
|
uint8_t bg_green = 0;
|
||||||
uint8_t bg_blue = 0;
|
uint8_t bg_blue = 0;
|
||||||
uint8_t txt_red = 0;
|
uint8_t txt_red = 0;
|
||||||
uint8_t txt_green = 0;
|
uint8_t txt_green = 0;
|
||||||
uint8_t txt_blue = 0;
|
uint8_t txt_blue = 0;
|
||||||
uint8_t nr_img = 0;
|
uint8_t nr_img = 0;
|
||||||
uint32_t result_bg = 0;
|
uint32_t result_bg = 0;
|
||||||
uint32_t result_txt = 0;
|
uint32_t result_txt = 0;
|
||||||
uint32_t result = 0;
|
uint32_t result = 0;
|
||||||
|
|
||||||
char text[200];
|
char text[200];
|
||||||
|
|
||||||
for(i = 0; i < 100;i++){
|
for(i = 0; i < 100;i++){
|
||||||
text[i] = 95; // _
|
text[i] = 95; // _
|
||||||
}
|
}
|
||||||
text[199] = '\0';
|
text[199] = '\0';
|
||||||
|
|
||||||
if (p != NULL){
|
if (p != NULL){
|
||||||
printf("data not null\n");
|
printf("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;
|
len =p->tot_len;
|
||||||
|
|
||||||
//putting the bufer in the register array
|
//putting the bufer in the register array
|
||||||
for( i=0; i<len; i++ ) {
|
for( i=0; i<len; i++ ) {
|
||||||
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] == 0x10){// Check if it's a Modbus Write Multiple Registers request (0x10)
|
if(registers[7] == 0x10){// Check if it's a Modbus Write Multiple Registers request (0x10)
|
||||||
printf("in writing multiple register mode\n");
|
printf("in writing multiple register mode\n");
|
||||||
}
|
}
|
||||||
//putting the values from the array in their variable
|
//putting the values from the array in their variable
|
||||||
bg_red = (uint8_t)(registers[14]);//01
|
bg_red = (uint8_t)(registers[14]);//01
|
||||||
bg_green = (uint8_t)(registers[16]);//02
|
bg_green = (uint8_t)(registers[16]);//02
|
||||||
bg_blue = (uint8_t)(registers[18]);//03
|
bg_blue = (uint8_t)(registers[18]);//03
|
||||||
txt_red = (uint8_t)(registers[20]);//04
|
txt_red = (uint8_t)(registers[20]);//04
|
||||||
txt_green = (uint8_t)(registers[22]);//05
|
txt_green = (uint8_t)(registers[22]);//05
|
||||||
txt_blue = (uint8_t)(registers[24]);//06
|
txt_blue = (uint8_t)(registers[24]);//06
|
||||||
nr_img = (uint8_t)(registers[26]);//07
|
nr_img = (uint8_t)(registers[26]);//07
|
||||||
//registers[428] //208
|
//registers[428] //208
|
||||||
|
|
||||||
printf("%d %d %d %d %d %d %d ",bg_red,bg_green,bg_blue,txt_red,txt_green,txt_blue,nr_img);
|
printf("%d %d %d %d %d %d %d ",bg_red,bg_green,bg_blue,txt_red,txt_green,txt_blue,nr_img);
|
||||||
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for(i = 28;i < 428;i++){
|
for(i = 28;i < 428;i++){
|
||||||
if(i % 2 == 0){
|
if(i % 2 == 0){
|
||||||
text[j]=registers[i];
|
text[j]=registers[i];
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(i = 0; i < 100;i++){
|
for(i = 0; i < 100;i++){
|
||||||
printf("%c ",text[i]);
|
printf("%c ",text[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
//processing the text data to screen
|
//processing the text data to screen
|
||||||
char *textstring = text;
|
char *textstring = text;
|
||||||
|
|
||||||
result_bg = 0xff000000;
|
result_bg = 0xff000000;
|
||||||
result_bg |= ((uint32_t)bg_red) << 16;
|
result_bg |= ((uint32_t)bg_red) << 16;
|
||||||
result_bg |= ((uint32_t)bg_green) << 8;
|
result_bg |= ((uint32_t)bg_green) << 8;
|
||||||
result_bg |= bg_blue;
|
result_bg |= bg_blue;
|
||||||
|
|
||||||
result_txt = 0xff000000;
|
result_txt = 0xff000000;
|
||||||
result_txt |= ((uint32_t)txt_red) << 16;
|
result_txt |= ((uint32_t)txt_red) << 16;
|
||||||
result_txt |= ((uint32_t)txt_green) << 8;
|
result_txt |= ((uint32_t)txt_green) << 8;
|
||||||
result_txt |= txt_blue;
|
result_txt |= txt_blue;
|
||||||
|
|
||||||
lcd_display_text(textstring, 10, 50, result_txt, result_bg, LCD_FONT24);
|
lcd_display_text(textstring, 10, 50, result_txt, result_bg, LCD_FONT24);
|
||||||
|
|
||||||
//proccesing the image index
|
//proccesing the image index
|
||||||
|
|
||||||
size_t number_of_files = llfs_file_count();//hoeveel files er zijn
|
size_t number_of_files = llfs_file_count();//hoeveel files er zijn
|
||||||
|
|
||||||
llfs_file_t file_list[number_of_files];//geheugen vrijmaken voor files
|
llfs_file_t file_list[number_of_files];//geheugen vrijmaken voor files
|
||||||
|
|
||||||
number_of_files = llfs_file_list(file_list, number_of_files, NULL);//vrijgemaakt geheugen invullen met de lijst
|
number_of_files = llfs_file_list(file_list, number_of_files, NULL);//vrijgemaakt geheugen invullen met de lijst
|
||||||
|
|
||||||
lcd_display_text(file_list[nr_img - 1].name, 10, 75, LCD_COLOR_MAGENTA, LCD_COLOR_YELLOW, LCD_FONT24);//putting the file name on screen
|
lcd_display_text(file_list[nr_img - 1].name, 10, 75, LCD_COLOR_MAGENTA, LCD_COLOR_YELLOW, LCD_FONT24);//putting the file name on screen
|
||||||
|
|
||||||
//functie_voor_naam
|
//functie_voor_naam
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else if (err == ERR_OK){
|
} else if (err == ERR_OK){
|
||||||
tcp_close(pcb);//when everithing was ok close the tcpconnection
|
tcp_close(pcb);//when everithing was ok close the tcpconnection
|
||||||
}
|
}
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static err_t modbus_accept(void *arg, struct tcp_pcb *pcb, err_t err )
|
static err_t modbus_accept(void *arg, struct tcp_pcb *pcb, err_t err )
|
||||||
|
|||||||
Reference in New Issue
Block a user