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.

TMS320C6678: UDP组播接收不到数据

Part Number: TMS320C6678

你好,

       我使用了TI的6678和6672的芯片,在这两款芯片上面准备使用UDP组播功能。当前单播的功能都正常没有任何问题,组播时候可以正常发送到组播组,PC端口都可以正常收到数据,

组播通过PC向DSP的组播组发送数据,DSP接收不到数据。

       

      组播发送代码: 在NDK的UDP历程里面,我新建了一个发送Task,发送Task里面新建一个socket,socket绑定本地IP(192.168.4.156),之后setsocket加入组播组(224.1.2.4),之后通过这个socket想外发送数据,数据可正常发送。

      组播接收代码:在NDK的UDP历程里面,新建了一个接收Task,接收Task里面新建一个socket,socket绑定本地IP(192.168.4.156),之后setsocket加入组播组(224.1.2.4),之后通过while(1){recvfrom();}函数进行收取,结果代码一直卡在recvfrom函数这,也不往下执行,并且没有任何返回值。

请问:1.667X系列DSP从TI的理论设计上可否实现UDP组播接收?

           2.UDP组播的接收有没有历程,或者我这个组播接收代码哪里使用不当吗?

           3.UDP组播接收可否跟单播接收一样,能够创建进程,在接收到数据以后直接触发进程?

  • 您好,我们已收到您的问题并升级到英文论坛寻求帮助,链接如下,如有答复将尽快回复您:

    e2e.ti.com/.../tms320c6678-udp-multicast-cannot-receive-data

  • 您好,

    请参阅请参阅以下使用组播发送和接收功能的组播测试代码("contest.c"):

    /*---------------------------------------------------------------------- */
    /* MulticastTest() */
    /* Test the Multicast socket API. */
    /*---------------------------------------------------------------------- */
    static void MulticastTest (void)
    {
        SOCKET          sudp1 = INVALID_SOCKET;
        SOCKET          sudp2 = INVALID_SOCKET;
        struct sockaddr_in sin1;
        char            buffer[1000];
        int             reuse = 1;
        struct ip_mreq  group;
        NDK_fd_set      msockets;
        int             iterations = 0;
        int             cnt;
        CI_IPNET        NA;
    
        ConPrintf ("=== Executing Multicast Test on Interface 1 ===\n");
    
        /* Create our UDP Multicast socket1 */
        sudp1 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
        if( sudp1 == INVALID_SOCKET )
        {
            ConPrintf ("Error: Unable to create socket\n");
            return;
        }
    
        /* Create our UDP Multicast socket1 */
        sudp2 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
        if( sudp2 == INVALID_SOCKET )
        {
            ConPrintf ("Error: Unable to create socket\n");
            return;
        }
    
        /* Set Port = 4040, leaving IP address = Any */
        memset( &sin1, 0, sizeof(struct sockaddr_in) );
        sin1.sin_family = AF_INET;
        sin1.sin_port   = NDK_htons(4040);
    
        /* Print the IP address information only if one is present. */
        if (CfgGetImmediate( 0, CFGTAG_IPNET, 1, 1, sizeof(NA), (unsigned char *)&NA) != sizeof(NA))
        {
            ConPrintf ("Error: Unable to get IP Address Information\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
    
        /* Set the Reuse Ports Socket Option for both the sockets.  */
        if (setsockopt(sudp1, SOL_SOCKET, SO_REUSEPORT, (char *)&reuse, sizeof(reuse)) < 0)
        {
            ConPrintf ("Error: Unable to set the reuse port socket option\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
        /* Reuse the ports; since multiple multicast clients will be executing. */
        if (setsockopt(sudp2, SOL_SOCKET, SO_REUSEPORT, (char *)&reuse, sizeof(reuse)) < 0)
        {
            ConPrintf ("Error: Unable to set the reuse port socket option\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
    
        /* Now bind both the sockets. */
        if (bind (sudp1, (struct sockaddr *) &sin1, sizeof(sin1)) < 0)
        {
            ConPrintf ("Error: Unable to bind the socket.\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
        if (bind (sudp2, (struct sockaddr *) &sin1, sizeof(sin1)) < 0)
        {
            ConPrintf ("Error: Unable to bind the socket.\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
    
        /* Now we join the groups for socket1
         *  Group: 224.1.2.4
         *  Group: 224.1.2.5 */
        group.imr_multiaddr.s_addr = inet_addr("224.1.2.4");
        group.imr_interface.s_addr = NA.IPAddr;
        if (setsockopt (sudp1, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&group, sizeof(group)) < 0)
        {
            ConPrintf ("Error: Unable to join multicast group\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
        group.imr_multiaddr.s_addr = inet_addr("224.1.2.5");
        group.imr_interface.s_addr = NA.IPAddr;
        if (setsockopt (sudp1, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&group, sizeof(group)) < 0)
        {
            ConPrintf ("Error: Unable to join multicast group\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
        ConPrintf ("-----------------------------------------\n");
        ConPrintf ("Socket Identifier %d has joined the following:-\n", sudp1);
        ConPrintf (" - Group 224.1.2.4\n");
        ConPrintf (" - Group 224.1.2.5\n");
        ConPrintf ("-----------------------------------------\n");
    
        /* Now we join the groups for socket2
         *  Group: 224.1.2.5
         *  Group: 224.1.2.6 */
        group.imr_multiaddr.s_addr = inet_addr("224.1.2.5");
        group.imr_interface.s_addr = NA.IPAddr;
        if (setsockopt (sudp2, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&group, sizeof(group)) < 0)
        {
            ConPrintf ("Error: Unable to join multicast group\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
        group.imr_multiaddr.s_addr = inet_addr("224.1.2.6");
        group.imr_interface.s_addr = NA.IPAddr;
        if (setsockopt (sudp2, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&group, sizeof(group)) < 0)
        {
            ConPrintf ("Error: Unable to join multicast group\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
        ConPrintf ("-----------------------------------------\n");
        ConPrintf ("Socket Identifier %d has joined the following:-\n", sudp2);
        ConPrintf (" - Group 224.1.2.5\n");
        ConPrintf (" - Group 224.1.2.6\n");
        ConPrintf ("-----------------------------------------\n");
    
        while (iterations < 4)
        {
            /* Initialize the FD Set. */
            NDK_FD_ZERO(&msockets);
            NDK_FD_SET(sudp1, &msockets);
            NDK_FD_SET(sudp2, &msockets);
    
            /* Wait for the multicast packets to arrive. */
            /* fdSelect 1st arg is a don't care, pass 0 64-bit compatibility */
            cnt = fdSelect( 0, &msockets, 0, 0 , 0);
    
            if(NDK_FD_ISSET(sudp1, &msockets))
            {
                cnt = (int)recv (sudp1, (void *)&buffer, sizeof(buffer), 0);
                if( cnt >= 0 )
                    ConPrintf ("Socket Identifier %d received %d bytes of multicast data\n", sudp1, cnt);
                else
                    ConPrintf ("Error: Unable to receive data\n");
    
                /* Increment the iterations. */
                iterations++;
            }
            if(NDK_FD_ISSET(sudp2, &msockets))
            {
                cnt = (int)recv (sudp2, (void *)&buffer, sizeof(buffer), 0);
                if( cnt >= 0 )
                    ConPrintf ("Socket Identifier %d received %d bytes of multicast data\n", sudp2, cnt);
                else
                    ConPrintf ("Error: Unable to receive data\n");
    
                /* Increment the iterations. */
                iterations++;
            }
        }
    
        /* Once the packet has been received. Leave the Multicast group! */
        if (setsockopt (sudp2, IPPROTO_IP, IP_DROP_MEMBERSHIP, (void *)&group, sizeof(group)) < 0)
        {
            ConPrintf ("Error: Unable to leave multicast group\n");
            fdClose (sudp1);
            fdClose (sudp2);
            return;
        }
    
        /* Leave only one of the multicast groups through the proper API. */
        NtIPN2Str (group.imr_multiaddr.s_addr, &buffer[0]);
        ConPrintf ("Leaving group %s through IP_DROP_MEMBERSHIP\n", buffer);
    
        /* Once we get out of the loop close socket2; this should internally leave all the groups. */
        fdClose (sudp1);
        fdClose (sudp2);
        ConPrintf("== End Multicast Test ==\n\n");
    }

    文件位于"C:\ti\ndk_3_61_01_01\packages/ti\ndk\tools\console"中。

    API 指南和NDK API 指南中还提到了针对组播的更多 NDK API 参考。 使用"NDK_setsockopt()"可以将 UDP 组播发送和接收的选项设置为"SO_REUSEPORT"。 请使用"NDK_recvfrom ()"(NDK API 函数)接收组播由中断触发。

    此外,还有一种方法可以使能组播回复:

    1. Icmp.xml:

        /*!
         *  Enable or disable replies to multicast.
         *  
         *  When enabled, the stack *does not* reply to ICMP echo request packets
         *  sent to multicast addresses.
         */ 
        config Bool icmpDontReplyToMcast = defaultIcmpMcastReply;

    2. Ip.xdc:

    <tr>
             <td colspan="2"><control type="checkbox" 
                 label="Disable multicast replies"
                 value="value:ti.ndk.config.Ip.icmpDontReplyToMcast" 
                 tooltip="value:ti.ndk.config.Ip.icmpDontReplyToMcast.$summary"/></td>
          </tr>

    文件位于"C:\ti\ndk_3_61_01_01\packages/ti\ndk\config"文件夹中。

    由于 Processor SDK 中并没有组播示例项目,您请尝试以上示例。