extern struct netif network_interfaces[1];
void interface_init_1(void)
{
for(int i = 0; i < 1; i++)
{
ip4_addr_t ipaddr, netmask, gw;
ip4_addr_set_zero(&gw);
ip4_addr_set_zero(&ipaddr);
ip4_addr_set_zero(&netmask);
/* network_interfaces[i] takes the IPV4 addresses from the respective configuration */
IP4_ADDR((&gw), 192,168, 0, 1);
IP4_ADDR((&ipaddr), 192, 168, 0, 200);
IP4_ADDR((&netmask), 255,255,255, 0);
netif_set_default( netif_add(&network_interfaces[i], &ipaddr, &netmask, &gw, NULL, enet_ethernetif_init, tcpip_input) );
netif_set_up(&network_interfaces[i]);
}
}
char msg[8192] = "MPC5748G";
void vInitTask(void* pvParamateres){
struct netconn *conn;
struct netbuf *buf;
ip_addr_t dst_addr;
int i;
err_t connection_err, send_err;
u16_t dst_port = 7000;
/* init the stack */
tcpip_init(NULL, NULL);
interface_init_1();
/* create a new connection */
conn = netconn_new(NETCONN_UDP);
/* set up the IP address of the remote host */
dst_addr.u_addr.ip4.addr = inet_addr("192.168.0.3");
/* connect the connection to the remote host */
connection_err = netconn_connect(conn, &dst_addr, dst_port);
// if (connection_err== ERR_OK) { PINS_DRV_TogglePins(PTB, 0x1000); } // blink LED PB12
/* create a new netbuf */
buf = netbuf_new();
/* point the buffer payload to the text */
netbuf_ref(buf, msg, sizeof(msg));
/* send the messagge five times */
while(1){
send_err = netconn_send(conn, buf); // THIS FAILS!!
// if (send_err == 0) { PINS_DRV_TogglePins(PTA, 0x2) ;} // blink the LED on PA1
for( i = 0 ; i < 2000; i++)
{
}
// vTaskDelay(1);
}
vTaskDelete(NULL);
}
Free-RTOS 发送udp数据
最新推荐文章于 2024-05-29 15:16:16 发布