コード例 #1
0
ファイル: rpl-timers.c プロジェクト: vuducdat/contiki-multi
/*---------------------------------------------------------------------------*/
void
rpl_schedule_dao(rpl_instance_t *instance)
{
  clock_time_t expiration_time;

  expiration_time = etimer_expiration_time(&instance->dao_timer.etimer);

  if(!etimer_expired(&instance->dao_timer.etimer)) {
    PRINTF("RPL: DAO timer already scheduled\n");
  } else {
    expiration_time = RPL_DAO_LATENCY / 2 +
      (random_rand() % (RPL_DAO_LATENCY));
    PRINTF("RPL: Scheduling DAO timer %u ticks in the future\n",
           (unsigned)expiration_time);
    ctimer_set(&instance->dao_timer, expiration_time,
               handle_dao_timer, instance);
  }
}
コード例 #2
0
ファイル: hello-world.c プロジェクト: andrewgrex/MethHardware
PROCESS_THREAD(hello_world_process, ev, data)
{
  static struct etimer et;
  PROCESS_BEGIN();

	while (1) {
		printf("Hello world\n");
		
		FLASH_LED(LEDS_BLUE);
    FLASH_LED(LEDS_GREEN);

    etimer_set(&et, 3*CLOCK_SECOND);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

	}
  
  PROCESS_END();
}
コード例 #3
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(timesync_master_process, ev, data)
{
    static struct etimer et;

    PROCESS_BEGIN();

    timesynch_set_authority_level(0);

    PT_INIT(&pt);

    // wait until network is synchronized
    etimer_set(&et, SYNCH_PERIOD);
    PROCESS_WAIT_UNTIL(etimer_expired(&et));

    rtimer_set(&rt, timesynch_time_to_rtimer(0), 0, (rtimer_callback_t)rtimer_task, NULL);

    PROCESS_END();
}
コード例 #4
0
ファイル: say-hi.c プロジェクト: beaucha3/contikiV
PROCESS_THREAD(shell_round_robin_start_process, ev, data)
{
	PROCESS_BEGIN();

	if (rimeaddr_node_addr.u8[0] == FIRST_NODE)
	{ 
		static struct etimer etimer0;
		uint8_t next_node = FIRST_NODE + 1;
		
		etimer_set(&etimer0, CLOCK_SECOND/FREQUENCY);
		leds_on(LEDS_ALL);
		PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&etimer0));
		transmit_unicast("Hello", next_node);
		leds_off(LEDS_ALL);
	}
	
	PROCESS_END();
}
コード例 #5
0
ファイル: phidgetstest.c プロジェクト: pingo/WIPS
PROCESS_THREAD(test_phidgets_process, ev, data)
{
	static struct etimer et;

	static int values[SAMPLES]; /* Buffer of SAMPLES latest values. */
	static int sample = 0;      /* Index of current sample in buffer. */

	static int i, v;
	static long avg;

	PROCESS_BEGIN();
	SENSORS_ACTIVATE(phidgets);

	for (;;)
	{
		etimer_set(&et, CLOCK_SECOND / 2);
		PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

		/*
		 * In the code below implements a Simple Moving Average filter.
		 */

		sample = (sample + 1) % SAMPLES; /* Wrap around in buffer. */

		v = phidgets.value(PHIDGET3V_1); /* Get new value from sensor. */
		values[sample] = v;

		/* Calculate average of the SAMPLES latest values. */
		avg = 0;
		for (i = 0; i < SAMPLES; i++)
			avg += values[i];
		avg /= SAMPLES;

		/* See if our newest value is off by more than DELTA from the average */
		if (abs(v - avg) > DELTA)
			leds_on(LEDS_RED);
		else
			leds_off(LEDS_RED);

		printf("v: %4d, avg: %4ld\n", v, avg);
	}

	PROCESS_END();
}
コード例 #6
0
ファイル: rest-engine.c プロジェクト: CurieBSP/zephyr
/*-----------------------------------------------------------------------------------*/
PROCESS_THREAD(rest_engine_process, ev, data, buf)
{
  PROCESS_BEGIN();

  /* pause to let REST server finish adding resources. */
  PROCESS_PAUSE();

  /* initialize the PERIODIC_RESOURCE timers, which will be handled by this process. */
  periodic_resource_t *periodic_resource = NULL;

  for(periodic_resource =
        (periodic_resource_t *)list_head(restful_periodic_services);
      periodic_resource; periodic_resource = periodic_resource->next) {
    if(periodic_resource->periodic_handler && periodic_resource->period) {
      PRINTF("Periodic: Set timer for /%s to %lu\n",
             periodic_resource->resource->url, periodic_resource->period);
      etimer_set(&periodic_resource->periodic_timer,
                 periodic_resource->period, &rest_engine_process);
    }
  }
  while(1) {
    PROCESS_WAIT_EVENT();

    if(ev == PROCESS_EVENT_TIMER) {
      for(periodic_resource =
            (periodic_resource_t *)list_head(restful_periodic_services);
          periodic_resource; periodic_resource = periodic_resource->next) {
        if(periodic_resource->period
           && etimer_expired(&periodic_resource->periodic_timer)) {

          PRINTF("Periodic: etimer expired for /%s (period: %lu)\n",
                 periodic_resource->resource->url, periodic_resource->period);

          /* Call the periodic_handler function, which was checked during adding to list. */
          (periodic_resource->periodic_handler)();

          etimer_reset(&periodic_resource->periodic_timer);
        }
      }
    }
  }

  PROCESS_END();
}
コード例 #7
0
PROCESS_THREAD(blink_process, ev, data) {
  PROCESS_POLLHANDLER();
  PROCESS_EXITHANDLER();
  PROCESS_BEGIN();
  while(1) {
    leds_toggle(LEDS_RED);
    if(adc > 0) {
      time = (CLOCK_SECOND*adc)/1024;
    } else {
      time = CLOCK_SECOND/64;
    }
    if(time == 0) {
      time = 1;
    }
    etimer_set(&etb, time);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&etb));
  }
  PROCESS_END();
}
コード例 #8
0
ファイル: snd_broadcast_UDP.c プロジェクト: PP90/ANAWS
PROCESS_THREAD(snd_process, ev, data){
	static struct etimer et;
	static struct simple_udp_connection broadcast_connection;
	static uip_ipaddr_t mcast_allnodes_address;

PROCESS_BEGIN();
	etimer_set(&et, CLOCK_SECOND*HOW_MUCH_TIME);
	set_address();
	simple_udp_register(&broadcast_connection, UDP_PORT, NULL,UDP_PORT, 		callback_function);
	mcast_allnodes_address=get_multicast_all_nodes_addr();

	while(1){//A broadcast message is sent periodically
		PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
		simple_udp_sendto(&broadcast_connection, "Hello", 5, (const 		uip_ipaddr_t*)&mcast_allnodes_address);
		etimer_reset(&et);
		}
	
PROCESS_END();
}
コード例 #9
0
ファイル: simple-udp-ping.c プロジェクト: Cancan79/mist
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(simple_udp_ping_process, ev, data)
{
  static struct etimer et;
  int i;

  PROCESS_BEGIN();

  for(i = 0; i < MAX_DESTINATIONS; i++) {
    pingconns[i].in_use = 0;
  }

  simple_udp_register(&ping_connection, UDP_PORT, NULL, UDP_PORT, receiver);

  while(1) {
#define PERIOD (3*CLOCK_SECOND)
    etimer_set(&et, PERIOD);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

    for(i = 0; i < MAX_DESTINATIONS; i++) {
      if (pingconns[i].in_use && pingconns[i].waiting) {
        struct pingconn_t* pingconn = &pingconns[i];

        pingconn->waiting = 0;

        /* Send ping */
#if DEBUG
        printf("Sending ping to ");
        uip_debug_ipaddr_print(&pingconn->host);
        printf("\n");
#endif
        simple_udp_sendto(&ping_connection, "ping", DATALEN, &pingconn->host);
        pingconn->echo_time = RTIMER_NOW();
        pingconn->echo_time2 = clock_time();
        pingconn->sent = 1;
        pingconn->replied = 0;
        break;
      }
    }

  }

  PROCESS_END();
}
コード例 #10
0
ファイル: tool-sample-stats.c プロジェクト: beaucha3/contikiV
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_sample_stats_process, ev, data) {

	static uint16_t data_sam[NUM_SAM]; 
	uint16_t sum = 0;
	uint16_t sqsum = 0;
	static struct etimer etimer;

	PROCESS_BEGIN();

	// Gather NUM_SAM samples over 1 second of time
	sensor_init();
	printf("Gathering data... ");
	for(counter = 0;counter < NUM_SAM;counter++) {
		// Get data for no change analysis.
		etimer_set(&etimer, CLOCK_SECOND / NUM_SAM);
		PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
		data_sam[counter] = sensor_read();
	}
	printf("done!\n");
	sensor_uinit();

	// Sum the no change data
	sum = 0;
	for(counter = 0;counter < NUM_SAM;counter++) {
		sum = sum + data_sam[counter];
	}
	sample_mean = 0;
	printf("sum = %d\n",sum);
	sample_mean = sum/NUM_SAM;
	printf("sample_mean = %d\n",sample_mean);

	// Caclulate sample_std_dev
	sqsum = 0;
	for(counter = 0;counter < NUM_SAM;counter++) {
		sqsum = sqsum + mypow2(abs_sub(data_sam[counter], sample_mean));
	}
	sample_std_dev = 0;
	sample_std_dev = sqsum/NUM_SAM;
	sample_std_dev = mysqrt(sample_std_dev);
	printf("std_dev = %d\n",sample_std_dev);

	PROCESS_END();
}
コード例 #11
0
ファイル: trickle-library.c プロジェクト: 13416795/contiki
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(trickle_protocol_process, ev, data)
{
  PROCESS_BEGIN();

  PRINTF("Trickle protocol started\n");

  uip_create_linklocal_allnodes_mcast(&ipaddr); /* Store for later */

  trickle_conn = udp_new(NULL, UIP_HTONS(TRICKLE_PROTO_PORT), NULL);
  udp_bind(trickle_conn, UIP_HTONS(TRICKLE_PROTO_PORT));

  PRINTF("Connection: local/remote port %u/%u\n",
         UIP_HTONS(trickle_conn->lport), UIP_HTONS(trickle_conn->rport));

  token = 0;

  trickle_timer_config(&tt, IMIN, IMAX, REDUNDANCY_CONST);
  trickle_timer_set(&tt, trickle_tx, &tt);
  /*
   * At this point trickle is started and is running the first interval. All
   * nodes 'agree' that token == 0. This will change when one of them randomly
   * decides to generate a new one
   */
  etimer_set(&et, NEW_TOKEN_INTERVAL);

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    } else if(etimer_expired(&et)) {
      /* Periodically (and randomly) generate a new token. This will trigger
       * a trickle inconsistency */
      if((random_rand() % NEW_TOKEN_PROB) == 0) {
        token++;
        PRINTF("At %lu: Generating a new token 0x%02x\n",
               (unsigned long)clock_time(), token);
        trickle_timer_reset_event(&tt);
      }
      etimer_set(&et, NEW_TOKEN_INTERVAL);
    }
  }
  PROCESS_END();
}
コード例 #12
0
PROCESS_THREAD(sender_process, ev, data)
{
    
    static struct etimer periodic;
    static struct ctimer backoff_timer;

    PROCESS_BEGIN();

//    PROCESS_PAUSE();

    set_global_address();
    
    PRINTF("The sender process begins.\n");
    
    print_local_addresses();
    /* new connection with remote host */
    sender_conn = udp_new(NULL, UIP_HTONS(UDP_SINK_PORT), NULL);
    if(sender_conn == NULL)
    {
        PRINTF("No UDP connection available, exiting the process!\n");
        PROCESS_EXIT();
    }
    udp_bind(sender_conn, UIP_HTONS(UDP_SENDER_PORT));
    PRINTF("Created a connection with the server ");
    PRINT6ADDR(&sender_conn->ripaddr);
    PRINTF(" local/remote port %u/%u\n", UIP_HTONS(sender_conn->lport),
                UIP_HTONS(sender_conn->rport));

    etimer_set(&periodic, SEND_INTERVAL * CLOCK_SECOND);
    while(1) {
        PROCESS_YIELD();
        if(ev == tcpip_event)
          tcpip_handler();

        if(etimer_expired(&periodic))
        {
            etimer_reset(&periodic);
            ctimer_set(&backoff_timer, RANDWAIT * CLOCK_SECOND, send_packet, NULL);
        }
    }

    PROCESS_END();
}
コード例 #13
0
ファイル: cc2538seed.c プロジェクト: jamella/MyRepository
PROCESS_THREAD(prng_test_process, ev, data)
{
    static unsigned char seed[SEEDLEN];

    PROCESS_BEGIN();

    lpm_set_max_pm(LPM_PM0);

    etimer_set(&et, WAIT_TIME);
    for (;;) {
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
        etimer_restart(&et);
        leds_on(LEDS_ALL);
        RfRnd(seed, sizeof(seed));
        leds_off(LEDS_ALL);
    }

    PROCESS_END();
}
コード例 #14
0
/*---------------------------------------------------------------------------*/
static char
counter_pthread(void *ptr)
{
  struct data *f = ptr;

  PT_BEGIN(&f->pt);
  f->counter = 0;
  etimer_set(&f->et, CLOCK_SECOND);

  printf("Start thread\r\n");
  while(1) {
      PT_WAIT_UNTIL(&f->pt,f->active && etimer_expired(&f->et));
      printf("Counter %d\r\n",f->counter++);
      etimer_reset(&f->et);
  }
  printf("End thread\r\n");

  PT_END(&f->pt);
}
コード例 #15
0
ファイル: sehpacket.c プロジェクト: kevinxusz/monjolo
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(ipv6_process, ev, data)
{


  PROCESS_BEGIN();

  // Set the local address
  uip_ip6addr(&my_addr, 0, 0, 0, 0, 0, 0, 0, 0);
  uip_ds6_set_addr_iid(&my_addr, &uip_lladdr);
  uip_ds6_addr_add(&my_addr, 0, ADDR_MANUAL);

  // Setup the destination address
  uiplib_ipaddrconv(RECEIVER_ADDR, &dest_addr);

  // Add a "neighbor" for our custom route
  // Setup the default broadcast route
  uiplib_ipaddrconv(ADDR_ALL_ROUTERS, &bcast_ipaddr);
  uip_ds6_nbr_add(&bcast_ipaddr, &bcast_lladdr, 0, NBR_REACHABLE);
  uip_ds6_route_add(&dest_addr, 128, &bcast_ipaddr);

  // Setup a udp "connection"
  client_conn = udp_new(&dest_addr, UIP_HTONS(RECEIVER_PORT), NULL);
  if (client_conn == NULL) {
    // Too many udp connections
    // not sure how to exit...stupid contiki
  }
  udp_bind(client_conn, UIP_HTONS(3001));

  etimer_set(&periodic_timer, 10*CLOCK_SECOND);

  while(1) {
    PROCESS_YIELD();

    if (etimer_expired(&periodic_timer)) {
      send_handler(ev, data);
      etimer_restart(&periodic_timer);
    } else if (ev == tcpip_event) {
      recv_handler();
    }
  }

  PROCESS_END();
}
コード例 #16
0
ファイル: udp-client.c プロジェクト: anhquang/contiki
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer et;
  uip_ipaddr_t ipaddr;

  PROCESS_BEGIN();
  PRINTF("UDP client process started\n");

