This commit is contained in:
Obe Van Lierde
2023-11-07 00:41:31 +01:00
parent 59712ff495
commit 1850f1de59

View File

@@ -14,14 +14,6 @@ struct Data_Modbus {//registers to hold the data of the modbus
struct Data_Modbus datamodbus; 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 ) static err_t echo_recv( void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err )
{ {
int i; 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(){ static err_t modbus_incomming_data(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err){
void *data; int i;
u16_t len; 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 ) 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( 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_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_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_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 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 ) void modbus_init( void )
{ {
struct tcp_pcb *tcp_pcb; struct tcp_pcb *modbus_pcb;
tcp_pcb = tcp_new(); modbus_pcb = tcp_new();//creating a new tcp pcb
tcp_bind(tcp_pcb, IP_ADDR_ANY, MODBUSPOORT); tcp_bind(modbus_pcb, IP_ADDR_ANY, MODBUSPOORT);//bind the modbus_pcb to port 502
tcp_pcb = tcp_listen( tcp_pcb ); modbus_pcb = tcp_listen( modbus_pcb );//listen
tcp_accept( tcp_pcb, modbus_accept ); tcp_accept(modbus_pcb, modbus_accept);//set callback function
} }