Free-RTOS 发送udp数据

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);
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值