Hi,
I try to understand how I can use the fnSendTCP function. Is it possible to use this function outside fnListener(...)?
My problem is following:
I have a TCP request to a client on the serial interface (Gateway functionality). After reception of the TCP frame I call the function fnWritetoMBrtu(). This function posts a message to the serial interface task. This is working.
My fnListener function looks like this:
static int fnMBtcpListener(USOCKET Socket, unsigned char ucEvent, unsigned char *ucIp_Data, unsigned short usPortLen)
{
switch(ucEvent)
{
case TCP_EVENT_CONREQ:
case TCP_EVENT_CONNECTED:
case TCP_EVENT_CLOSE:
case TCP_EVENT_ACK:
case TCP_EVENT_ARP_RESOLUTION_FAILED:
case TCP_EVENT_PARTIAL_ACK:
break;
case TCP_EVENT_REGENERATE:
case TCP_EVENT_DATA:
//Extract MB Header from TCP data
fnExtractMBtcpData(&mbTcpMessageRx, ucIp_Data);
//Send Message to Serial Interface Task
fnWriteToMBrtu();
return APP_REJECT_DATA;
break;
case TCP_EVENT_ABORT:
case TCP_EVENT_CLOSED:
fnTCP_Listen(Socket, MODBUS_TCP_PORT, 0);
break;
default:
break;
}
return APP_ACCEPT;
}
Now my question: Where do I have to call the fnSendTCP(...) function?
At the moment I don't understand how coming back from the Serial Task to the fnListener(...) function. So I tried to call the fnSendTCP(...) within the serial task.
case DO_MB_TCP_TIMEOUT:
mbTcpMessageRx.mbTcpHeader.packetLength = 0x3;
uStrcpy((char*)mbTcpMessageRx.mbTcpData, mbException);
fnSendTCP(mbTcpSocket, (unsigned char *)&mbTcpMessageRx.tcpHeader, 9,
TCP_FLAG_PUSH);
uTaskerMonoTimer(TASK_U1K, (DELAY_LIMIT)(1*SEC), DO_TIMEOUT);
break;
I don't get the expected TCP response. Can anybody help me?
Regards,
Michael