Hello guys,
I am developing a system that communicate using UDP socket and
I have managed to establish UDP connection and sent some data, must say thanks to everyone of you.
Now, I have a problem that the Data Handler function is called infinitely when I have received data only once.
Here are my code:
call InitUdpSocket() first..
/************************************************************
Function : InitUdpSocket
************************************************************/
void InitUdpSocket(u8 ID)
{
s8 returnCode;
UdpParams.UdpPort = 2001;
UdpParams.UdpTxDelay = 1000;
sprintf(UdpParams.UdpServ, "xxx.xx.xx.xx");
// Init UDP Socket
returnCode = ed_UdpSocketSetConfig(&UdpParams);
if (returnCode == 0)
{
adl_tmrSubscribe(FALSE, 10, ADL_TMR_TYPE_100MS, StartUdpSocket);
}
}
/************************************************************
Function : StartUdpSocket
************************************************************/
void StartUdpSocket(u8 ID)
{
s8 returnCode;
returnCode = ed_SocketUDPStart(0, UDP_ResponseCallback, UDP_DataHandler, UDP_DataRequest);
}
/************************************************************
Function : UDP_ResponseCallback
************************************************************/
void UDP_ResponseCallback(s32 ResponseCode, TeDHandle id)
{
}
/************************************************************
Function : UDP_DataHandler
************************************************************/u16 UDP_DataHandler(u16 DataLen, u8 *Data, TeDHandle id)
{
return 0;
}
/************************************************************
Function : UDP_DataRequest
************************************************************/
void UDP_DataRequest(u16 MaxLen, TeDHandle id)
{
char strSend[20] = "TEST STRING";
ed_SendData(strSend, sizeof(strSend), FALSE);
}
My questions are:
(1) Is it ok to use ‘ed_SendData()’ function for UDP connection?
(2) My program keep calls ‘UDP_DataRequest’ function. Is it because the program is at idle state(ready to send state)?
(3) When a reply is received from a remote server, ‘UDP_DataHandler’ function is called. However, the server seemed to sent a reply ONCE but the function is kept called infinitely. Why is this?
Thanks guys.
Hi jimba81,
The UDP data handler function is called infinitely in your case because you are returning a 0 from the UDP data handler function. The return value from this function should be the amount of bytes processed by the Open-AT application. In case, you return a 0, the received data will be presented to your Open-AT application again and again (by calling the UDP data handler function) until the cumulative result of all the return values from the UDP data handler equals the amount of bytes that were received.
Hence, so solve the problem, you should ideally return the DataLen variable from the data handler (in case you applicaiton has processed all the data received over UDP). In case, your applicaiton is not able to process all the data, you should return the amount of bytes that are processed. The remaining bytes will be presented to your applicaiton by calling UDP data handler again (of course, now the DataLen parameter will be equal to Bytes received initially - bytes returned from data handler + New bytes received from UDP socket).
ed_SendData () function should be used to transfer data while using a UDP socket.
I think the above explanation will clear the queries asked by you.
Best Regards,
Open AT Fan.
OpenAT_Fan,
Thank you very much for your help. I really appreciate it.
Cheers.
Hello OpenAT_Fan,
At this stage, I send a test string via UDP.
Now I am trying to:
(1)Get input string from serial port2(serial port1 is used for downloading software and debug trace).
(2)Process the input string, generate output UDP packet.
(3)Send the output UDP packet via UDP socket.
The problem is that the Data Request function, UDP_DataRequest, is called infinitely and sends a test string therefore I cannot do something else(eg. get input string from serial port2, generate output string, etc).
My questions are:
(1)Can you tell me why this Data Request function is called infinitely? And how does this function triggered?
(2)Should I use FCM to resolve this issue? If it’s so, is FCM going to work with ed_udp function calls? Can you tell me how I can do that?
(3)Is there any good example how to initiate serial port2(UART2)?
Thanks.
Hi jimba81,
Data request function is called whenever you send data using ed_SendData () in order to indicate you the amount of data that you can send now. For intance, whenever the Open-AT applicaiton calls ed_
SendData (), the data request function will be called, provinding you the new value for “DataLen” parameter. In your case, it is being called infinitely because, you are calling ed_SendData () from within the Data Request function. Hence, after each call to ed_SendData (), the Data Request handler is called again.
As a matter of fact, you can note that Data Request handler will be called whenever you call ed_SendData () function (i.e. after completing the execution of the function from which ed_SendData () API is called).
You can use FCM for serial flow with edlib functions. There is no problem using FCM for V24 and the eDlib APIs.
In order to initiate UART2, you should first enable it. For instance, under X50 version of core AT software, you should give AT+WMFM=0,1,1 command to enable the UART2. Now, you can open FCM flow on this UART using adl_fcmSubscribe API. When the FCM flow opens, switch the flow to data mode and after this point any thing you sent to UART2 will be received in the FCM data handler. From the FCM data handler, you can send data on the UDP socket (I assume it is already opened) using ed_SendData () function. In case, you feel that data on UART2 is being received very fast and the socket is not able to sent it immediately, you can use the concept of credits to enable the flow control on the UART to prevent arrival of data too fast.
Please refer to the link
http://www.wavecom.com/modules/movie/scenes/forums/viewtopic.php?t=200
for more information on credits.
You can also refer to AUG (ADL user guide) for more info on this.
Best Regards,
Open AT Fan.
Thanks OpenAT_Fan,
I have more questions.
(1)Can you tell me what is “X50 version of core AT software”?
In my program, the ‘AT+WMFM=0,1,1’ command is fetched by
adl_atCmdCreate( "'AT+WMFM=0,1,1", FALSE, Handler, "*", NULL );
Is this ok?
(2)I am switching to Data Mode by sending “AT0” command.
Then, does this command set every port to become Data mode?
(3)I am trying to setup UART2 and I don’t know how to set baud rate, stop bit, etc.
Cheers,
I really appreciate for your help.
Hi jimba81,
“X50 version of core AT software” means the core operating system version that is downloaded in your module. You can execute ATI3 command and find the response to this command. If the response is like 650a09gg…, then it means that you have X50a version of core AT software.
If you get 651_09…then it means that you are having X51 version of core AT software.
If you are using X50 version of core AT software, then the command to enable UART2 is AT+WMFM=0,1,1. In X51 version of core AT software, it is AT+WMFM=0,1,2. You can refer to the AT command interface guide for more information on this.
-
The format of sending the command to activate the UART2 is OK in case you are using X50 version of core AT software. In case, your module is having X51, then you should give
adl_atCmdCreate( “'AT+WMFM=0,1,2”, FALSE, Handler, “*”, NULL );
-
If you use ATO command to switch to data mode, then only the port on which you give the ATO command will be switched to data mode. There will be no effect to state of the other port. Hence, only the port on which ATO command is executed will be switched to data mode.
-
If you want to setup UART2 from within your Open-AT application (for baud rate, parity etc), then you have to use adl_atCmdCreate () API to create the commands for UART2 which would configure it. Please note that in this API you have to use ADL_PORT_TYPE macro for second parameter to specify the port to which the command should take effect. For instance,
adl_atCmdCreate(“AT+IPR=115200”,ADL_AT_PORT_TYPE(ADL_AT_UART2),FALSE,Handler,"*",NULL);
Please note that these command (to configure UART2) should be sent after enabling the UART2. It would be better if you incoporate a timer to send these command and not send the commands one after the other using adl_atCmdCreate () API. THis will provide some time to the module to configure the UART2.
Similarly you can create commands to setup the UART2 configuration.
If you are using an external applicaiton (like PC) to setup UART2, then enable the UART2 and then send the command to set the configuration from the PC.
Best Regards,
Open AT Fan.