int main(void)
{struct netif *pGB_netif, GB_netif;structip_addr IPaddr, NetMask, GateWay;
u8 MacAddr[]= {0x00, 0x0a, 0x35, 0x00, 0x01, 0x02};
pGB_netif= &GB_netif;
Debugout("\r\n\r\n");
Debugout("------------- Main vernsion 1.8-------------\r\n");
Debugout("-----lwIP RAW Mode Demo Application ------\r\n");/*1. Initialize the platform.*/
if (init_platform() < 0)
{
ErrorInfo("Platform initailize fail!\n");return -1;
}/*2. Set the IP*/IP4_ADDR(&IPaddr, 10, 10, 22, 10);
IP4_ADDR(&NetMask, 255, 255, 255, 0);
IP4_ADDR(&GateWay, 10, 10, 22, 1);
print_ip_settings(&IPaddr, &NetMask, &GateWay);/*3. Initialize the lwIP stack.*/lwip_init();/*4. Add IP to network interface.*/
if (!xemac_add(pGB_netif, &IPaddr, &NetMask, &GateWay, MacAddr, PLATFORM_EMAC_BASEADDR))
{
ErrorInfo("Not able to add IP to the network interface!\n");return -1;
}
netif_set_default(pGB_netif);/*5. Enable the interrupts.*/platform_enable_interrupts();/*6. Set up the network interface.*/netif_set_up(pGB_netif);/*7. Create the TCP server.*/
//GB_InitTCPSrv();
GB_InitTcpClnt();/*8. Dead cycle to receive data.*/
while (1)
{
xemacif_input(pGB_netif);//GB_send();
}return 0;
}
err_t GB_CBF_sent(void *arg, struct tcp_pcb *tpcb, u16_t len)
{
Debugout("Inside CBF_sent\n");returnERR_OK;
}
err_t GB_CBF_connect(void *arg, struct tcp_pcb *pTCPpcb, err_t errNum)
{//err_t errNum = 0;
Debugout("Inside CBF for connect!\n");//g_pClntPCB = pTCPpcb;
tcp_arg(pTCPpcb, NULL);
tcp_sent(pTCPpcb, GB_CBF_sent);returnERR_OK;
}static int GB_InitTcpClnt(void)
{struct tcp_pcb *pClntPcb =NULL;
err_t errNum= 0;char cRet = 0;structip_addr RemoteIP;
pClntPcb=tcp_new();if (NULL ==pClntPcb)
{
ErrorInfo("Create client PCB error!\n");returnRET_FAIL;
}
cRet=tcp_bind(pClntPcb, IPADDR_ANY, CONTROL_CHANNEL_PORT);if (ERR_OK !=cRet)
{
ErrorInfo("Bind Error!\n");returnRET_FAIL;
}//tcp_arg(pClntPcb, NULL);//tcp_setprio(pClntPcb, TCP_PRIO_NORMAL+1);
IP4_ADDR(&RemoteIP, 10,10,22,100);
errNum= tcp_connect(pClntPcb, &RemoteIP, (u16_t)8960, GB_CBF_connect);if (ERR_OK !=errNum)
{
ErrorInfo("Client Connect Error![%d]\n", errNum);returnRET_FAIL;
}
g_pClntPCB=pClntPcb;//tcp_output(pClntPcb);//tcp_sent(pClntPcb, );//Debugout("Client TCP Created succussfully\n");
}