From 1850f1de59e3b70fe5641349bafb6ede0ed42ff3 Mon Sep 17 00:00:00 2001 From: Obe Van Lierde Date: Tue, 7 Nov 2023 00:41:31 +0100 Subject: [PATCH] check --- project/Core/Src/modbus.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/project/Core/Src/modbus.c b/project/Core/Src/modbus.c index 6dade1d..9b6dee0 100644 --- a/project/Core/Src/modbus.c +++ b/project/Core/Src/modbus.c @@ -14,14 +14,6 @@ struct Data_Modbus {//registers to hold the data of the modbus struct Data_Modbus datamodbus; /* -static void echo_close (struct tcp_pcb *pcb ) -{ - tcp_arg(pcb, NULL); - tcp_sent(pcb, NULL); - tcp_recv(pcb, NULL); - tcp_close(pcb); -} - static err_t echo_recv( void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err ) { int i; @@ -64,11 +56,14 @@ static err_t echo_recv( void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t er } */ -static void modbus_incomming_data(){ - void *data; - u16_t len; +static err_t modbus_incomming_data(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err){ + int i; + int len; + char *pc; + printf("data incomming\n"); + return ERR_OK; } static err_t modbus_accept(void *arg, struct tcp_pcb *pcb, err_t err ) @@ -76,7 +71,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( err );//Eliminates compiler warning about unused arguments tcp_setprio( pcb, TCP_PRIO_MIN );//Sets the priority of a connection. - tcp_recv( pcb, modbus_incomming_data() );//sets which function is being called when new data arives + tcp_recv( pcb, modbus_incomming_data);//sets which function is being called when new data arives tcp_err( pcb, NULL );//sets the function thats called when an error ocours tcp_poll( pcb, NULL, 4 );//the aplication is being polled every 4 seconds tcp_write( pcb, "TEST\r\n", 8, 0 );//pcb , data , lenght in bytes , apiflags @@ -88,10 +83,10 @@ static err_t modbus_accept(void *arg, struct tcp_pcb *pcb, err_t err ) void modbus_init( void ) { - struct tcp_pcb *tcp_pcb; - tcp_pcb = tcp_new(); - tcp_bind(tcp_pcb, IP_ADDR_ANY, MODBUSPOORT); + struct tcp_pcb *modbus_pcb; + modbus_pcb = tcp_new();//creating a new tcp pcb + tcp_bind(modbus_pcb, IP_ADDR_ANY, MODBUSPOORT);//bind the modbus_pcb to port 502 - tcp_pcb = tcp_listen( tcp_pcb ); - tcp_accept( tcp_pcb, modbus_accept ); + modbus_pcb = tcp_listen( modbus_pcb );//listen + tcp_accept(modbus_pcb, modbus_accept);//set callback function }