#if UIP_CONF_ROUTER
  set_global_address();
#endif

  print_local_addresses();

  set_connection_address(&ipaddr);

  /* new connection with remote host */
  client_conn = udp_new(&ipaddr, UIP_HTONS(3000), NULL);
  udp_bind(client_conn, UIP_HTONS(3001));

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

  etimer_set(&et, SEND_INTERVAL);
  while(1)
  {
    PROCESS_YIELD();
    if(etimer_expired(&et))
    {
      timeout_handler();
      etimer_restart(&et);
    }
    else if(ev == tcpip_event)
    {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
コード例 #17
0
ファイル: main_hrm.c プロジェクト: Echoskope/KreyosFirmware
//----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////
// main
//
// main function
//
// Configures device simulator and HRM TX channel.
//
// \return: This function does not return.
////////////////////////////////////////////////////////////////////////////
PROCESS_THREAD(ant_process, ev, data)
{
  static struct etimer timer;
  static UCHAR* pucRxBuffer;

  PROCESS_BEGIN();

  // wait about 500ms for ant module to start
  etimer_set(&timer, CLOCK_SECOND/2);
  PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
  ANT_Reset();

  // Main loop
  while(TRUE)
  {
    pucRxBuffer = ANTInterface_Transaction();                // Check if any data has been recieved from serial

    if(pucRxBuffer)
    {
      ANTPLUS_EVENT_RETURN stEventStruct;
      if (mode == MODE_HRM)
      {
        HRMRX_ChannelEvent(pucRxBuffer, &stEventStruct);
        ProcessANTHRMRXEvents(&stEventStruct);
      }
      else if (mode == MODE_CBSC)
      {
        CBSCRX_ChannelEvent(pucRxBuffer, &stEventStruct);
        ProcessANTCBSCRXEvents(&stEventStruct);
      }

      ProcessAntEvents(pucRxBuffer);
      ANTInterface_Complete();                              // Release the serial buffer

      continue;
    }

    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
  }

  PROCESS_END();
}
コード例 #18
0
ファイル: server.c プロジェクト: Cremesis/IoT
PROCESS_THREAD(udp_server_process, ev, data)
{

  PROCESS_BEGIN();
  static uip_ipaddr_t ipaddr;
  rpl_dag_t *dag;
  int i;
  uint8_t state;
  static struct etimer timer;
  static struct simple_udp_connection connection;
  static int packet = 0;

  uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
  uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr);
  uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); 

  //uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
  //dag = rpl_set_root(RPL_DEFAULT_INSTANCE, (uip_ip6addr_t*) &ipaddr);
  //rpl_set_prefix(dag, &ipaddr, 64);

  simple_udp_register(&connection, UDP_PORT-1, NULL, UDP_PORT, receiver);

  printf("IPv6 addresses: ");
  for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
    state = uip_ds6_if.addr_list[i].state;
    if(uip_ds6_if.addr_list[i].isused &&
       (state == ADDR_TENTATIVE 
       || state == ADDR_PREFERRED)) {
            uip_debug_ipaddr_print(
               &uip_ds6_if.addr_list[i].ipaddr);
            printf("\n");
    }
  }
  printf("UDP server started\n");
  etimer_set(&timer, CLOCK_SECOND >> 1);
  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
    etimer_restart(&timer);
    leds_toggle(LEDS_GREEN);
  }
  PROCESS_END();
}
コード例 #19
0
ファイル: test.c プロジェクト: atiselsts/contiki
/* -------------------------------------------------------------------- */
PROCESS_THREAD(test_process, ev, data)
{
  static struct etimer timer;
  static struct packet_s packet;

  PROCESS_BEGIN();

  rime_sniffer_add(&print_sniffer);

  if(node_id == 1) {
    printf("Receiving...\n");
    /* receiver */
    for(;;) {
      PROCESS_YIELD();
    }
  } else {
    printf("Sending...\n");
    /* sender */
    etimer_set(&timer, CLOCK_SECOND);
    for(;;) {
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));

      leds_on(LEDS_ALL);

      /* send to radio */
      NETSTACK_RADIO.send(&packet, sizeof(packet));

      packet.number++;
      if(packet.number >= 100) {
        packet.number = 0;
        etimer_set(&timer, SEND_PERIOD * 10);
        printf("100 packets sent\n");
      } else {
        etimer_set(&timer, SEND_PERIOD);
      }

      leds_off(LEDS_ALL);
    }
  }

  PROCESS_END();
}
コード例 #20
0
ファイル: sd-test.c プロジェクト: AlphaBetaPhi/contiki
PROCESS_THREAD(sd_test, event, data)
{
  static unsigned long iter;
  static unsigned long offset;
  char buf[BUF_SIZE];
  static struct etimer et;
  int r, buflen;

  PROCESS_BEGIN();

  etimer_set(&et, CLOCK_SECOND / 16);

  offset = 0;
  for(iter = 1;; iter++) {
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));

    memset(buf, 0, sizeof(buf));
    buflen = sprintf(buf, "(%ld) Testing the SD card (%ld)", iter, iter);

    if((iter & 7) == 0) {
      offset = random_rand() & 0xffff;
    } else {
      offset += random_rand() & 0xff;
    }

    r = sd_write(offset, buf, buflen + 1);
    if(r > 0) {
      memset(buf, 0, sizeof(buf));
      r = sd_read(offset, buf, buflen + 1);
      if(r > 0) {
        printf("read %s (offset %lu)\n", buf, offset);
      } else {
        printf("read error: %d (%s)\n", r, sd_error_string(r));
      }
    } else {
      printf("write error: %d (%s)\n", r, sd_error_string(r));
    }
    etimer_restart(&et);
  }

  PROCESS_END();
}
コード例 #21
0
ファイル: native-rdc.c プロジェクト: Scypho/6lbr
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(native_rdc_process, ev, data)
{
    PROCESS_BEGIN();

    static struct etimer et;
    do
    {
        slip_reboot();
        while(!radio_mac_addr_ready) {
            etimer_set(&et, CLOCK_SECOND);
            slip_request_mac();
            PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
        }
        //Set radio channel
        slip_set_rf_channel(nvm_data.channel);
        radio_ready = 1;
        PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
    } while(1);
    PROCESS_END();
}
コード例 #22
0
static void tls_handler(process_event_t ev, process_data_t data){

	if (ev == tls_event){
		if (tls_connected()){
			//raven_lcd_show_text("conn");
			connection = (Connection*)data;
			//TLS_Write(connection, "1", 1);
			//etimer_set(&et, CLOCK_CONF_SECOND);
		} /*else if (tls_newdata()){
			tls_appdata[5] = 0;
			TLS_Write(connection, "1", 1);
		}*/
	} else if (ev == PROCESS_EVENT_TIMER){
		if (etimer_expired(&et)){
			tls_write(connection, "1",1);
			etimer_set(&et, CLOCK_CONF_SECOND);
		}
	}

}
コード例 #23
0
ファイル: udp-client.c プロジェクト: iris-yu/6Lo-ND-contiki
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer periodic;
  static struct ctimer backoff_timer;

  PROCESS_BEGIN();
  PROCESS_PAUSE();

  powertrace_start(CLOCK_SECOND * 2);
 
  PRINTF("UDP client process started\n");
 
  /*create new connection with remote server*/
  client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL);
  if(client_conn == NULL) {
    PRINTF("No UDP connection available, exiting the process!\n");
    PROCESS_EXIT();
  }

  udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT));

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

   etimer_set(&periodic, SEND_INTERVAL);
   while(1) {
	PROCESS_YIELD();
        if(ev == tcpip_event) {
           tcpip_handler();
         }
       
        if(etimer_expired(&periodic)){
	   etimer_reset(&periodic);
           ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL);
         }
   }
  
  PROCESS_END();
}
コード例 #24
0
ファイル: test-tsl2563.c プロジェクト: 13416795/contiki
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(remote_tsl2563_process, ev, data)
{
  PROCESS_BEGIN();
  static uint16_t light;

  /* Use Contiki's sensor macro to enable the sensor */
  SENSORS_ACTIVATE(tsl2563);

  /* Default integration time is 402ms with 1x gain, use the below call to
   * change the gain and timming, see tsl2563.h for more options
   */
  /* tsl2563.configure(TSL2563_TIMMING_CFG, TSL2563_G16X_402MS); */

  /* Register the interrupt handler */
  TSL2563_REGISTER_INT(light_interrupt_callback);

  /* Enable the interrupt source for values over the threshold.  The sensor
   * compares against the value of CH0, one way to find out the required
   * threshold for a given lux quantity is to enable the DEBUG flag and see
   * the CH0 value for a given measurement.  The other is to reverse the
   * calculations done in the calculate_lux() function.  The below value roughly
   * represents a 2500 lux threshold, same as pointing a flashlight directly
   */
  tsl2563.configure(TSL2563_INT_OVER, 0x15B8);

  /* And periodically poll the sensor */

  while(1) {
    etimer_set(&et, SENSOR_READ_INTERVAL);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
    light = tsl2563.value(TSL2563_VAL_READ);
    if(light != TSL2563_ERROR) {
      printf("Light = %u\n", (uint16_t)light);
    } else {
      printf("Error, enable the DEBUG flag in the tsl2563 driver for info, ");
      printf("or check if the sensor is properly connected\n");
      PROCESS_EXIT();
    }
  }
  PROCESS_END();
}
コード例 #25
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(UDP_ping_process, ev, data)
{
    static uip_ipaddr_t serveraddr;
    static struct uip_udp_conn *udpconn;
    static struct etimer et;

    PROCESS_BEGIN();

    /* Create the remote connection */
    uiplib_ipaddrconv(remote, &serveraddr);
    udpconn = udp_new(&serveraddr, uip_htons(remote_port), NULL);
    while (1)
    {
        /* Send a packet every INTERVAL */
        etimer_set(&et, INTERVAL);
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
        uip_udp_packet_send(udpconn, "Hello world !!!", 16);
    }

    PROCESS_END();
}
コード例 #26
0
ファイル: powertrace.c プロジェクト: pvhau/contiki-ext
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(powertrace_process, ev, data)
{
  static struct etimer periodic;
  clock_time_t *period;
  PROCESS_BEGIN();

  period = data;

  if(period == NULL) {
    PROCESS_EXIT();
  }
  etimer_set(&periodic, *period);

  while(1) {
    PROCESS_WAIT_UNTIL(etimer_expired(&periodic));
    etimer_reset(&periodic);
    powertrace_print("");
  }

  PROCESS_END();
}
コード例 #27
0
ファイル: consumptionrate.c プロジェクト: ischweizer/C-SDF
/**
 * updates periodically energy harvested by solar panel
 */
