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: 6678 udp组播(client)的例程

Part Number: TMS320C6678


1、请问有6678 有udp 组播客户端的案例可供参考吗?或者参考资料;

2、已经udp单播正常接收数据,修改为udp组播(client)时,无法接收到数据。查阅手册SPRU524H中3.6节第77页中提到NDK不支持server mode,但是支持client operation(The NDK does not currently support IP multicast routing, so there is no need to use IGMP in server mode.However, the software does support IGMP client operation.)。

3、自己修改的接收端函数见recive.c(参考https://www.ibm.com/docs/en/i/7.1?topic=inet-example-receiving-multicast-datagrams)编写。但是不能接收数据。

  • static void UDP_Recv_GDJ_Tsk(void)
    {
        SOCKET          sudp = INVALID_SOCKET;
        char*           pBufPing = NULL,*pBufPong = NULL;
        HANDLE          hBuffer;
        int32_t         bytes;
        uint32_t        tsMsec, ts1Msec, startMsec, endMsec;
        uint32_t        ts, ts1, tn;
        uint32_t        totalBytes = 0;
        int32_t         counter = 0;
        float           lost_rate =0;
        struct timeval  timeout;
        struct sockaddr_in sin1,sin2;
        struct ip_mreq group;
        uint32_t FrameNum0 = 0;
        char flag_Firt= 1;
    
        int *pData;
        pData = GDJDATA_PING;
        Task_sleep(150);
    //    Semaphore_pend(sem5_START_RECV_GDJ, BIOS_WAIT_FOREVER);
        printf( "3 UDP_Recv_GDJ_Tsk started\n");
    
        /* Allocate the file environment for this task */
        fdOpenSession(TaskSelf());
    
        /* 1 Create the main UDP listen socket */
        sudp = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
        if(sudp == INVALID_SOCKET) {
            printf( "Failed to create the receive socket \n");
            goto leave;
        }
    
        /* 2 Set Port = 65000, leaving IP address = Any */
        bzero(&sin1, sizeof(struct sockaddr_in));
        sin1.sin_family = AF_INET;
        sin1.sin_len    = sizeof(sin1);
        //sin1.sin_addr.s_addr    = inet_addr("224.0.0.88");
        sin1.sin_addr.s_addr    = inet_addr(INADDR_ANY);
        sin1.sin_port   = htons(65000);
    
        /* 3 Bind the socket */
        if(bind( sudp, (PSA) &sin1, sizeof(sin1)) < 0) {
            printf("Failed to bind the receive socket \n");
            goto leave;
        }
    
        /* Set a time out for the receive in case there is data loss.. time out is in seconds */
        timeout.tv_sec  = 5;    /* wait up to 5 seconds per packet */
        timeout.tv_usec = 0;
        if(setsockopt(sudp, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0) {
            printf( "Failed to set the sockopt for receive socket \n");
            goto leave;
        }
    	//4 join multicast
        bzero(&group, sizeof(struct ip_mreq));
        group.imr_multiaddr.s_addr = inet_addr("224.0.0.88");//组播IP
        group.imr_interface.s_addr = inet_addr("192.168.172.110");//本机IP
    
        if(setsockopt(sudp, IPPROTO_IP, IP_ADD_MEMBERSHIP, &group, sizeof(group)) < 0) {
            printf("Failed to adding multicast group, %d\n", fdError());
            goto leave;
        }
        bzero(&sin2, sizeof(struct sockaddr_in));
    
    
        /* Allocate a working buffer */
        if(!(pBufPing = (char *)malloc(2048))) {
            printf("UDP_Send_ZT_Tsk Failed pBufPing buffer allocation\n");
            goto leave;
        }
    
        totalBytes = 0;
        int tmp;
        tmp=sizeof(sin2);
        for(;;){
    
            bytes = (int)recvncfrom(sudp, (void **)&pBufPing, 0, (PSA)&sin2, &tmp, &hBuffer);
    
        }
    
    
    leave:
        if(pBufPing) {
            free(pBufPing);
        }
        if(pBufPong) {
            free(pBufPong);
        }
        if(sudp != INVALID_SOCKET)
           fdClose(sudp);
        UARTprintf(&uart0cfg,"leave : %d \n", fdError());
        TaskSleep(2000);
        fdCloseSession(TaskSelf());
        TaskDestroy(TaskSelf());
        return;
    }
    
    
    
    这是recive.c文件

  • 请看一下下面的文档是否有帮助?
    https://www.ti.com/lit/an/spraai3/spraai3.pdf