int main(int argc, char **argv) { int sock, length; struct sockaddr_in server; int msgsock; int i; // intalization lwip_tcpip_init(); /* DHCP */ //enum { BUF_SIZE = Nic::Packet_allocator::DEFAULT_PACKET_SIZE * 128 }; int BUF_SIZE= 200000; if (lwip_nic_init(0, 0, 0, BUF_SIZE, BUF_SIZE)) { printf("ERROR: We got no IP address!\n"); return 1; } /* Create socket */ sock = lwip_socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { perror("opening stream socket"); exit(1); } /* Name socket using wildcards */ server.sin_family = AF_INET; server.sin_addr.s_addr = INADDR_ANY; server.sin_port = htons(SRV_PORT); if (lwip_bind(sock, (struct sockaddr *)&server, sizeof(server))) { perror("binding stream socket"); exit(1); } /* Find out assigned port number and print it out */ //length = sizeof(server); //if (getsockname(sock, (struct sockaddr *)&server, &length)) { // perror("getting socket name"); // exit(1); // } // printf("Socket has port #%d\n", ntohs(server.sin_port)); printf("Socket has port #%d\n",3333); /* Start accepting connections */ lwip_listen(sock, 5); do { msgsock = lwip_accept(sock, 0, 0); if (msgsock == -1) perror("accept"); printf("process message on msgsock %d \n ",msgsock); process_client(msgsock); close(msgsock); } while (TRUE); /* * Since this program has an infinite loop, the socket "sock" is * never explicitly closed. However, all sockets will be closed * automatically when a process is killed or terminates normally. */ }
void wifi_initial_task() { struct netif *sta_if; wifi_init(&wifi_config, NULL); lwip_tcpip_init(&tcpip_config, WIFI_MODE_STA_ONLY); ip_ready = xSemaphoreCreateBinary(); sta_if = netif_find_by_type(NETIF_TYPE_STA); netif_set_status_callback(sta_if, _ip_ready_callback); dhcp_start(sta_if); xSemaphoreTake(ip_ready, portMAX_DELAY); mcs_tcp_init(tcp_callback); vTaskDelete(NULL); }
void lwip_network_init(uint8_t opmode) { lwip_tcpip_config_t tcpip_config = {{0}, {0}, {0}, {0}, {0}, {0}}; ip4addr_aton(STA_IPADDR, &(tcpip_config.sta_addr)); ip4addr_aton(STA_NETMASK, &tcpip_config.sta_mask); ip4addr_aton(STA_GATEWAY, &tcpip_config.sta_gateway); ip4addr_aton(AP_IPADDR, &(tcpip_config.ap_addr)); ip4addr_aton(AP_NETMASK, &tcpip_config.ap_mask); ip4addr_aton(AP_GATEWAY, &tcpip_config.ap_gateway); wifi_connected = xSemaphoreCreateBinary(); #if USE_DHCP ip_ready = xSemaphoreCreateBinary(); #endif lwip_tcpip_init(&tcpip_config, opmode); }
void stm32_soc_init(void) { HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /**Configure the Systick interrupt time */ HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/RHINO_CONFIG_TICKS_PER_SECOND); /* PendSV_IRQn interrupt configuration */ HAL_NVIC_SetPriority(PendSV_IRQn, 0x0f, 0); MX_GPIO_Init(); /*default uart init*/ stduart_init(); /*ethernet if init*/ lwip_tcpip_init(); }