关于TI LM3S8962评估套件中的LWIP客户端跟服务端问题

2019-03-24 14:51发布

看了论坛里的一些资料学着改了下,为什么使用TCP_CONNECT后返回是ERR_OK但是不会调用此函数中的回调函数?在ENET_IO的基础上修改,代码如下:       
unsigned long ulUser0, ulUser1;
    unsigned char pucMACArray[8]={0x00,0x16,0x4e,0x22,0x13,0x14};
        struct tcp_pcb *pstClient_Pcb;
        struct ip_addr ullipaddr;
    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);

    //
    // Initialize the OLED display.
    //
    RIT128x96x4Init(1000000);
    RIT128x96x4StringDraw("Web-Based I/O Control", 0, 0, 15);
    RIT128x96x4StringDraw("Browser Message:", 0, 53, 15);

    //
    // Enable and Reset the Ethernet Controller.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ETH);
    SysCtlPeripheralReset(SYSCTL_PERIPH_ETH);

    //
    // Enable Port F for Ethernet LEDs.
    //  LED0        Bit 3   Output
    //  LED1        Bit 2   Output
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeEthernetLED(GPIO_PORTF_BASE, GPIO_PIN_2 | GPIO_PIN_3);

    //
    // Configure SysTick for a periodic interrupt.
    //
    SysTickPeriodSet(SysCtlClockGet() / SYSTICKHZ);
    SysTickEnable();
    SysTickIntEnable();

    //
    // Enable processor interrupts.
    //
    IntMasterEnable();
    // Configure the hardware MAC address for Ethernet Controller filtering of
    // incoming packets.
    //
    // For the LM3S6965 Evaluation Kit, the MAC address will be stored in the
    // non-volatile USER0 and USER1 registers.  These registers can be read
    // using the FlashUserGet function, as illustrated below.
    //
    FlashUserGet(&ulUser0, &ulUser1);
/*  if((ulUser0 == 0xffffffff) || (ulUser1 == 0xffffffff))
    {
        //
        // We should never get here.  This is an error if the MAC address
        // has not been programmed into the device.  Exit the program.
        //
        RIT128x96x4StringDraw("MAC Address", 0, 16, 15);
        RIT128x96x4StringDraw("Not Programmed!", 0, 24, 15);
        while(1);
    }  */

    //
    // Convert the 24/24 split MAC address from NV ram into a 32/16 split
    // MAC address needed to program the hardware registers, then program
    // the MAC address into the Ethernet Controller registers.
    //
    pucMACArray[0] = ((ulUser0 >>  0) & 0xff);
    pucMACArray[1] = ((ulUser0 >>  8) & 0xff);
    pucMACArray[2] = ((ulUser0 >> 16) & 0xff);
    pucMACArray[3] = ((ulUser1 >>  0) & 0xff);
    pucMACArray[4] = ((ulUser1 >>  8) & 0xff);
    pucMACArray[5] = ((ulUser1 >> 16) & 0xff);

    //
    // Initialze the lwIP library, using DHCP.
    //       
    //IP4_ADDR(ipaddr, a, b, c, d)
//    lwIPInit(pucMACArray, 0, 0, 0, IPADDR_USE_AUTOIP);
        IP4_ADDR(&ullipaddr, 179, 1, 254, 169);
        lwIPInit(pucMACArray, ullipaddr.addr,
                                                        (255<<24 | 255<<16 | 0<<8 | 0),
                                                        (169<<24 | 254<<16 | 1<<8 | 1),IPADDR_USE_STATIC);
       
    //lwIPInit(pucMACAddress,ulIPAddr.addr, ulNetMask.addr, ulGWAddr.addr, IPADDR_USE_STATIC);

    //
    // Setup the device locator service.
    //
    LocatorInit();
    LocatorMACAddrSet(pucMACArray);
    LocatorAppTitleSet("EK-LM3S8962 enet_io");


        pstClient_Pcb = tcp_new();
        tcp_bind(pstClient_Pcb, IP_ADDR_ANY, 1026);
        if(tcp_connect(pstClient_Pcb,&ullipaddr, 1026, TCP_CLICONNECT)== ERR_OK)
                {
                        RIT128x96x4StringDraw("connect ok", 0, 74, 15);
                }
        else
                {
                        RIT128x96x4StringDraw("connect error", 0, 74, 15);
                }

/*
    //
    // Initialize a sample httpd server.
    //
    httpd_init();

    //
    // Pass our tag information to the HTTP server.
    //
    http_set_ssi_handler(SSIHandler, g_pcConfigSSITags,
                         NUM_CONFIG_SSI_TAGS);

    //
    // Pass our CGI handlers to the HTTP server.
    //
    http_set_cgi_handlers(g_psConfigCGIURIs, NUM_CONFIG_CGI_URIS);
*/
    //
    // Initialize IO controls
    //
    io_init();

    //
    // Loop forever.  All the work is done in interrupt handlers.
    //
    while(1)
    {
    }
另外想问下端口口是如何设置?默认是什么样的?我只知道TCP_BIND函数中有端口绑定,是否这个时候就会设置成这个端口?如果是,那做服务器模式时如何获知?我是个新手,求各位高手帮忙了! 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
1条回答
Study_Stellaris
2019-03-24 20:11
TCP_BIND 会设置端口。HTTP 的端口就是 80.

一周热门 更多>

相关问题

    相关文章