PROCESS_THREAD(consumptionrate_solarpanel_process, ev, data) {
	PROCESS_BEGIN();

	// timer for updating  solar calculation periodically
	static struct etimer timer_update_solar;
	etimer_set(&timer_update_solar, CLOCK_SECOND * 60 / SPEEDMULTIPLIER);

	// update loop
	while(1) {
		PROCESS_WAIT_UNTIL(etimer_expired(&timer_update_solar));

		// calculate energy flow & save
		fpint fp_capacity = solarpanel_capacity(60);
		fp_solar_energy = fpint_add(fp_solar_energy, fp_capacity);

		// restart timer
		etimer_reset(&timer_update_solar);
	}

	PROCESS_END();
}
コード例 #28
0
ファイル: test-msg.c プロジェクト: kyanhNG/casan-contiki
PROCESS_THREAD(test, ev, data)
{
	static struct etimer et;
	PROCESS_BEGIN();

    printf("rimeaddr_node_addr = [%u, %u]\n", rimeaddr_node_addr.u8[0],
                         rimeaddr_node_addr.u8[1]);

    while(1) {     
    	test_msg();

    	printf("\n");
    	printf("*************************************************************************");
    	printf("\n");
        etimer_set(&et,5*CLOCK_SECOND); 
        PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
    }

    PROCESS_END();

}
コード例 #29
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(example_mlst_node_process, ev, data)
{
	static struct etimer et;

	PROCESS_BEGIN();

	//Initialize the mlst-network. Has to be done to open ports, etc.
	mlst_init();	
	eamlst_set_energy_state(ENERGY_STATE);

	while(1) {
		mlst_print_state();
		rsunicast_print_state();
		etimer_set(&et, CLOCK_SECOND * 4 * getRandomFloat(0.5,1.0));
		//uint8_t data[7];
		//mlst_send(&data, sizeof(data));
		PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
	}

	PROCESS_END();
}
コード例 #30
0
ファイル: say-hi.c プロジェクト: beaucha3/contikiV
PROCESS_THREAD(shell_round_robin_blink_process, ev, data)
{
	PROCESS_BEGIN();

	static struct etimer etimer;
	static uint8_t my_node;
	my_node = rimeaddr_node_addr.u8[0];
	static uint8_t next_node;
	next_node = my_node + 1;
	
	if (my_node == LAST_NODE)
		next_node = FIRST_NODE;

	etimer_set(&etimer, CLOCK_SECOND/FREQUENCY);
	leds_on(LEDS_ALL);
	PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&etimer));
	transmit_unicast("Hello", next_node);
	leds_off(LEDS_ALL);
	
	PROCESS_END();
}