2024-06-25 06:55 AM
2024-06-25 07:27 AM
Hello @VSomasekhar,
By tweaking the options in lwipopts.h, it should be possible to receive more incoming connections: MEMP_NUM_TCP_PCB, MEMP_NUM_TCP_PCB_LISTEN, MEMP_NUM_NETCONN, etc...
You can refer to the following link for lwIP internal memory pool management: http://www.nongnu.org/lwip/2_0_x/group__lwip__opts__memp.html.
Refer to Solved: How to tune LwIP to receive more incoming connecti... - STMicroelectronics Community
Regards
2024-07-04 05:59 AM
Hello @VSomasekhar,
Any updates on this ?
Regards
2024-07-05 07:33 AM
Hi,
I've found the specified Macros at:
STM32CubeIDE\workspace_1.13.2\J1424\Middlewares\Third_Party\LwIP\src\include\lwip\opt.h
Those Macros are already having certain default values. I am not exactly sure what other values should be there for these Macros. I've attached a text file (partof_opts.h) with these Macros definitions in the opts.h file. Please check and mention if these default values are OK.
Let me make the observation more clear:
When I connect the ModScan32 tool to the Modbus server on the Board, the very first request will be answered correctly in a Modbus response packet. The tool continues to send the requests, which are not answered. Since this Modbus server is based on the TCP Raw Socket Echo server, it simply echoes the request data in the response packet for the 2nd request onwards. Hope this helps.
2024-07-05 07:48 AM
Hello @VSomasekhar ,
This is clearly a problem with your implementation of callbacks when receiving a message. can you share the app implementation in which you construct the Modbus response. as you based your implementation on the TCP Raw Socket Echo server example you need to construct a packet for each message received in tcp_echoserver.c I assume.
Regards
2024-07-08 07:34 AM
Hi,
I have attached the TCP Raw Server .c and .h files in text format, also described below.
RawTCPServer.c : This contains the entry point to the TCP Raw Server, tcpRawServer(), which is called from the main application. This function calls tcp_echoserver_init(portnum), which takes the execution through the raw socket APIs.
RawTCPServer.h : This contains the implementation of all the TCP raw socket APIs. In the function tcp_echoserver_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err), the 3rd parameter contains the packet buffer pointer having the Modbus request packet. When the Echo Server state is ES_ACCEPTED, I've passed the same packet buffer pointer p, to the Modbus entry point, as given below.
//Modbus entry point
pTx = ModbusIxFace(p);
p is processed internally within the Modbus protocol and a response packet is generated, and received into pTx,
which is then linked to the echo server structure 'es' and sent out using the following statement.
/* send back the received data (echo) */
tcp_echoserver_send(tpcb, es);
All the details mentioned above are present in the attachments. If any more details are required, I'll provide.
Please help. Thanks.
2024-07-09 03:06 AM
Hello @VSomasekhar ,
In the code you shared in tcp_echoserver_recv you treat the first incoming data with a Modbus response, and you start to echo back the messages received (see the comments in code)
/* first data chunk in p->payload */ the first packet recieved
es->state = ES_RECEIVED_SERVER;
//Modbus entry point
pTx = ModbusIxFace(p);
/* store reference to incoming pbuf (chain) */
es->p = pTx;
/* initialize LwIP tcp_sent callback function */
tcp_sent(tpcb, tcp_echoserver_sent);
/* send back the received data (echo) */
tcp_echoserver_send(tpcb, es);
ret_err = ERR_OK;
}
else if (es->state == ES_RECEIVED_SERVER)
{
/* more data received from client and previous data has been already sent*/other packets
if(es->p == NULL)
{
es->p = p; //pTx->next;
/* send back received data */
tcp_echoserver_send(tpcb, es);
}
/* first data chunk in p->payload */ the first packet recieved
es->state = ES_RECEIVED_SERVER;
//Modbus entry point
pTx = ModbusIxFace(p);
/* store reference to incoming pbuf (chain) */
es->p = pTx;
/* initialize LwIP tcp_sent callback function */
tcp_sent(tpcb, tcp_echoserver_sent);
/* send back the received data (echo) */
tcp_echoserver_send(tpcb, es);
ret_err = ERR_OK;
}
else if (es->state == ES_RECEIVED_SERVER)
{
/* more data received from client and previous data has been already sent*/other packets
if(es->p == NULL)
{
//Modbus entry point
pTx = ModbusIxFace(p);
/* store reference to incoming pbuf (chain) */
es->p = pTx;
/* send back received data */
tcp_echoserver_send(tpcb, es);
}
this is my suggestion after seeing you code and what I got from your description of its behavior. I'm still clawless to the way the ModbusIxFace() function constructs Modbus packets.
Regards
2024-07-09 07:23 AM
I have implemented the suggested code change. Now I'm getting more number of responses, around 8-12. After that, the server-client connection is breaking. The server continues to run, but there is no ping response and Modbus response from the Board.
These are the requested details regarding the Modbus processing. The ModbusIxFace(..) function is implemented as follows:
struct pbuf * ModbusIxFace(struct pbuf *p)
{
MBDEFS_BOOL mbHandle;
struct pbuf *pTx = pbuf_alloc(Layer, TX_BUFFER_SIZE, bufType);
mbHandle = HandleModbusRequest(p->payload);
memcpy(pTx->payload, (void *)(QUERY_MESG_HEADER *)MBSlave_SendBuffer, sizeof(MBSlave_SendBuffer));
//pIx = p;
return pTx;
}
The HandleModbusRequest(p->payload) function receives the Modbus request packet in payload of
the packet buffer p. The payload is typecasted into the Modbus packet structure, and the internal
fields are accessed. As per the Modbus protocol specification, the field values are processed, and
the response is built into the byte array, as given below:
MBSlave_SendBuffer[TX_BUFFER_SIZE]
This byte array is copied into the payload of the received packet buffer, pTx, as shown in the
above function.
Although one response packet is sufficient for one request, the response has to be there for
every request. Please help in this regard.
2024-07-10 02:11 AM
One small correction please. pTx is a new packet buffer and not the received packet buffer.
2024-07-10 06:04 AM
Today's observations: The ModPoll tool continuously sends the configured Modbus requests. With the suggested source code changes, the expected Modbus response is sent for the first 9 requests. I've repeated and confirmed that this is the case. Why is it 9? After 9 responses, it is falling back to echo server mode. I can see the logic in the suggested code changes, and I think it should work. Or maybe the state changes have to be managed more suitably? Or a different Server altogether need to be installed? My initial understanding was that by properly setting the Response, it should be possible to change it to a standard server. I did this attempt, as I couldn't find a better option. I need help in this regard. Many thanks in advance.