コード例 #1
0
ファイル: ard_tcp.c プロジェクト: 4bcat/Arduino
/**
 * Start UDP transfer.
 */
static int udp_start(struct ttcp* ttcp) {
	ttcp->udp_end_marker_left = 5;
	ttcp->upcb = udp_new();
	if (ttcp->upcb == NULL) {
		printk("TTCP [%p]: could not allocate pcb\n", ttcp);
		return -1;
	}

	if (ttcp->mode == TTCP_MODE_TRANSMIT) {
		if (udp_connect(ttcp->upcb, &ttcp->addr, ttcp->port) != ERR_OK) {
			printk("TTCP [%p]: udp connect failed\n", ttcp);
			return -1;
		}
		udp_send_data(ttcp);
	} else {
		udp_recv(ttcp->upcb, udp_recv_cb, ttcp);
	}

	return 0;
}
コード例 #2
0
ファイル: control_ipv6.c プロジェクト: z4nder/inga-ps-control
PROCESS_THREAD(default_app_process, ev, data) {

    uip_ipaddr_t ipaddr;
    
    PROCESS_BEGIN();
    
    set_connection_address(&ipaddr);
    
    /* new connection with remote host */
    client_conn = udp_new(&ipaddr, UIP_HTONS(3002), NULL);
    udp_bind(client_conn, UIP_HTONS(3003));

    PRINTF("Created a connection with the server ");
    PRINT6ADDR(&client_conn->ripaddr);
    PRINTF(" local/remote port %u/%u\n",
    UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

    SENSORS_ACTIVATE(acc_sensor);
    etimer_set(&timer, CLOCK_SECOND * 0.05);
    
    printf("Node configured as ");
    print_control();
    printf("\n");
    
    while (1) { 
        PROCESS_YIELD();
        if ( etimer_expired(&timer) ) {
            etimer_set(&timer, CLOCK_SECOND*0.05);
            x = acc_sensor.value(ACC_Y_RAW);
            if (x > 380) { 
                //send
                udp_send_data();
                etimer_set(&timer, CLOCK_SECOND*0.3);
                count++;
            } 
        }
    }
    PROCESS_END();
}
コード例 #3
0
/**
 * Only used in UDP mode. Scheduled after data has been sent in udp_send_data()
 * if we have more data to send.
 */
static void udp_timeout_cb(void *ctx)
{
        struct ttcp* ttcp = ctx;
        udp_send_data(ttcp);
}
コード例 #4
0
ファイル: web-sensor.c プロジェクト: notank/contiki
/*-------------------------------------------------------------------------------------------*/
PROCESS_THREAD(test_process, ev, data)
{
	           user.userID=1;
	           uip_ipaddr_t ipaddr;

	           ds2401_init();
	          int ii;
	           for (ii = 0; ii < 7; ii++) {
	             printf("%02x:", ds2401_id[ii]);
	           }
	           printf("%02x\n", ds2401_id[7]);
				static struct etimer timer;

				struct udp_tx *udp_tx_info = (udp_tx*) malloc(sizeof(udp_tx));

				PROCESS_BEGIN();

			   uip_ip6addr(&ipaddr, ipv6_addr[0], ipv6_addr[1],ipv6_addr[2],ipv6_addr[3],
						                          ipv6_addr[4],ipv6_addr[5],ipv6_addr[6],ipv6_addr[7]);

			   server_conn = udp_new(NULL,UIP_HTONS(0), NULL);
			   server_conn2 = udp_new(&ipaddr,UIP_HTONS(3007), NULL);

			   udp_bind(server_conn, uip_htons(3001));
			   udp_bind(server_conn2, uip_htons(3005));
				memset(udp_tx_info, 0, sizeof(udp_tx));

			   while(1)
				{
/*--------------------------------------------------------------------------------------------*/
				   if(Sendonce_flag == 0){
					   etimer_set(&timer, CLOCK_SECOND*5);
					   PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
					   udp_send_register(udp_tx_info);
					 //  udp_send_data(udp_tx_info);
					   PRINTF("udp_tx_info->len = %d\r\n",udp_tx_info->len);
					   server_conn2->rport=uip_htons(3007);
					   uip_udp_packet_send(server_conn2, &udp_tx_info->buf[0], udp_tx_info->len);
					   server_conn2->rport=0;
					   Sendonce_flag = 1;
					  			printf("Send once!\n");
					  			leds_toggle(LEDS_GREEN);
				   }
  /*--------------------------------------------------------------------------------------------*/
			       if(Sample_begin_flag==1)
			       {
			    	   etimer_set(&timer, CLOCK_SECOND*Sample_Interval);
			    	   printf("Sample_Interval:%d\n",Sample_Interval);
			    	  do{
			                   PROCESS_WAIT_EVENT();
			             	 if (ev == PROCESS_EVENT_TIMER)
			             	 {
			             		 printf("data send lym 001\n");
			             		udp_send_data(udp_tx_info);
			             	    PRINTF("udp_tx_info->len = %d\r\n",udp_tx_info->len);
			             	    uip_udp_packet_send(server_conn2, &udp_tx_info->buf[0], udp_tx_info->len);
			             		 printf("wait\n");
			             		 etimer_reset(&timer);
			             		leds_toggle(LEDS_GREEN);
			             	 }
			             	 else if(ev == tcpip_event)
			             	 {
			             		 tcpip_handler(udp_tx_info);
			             	 }
			    	     }
			    	  while(Sample_begin_flag==1);
			       }
/*--------------------------------------------------------------------------------------------*/
				   PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
				   tcpip_handler(udp_tx_info);
			    }
			    PROCESS_END();
}