This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMDXEVM6678LE sending UDP message to desktop, but only one message able to send thru

Hi, I'm currently practicing on some examples as I'm new, and I faced an issue which I'm not sure how to solve, hope u guys can help.

CCS: ccsv5

Board: TMDXEVM6678LE

Problem:

I previously wrote two piece of code, one which sends UDP message and the other receives and displays the messages. I'm trying to load the sending code into the DSP so that it can send messages while my desktop receives.

But currently it seems that I'm only able to receive the latest message sent. Eg:

Core.send(reinterpret_cast<char*>(&sendData1), sizeof(sendData1), "192.168.x.xxx", 50001);

Core.send(reinterpret_cast<char*>(&sendData2), sizeof(sendData2), "192.168.x.xxx", 50001);

Only sendData2 will be sent/received, I've also tried adding a delay between send but doesn't seem to solve. I was wondering if anyone here would have any knowledge or advice on how I could solve this.

 

PS: I'm sorry of my description of the problem is vague, I'll try to provide more information if requested, as I'm not sure what is required. Typing this from my phone as there's no internet on the PC T_T

  • Hello,

    This is a tricky issue, one that it is hard to give advice since it is most likely system and application specific. I will move this into the keystone forum where the experts there can provide some better suggestions to help debug the issue. If this turns out to be a tools issue, please let me know.

    Thanks

    ki

  • Hi,

    I have tested the UDP sends the data from board to PC. You can use the helloworld example from MCSDK. Here you need to replace the udpHello.c and helloWorld.cfg files.

    C:\ti\mcsdk_2_01_02_06\examples\ndk\helloWorld

    In addition that, comment out the "dtask_udp_hello" task in helloWorld.c file like below,

    // Create our local server
    /* hHello = DaemonNew( SOCK_DGRAM, 0, 7, dtask_udp_hello,
    OS_TASKPRINORM, OS_TASKSTKNORM, 0, 1 ); */

    4544.udpHello.c
    /*
     * udpHello.c
     *
     * This program implements a UDP echo server, which echos back any
     * input it receives.
     *
     * Copyright (C) 2007 Texas Instruments Incorporated - http://www.ti.com/ 
     * 
     * 
     *  Redistribution and use in source and binary forms, with or without 
     *  modification, are permitted provided that the following conditions 
     *  are met:
     *
     *    Redistributions of source code must retain the above copyright 
     *    notice, this list of conditions and the following disclaimer.
     *
     *    Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the 
     *    documentation and/or other materials provided with the   
     *    distribution.
     *
     *    Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
     *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
     *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
     *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
     *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
     *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
     *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
     *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
    */
    
    #include <ti/ndk/inc/netmain.h>
    
    SOCKET   socksend = INVALID_SOCKET;
    static int PktNum = 0;
    char buff1[1024] = {0};
    //
    // dtask_udp_hello() - UDP Echo Server Daemon Function
    // (SOCK_DGRAM, port 7)
    //
    // Returns "1" if socket 's' is still open, and "0" if its been closed
    //
    int dtask_udp_hello( SOCKET s, UINT32 unused )
    {
        struct sockaddr_in sin1;
        struct timeval     to;
        int                i,tmp;
        char               *pBuf;
        HANDLE             hBuffer;
    
        (void)unused;
    
        // Configure our socket timeout to be 3 seconds
        to.tv_sec  = 3;
        to.tv_usec = 0;
        setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof( to ) );
        setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ) );
    
        for(;;)
        {
            tmp = sizeof( sin1 );
            i = (int)recvncfrom( s, (void **)&pBuf, 0, (PSA)&sin1, &tmp, &hBuffer );
    
            // Spit any data back out
            if( i >= 0 )
            {
                sendto( s, pBuf, i, 0, (PSA)&sin1, sizeof(sin1) );
                recvncfree( hBuffer );
            }
            else
                break;
        }
    
        // Since the socket is still open, return "1"
        // (we need to leave UDP sockets open)
        return(1);    
    }
    
    int sendUDPTsk()
    {
        struct   sockaddr_in sinData, cliAddr;
    	int sa_size1 = 0, err = 0;
    	int retSize1 = 0, buff_size1 = 0, i = 0, chain = 0;
    
        //Allocate the file environment for this task
        fdOpenSession( TaskSelf() );
    
        //Initialize the socket
        socksend  = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
        if (socksend == INVALID_SOCKET)
        {
    		printf(" socket(socksend) failed \n");
    		return -1;
        }
    
        err = setsockopt( socksend, SOL_SOCKET, SO_REUSEADDR, buff1, 1472 );
    	err = setsockopt( socksend, SOL_SOCKET, SO_REUSEPORT, buff1, 1472 );
    
        //Initialize socket address in structure
        bzero( &sinData, sizeof(struct sockaddr_in) );
        sinData.sin_family = AF_INET;
        sinData.sin_len    = sizeof( sinData );
        sinData.sin_addr.s_addr = INADDR_ANY;
        sinData.sin_port = htons(2500);
    
        //Bind the socket
        err = bind (socksend, (struct sockaddr *)&sinData, sizeof(sinData));
    	if(err == 0)
    		printf("Send-Bind operation successfully done\n");
    	else
    	{
    		printf("Send-Bind operation failed errno= %d\n", fdError());
    		return -1;
    	}
    
        bzero( &cliAddr, sizeof(struct sockaddr_in) );
        cliAddr.sin_family = AF_INET;
        cliAddr.sin_len    = sizeof( cliAddr );
        cliAddr.sin_addr.s_addr = inet_addr("10.100.1.209"); //Target IP(PC IP address)
        cliAddr.sin_port = htons(2501);
    	sa_size1 = sizeof(struct sockaddr_in);
    	buff_size1 = 1024; //1472;
    
    	TaskSleep(10000);
    	buff1[0] = 48;
    
    	while(1)
    	{
    
    	    TaskSleep(500);
    		buff1[1] = i + 48;
    		i++;
    		chain ^= 1;
    		if(chain == 0)
    			memset(buff1, '1', 1024);
    		else
    			memset(buff1, 'A', 1024);
    
    		retSize1 = sendto(socksend, buff1, buff_size1, 0, (struct sockaddr *)&cliAddr, sa_size1);
    		if(retSize1 < 0)
    			printf(" Error Sending sendto() %d \n", fdError());
            else
    			printf(" %d.Send_Size = %d \n ", PktNum,retSize1);
    			PktNum++;
    
    		if(i==10)
            	i = 0;
    
    
    	}
    
    
    }
    

    0640.helloWorld.cfg

  • Hi Pubesh,

    Thanks for responding. Okay, when u said replace udphello.c, u meant replacing the original helloworld.c with the one u provided right? But why do I not see a main function in ur code? Also is the function stack test() not needed?

    PS: I'm working in a non-internet environment so I'm unable to just copy and paste to try it out. I'll have to type n try, but I don't understand why I don't see a main function.

  • Jing,

    Replace the original udphello.c file with attached the udphello.c file , not helloworld.c file.

     

  • Jing, 

    Before build the project,

    In addition that, comment out the "dtask_udp_hello" task in helloWorld.c file like below,

    // Create our local server
    /* hHello = DaemonNew( SOCK_DGRAM, 0, 7, dtask_udp_hello,
    OS_TASKPRINORM, OS_TASKSTKNORM, 0, 1 ); */

  • Jing,

    Find the modified code for UDP send from DSP to Desktop PC IP address. 

    5277.helloworld_evmc6678l.zip

  • Jing,

    However this discussion of thread can helpful for future readers, If you verified this thread.

  • Yes, it seems to be working.. Just a few modifications vere n there to suit my needs but generally it works.. Thank you so much" :)

  • Jing,

    Thanks for the update. Glad to hear, its working your side.